Code Monkey home page Code Monkey logo

osm2pgsql's Introduction

osm2pgsql

osm2pgsql is a tool for loading OpenStreetMap data into a PostgreSQL / PostGIS database suitable for applications like rendering into a map, geocoding with Nominatim, or general analysis.

Travis Build Status Appveyor Build status Packaging status

Features

  • Converts OSM files to a PostgreSQL DB
  • Conversion of tags to columns is configurable in the style file
  • Able to read .gz, .bz2, .pbf and .o5m files directly
  • Can apply diffs to keep the database up to date
  • Support the choice of output projection
  • Configurable table names
  • Gazetteer back-end for Nominatim
  • Support for hstore field type to store the complete set of tags in one database field if desired

Installing

Most Linux distributions include osm2pgsql. It is also available on macOS with Homebrew.

Unoffical builds for Windows are available from AppVeyor but you need to find the right build artifacts. Builds for releases may also be downloaded from the OpenStreetMap Dev server.

Building

The latest source code is available in the osm2pgsql git repository on GitHub and can be downloaded as follows:

$ git clone git://github.com/openstreetmap/osm2pgsql.git

Osm2pgsql uses the cross-platform CMake build system to configure and build itself and requires

Required libraries are

It also requires access to a database server running PostgreSQL 9.3+ and PostGIS 2.2+.

Make sure you have installed the development packages for the libraries mentioned in the requirements section and a C++ compiler which supports C++11. GCC 5 and later and Clang 3.5 and later are known to work.

First install the dependencies.

On a Debian or Ubuntu system, this can be done with:

sudo apt-get install make cmake g++ libboost-dev libboost-system-dev \
  libboost-filesystem-dev libexpat1-dev zlib1g-dev \
  libbz2-dev libpq-dev libproj-dev lua5.3 liblua5.3-dev

On a Fedora system, use

sudo dnf install cmake make gcc-c++ boost-devel expat-devel zlib-devel \
  bzip2-devel postgresql-devel proj-devel proj-epsg lua-devel

On RedHat / CentOS first run sudo yum install epel-release then install dependencies with:

sudo yum install cmake make gcc-c++ boost-devel expat-devel zlib-devel \
  bzip2-devel postgresql-devel proj-devel proj-epsg lua-devel

On a FreeBSD system, use

pkg install devel/cmake devel/boost-libs textproc/expat2 \
  databases/postgresql94-client graphics/proj lang/lua52

Once dependencies are installed, use CMake to build the Makefiles in a separate folder

mkdir build && cd build
cmake ..

If some installed dependencies are not found by CMake, more options may need to be set. Typically, setting CMAKE_PREFIX_PATH to a list of appropriate paths is sufficient.

When the Makefiles have been successfully built, compile with

make

The compiled files can be installed with

sudo make install

By default, the Release build with debug info is created and no tests are compiled. You can change that behavior by using additional options like following:

cmake .. -G "Unix Makefiles" -DCMAKE_BUILD_TYPE=Debug -DBUILD_TESTS=ON

Usage

Osm2pgsql has one program, the executable itself, which has 43 command line options.

Before loading into a database, the database must be created and the PostGIS and optional hstore extensions must be loaded. A full guide to PostgreSQL setup is beyond the scope of this readme, but with reasonably recent versions of PostgreSQL and PostGIS this can be done with

createdb gis
psql -d gis -c 'CREATE EXTENSION postgis; CREATE EXTENSION hstore;'

A basic invocation to load the data into the database gis for rendering would be

osm2pgsql --create --database gis data.osm.pbf

This will load the data from data.osm.pbf into the planet_osm_point, planet_osm_line, planet_osm_roads, and planet_osm_polygon tables.

When importing a large amount of data such as the complete planet, a typical command line would be

osm2pgsql -c -d gis --slim -C <cache size> \
  --flat-nodes <flat nodes> planet-latest.osm.pbf

where

  • <cache size> is about 75% of memory in MiB, to a maximum of about 30000. Additional RAM will not be used.
  • <flat nodes> is a location where a 36GiB+ file can be saved.

Many different data files (e.g., .pbf) can be found at planet.osm.org.

The databases from either of these commands can be used immediately by Mapnik for rendering maps with standard tools like renderd/mod_tile, TileMill, Nik4, among others. It can also be used for spatial analysis or shapefile exports.

Additional documentation is available on writing command lines.

Alternate backends

In addition to the standard pgsql backend designed for rendering there is also the gazetteer database for geocoding, principally with Nominatim, and the null backend for testing.

Also available is the new flex backend. It is much more flexible than the other backends. IT IS CURRENTLY EXPERIMENTAL AND SUBJECT TO CHANGE. The flex backend is only available if you have compiled osm2pgsql with Lua support. More details at osm2pgsql-dev#1036 .

LuaJIT support

To speed up Lua tag transformations, LuaJIT can be optionally enabled on supported platforms. Performance measurements have shown about 25% runtime reduction for a planet import, with about 40% reduction on parsing time.

On a Debian or Ubuntu system, this can be done with:

sudo apt install libluajit-5.1-dev

Configuration parameter WITH_LUAJIT=ON needs to be added to enable LuaJIT. Otherwise make and installation steps are identical to the description above.

cmake -D WITH_LUAJIT=ON ..

Use osm2pgsql --version to verify that the build includes LuaJIT support:

./osm2pgsql --version
osm2pgsql version 1.2.0

Compiled using the following library versions:
Libosmium 2.15.6
Lua 5.1.4 (LuaJIT 2.1.0-beta3)

Contributing

We welcome contributions to osm2pgsql. If you would like to report an issue, please use the issue tracker on GitHub.

More information can be found in CONTRIBUTING.md.

General queries can be sent to the tile-serving@ or dev@ mailing lists.

osm2pgsql's People

Contributors

alex85k avatar apmon avatar artemp avatar daniel-j-h avatar derdakon avatar giggls avatar gravitystorm avatar hiddewie avatar hollinger avatar imresamu avatar jburgess777 avatar jocelynj avatar joto avatar keithsharp avatar kevinkreiser avatar lonvia avatar mmd-osm avatar nakaner avatar nickw1 avatar pnorman avatar ravualhemio avatar rodo avatar schuyler avatar sebastic avatar stevec avatar styxman avatar tomhughes avatar twain47 avatar woodpeck avatar zerebubuth avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.