Merge branch 'gdb10lt'

This breaks "test-rivers" for Nemunas.
This commit is contained in:
Motiejus Jakštys 2021-05-19 22:57:50 +03:00 committed by Motiejus Jakštys
parent 2c7be0989a
commit d9472757f5
5 changed files with 47 additions and 32 deletions

View File

@ -1,8 +1,9 @@
OSM ?= lithuania-latest.osm.pbf OSM ?= lithuania-latest.osm.pbf
WHERE ?= name='Visinčia' OR name='Šalčia' OR name='Nemunas' OR name='Merkys' RIVERFILTER = Visinčia|Šalčia|Nemunas
#WHERE ?= name like '%'
SLIDES = slides-2021-03-29.pdf SLIDES = slides-2021-03-29.pdf
GDB10LT ?= $(wildcard GDB10LT-static-*.zip)
# Max figure size (in meters) is when it's width is TEXTWIDTH_CM on scale 1:25k # Max figure size (in meters) is when it's width is TEXTWIDTH_CM on scale 1:25k
SCALEDWIDTH = $(shell awk '/^TEXTWIDTH_CM/{print 25000/100*$$3}' layer2img.py) SCALEDWIDTH = $(shell awk '/^TEXTWIDTH_CM/{print 25000/100*$$3}' layer2img.py)
@ -281,12 +282,20 @@ $(OSM):
wget http://download.geofabrik.de/europe/$@ wget http://download.geofabrik.de/europe/$@
.PHONY: refresh-rivers .PHONY: refresh-rivers
refresh-rivers: aggregate-rivers.sql $(OSM) .faux_db ## Refresh rivers.sql from Open Street Maps refresh-rivers: aggregate-rivers.sql .faux_db ## Refresh rivers.sql from GDB10LT
PGPASSWORD=osm osm2pgsql -c --multi-geometry -H 127.0.0.1 -d osm -U osm $(OSM) @if [ ! -f "$(GDB10LT)" ]; then \
bash db -v where="$(WHERE)" -f $< echo "ERROR: GDB10LT-static-*.zip not found. Do GDB10LT=<...>"; \
exit 1; \
fi
mkdir -p .tmp/shp; unzip -d .tmp/shp "$(GDB10LT)" 'HIDRO_L.*'
shp2pgsql -s 3857 -d ".tmp/shp/HIDRO_L.shp" | \
awk '!/^INSERT/{print}; /^INSERT/&&/$(RIVERFILTER)/{print;next}' | \
bash ./db
bash db -f $<
(\ (\
echo '-- Generated at $(shell TZ=UTC date +"%FT%TZ") on $(shell whoami)@$(shell hostname -f)'; \ echo '-- Generated at $(shell TZ=UTC date +"%FT%TZ") on $(shell whoami)@$(shell hostname -f)'; \
echo '-- Select: $(WHERE)'; \ echo '-- Rivers: $(RIVERFILTER)'; \
docker exec wm-mj pg_dump --clean -Uosm osm -t wm_rivers | tr -d '\r' \ docker exec wm-mj pg_dump --clean -Uosm osm -t wm_rivers | tr -d '\r' \
) > rivers.sql.tmp ) > rivers.sql.tmp
mv rivers.sql.tmp rivers.sql mv rivers.sql.tmp rivers.sql
rm -fr .tmp/shp

View File

