wip data import from OSM

This commit is contained in:
Motiejus Jakštys 2021-03-13 15:53:22 +02:00
parent 6f95702cb9
commit 4b2f8bd65d
6 changed files with 44 additions and 2 deletions

3
.gitignore vendored
View File

@ -32,3 +32,6 @@ version.tex
db/
_minted-*/
*.qgz
.faux*
*.pbf

23
IV/Makefile Normal file
View File

@ -0,0 +1,23 @@
# HACK HACK
EMPTY :=
SPACE := $(EMPTY) $(EMPTY)
RIVERS ?= Visinčia Šalčia Žeimena Lakaja
.faux_filter-rivers: .faux_import-osm
./filter-rivers-query.awk $(RIVERS) | ./db -f -
touch $@
.faux_import-osm: lithuania-latest.osm.pbf .faux.db
PGPASSWORD=osm osm2pgsql \
-c --multi-geometry \
-H 127.0.0.1 -d osm -U osm \
$<
touch $@
.faux.db:
./db start
touch $@
lithuania-latest.osm.pbf:
wget http://download.geofabrik.de/europe/lithuania-latest.osm.pbf

1
IV/db
View File

@ -28,6 +28,7 @@ _wait_for_postgres() {
case ${1:-} in
start)
_psql -qc '\q' 2>/dev/null && exit 0
docker run -d --rm \
-p 5432:5432 \
-e POSTGRES_DBNAME=osm \

12
IV/filter-rivers-query.awk Executable file
View File

@ -0,0 +1,12 @@
#!/usr/bin/awk -f
BEGIN {
print "DROP TABLE IF EXISTS rivers;";
printf "CREATE TABLE rivers AS SELECT name,way FROM planet_osm_line WHERE "
for (i = 1; i < ARGC; i++) {
printf "name='%s'", ARGV[i]
if (i != ARGC - 1)
printf " OR ";
}
print ";";
}

View File

@ -51,6 +51,9 @@ insert into selfcrossing select name, (self_crossing(ways)).* from inflections;
create table demo_selfcrossing3 (name text, i bigint, way geometry);
insert into demo_selfcrossing3 select name, generate_subscripts(ways, 1), unnest(ways) from selfcrossing;
-- COMBINED
drop table if exists demo_wm;
create table demo_wm (name text, i bigint, way geometry);
do $$
declare

View File

@ -296,9 +296,9 @@ begin
end loop;
if l_type = 'ST_LineString' then
return geoms[1];
return bends[1];
elseif l_type = 'ST_MultiLineString' then
return st_union(geoms);
return st_union(bends);
end if;
end
$$ language plpgsql;