Osmosis/PostGIS Setup

From OpenStreetMap Wiki
Jump to: navigation, search
Available languages — Osmosis/PostGIS Setup
English

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;

Load the scripts

psql -d pgsnapshot -f osmosis_dir/script/pgsnapshot_schema_0.6.sql
psql -d pgsnapshot -f osmosis_dir/script/pgsnapshot_schema_0.6_linestring

(don't run linestring if you don't want linestrings)

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.

See also