Import OSM data into PostGIS using Osmosis

This blog post is made as a “note-to-self” so that I can remember the procedure. You are of course welcome to read along. It’s does nothing fancy, simply imports the planet.osm file into PostGIS using Osmosis with the Snapshot Schema.

Step by step

Assuming Osmosis is installed (if not download osmosis), and a planet.osm file has been download.

Create database

Update: there is a new way to enable PostGIS and hstore on database, namely ‘create extension postgis’ and ‘create extension hstore’.

My traditional way:

createdb osm
createlang plpgsql osm
# locate hstore.sql
psql -d osm -f /PATH/TO/hstore.sql
# locate postgis.sql
psql -d osm -f /PATH/TO/postgis.sql

New way:

create extension postgis;
create extension hstore;

Create schema

SQL-script files located in Osmosis script directory. Here we’re using the “snapshot schema” (the “simple schema” is another way to go):

psql -d osm -f pgsnapshot_schema_0.6.sql
psql -d osm -f pgsnapshot_load_0.6.sql
psql -d osm -f pgsnapshot_schema_0.6_action.sql
psql -d osm -f pgsnapshot_schema_0.6_bbox.sql
psql -d osm -f pgsnapshot_schema_0.6_linestring.sql

Import data

(if you use the “simple schema”, use --write-pgsimp instead of --write-pgsql):

osmosis \
--read-xml file="planet.osm" \
--write-pgsql host="localhost" database="osm" user="x" password='x'

Wait… (between a couple of minutes and a couple of days, depending on size of planet.osm)

Comments

2 responses to “Import OSM data into PostGIS using Osmosis”

  1. […] written another blog post that uses Osmosis to import OSM data into a PostGIS enabled database: Import OSM data into PostGIS using Osmosis | skipperkongen.dk Hope that helps. I vaguely remember that there is an option to osm2pgsql to give the name of the […]

  2. Ram Shrestha Avatar
    Ram Shrestha

    I tried these steps but i get error:

    Task type write-pgsimp doesn’t exist.

    can you help me?

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.