wip debug

This commit is contained in:
Motiejus Jakštys 2021-03-15 18:58:16 +02:00
parent 09f8e01a0e
commit d9c155807d
4 changed files with 59 additions and 13 deletions

View File

@ -1,6 +1,14 @@
SOURCE ?= lithuania-latest.osm.pbf
WHERE ?= name='Visinčia' OR name='Šalčia' OR name='Nemunas'
.PHONY: test
test: tests.sql .faux.db
./db -f tests.sql
.PHONY: integration-test
integration-test: .faux_filter_rivers
./db -f integration-tests.sql
.faux_filter-rivers: .faux_import-osm
./db -v where="$(WHERE)" -f aggregate-rivers.sql
touch $@

View File

@ -6,32 +6,32 @@ declare
cc record;
changed boolean;
begin
while (select count(1) from agg_tmp_objects) > 0 loop
select * from agg_tmp_objects limit 1 into c;
delete from agg_tmp_objects a where a.osm_id = c.osm_id;
while (select count(1) from aggregate_rivers_tmp) > 0 loop
select * from aggregate_rivers_tmp limit 1 into c;
delete from aggregate_rivers_tmp a where a.osm_id = c.osm_id;
changed = true;
while changed loop
changed = false;
for cc in (select * from agg_tmp_objects a where a.name = c.name and st_dwithin(a.way, c.way, 500)) loop
for cc in (select * from aggregate_rivers_tmp a where a.name = c.name and st_dwithin(a.way, c.way, 500)) loop
c.way = st_linemerge(st_union(c.way, cc.way));
delete from agg_tmp_objects a where a.osm_id = cc.osm_id;
delete from aggregate_rivers_tmp a where a.osm_id = cc.osm_id;
changed = true;
end loop;
end loop; -- while changed
return query select c.osm_id, c.name, c.way;
end loop; -- count(1) from agg_tmp_objects > 0
end loop; -- count(1) from aggregate_rivers_tmp > 0
return;
end
$$ language plpgsql;
create temporary table agg_tmp_objects (osm_id bigint, name text, way geometry);
create index agg_tmp_objects_id on agg_tmp_objects(osm_id);
create index agg_tmp_objects_gix on agg_tmp_objects using gist(way) include(name);
create temporary table aggregate_rivers_tmp (osm_id bigint, name text, way geometry);
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);
insert into agg_tmp_objects
insert into aggregate_rivers_tmp
select p.osm_id, p.name, p.way from planet_osm_line p
where waterway in ('river', 'stream', 'canal') and :where;
drop table if exists agg_rivers;
create table agg_rivers as (select * from aggregate_rivers());
drop table agg_tmp_objects;
drop table aggregate_rivers_tmp;

View File

@ -35,8 +35,7 @@ analizė Lietuvos upėms.
- grafinis palyginimas.
- galbūt duoti kartografijos ekspertams.
- Pritaikomumas: GDR50 ir GDR250 yra tiesiogiai pritaikomi žemėlapiams. Jei
algoritmas yra geresnis, žemėlapių kartografinis pagrindas gali būti
geresnis.
algoritmas yra geresnis, žemėlapių geografinis pagrindas gali būti geresnis.
- Literatūros apžvalga (?)
- Metodika:
- implementacijos paaiškinimas: tai, kas neparašyta straipsnyje, bet su kuo

View File

@ -303,3 +303,42 @@ begin
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;
geoms geometry[];
bends geometry[];
mutated boolean;
l_type text;
begin
l_type = st_geometrytype(geom);
if l_type = 'ST_LineString' then
geoms = array[geom];
elseif l_type = 'ST_MultiLineString' then
geoms = 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;
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)
bends = detect_bends(line);
bends = fix_gentle_inflections(bends);
select * from self_crossing(bends) into bends, mutated;
end loop;
end loop;
if l_type = 'ST_LineString' then
return bends[1];
elseif l_type = 'ST_MultiLineString' then
return st_union(bends);
end if;
end
$$ language plpgsql;