bugfix: remove leftover segment
This commit is contained in:
parent
3efef0864d
commit
5657df8543
@ -14,12 +14,12 @@ 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 ('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);
|
||||
|
27
wm.sql
27
wm.sql
@ -220,49 +220,32 @@ begin
|
||||
p2 = st_pointn(bends[j], 1);
|
||||
p3 = st_pointn(bends[j], -1);
|
||||
|
||||
raise notice 'j: %, i: %', j, i;
|
||||
|
||||
-- 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));
|
||||
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));
|
||||
|
||||
-- real self-crossing detected! Remove it.
|
||||
-- if j < i:
|
||||
-- bends[j] = multi[1][1...n-1]; that will have all the vertices of
|
||||
-- bends[j], except the crossing and what comes after it.
|
||||
-- bends[j] = append(bends[j], bends[i][-1])
|
||||
-- remove bends from bends[j+1] to bends[i] inclusive.
|
||||
-- j := i+1
|
||||
-- elif j > i:
|
||||
-- bends[i-1] = st_removepoint(bends[i-1], -1)
|
||||
-- bends[i] = bends[i][1]
|
||||
-- bends[i] = append(bends[i], multi[2][2..n])
|
||||
-- remove bends from bends[i+1] to bends[j] inclusive.
|
||||
|
||||
|
||||
raise notice '';
|
||||
prev_length = array_length(bends, 1);
|
||||
if j < i then
|
||||
-- remove first vertex of the following bend, because the last
|
||||
-- segment is always duplicated with the i-th bend.
|
||||
bends[i+1] = st_removepoint(bends[i+1], 0);
|
||||
bends[j] = st_geometryn(multi, 1);
|
||||
bends[j] = st_setpoint(bends[j], st_npoints(bends[j])-1,
|
||||
st_pointn(bends[i], st_npoints(bends[i])));
|
||||
bends = bends[1:j] || bends[i+1:prev_length];
|
||||
j = i;
|
||||
else
|
||||
-- remove last vertex of the previous bend, because the last
|
||||
-- segment is duplicated with the i'th bend.
|
||||
bends[i-1] = st_removepoint(bends[i-1], st_npoints(bends[i-1])-1);
|
||||
bends[i] = st_makeline(
|
||||
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;
|
||||
bends = bends[1:i] || bends[j+1:prev_length];
|
||||
end if;
|
||||
j = j - prev_length + array_length(bends, 1);
|
||||
|
Loading…
Reference in New Issue
Block a user