easier debugging
This commit is contained in:
parent
d1380ec907
commit
5b805bde9c
2
Makefile
2
Makefile
@ -16,7 +16,7 @@ clean:
|
||||
|
||||
.PHONY: clean-tables
|
||||
clean-tables:
|
||||
for t in $$(./db -c '\dt' | awk '/demo|integ/{print $$3}'); do \
|
||||
for t in $$(./db -c '\dt' | awk '/demo|debug|integ/{print $$3}'); do \
|
||||
./db -c "drop table $$t"; \
|
||||
done
|
||||
|
||||
|
@ -2,4 +2,4 @@
|
||||
|
||||
drop table if exists agg_rivers_wm;
|
||||
create table agg_rivers_wm (name text, way geometry);
|
||||
insert into agg_rivers_wm (name, way) select name, ST_SimplifyWM_DEBUG(way) from agg_rivers where name='Nemunas';
|
||||
insert into agg_rivers_wm (name, way) select name, ST_SimplifyWM(way, true) from agg_rivers where name='Nemunas';
|
||||
|
@ -56,7 +56,7 @@ insert into demo_selfcrossing3 select name, generate_subscripts(ways, 1), unnest
|
||||
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,-1 15,0 16,1 15,5 11))'));
|
||||
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_DEBUG(way) from figures where name='multi-island';
|
||||
insert into demo_wm (name, way) select name, ST_SimplifyWM(way, true) from figures where name='multi-island';
|
||||
|
||||
do $$
|
||||
declare
|
||||
|
98
wm.sql
98
wm.sql
@ -270,8 +270,9 @@ $$ language plpgsql;
|
||||
-- "Line Generalization Based on Analysis of Shape Characteristics" algorithm,
|
||||
-- 1998.
|
||||
drop function if exists ST_SimplifyWM;
|
||||
create function ST_SimplifyWM(geom geometry) returns geometry as $$
|
||||
create function ST_SimplifyWM(geom geometry, dbg boolean default false) returns geometry as $$
|
||||
declare
|
||||
dbg_stage integer;
|
||||
line geometry;
|
||||
lines geometry[];
|
||||
bends geometry[];
|
||||
@ -287,68 +288,55 @@ begin
|
||||
raise 'Unknown geometry type %', l_type;
|
||||
end if;
|
||||
|
||||
if dbg then
|
||||
drop table if exists debug_wm;
|
||||
create table debug_wm(name text, i bigint, way geometry);
|
||||
end if;
|
||||
|
||||
dbg_stage = 1;
|
||||
foreach line in array lines loop
|
||||
mutated = true;
|
||||
while mutated loop
|
||||
if dbg then
|
||||
insert into debug_wm (name, way) values(
|
||||
dbg_stage || 'afigures',
|
||||
line
|
||||
);
|
||||
end if;
|
||||
|
||||
bends = detect_bends(line);
|
||||
|
||||
if dbg then
|
||||
insert into debug_wm(name, i, way) values(
|
||||
dbg_stage || 'bbends',
|
||||
generate_subscripts(bends, 1),
|
||||
unnest(bends)
|
||||
);
|
||||
end if;
|
||||
|
||||
bends = fix_gentle_inflections(bends);
|
||||
|
||||
if dbg then
|
||||
insert into debug_wm(name, i, way) values(
|
||||
dbg_stage || 'cinflections',
|
||||
generate_subscripts(bends, 1),
|
||||
unnest(bends)
|
||||
);
|
||||
end if;
|
||||
|
||||
select * from self_crossing(bends) into bends, mutated;
|
||||
|
||||
if dbg then
|
||||
insert into debug_wm(name, i, way) values(
|
||||
dbg_stage || 'dcrossings',
|
||||
generate_subscripts(bends, 1),
|
||||
unnest(bends)
|
||||
);
|
||||
end if;
|
||||
|
||||
line = st_linemerge(st_union(bends));
|
||||
end loop;
|
||||
end loop;
|
||||
|
||||
if l_type = 'ST_LineString' then
|
||||
return st_linemerge(st_union(bends));
|
||||
elseif l_type = 'ST_MultiLineString' then
|
||||
return st_union(bends);
|
||||
end if;
|
||||
end
|
||||
$$ language plpgsql;
|
||||
|
||||
drop function if exists ST_SimplifyWM_DEBUG;
|
||||
create function ST_SimplifyWM_DEBUG(geom geometry) returns geometry as $$
|
||||
declare
|
||||
i integer;
|
||||
line geometry;
|
||||
lines geometry[];
|
||||
bend geometry;
|
||||
bends geometry[];
|
||||
mutated boolean;
|
||||
l_type text;
|
||||
begin
|
||||
l_type = st_geometrytype(geom);
|
||||
if l_type = 'ST_LineString' then
|
||||
lines = array[geom];
|
||||
elseif l_type = 'ST_MultiLineString' then
|
||||
lines = array((select a.geom from st_dump(geom) a order by path[1] asc));
|
||||
else
|
||||
raise 'Unsupported geometry type %', l_type;
|
||||
end if;
|
||||
|
||||
|
||||
i = 1;
|
||||
foreach line in array lines loop
|
||||
mutated = true;
|
||||
while mutated loop
|
||||
execute format('create table if not exists integ_%safigures (way geometry)', i);
|
||||
-- if anyone has suggestions how to insert a variable to a table without
|
||||
-- such hackery, I'll be glad to know
|
||||
raise notice 'inserting: %', st_astext(unnest(array[line]));
|
||||
execute format('insert into integ_%safigures select $1;', i) using (select unnest(array[line]));
|
||||
raise notice 's: %', array((select st_summary(way) from integ_1afigures));
|
||||
bends = detect_bends(line);
|
||||
|
||||
execute format('create table if not exists integ_%sbbends (i bigint, way geometry)', i);
|
||||
execute format('insert into integ_%sbbends (i, way) select generate_subscripts($1, 1), unnest($1)', i) using bends;
|
||||
bends = fix_gentle_inflections(bends);
|
||||
execute format('create table if not exists integ_%scinflections (i bigint, way geometry)', i);
|
||||
execute format('insert into integ_%scinflections (i, way) select generate_subscripts($1, 1), unnest($1)', i) using bends;
|
||||
select * from self_crossing(bends) into bends, mutated;
|
||||
execute format('create table if not exists integ_%sdselfcrossing (i bigint, way geometry)', i);
|
||||
execute format('insert into integ_%sdselfcrossing (i, way) select generate_subscripts($1, 1), unnest($1)', i) using bends;
|
||||
line = st_linemerge(st_union(bends));
|
||||
end loop;
|
||||
i = i + 1;
|
||||
dbg_stage = dbg_stage + 1;
|
||||
end loop;
|
||||
|
||||
if l_type = 'ST_LineString' then
|
||||
|
Loading…
Reference in New Issue
Block a user