@ -1,7 +1,7 @@
/* Aggregates rivers by name and proximity. */ /* Aggregates rivers by name and proximity. */
drop function if exists aggregate_rivers; drop function if exists aggregate_rivers;
create function aggregate_rivers() returns table( create function aggregate_rivers() returns table(
osm_id bigint, id bigint,
name text, name text,
way geometry way geometry
) as $$ ) as $$
@ -12,7 +12,7 @@ declare
begin begin
while (select count(1) from wm_rivers_tmp) > 0 loop while (select count(1) from wm_rivers_tmp) > 0 loop
select * from wm_rivers_tmp limit 1 into c; select * from wm_rivers_tmp limit 1 into c;
delete from wm_rivers_tmp a where a.osm_id = c.osm_id; delete from wm_rivers_tmp a where a.id = c.id;
changed = true; changed = true;
while changed loop while changed loop
changed = false; changed = false;
@ -22,11 +22,11 @@ begin
st_dwithin(a.way, c.way, 500) st_dwithin(a.way, c.way, 500)
) loop ) loop
c.way = st_linemerge(st_union(c.way, cc.way)); c.way = st_linemerge(st_union(c.way, cc.way));
delete from wm_rivers_tmp a where a.osm_id = cc.osm_id; delete from wm_rivers_tmp a where a.id = cc.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.id, c.name, c.way;
end loop; -- count(1) from wm_rivers_tmp > 0 end loop; -- count(1) from wm_rivers_tmp > 0
return; return;
end end
@ -35,13 +35,12 @@ $$ language plpgsql;
drop index if exists wm_rivers_tmp_id; drop index if exists wm_rivers_tmp_id;
drop index if exists wm_rivers_tmp_gix; drop index if exists wm_rivers_tmp_gix;
drop table if exists wm_rivers_tmp; drop table if exists wm_rivers_tmp;
create temporary table wm_rivers_tmp (osm_id bigint, name text, way geometry); create temporary table wm_rivers_tmp (id bigint, name text, way geometry);
create index wm_rivers_tmp_id on wm_rivers_tmp(osm_id); create index wm_rivers_tmp_id on wm_rivers_tmp(id);
create index wm_rivers_tmp_gix on wm_rivers_tmp using gist(way) include(name); create index wm_rivers_tmp_gix on wm_rivers_tmp using gist(way) include(name);
insert into wm_rivers_tmp insert into wm_rivers_tmp
select p.osm_id, p.name, p.way from planet_osm_line p select p.gid as id, p.vardas as name, p.geom as way from hidro_l p;
where waterway in ('river', 'stream', 'canal') and :where;
drop table if exists wm_rivers; drop table if exists wm_rivers;
create table wm_rivers as ( create table wm_rivers as (

File diff suppressed because one or more lines are too long

View File

@ -68,6 +68,7 @@ end $$ language plpgsql;
delete from wm_visuals where name like 'salvis%'; delete from wm_visuals where name like 'salvis%';
insert into wm_visuals(name, way) values('salvis', ( insert into wm_visuals(name, way) values('salvis', (
with multismall as (
select st_intersection( select st_intersection(
(select st_union(way) from wm_rivers where name in ('Šalčia', 'Visinčia')), (select st_union(way) from wm_rivers where name in ('Šalčia', 'Visinčia')),
wm_bbox( wm_bbox(
@ -77,7 +78,13 @@ insert into wm_visuals(name, way) values('salvis', (
), ),
:scaledwidth :scaledwidth
) )
) ways
) )
-- protecting against very small bends that were cut
-- in the corner of the picture
select st_union(a.geom)
from st_dump((select ways from multismall)) a
where st_length(a.geom) >= 100
)); ));
do $$ do $$
@ -110,7 +117,7 @@ begin
foreach i in array array[16, 64, 256] loop foreach i in array array[16, 64, 256] loop
geom1 = st_simplify((select way from wm_visuals where name='salvis'), i); geom1 = st_simplify((select way from wm_visuals where name='salvis'), i);
geom2 = st_simplifyvw((select way from wm_visuals where name='salvis'), i*i); geom2 = st_simplifyvw((select way from wm_visuals where name='salvis'), i*i);
geom3 = st_simplifywm((select way from wm_visuals where name='salvis'), i); geom3 = st_simplifywm((select way from wm_visuals where name='salvis'), i, 50, 'salvis-' || i);
insert into wm_visuals(name, way) values insert into wm_visuals(name, way) values
('salvis-douglas-' || i, geom1), ('salvis-douglas-' || i, geom1),
('salvis-douglas-' || i || '-chaikin', st_chaikinsmoothing(geom1, 5)), ('salvis-douglas-' || i || '-chaikin', st_chaikinsmoothing(geom1, 5)),

2
wm.sql
View File

@ -335,7 +335,7 @@ create function wm_bend_attrs(
dbggen integer default null dbggen integer default null
) returns wm_t_attrs[] as $$ ) returns wm_t_attrs[] as $$
declare declare
isolation_threshold constant real default 0.5; isolation_threshold constant real default 0.3;
attrs wm_t_attrs[]; attrs wm_t_attrs[];
attr wm_t_attrs; attr wm_t_attrs;
bend geometry; bend geometry;