diff --git a/.gitignore b/.gitignore index be8bc34..12d3767 100644 --- a/.gitignore +++ b/.gitignore @@ -32,3 +32,6 @@ version.tex db/ _minted-*/ *.qgz + +.faux* +*.pbf diff --git a/IV/Makefile b/IV/Makefile new file mode 100644 index 0000000..f9b22a8 --- /dev/null +++ b/IV/Makefile @@ -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 diff --git a/IV/db b/IV/db index 238a0d5..8b76a19 100755 --- a/IV/db +++ b/IV/db @@ -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 \ diff --git a/IV/filter-rivers-query.awk b/IV/filter-rivers-query.awk new file mode 100755 index 0000000..f82101c --- /dev/null +++ b/IV/filter-rivers-query.awk @@ -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 ";"; +} diff --git a/IV/tests.sql b/IV/tests.sql index 8560031..4c048b2 100644 --- a/IV/tests.sql +++ b/IV/tests.sql @@ -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 diff --git a/IV/wm.sql b/IV/wm.sql index 93cd0c6..902f6b3 100644 --- a/IV/wm.sql +++ b/IV/wm.sql @@ -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;