Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Jiggled imposm pieces around until they successfully make shapefiles

  • Loading branch information...
commit 51b0541b19880f43b33b3b2dbf78aca04af7ce37 1 parent e797163
@migurski authored
Showing with 84 additions and 10 deletions.
  1. +78 −8 build-osm2pgsql-script.py
  2. +6 −2 extract.sh
View
86 build-osm2pgsql-script.py
@@ -17,24 +17,24 @@
# This script expects to be run as the postgres user.
#
-createdb osm
+createdb -E utf8 -T template0 osm
createlang plpgsql osm
psql -f /usr/share/postgresql/8.4/contrib/postgis-1.5/postgis.sql osm
psql -f /usr/share/postgresql/8.4/contrib/postgis-1.5/spatial_ref_sys.sql osm
curl -o tmp/default.style http://svn.openstreetmap.org/applications/utils/export/osm2pgsql/default.style
-function osm2geodata
+function osm2pgsql_shapefiles
{
slug=$1
- prefix=${slug/-/_}_osm
+ prefix=${slug//-/_}_osm
- osm2pgsql -sluc -C 1024 -d osm -S tmp/default.style -p ${prefix} ex/$slug.osm.bz2 > /dev/null 2>&1
+ osm2pgsql -sluc -C 1024 -d osm -S osm2pgsql.style -p ${prefix} ex/$slug.osm.bz2 > /dev/null 2>&1
pgsql2shp -rk -f tmp/$slug.osm-point.shp osm ${prefix}_point
pgsql2shp -rk -f tmp/$slug.osm-polygon.shp osm ${prefix}_polygon
pgsql2shp -rk -f tmp/$slug.osm-line.shp osm ${prefix}_line
- zip -j tmp/$slug.shapefiles.zip tmp/$slug.osm-*.shp tmp/$slug.osm-*.prj tmp/$slug.osm-*.dbf tmp/$slug.osm-*.shx
+ zip -j tmp/$slug.osm2pgsql-shapefiles.zip tmp/$slug.osm-*.shp tmp/$slug.osm-*.prj tmp/$slug.osm-*.dbf tmp/$slug.osm-*.shx
rm tmp/$slug.osm-*.*
@@ -46,11 +46,81 @@
echo "DROP TABLE ${prefix}_roads" | psql osm
echo "DROP TABLE ${prefix}_ways" | psql osm
}
+
+function imposm_shapefiles
+{
+ slug=$1
+ prefix=${slug//-/_}
+
+ mkdir tmp/$slug-imposm
+
+ imposm --read --cache-dir tmp/$slug-imposm --write --table-prefix=${prefix}_ --connect postgis://postgres:@127.0.0.1/osm ex/$slug.osm.pbf
+
+ pgsql2shp -rk -f tmp/$slug-imposm/$slug.osm-admin.shp osm ${prefix}_admin
+ pgsql2shp -rk -f tmp/$slug-imposm/$slug.osm-aeroways.shp osm ${prefix}_aeroways
+ pgsql2shp -rk -f tmp/$slug-imposm/$slug.osm-amenities.shp osm ${prefix}_amenities
+ pgsql2shp -rk -f tmp/$slug-imposm/$slug.osm-buildings.shp osm ${prefix}_buildings
+ pgsql2shp -rk -f tmp/$slug-imposm/$slug.osm-landusages.shp osm ${prefix}_landusages
+ pgsql2shp -rk -f tmp/$slug-imposm/$slug.osm-landusages_gen0.shp osm ${prefix}_landusages_gen0
+ pgsql2shp -rk -f tmp/$slug-imposm/$slug.osm-landusages_gen1.shp osm ${prefix}_landusages_gen1
+ pgsql2shp -rk -f tmp/$slug-imposm/$slug.osm-mainroads.shp osm ${prefix}_mainroads
+ pgsql2shp -rk -f tmp/$slug-imposm/$slug.osm-mainroads_gen0.shp osm ${prefix}_mainroads_gen0
+ pgsql2shp -rk -f tmp/$slug-imposm/$slug.osm-mainroads_gen1.shp osm ${prefix}_mainroads_gen1
+ pgsql2shp -rk -f tmp/$slug-imposm/$slug.osm-minorroads.shp osm ${prefix}_minorroads
+ pgsql2shp -rk -f tmp/$slug-imposm/$slug.osm-motorways.shp osm ${prefix}_motorways
+ pgsql2shp -rk -f tmp/$slug-imposm/$slug.osm-motorways_gen0.shp osm ${prefix}_motorways_gen0
+ pgsql2shp -rk -f tmp/$slug-imposm/$slug.osm-motorways_gen1.shp osm ${prefix}_motorways_gen1
+ pgsql2shp -rk -f tmp/$slug-imposm/$slug.osm-places.shp osm ${prefix}_places
+ pgsql2shp -rk -f tmp/$slug-imposm/$slug.osm-railways.shp osm ${prefix}_railways
+ pgsql2shp -rk -f tmp/$slug-imposm/$slug.osm-railways_gen0.shp osm ${prefix}_railways_gen0
+ pgsql2shp -rk -f tmp/$slug-imposm/$slug.osm-railways_gen1.shp osm ${prefix}_railways_gen1
+ pgsql2shp -rk -f tmp/$slug-imposm/$slug.osm-roads.shp osm ${prefix}_roads
+ pgsql2shp -rk -f tmp/$slug-imposm/$slug.osm-roads_gen0.shp osm ${prefix}_roads_gen0
+ pgsql2shp -rk -f tmp/$slug-imposm/$slug.osm-roads_gen1.shp osm ${prefix}_roads_gen1
+ pgsql2shp -rk -f tmp/$slug-imposm/$slug.osm-transport_areas.shp osm ${prefix}_transport_areas
+ pgsql2shp -rk -f tmp/$slug-imposm/$slug.osm-transport_points.shp osm ${prefix}_transport_points
+ pgsql2shp -rk -f tmp/$slug-imposm/$slug.osm-waterareas.shp osm ${prefix}_waterareas
+ pgsql2shp -rk -f tmp/$slug-imposm/$slug.osm-waterareas_gen0.shp osm ${prefix}_waterareas_gen0
+ pgsql2shp -rk -f tmp/$slug-imposm/$slug.osm-waterareas_gen1.shp osm ${prefix}_waterareas_gen1
+ pgsql2shp -rk -f tmp/$slug-imposm/$slug.osm-waterways.shp osm ${prefix}_waterways
+
+ zip -j tmp/$slug.imposm-shapefiles.zip tmp/$slug-imposm/$slug.osm-*.shp tmp/$slug-imposm/$slug.osm-*.prj tmp/$slug-imposm/$slug.osm-*.dbf tmp/$slug-imposm/$slug.osm-*.shx
+
+ rm -r tmp/$slug-imposm
+
+ echo "DROP VIEW ${prefix}_roads" | psql osm
+ echo "DROP VIEW ${prefix}_roads_gen0" | psql osm
+ echo "DROP VIEW ${prefix}_roads_gen1" | psql osm
+ echo "DROP TABLE ${prefix}_admin" | psql osm
+ echo "DROP TABLE ${prefix}_aeroways" | psql osm
+ echo "DROP TABLE ${prefix}_amenities" | psql osm
+ echo "DROP TABLE ${prefix}_buildings" | psql osm
+ echo "DROP TABLE ${prefix}_landusages" | psql osm
+ echo "DROP TABLE ${prefix}_landusages_gen0" | psql osm
+ echo "DROP TABLE ${prefix}_landusages_gen1" | psql osm
+ echo "DROP TABLE ${prefix}_mainroads" | psql osm
+ echo "DROP TABLE ${prefix}_mainroads_gen0" | psql osm
+ echo "DROP TABLE ${prefix}_mainroads_gen1" | psql osm
+ echo "DROP TABLE ${prefix}_minorroads" | psql osm
+ echo "DROP TABLE ${prefix}_motorways" | psql osm
+ echo "DROP TABLE ${prefix}_motorways_gen0" | psql osm
+ echo "DROP TABLE ${prefix}_motorways_gen1" | psql osm
+ echo "DROP TABLE ${prefix}_places" | psql osm
+ echo "DROP TABLE ${prefix}_railways" | psql osm
+ echo "DROP TABLE ${prefix}_railways_gen0" | psql osm
+ echo "DROP TABLE ${prefix}_railways_gen1" | psql osm
+ echo "DROP TABLE ${prefix}_transport_areas" | psql osm
+ echo "DROP TABLE ${prefix}_transport_points" | psql osm
+ echo "DROP TABLE ${prefix}_waterareas" | psql osm
+ echo "DROP TABLE ${prefix}_waterareas_gen0" | psql osm
+ echo "DROP TABLE ${prefix}_waterareas_gen1" | psql osm
+ echo "DROP TABLE ${prefix}_waterways" | psql osm
+}
"""
-for offset in range(0, len(cities), 2):
- for city in cities[offset:offset+2]:
- print >> osm2pgsql, 'osm2geodata %(slug)s &' % city
+for city in cities:
+ print >> osm2pgsql, 'osm2pgsql_shapefiles %(slug)s &' % city
+ print >> osm2pgsql, 'imposm_shapefiles %(slug)s &' % city
print >> osm2pgsql, 'wait'
osm2pgsql.close()
View
8 extract.sh
@@ -20,6 +20,10 @@ pip install shapely imposm.parser imposm
PERL_MM_USE_DEFAULT=1 perl -MCPAN -e 'install Tree::R' >> install.txt 2>&1
PERL_MM_USE_DEFAULT=1 perl -MCPAN -e 'install Bit::Vector' >> install.txt 2>&1
+echo 'local all postgres ident' > /etc/postgresql/8.4/main/pg_hba.conf
+echo 'host all all 127.0.0.1/32 trust' >> /etc/postgresql/8.4/main/pg_hba.conf
+/etc/init.d/postgresql restart
+
svn co http://svn.openstreetmap.org/applications/utils/coastcheck cc >> install.txt 2>&1
cd cc
make >> install.txt 2>&1
@@ -73,9 +77,9 @@ mkdir ex
./osmosis.sh > osmosis.txt 2>&1
-# makes *.shapefiles.zip files in tmp
+# makes *-shapefiles.zip files in tmp
sudo -u postgres ./osm2pgsql.sh > osm2pgsql.txt 2>&1
-cp tmp/*.shapefiles.zip ex/
+cp tmp/*-shapefiles.zip ex/
wait
Please sign in to comment.
Something went wrong with that request. Please try again.