From 1607bfe225b4eefa0e1eb80491191cfd65d1899d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Motiejus=20Jak=C5=A1tys?= Date: Mon, 5 Apr 2021 16:18:33 +0300 Subject: [PATCH] fix bug in tests: detect_bends() works only on lines --- IV/tests.sql | 25 +++++-------------------- IV/wm.sql | 21 +++++++++++++-------- 2 files changed, 18 insertions(+), 28 deletions(-) diff --git a/IV/tests.sql b/IV/tests.sql index fac49bb..0900304 100644 --- a/IV/tests.sql +++ b/IV/tests.sql @@ -25,10 +25,10 @@ insert into figures (name, way) values ('fig5',ST_GeomFromText('LINESTRING(0 39, insert into figures (name, way) values ('fig6',ST_GeomFromText('LINESTRING(84 47,91 59,114 64,122 80,116 92,110 93,106 106,117 118,136 107,135 76,120 45,125 39,141 39,147 32)')); insert into figures (name, way) values ('fig6-rev',ST_Reverse(ST_Translate((select way from figures where name='fig6'), 60, 0))); insert into figures (name, way) values ('fig6-combi', - ST_LineMerge(ST_Union( + ST_Union( ST_Translate((select way from figures where name='fig6'), 0, 90), ST_Translate((select way from figures where name='fig6'), 80, 90) - )) + ) ); insert into figures (name, way) values ('inflection-1',ST_GeomFromText('LINESTRING(110 24,114 20,133 20,145 15,145 0,136 5,123 7,114 7,111 2)')); insert into figures (name, way) values ('multi-island',ST_GeomFromText('MULTILINESTRING((-15 10,-10 10,-5 11,0 11,5 11,10 10,11 9,13 10,15 9),(-5 11,-2 15,0 16,2 15,5 11))')); @@ -64,7 +64,7 @@ $$ language plpgsql; -- COMBINED drop table if exists demo_wm; create table demo_wm (name text, i bigint, way geometry); -insert into demo_wm (name, way) select name, ST_SimplifyWM(way, name) from figures where name='fig6-combi'; +insert into demo_wm (name, way) select name, ST_SimplifyWM(way, name) from figures; do $$ declare @@ -125,25 +125,10 @@ begin ) from (select unnest(vcrossings) way) a) ); - elems1 = array((select way from debug_wm where stage='cinflections' and name='fig6-combi' and gen=1)); - elems2 = (select ways from inflections where name='fig6-combi'); - - foreach elem in array elems1 loop - raise notice 'elem 1: %', st_astext(elem); - end loop; - - foreach elem in array elems2 loop - raise notice 'elem 2: %', st_astext(elem); - end loop; - - - select (self_crossing(elems1)).* into vcrossings, mutated; - --select (self_crossing(elems2)).* into vcrossings, mutated; - --select (self_crossing((select ways from inflections where name='fig6-combi'))).* into vcrossings, mutated; - --select (self_crossing(array((select way from debug_wm where stage='cinflections' and name='fig6-combi')))).* into vcrossings, mutated; + select (self_crossing(array((select way from debug_wm where stage='cinflections' and name='fig6-combi' and gen=1)))).* into vcrossings, mutated; perform assert_equals(true, mutated); perform assert_equals( - 'LINESTRING(84 137,91 149,114 154,120 135,125 129,141 129,147 122,164 137,171 149,194 154,200 135,205 129,221 129,227 122)', + 'MULTILINESTRING((84 137,91 149,114 154,120 135,125 129,141 129,147 122),(164 137,171 149,194 154,200 135,205 129,221 129,227 122))', (select st_astext( st_linemerge(st_union(way)) ) from (select unnest(vcrossings) way) a) diff --git a/IV/wm.sql b/IV/wm.sql index 7c16cb4..f4f2706 100644 --- a/IV/wm.sql +++ b/IV/wm.sql @@ -13,7 +13,13 @@ declare bend geometry; prev_sign int4; cur_sign int4; + l_type text; begin + --l_type = st_geometrytype(line); + --if l_type != 'ST_LineString' then + -- raise 'This function works with ST_LineString, got %', l_type; + --end if; + -- The last vertex is iterated over twice, because the algorithm uses 3 -- vertices to calculate the angle between them. -- @@ -323,7 +329,7 @@ $$ language plpgsql; drop function if exists ST_SimplifyWM; create function ST_SimplifyWM(geom geometry, dbgname text default null) returns geometry as $$ declare - dbg_stage integer; + stagenum integer; i integer; line geometry; lines geometry[]; @@ -342,13 +348,13 @@ begin for i in 1..array_length(lines, 1) loop mutated = true; - dbg_stage = 1; + stagenum = 1; while mutated loop if dbgname is not null then insert into debug_wm (stage, name, gen, nbend, way) values( 'afigures', dbgname, - dbg_stage, + stagenum, i, lines[i] ); @@ -360,20 +366,19 @@ begin insert into debug_wm(stage, name, gen, nbend, way) values( 'bbends', dbgname, - dbg_stage, + stagenum, generate_subscripts(bends, 1), unnest(bends) ); end if; - raise notice 'before inflections: %', dbg_geomsummary(bends); bends = fix_gentle_inflections(bends); if dbgname is not null then insert into debug_wm(stage, name, gen, nbend, way) values( 'cinflections', dbgname, - dbg_stage, + stagenum, generate_subscripts(bends, 1), unnest(bends) ); @@ -385,7 +390,7 @@ begin insert into debug_wm(stage, name, gen, nbend, way) values( 'dcrossings', dbgname, - dbg_stage, + stagenum, generate_subscripts(bends, 1), unnest(bends) ); @@ -393,7 +398,7 @@ begin if mutated then lines[i] = st_linemerge(st_union(bends)); - dbg_stage = dbg_stage + 1; + stagenum = stagenum + 1; continue; end if;