Osmosis/PostGIS Setup
This is a description of Setup PostGIS in Debian / Ubuntu
Procedure to import data into PostgreSQL
A bit of set-up is required to get PostgreSQL to work with osmosis. This page describes a procedure to get it set up to import a Planet dump.
As only an outline is given, some shell and PostgreSQL knowledge is required.
Install Postgresql and PostGIS
On a recent Ubuntu system, use
sudo apt install postgis
Install and compile Osmosis
See https://wiki.openstreetmap.org/wiki/Osmosis#Downloading
On a recent Ubuntu system, use
sudo apt install osmosis
Create and Initialise Database
Create a user in PostgreSQL that bears the same username as your current Linux user (needed for peer authentication). Defining a password (-P) is required for Osmosis.
sudo -u postgres createuser -Ps $user
Then create a database (here named pgsnapshot) and enable postgis and hstore extensions on it.
createdb pgsnapshot psql -d pgsnapshot -c 'CREATE EXTENSION postgis; CREATE EXTENSION hstore;'
Run the pgsnapshot_schema_0.6.sql script to create the schema needed for importing data. On Debian-based distributions, scripts are located in /usr/share/doc/osmosis/examples/ .
psql -d pgsnapshot -f /usr/share/doc/osmosis/examples/pgsnapshot_schema_0.6.sql
When needed, and this can also be at a later stage when specific queries require this (and will report that they need it), one or more the following support scripts can also be run:
psql -d pgsnapshot -f /usr/share/doc/osmosis/examples/pgsnapshot_schema_0.6_action.sql psql -d pgsnapshot -f /usr/share/doc/osmosis/examples/pgsnapshot_schema_0.6_bbox.sql psql -d pgsnapshot -f /usr/share/doc/osmosis/examples/pgsnapshot_schema_0.6_linestring.sql
Please, see the header of each individual file for what it contributes. If you don't know what it means you can skip them.[1]
Note that you can ignore this message
psql:/usr/share/doc/osmosis/examples/pgsnapshot_schema_0.6.sql:4: NOTICE: table "actions" does not exist, skipping
Running osmosis
You can either use write pgsql or write pgsql dump. This example uses write pgsql. Replace YOUR_POSTGRESQL_PASSWORD with the password defined earlier.
osmosis --read-pbf extract.osm.pbf --log-progress --write-pgsql database=pgsnapshot password=YOUR_POSTGRESQL_PASSWORD
You may need to set up postgresql's pg_hba.conf.
For small extracts when building geometry with lots of RAM nodeLocationStoreType=InMemory can be faster.
For recent planets, InMemory takes close to 64GB of RAM.
Import/Export standard files
As PostGIS is the most reliable tool for handling shape files (shp-to-PostGIS and PostGIS-to-shape), the other commom task is to convert OSM files, that is accomplished by Osmosis, eg.
osmosis --read-apidb host="x" database="x" user="x" password="x" --write-xml file="planet.osm"
See more details at Detailed Usage / PostGIS Tasks.
See also
- A single command to install postgresql & postgis and have your OSM data ready: Osm2postgresql
- User:Lübeck/Postgis92 Win7 64bit (german)