From 7937aece8b97a84099acaed3051e7e3594ebfe6d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Motiejus=20Jak=C5=A1tys?= Date: Thu, 8 Apr 2021 15:19:36 +0300 Subject: [PATCH] convert to jsonb --- IV/tests-integration.sql | 2 +- IV/tests.sql | 2 +- IV/wm.sql | 19 ++++++++++++++++++- 3 files changed, 20 insertions(+), 3 deletions(-) diff --git a/IV/tests-integration.sql b/IV/tests-integration.sql index 9f7a5ae..cde2764 100644 --- a/IV/tests-integration.sql +++ b/IV/tests-integration.sql @@ -1,7 +1,7 @@ \i wm.sql drop table if exists wm_debug; -create table wm_debug(stage text, name text, gen bigint, nbend bigint, way geometry, props json); +create table wm_debug(stage text, name text, gen bigint, nbend bigint, way geometry, props jsonb); drop table if exists wm_demo; create table wm_demo (name text, i bigint, way geometry); diff --git a/IV/tests.sql b/IV/tests.sql index 253e6ca..4606c63 100644 --- a/IV/tests.sql +++ b/IV/tests.sql @@ -24,7 +24,7 @@ $$ language plpgsql; -- to preview this somewhat conveniently in QGIS: -- stage || '_' || name || ' gen:' || coalesce(gen, 'Ø') || ' nbend:' || lpad(nbend, 2, '0') drop table if exists wm_debug; -create table wm_debug(stage text, name text, gen bigint, nbend bigint, way geometry, props json); +create table wm_debug(stage text, name text, gen bigint, nbend bigint, way geometry, props jsonb); drop table if exists wm_figures; create table wm_figures (name text, way geometry); diff --git a/IV/wm.sql b/IV/wm.sql index 0ac38cd..6d9b875 100644 --- a/IV/wm.sql +++ b/IV/wm.sql @@ -314,7 +314,7 @@ begin dbgname, i, bend, - json_build_object( + jsonb_build_object( 'area', res.area, 'cmp', res.cmp, 'adjsize', res.adjsize, @@ -333,11 +333,14 @@ declare isolation_threshold constant real default 0.2; -- if neighbor's curvatures are within, it's isolated this real; res t_bend_attrs; + prev_i int4; i int4; begin i = 2; while i < array_length(bendattrs, 1)-1 loop + raise notice 'number of bends in %: %', dbgname, array_length(bendattrs, 1); this = bendattrs[i].curvature * isolation_threshold; + prev_i = i; if bendattrs[i-1].curvature < this and bendattrs[i+1].curvature < this then res = bendattrs[i]; res.isolated = true; @@ -346,6 +349,19 @@ begin else i = i + 1; end if; + + if dbgname is not null then + insert into wm_debug (stage, name, nbend, way, props) values( + 'fisolated_bends', + dbgname, + prev_i, + res.bend, + jsonb_build_object( + 'isolated', res.isolated + ) + ); + end if; + end loop; end $$ language plpgsql; @@ -433,6 +449,7 @@ begin -- self-crossing mutations are done, calculate bend properties bend_attrs = array((select bend_attrs(bends, dbgname))); + perform isolated_bends(bend_attrs, dbgname); end loop; end loop;