Osm2pgsql: Difference between revisions

From OpenStreetMap Wiki
Jump to navigation Jump to search
(→‎Windows: osm2pgsql.zip has been updated)
(Elaborate on --slim mode)
Line 3: Line 3:
osm2pgsql is a lossy conversion utility. It only adds features that have certain tags, as defined in the config file, and it converts nodes and ways to linestrings and polygons. This means that you can't tell which linestring is connected to which, but for rendering a map that's not important (c.f. routing).
osm2pgsql is a lossy conversion utility. It only adds features that have certain tags, as defined in the config file, and it converts nodes and ways to linestrings and polygons. This means that you can't tell which linestring is connected to which, but for rendering a map that's not important (c.f. routing).


osm2pgsql has two main modes of running - normal (is this what it's called?) and slim mode. The first uses RAM for intermediate storage, the second uses object tracking tables (planet_osm_nodes, planet_osm_ways and planet_osm_rels) in the database on-disk. As of early 2009, you must use slim-mode for planet imports on 32-bit systems, since there are too many nodes to store in RAM otherwise. This limitation doesn't apply to 64-bit systems.
osm2pgsql has two main modes of running: ''default'' and ''slim'' mode. The first uses RAM for intermediate storage, the second uses object tracking tables (planet_osm_nodes, planet_osm_ways and planet_osm_rels) in the database on-disk. As of early 2009, you must use slim-mode for planet imports on 32-bit systems, since there are too many nodes to store in RAM otherwise. This limitation doesn't apply to 64-bit systems.


Incremental updates (planet diffs) work in slim mode only (including initial load to populate the track tables).
Incremental updates (planet diffs) work '''in slim mode only''' (including initial load to populate the track tables). A lot of database indexes will also only be created in slim mode which will make your database larger (but queries & rendering will be faster), see [http://lists.openstreetmap.org/pipermail/dev/2009-July/016059.html this mailing list post].


You can either build osm2pgsql from scratch, or grab the existing Linux packages.
You can either build osm2pgsql from scratch, or grab the existing Linux packages.

Revision as of 09:15, 21 July 2009

osm2pgsql is a utility program that converts OpenStreetMap (.OSM) data into a format that can be loaded into PostgreSQL. It is often used to render OSM data visually using Mapnik, as Mapnik can query PostgreSQL for map data, but does not work directly with OSM files. For more information on using osm2pgsql to render OpenStreetMap data with Mapnik, see the Mapnik page.

osm2pgsql is a lossy conversion utility. It only adds features that have certain tags, as defined in the config file, and it converts nodes and ways to linestrings and polygons. This means that you can't tell which linestring is connected to which, but for rendering a map that's not important (c.f. routing).

osm2pgsql has two main modes of running: default and slim mode. The first uses RAM for intermediate storage, the second uses object tracking tables (planet_osm_nodes, planet_osm_ways and planet_osm_rels) in the database on-disk. As of early 2009, you must use slim-mode for planet imports on 32-bit systems, since there are too many nodes to store in RAM otherwise. This limitation doesn't apply to 64-bit systems.

Incremental updates (planet diffs) work in slim mode only (including initial load to populate the track tables). A lot of database indexes will also only be created in slim mode which will make your database larger (but queries & rendering will be faster), see this mailing list post.

You can either build osm2pgsql from scratch, or grab the existing Linux packages.

Installation

From source
$ svn co http://svn.openstreetmap.org/applications/utils/export/osm2pgsql/ 
$ cd osm2pgsql
$ make

When compiling under Ubuntu, you will need the following dependencies:

$ sudo apt-get install build-essential libxml2-dev libgeos-dev libpq-dev libbz2-dev proj

If using an old version of gcc then you may get an error: unrecognized option `-Wextra'. In this case simply amend the Makefile to remove this unnecessary option.

For Debian Etch

Configure your system with access to the backports.org repository (see http://www.backports.org/).

# apt-get update
# apt-get install osm2pgsql

Feel free to contact dom@earth.li with questions about these packages.

Be warned: the packages might be old. If you see rendering artifacts, try compiling osm2pgsql from source.

For Debian Lenny (stable) or Sid (unstable) or ubuntu (8.04 or later)

osm2pgsql is already packaged so you can just install it!

aptitude install osm2pgsql

Be warned: the packages might be old. If you see rendering artifacts, try compiling osm2pgsql from source.

Fedora

Fetch the dependencies

yum install geos-devel proj-devel postgresql-devel libxml2-devel bzip2-devel gcc-c++

Follow "From source" instructions

openSUSE 11.0

You've to add a community package repository:

http://download.opensuse.org/repositories/Application:/Geo/openSUSE_11.0

The fetch the dependencies

libgeos-devel libproj-devel postgresql-devel libxml2-devel libbzip2-devel gcc-c++

Follow "From source" instructions

openSUSE 11.1

You've to add a community package repository:

http://download.opensuse.org/repositories/Application:/Geo/openSUSE_11.1

The fetch the dependencies

libgeos-devel libproj-devel postgresql-devel libxml2-devel libbz2-devel gcc-c++

Follow "From source" instructions

Arch Linux

Download the PKGBUILD tar.gz from here:

http://aur.archlinux.org/packages.php?ID=22107
Windows

You can find a fairly uptodate version from July 10, 2009 for Windows here:

http://tile.openstreetmap.org/osm2pgsql.zip

Just unzip, add directory to your path and run. The version from http://artem.dev.openstreetmap.org/files/ is a bit out-of-date (no relations import)

Mac OSX with MacPorts

The only catch to installing on Mac OSX with MacPorts is the fact that the default Postgres 8.3 installation doesn't install pg_config in the shell, so the call to pg_config --includedir and pg_config --libdir fails. Therefore, either change these paths in the Makefile or add pg_config to your shell via .bashrc, etc. For reference, an installation of 8.3 usually places the binary file at

/opt/local/lib/postgresql83/bin/pg_config

see also

Osmosis - can also do import of osm file to postgre DB with postgis extension