diff --git a/IV/tests.sql b/IV/tests.sql index 37e7e9d..26cd318 100644 --- a/IV/tests.sql +++ b/IV/tests.sql @@ -14,12 +14,15 @@ drop table if exists figures; create table figures (name text, way geometry); -- to "normalize" a new line: -- select st_astext(st_snaptogrid(st_transscale(geometry, 80, 130, .3, .3), 1)) from f; -insert into figures (name, way) values ('fig3',ST_GeomFromText('LINESTRING(0 0,12 0,13 4,20 2,20 0,32 0,33 10,38 16,43 15,44 10,44 0,60 0)')); -insert into figures (name, way) values ('fig3-1',ST_GeomFromText('LINESTRING(0 0,12 0,13 4,20 2,20 0,32 0,33 10,38 16,43 15,44 10,44 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)')); +--insert into figures (name, way) values ('fig3',ST_GeomFromText('LINESTRING(0 0,12 0,13 4,20 2,20 0,32 0,33 10,38 16,43 15,44 10,44 0,60 0)')); +--insert into figures (name, way) values ('fig3-1',ST_GeomFromText('LINESTRING(0 0,12 0,13 4,20 2,20 0,32 0,33 10,38 16,43 15,44 10,44 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)')); 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'), 80, 0))); -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 ('fig6-rev',ST_Reverse(ST_Translate((select way from figures where name='fig6'), 80, 0))); +--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)')); + +drop table if exists debug; +create table debug (i bigint, way geometry); -- DETECT BENDS drop table if exists bends, demo_bends1; @@ -28,6 +31,23 @@ insert into bends select name, detect_bends(way) from figures; create table demo_bends1 (name text, i bigint, way geometry); insert into demo_bends1 select name, generate_subscripts(ways, 1), unnest(ways) from bends; +-- FIX BEND INFLECTIONS +drop table if exists inflections, demo_inflections2; +create table inflections (name text, ways geometry[]); +insert into inflections select name, fix_gentle_inflections(ways) from bends; +create table demo_inflections2 (name text, i bigint, way geometry); +insert into demo_inflections2 select name, generate_subscripts(ways, 1), unnest(ways) from inflections; + +-- SELF-LINE CROSSING +drop table if exists selfcrossing, demo_selfcrossing3; +create table selfcrossing (name text, ways geometry[]); +insert into selfcrossing select name, self_crossing(ways) from inflections; +create table demo_selfcrossing3 (name text, i bigint, way geometry); +insert into demo_selfcrossing3 select name, generate_subscripts(ways, 1), unnest(ways) from selfcrossing; + + +\q + do $$ declare vbends geometry[]; @@ -43,13 +63,6 @@ begin perform assert_equals(3, array_length(vbends, 1)); end $$ language plpgsql; --- FIX BEND INFLECTIONS -drop table if exists inflections, demo_inflections2; -create table inflections (name text, ways geometry[]); -insert into inflections select name, fix_gentle_inflections(ways) from bends; -create table demo_inflections2 (name text, i bigint, way geometry); -insert into demo_inflections2 select name, generate_subscripts(ways, 1), unnest(ways) from inflections; - do $$ declare vbends geometry[]; @@ -68,13 +81,3 @@ begin perform assert_equals('LINESTRING(114 20,133 20,145 15,145 0,136 5,123 7,114 7)', st_astext(vinflections[2])); perform assert_equals('LINESTRING(123 7,114 7,111 2)', st_astext(vinflections[3])); end $$ language plpgsql; - -drop table if exists debug; -create table debug (i bigint, way geometry); - --- SELF-LINE CROSSING -drop table if exists selfcrossing, demo_selfcrossing3; -create table selfcrossing (name text, ways geometry[]); -insert into selfcrossing select name, self_crossing(ways) from inflections; -create table demo_selfcrossing3 (name text, i bigint, way geometry); -insert into demo_selfcrossing3 select name, generate_subscripts(ways, 1), unnest(ways) from selfcrossing; diff --git a/IV/wm.sql b/IV/wm.sql index ee5ba73..b2a9b6f 100644 --- a/IV/wm.sql +++ b/IV/wm.sql @@ -222,18 +222,26 @@ begin p2 = st_pointn(bends[j], 1); p3 = st_pointn(bends[j], -1); + raise notice 'j: %, i: %', j, i; + -- are p2 and p3 on the different sides of line(p0,p1)? vector -- multiplication; https://stackoverflow.com/questions/1560492/ s2 = (st_x(p0)-st_x(p1)*(st_y(p2)-st_y(p1))- (st_y(p0)-st_y(p1))*(st_x(p2)-st_x(p1))); s3 = (st_x(p0)-st_x(p1)*(st_y(p3)-st_y(p1))- (st_y(p0)-st_y(p1))*(st_x(p3)-st_x(p1))); + raise notice 'sign(s2): %, sign(s3): %', sign(s2), sign(s3); continue when sign(s2) = sign(s3); -- do end vertices of bend[i] cross bend[j]? a = st_pointn(bends[i], 1); b = st_pointn(bends[i], -1); multi = st_split(bends[j], st_makeline(a, b)); + insert into debug (i, way) values (0, st_geometryn(multi, 1)); + raise notice 'bends[i]: %', st_astext(bends[i]); + raise notice 'bends[j]: %', st_astext(bends[j]); + raise notice 'a: %, b: %', st_astext(a), st_astext(b); + raise notice 'multi: %', st_astext(multi); continue when st_numgeometries(multi) = 1; continue when st_numgeometries(multi) = 2 and (st_contains(bends[j], a) or st_contains(bends[j], b)); @@ -251,11 +259,6 @@ begin -- bends[i] = append(bends[i], multi[2][2..n]) -- remove bends from bends[i+1] to bends[j] inclusive. - raise notice 'j: %, i: %', j, i; - raise notice 'bends[i]: %', st_astext(bends[i]); - raise notice 'bends[j]: %', st_astext(bends[j]); - raise notice 'a: %, b: %', st_astext(a), st_astext(b); - raise notice 'multi: %', st_astext(multi); raise notice ''; prev_length = array_length(bends, 1); @@ -271,7 +274,7 @@ begin st_pointn(bends[i], 1), st_removepoint(st_geometryn(multi, st_numgeometries(multi)), 0) ); - insert into debug select x.path[1], x.geom from st_dump(bends[i-1]) x; + --insert into debug select x.path[1], x.geom from st_dump(bends[i-1]) x; bends = bends[1:i] || bends[j+1:prev_length]; end if; j = j - prev_length + array_length(bends, 1);