From 50a2ebfb1e98c702fe3cfed51056a547152586c6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Motiejus=20Jak=C5=A1tys?= Date: Thu, 18 Feb 2021 10:00:14 +0200 Subject: [PATCH] bends are arrays now --- IV/tests.sql | 9 +++++++-- IV/wm.sql | 8 +++++--- 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/IV/tests.sql b/IV/tests.sql index 36bee92..6cbad3b 100644 --- a/IV/tests.sql +++ b/IV/tests.sql @@ -18,7 +18,12 @@ insert into figures (name, way) values ('fig3-1', ST_GeomFromText('LINESTRING(0 insert into figures (name, way) values ('fig5', ST_GeomFromText('LINESTRING(0 39,19 52,27 77,26 104,41 115,49 115,65 103,65 75,53 45,63 15,91 0,91 0)')); do $$ +declare + bends geometry[]; begin - perform assert_equals(3::bigint, (select count(1) from detect_bends((select way from figures where name='fig3')))); - perform assert_equals(3::bigint, (select count(1) from detect_bends((select way from figures where name='fig3-1')))); + perform assert_equals(3, array_length(detect_bends((select way from figures where name='fig3')), 1)); + perform assert_equals(3, array_length(detect_bends((select way from figures where name='fig3-1')), 1)); + + select detect_bends((select way from figures where name='fig5')) into bends; + perform assert_equals(2, array_length(bends, 1)); end $$ language plpgsql; diff --git a/IV/wm.sql b/IV/wm.sql index 5cd9bf8..92f8be1 100644 --- a/IV/wm.sql +++ b/IV/wm.sql @@ -1,14 +1,16 @@ \set ON_ERROR_STOP on SET plpgsql.extra_errors TO 'all'; +drop function if exists detect_bends; -- detect_bends detects bends using the inflection angles. It does not do corrections. -create or replace function detect_bends(line geometry) returns table(bend geometry) as $$ +create or replace function detect_bends(line geometry, OUT bends geometry[]) as $$ declare pi real; p geometry; p1 geometry; p2 geometry; p3 geometry; + bend geometry; prev_sign int4; cur_sign int4; begin @@ -27,7 +29,7 @@ begin if prev_sign + cur_sign = 0 then if bend is not null then - return next; + bends = bends || bend; end if; bend = st_makeline(p3, p2); end if; @@ -38,7 +40,7 @@ begin -- to avoid that, return the last bend if the last accumulation has >3 -- vertices. if (select count(1) from ((select st_dumppoints(bend) as a)) b) >= 3 then - return next; + bends = bends || bend; end if; end $$ language plpgsql;