wip debug

This commit is contained in:
Motiejus Jakštys 2021-05-19 22:57:46 +03:00 committed by Motiejus Jakštys
parent 6aa674a82f
commit 4b0f214ef9
4 changed files with 59 additions and 13 deletions

View File

@ -1,6 +1,14 @@
SOURCE ?= lithuania-latest.osm.pbf SOURCE ?= lithuania-latest.osm.pbf
WHERE ?= name='Visinčia' OR name='Šalčia' OR name='Nemunas' 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 .faux_filter-rivers: .faux_import-osm
./db -v where="$(WHERE)" -f aggregate-rivers.sql ./db -v where="$(WHERE)" -f aggregate-rivers.sql
touch $@ touch $@

View File

@ -6,32 +6,32 @@ declare
cc record; cc record;
changed boolean; changed boolean;
begin begin
while (select count(1) from agg_tmp_objects) > 0 loop while (select count(1) from aggregate_rivers_tmp) > 0 loop
select * from agg_tmp_objects limit 1 into c; select * from aggregate_rivers_tmp limit 1 into c;
delete from agg_tmp_objects a where a.osm_id = c.osm_id; delete from aggregate_rivers_tmp a where a.osm_id = c.osm_id;
changed = true; changed = true;
while changed loop while changed loop
changed = false; 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)); 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; changed = true;
end loop; end loop;
end loop; -- while changed end loop; -- while changed
return query select c.osm_id, c.name, c.way; 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; return;
end end
$$ language plpgsql; $$ language plpgsql;
create temporary table agg_tmp_objects (osm_id bigint, name text, way geometry); create temporary table aggregate_rivers_tmp (osm_id bigint, name text, way geometry);
create index agg_tmp_objects_id on agg_tmp_objects(osm_id); create index aggregate_rivers_tmp_id on aggregate_rivers_tmp(osm_id);
create index agg_tmp_objects_gix on agg_tmp_objects using gist(way) include(name); 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 select p.osm_id, p.name, p.way from planet_osm_line p
where waterway in ('river', 'stream', 'canal') and :where; where waterway in ('river', 'stream', 'canal') and :where;
drop table if exists agg_rivers; drop table if exists agg_rivers;
create table agg_rivers as (select * from aggregate_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. - grafinis palyginimas.
- galbūt duoti kartografijos ekspertams. - galbūt duoti kartografijos ekspertams.
- Pritaikomumas: GDR50 ir GDR250 yra tiesiogiai pritaikomi žemėlapiams. Jei - Pritaikomumas: GDR50 ir GDR250 yra tiesiogiai pritaikomi žemėlapiams. Jei
algoritmas yra geresnis, žemėlapių kartografinis pagrindas gali būti algoritmas yra geresnis, žemėlapių geografinis pagrindas gali būti geresnis.
geresnis.
- Literatūros apžvalga (?) - Literatūros apžvalga (?)
- Metodika: - Metodika:
- implementacijos paaiškinimas: tai, kas neparašyta straipsnyje, bet su kuo - implementacijos paaiškinimas: tai, kas neparašyta straipsnyje, bet su kuo

39
wm.sql
View File

@ -303,3 +303,42 @@ begin
end if; end if;
end end
$$ language plpgsql; $$ 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;