Merge branch 'gdb10lt'

This breaks "test-rivers" for Nemunas.
This commit is contained in:
Motiejus Jakštys 2021-05-11 20:29:41 +03:00
commit dcf4c02307
5 changed files with 47 additions and 32 deletions

View File

@ -1,8 +1,9 @@
OSM ?= lithuania-latest.osm.pbf
WHERE ?= name='Visinčia' OR name='Šalčia' OR name='Nemunas' OR name='Merkys'
#WHERE ?= name like '%'
RIVERFILTER = Visinčia|Šalčia|Nemunas
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
SCALEDWIDTH = $(shell awk '/^TEXTWIDTH_CM/{print 25000/100*$$3}' layer2img.py)
@ -281,12 +282,20 @@ $(OSM):
wget http://download.geofabrik.de/europe/$@
.PHONY: refresh-rivers
refresh-rivers: aggregate-rivers.sql $(OSM) .faux_db ## Refresh rivers.sql from Open Street Maps
PGPASSWORD=osm osm2pgsql -c --multi-geometry -H 127.0.0.1 -d osm -U osm $(OSM)
bash db -v where="$(WHERE)" -f $<
refresh-rivers: aggregate-rivers.sql .faux_db ## Refresh rivers.sql from GDB10LT
@if [ ! -f "$(GDB10LT)" ]; then \
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 '-- Select: $(WHERE)'; \
echo '-- Rivers: $(RIVERFILTER)'; \
docker exec wm-mj pg_dump --clean -Uosm osm -t wm_rivers | tr -d '\r' \
) > rivers.sql.tmp
mv rivers.sql.tmp rivers.sql
rm -fr .tmp/shp

View File

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

File diff suppressed because one or more lines are too long

View File

@ -68,16 +68,23 @@ end $$ language plpgsql;
delete from wm_visuals where name like 'salvis%';
insert into wm_visuals(name, way) values('salvis', (
select st_intersection(
(select st_union(way) from wm_rivers where name in ('Šalčia', 'Visinčia')),
wm_bbox(
st_closestpoint(
(select way from wm_rivers where name='Šalčia'),
(select way from wm_rivers where name='Visinčia')
),
:scaledwidth
)
with multismall as (
select st_intersection(
(select st_union(way) from wm_rivers where name in ('Šalčia', 'Visinčia')),
wm_bbox(
st_closestpoint(
(select way from wm_rivers where name='Šalčia'),
(select way from wm_rivers where name='Visinčia')
),
: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 $$
@ -110,7 +117,7 @@ begin
foreach i in array array[16, 64, 256] loop
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);
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
('salvis-douglas-' || i, geom1),
('salvis-douglas-' || i || '-chaikin', st_chaikinsmoothing(geom1, 5)),

View File

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