easier debugging

This commit is contained in:
Motiejus Jakštys 2021-03-25 11:34:30 +02:00
parent 5099c933b2
commit 6e5f66ee6b
4 changed files with 46 additions and 58 deletions

View File

@ -16,7 +16,7 @@ clean:
.PHONY: clean-tables .PHONY: clean-tables
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"; \ ./db -c "drop table $$t"; \
done done

View File

@ -2,4 +2,4 @@
drop table if exists agg_rivers_wm; drop table if exists agg_rivers_wm;
create table agg_rivers_wm (name text, way geometry); 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';

View File

@ -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))')); 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; drop table if exists demo_wm;
create table demo_wm (name text, i bigint, way geometry); 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 $$ do $$
declare declare

View File

@ -270,8 +270,9 @@ $$ language plpgsql;
-- "Line Generalization Based on Analysis of Shape Characteristics" algorithm, -- "Line Generalization Based on Analysis of Shape Characteristics" algorithm,
-- 1998. -- 1998.
drop function if exists ST_SimplifyWM; 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 declare
dbg_stage integer;
line geometry; line geometry;
lines geometry[]; lines geometry[];
bends geometry[]; bends geometry[];
@ -287,68 +288,55 @@ begin
raise 'Unknown geometry type %', l_type; raise 'Unknown geometry type %', l_type;
end if; 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 foreach line in array lines loop
mutated = true; mutated = true;
while mutated loop while mutated loop
if dbg then
insert into debug_wm (name, way) values(
dbg_stage || 'afigures',
line
);
end if;
bends = detect_bends(line); 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); 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; 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)); line = st_linemerge(st_union(bends));
end loop; end loop;
end loop; dbg_stage = dbg_stage + 1;
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;
end loop; end loop;
if l_type = 'ST_LineString' then if l_type = 'ST_LineString' then