debugging

This commit is contained in:
Motiejus Jakštys 2021-03-17 11:32:12 +02:00
parent d9c155807d
commit 8a651b2f51
4 changed files with 33 additions and 16 deletions

View File

@ -5,9 +5,9 @@ WHERE ?= name='Visinčia' OR name='Šalčia' OR name='Nemunas'
test: tests.sql .faux.db
./db -f tests.sql
.PHONY: integration-test
integration-test: .faux_filter_rivers
./db -f integration-tests.sql
.PHONY: test-integration
test-integration: .faux_filter-rivers
./db -f tests-integration.sql
.faux_filter-rivers: .faux_import-osm
./db -v where="$(WHERE)" -f aggregate-rivers.sql

View File

@ -24,7 +24,7 @@ begin
end
$$ language plpgsql;
create temporary table aggregate_rivers_tmp (osm_id bigint, name text, way geometry);
create temporary table aggregate_rivers_tmp (osm_id bigint, name text, way geometry) on commit drop;
create index aggregate_rivers_tmp_id on aggregate_rivers_tmp(osm_id);
create index aggregate_rivers_tmp_gix on aggregate_rivers_tmp using gist(way) include(name);
@ -34,4 +34,3 @@ insert into aggregate_rivers_tmp
drop table if exists agg_rivers;
create table agg_rivers as (select * from aggregate_rivers());
drop table aggregate_rivers_tmp;

3
IV/tests-integration.sql Normal file
View File

@ -0,0 +1,3 @@
\i wm.sql
select ST_SimplifyWM_DEBUG(way) from agg_rivers;

View File

@ -273,26 +273,27 @@ drop function if exists ST_SimplifyWM;
create function ST_SimplifyWM(geom geometry) returns geometry as $$
declare
line geometry;
geoms geometry[];
lines geometry[];
bends geometry[];
mutated boolean;
l_type text;
begin
l_type = st_geometrytype(geom);
if l_type = 'ST_LineString' then
geoms = array[geom];
lines = array[geom];
elseif l_type = 'ST_MultiLineString' then
geoms = array((select a.geom from st_dump(geom) a order by path[1] desc));
lines = array((select a.geom from st_dump(geom) a order by path[1] desc));
else
raise 'Unknown geometry type %', l_type;
end if;
foreach line in array geoms loop
foreach line in array lines loop
mutated = true;
while mutated loop
bends = detect_bends(line);
bends = fix_gentle_inflections(bends);
select * from self_crossing(bends) into bends, mutated;
line = st_linemerge(st_union(bends));
end loop;
end loop;
@ -309,29 +310,43 @@ create function ST_SimplifyWM_DEBUG(geom geometry) returns geometry as $$
declare
i integer;
line geometry;
geoms geometry[];
lines geometry[];
bends geometry[];
mutated boolean;
l_type text;
begin
l_type = st_geometrytype(geom);
if l_type = 'ST_LineString' then
geoms = array[geom];
lines = array[geom];
elseif l_type = 'ST_MultiLineString' then
geoms = array((select a.geom from st_dump(geom) a order by path[1] desc));
lines = array((select a.geom from st_dump(geom) a order by path[1] desc));
else
raise 'Unknown geometry type %', l_type;
end if;
i = 1;
foreach line in array geoms loop
mutated = true;
foreach line in array lines loop
while mutated loop
execute format('create table figures_%I (name text, i bigint, way geometry)', i);
execute format('insert into figures_%I select name, generate_subscripts(ways)
execute format('drop table if exists demo_%sfigures0', i);
execute format('create table demo_%sfigures0 (way geometry)', i);
-- if anyone has suggestions how to insert a variable to a table without such
-- hackery, I'll be glad to know
execute format('insert into demo_%sfigures0 select $1;', i) using (select unnest(array[line]));
bends = detect_bends(line);
execute format('drop table if exists demo_%sbends1', i);
execute format('create table demo_%sbends1 (i bigint, way geometry)', i);
execute format('insert into demo_%sbends1 (i, way) select generate_subscripts($1, 1), unnest($1)', i) using bends;
bends = fix_gentle_inflections(bends);
execute format('drop table if exists demo_%sinflections2', i);
execute format('create table demo_%sinflections2 (i bigint, way geometry)', i);
execute format('insert into demo_%sinflections2 (i, way) select generate_subscripts($1, 1), unnest($1)', i) using bends;
select * from self_crossing(bends) into bends, mutated;
execute format('drop table if exists demo_%sselfcrossing3', i);
execute format('create table demo_%sselfcrossing3 (i bigint, way geometry)', i);
execute format('insert into demo_%sselfcrossing3 (i, way) select generate_subscripts($1, 1), unnest($1)', i) using bends;
line = st_linemerge(st_union(bends));
i = i + 1;
end loop;
end loop;