wip GDB10LT instead of OSM

This commit is contained in:
Motiejus Jakštys 2021-05-10 23:20:01 +03:00
parent 44ee741e82
commit dd9fd60cd0
3 changed files with 29 additions and 21 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