bends are arrays now
This commit is contained in:
parent
1224fddcec
commit
35d9a5a4f5
@ -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;
|
||||
|
8
wm.sql
8
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;
|
||||
|
Loading…
Reference in New Issue
Block a user