Osmosis/PostGIS Setup

From OpenStreetMap Wiki
< Osmosis(Redirected from Osmosis PostGIS Setup)
Jump to navigation Jump to search

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 postgresql-9.4-postgis-2.1 openjdk-7-jre-headless

Any version 9.1/2.0 or later should work.

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

sudo -u postgres createuser -s your_username
createdb pgsnapshot
psql -d pgsnapshot 'CREATE EXTENSION postgis; CREATE EXTENSION hstore;'

Run the script

psql -d pgsnapshot -f osmosis_dir/script/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 osmosis_dir/script/pgsnapshot_schema_0.6_action.sql
psql -d pgsnapshot -f osmosis_dir/script/pgsnapshot_schema_0.6_bbox.sql
psql -d pgsnapshot -f osmosis_dir/script/pgsnapshot_schema_0.6_linestring.sql

Please, see the header of each individual file for what it contributes. If you don't know what is 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

osmosis --read-pbf extract.osm.pbf --log-progress --write-pgsql database=pgsnapshot 

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