• Stars
    star
    1,390
  • Rank 33,811 (Top 0.7 %)
  • Language
    C++
  • License
    GNU General Publi...
  • Created over 14 years ago
  • Updated about 1 year ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

OpenStreetMap data to PostgreSQL converter

osm2pgsql

https://osm2pgsql.org

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.

See the documentation for instructions on how to install and run osm2pgsql.

Github Actions 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
  • 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 available on macOS with Homebrew and Windows builds are also available. See https://osm2pgsql.org/doc/install.html for details.

Building

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

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

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

Required libraries are

The following libraries are included in the contrib directory. You can build with other versions of those libraries (set the EXTERNAL_*libname* option to ON) but make sure you are using a compatible version:

It also requires access to a database server running PostgreSQL 9.6+ 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++17. We officially support gcc >= 7.0 and clang >= 8.

To rebuild the included man page you'll need the pandoc tool.

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 libpotrace-dev cimg-dev \
  libbz2-dev libpq-dev libproj-dev lua5.3 liblua5.3-dev pandoc \
  nlohmann-json3-dev pyosmium

On a Fedora system, use

sudo dnf install cmake make gcc-c++ boost-devel expat-devel zlib-devel \
  potrace-devel cimg-devel json-devel python3-osmium \
  bzip2-devel postgresql-devel proj-devel proj-epsg lua-devel pandoc

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 \
  potrace-devel cimg-devel json-devel python3-osmium \
  bzip2-devel postgresql-devel proj-devel proj-epsg lua-devel pandoc

On a FreeBSD system, use

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

On Alpine, use

apk --update-cache add cmake make g++ boost-dev expat-dev \
  bzip2-dev zlib-dev libpq proj-dev lua5.3-dev postgresql-dev

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 man page can be rebuilt with:

make man

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

Note that Debug builds will be much slower than release build. For production Release or RelWithDebInfo builds are recommended.

Using the PROJ library

Osm2pgsql has builtin support for the Latlong (WGS84, EPSG:4326) and the WebMercator (EPSG:3857) projection. If you need other projections you have to compile with the PROJ library.

Both the older API (PROJ version 4) and the newer API (PROJ version 6.1 and above) are supported. Usually the CMake configuration will find a suitable version and use it automatically, but you can set the USE_PROJ_LIB CMake cache variable to choose between the following behaviours:

  • 4: Look for PROJ library with API version 4. If it is not found, stop with error.
  • 6: Look for PROJ library with API version 6. If it is not found, stop with error.
  • off: Build without PROJ library.
  • auto: Choose API 4 if available, otherwise API 6. If both are not available build without PROJ library. (This is the default.)

Using LuaJIT

To speed up Lua tag transformations, LuaJIT can be optionally enabled on supported platforms. This can speed up processing considerably.

On a Debian or Ubuntu system install the LuaJIT library:

sudo apt-get 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. The output should show something like

Lua 5.1.4 (LuaJIT 2.1.0-beta3)

Generalization

There is some experimental support for data generalization. See https://osm2pgsql.org/generalization/ for details.

Help/Support

If you have problems with osm2pgsql or want to report a bug, go to https://osm2pgsql.org/support/ .

License

This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

Contributing

We welcome contributions to osm2pgsql. See CONTRIBUTING.md and https://osm2pgsql.org/contribute/ for information on how to contribute.

More Repositories

1

iD

๐Ÿ†” The easy-to-use OpenStreetMap editor in JavaScript.
JavaScript
3,369
star
2

openstreetmap-website

The Rails application that powers OpenStreetMap
Ruby
2,188
star
3

osmosis

Osmosis is a command line Java application for processing OSM data.
Java
672
star
4

mod_tile

Renders map tiles with mapnik and serves them using apache
C++
287
star
5

merkaartor

Home of Merkaartor, an openstreetmap mapping program.
C++
280
star
6

OSM-binary

Java
193
star
7

id-tagging-schema

๐Ÿ†”๐Ÿท The presets and other tagging data used by the iD editor
JavaScript
158
star
8

mapnik-stylesheets

Mirror of the mapnik stylesheets formerly used on OpenStreetMap.org
Python
153
star
9

leaflet-osm

OpenStreetMap plugin for Leaflet
JavaScript
110
star
10

operations

OSMF Operations Working Group issue tracking
99
star
11

chef

Chef configuration management repo for configuring & maintaining the OpenStreetMap servers.
Ruby
95
star
12

tirex

Tirex tile queue manager. A drop-in replacement for renderd.
Perl
65
star
13

openstreetmap-mirror

Scripts to mirror remote repositories to http://github.com/openstreetmap
Shell
60
star
14

potlatch2

Potlatch 2 OpenStreetMap Editor
ActionScript
50
star
15

owg-website

The website for the OSMF Operations Working Group (OWG)
CSS
50
star
16

osmembrane

OSMembrane is a GUI front-end for โ€œOsmosisโ€ used by the OpenStreetMap project.
Java
42
star
17

map-icons

Mirror of the map icons used on OpenStreetMap.org
HTML
40
star
18

mkgmap

Mirror of mkgmap's Subversion repository
Java
32
star
19

tile-attribution

This repository is used for reporting and tracking sites which are using tile.openstreetmap.org tiles but without attributing OpenStreetMap. The sites are tracked in the issue tracker.
Ruby
32
star
20

osmdbt

OSM Database Replication Tools
C++
21
star
21

cgimap

Mirror of CGImap, the optimized implementation of the OpenStreetMap "/map" API call. PRs via: https://github.com/zerebubuth/openstreetmap-cgimap
C++
19
star
22

dns

OpenStreetMap DNS
JavaScript
15
star
23

gosmore

Mirror of Gosmore's Subversion repository
C++
13
star
24

stateofthemap-2019

State of the Map 2019 website
HTML
11
star
25

stateofthemap-2022

CSS
11
star
26

lane-icons

โฌ†๏ธ SVG icons for common lane markings
11
star
27

svn-archive

Archived git conversion of svn.openstreetmap.org
Java
9
star
28

stateofthemap-2020

State of the Map 2020 website
CSS
9
star
29

shp2osm

Mirror of the shp2osm Subversion repository
Python
9
star
30

osm2pgsql-website

Website for the osm2pgsql project
SCSS
8
star
31

potlatch

Mirror of Potlatch's subversion repository
ActionScript
7
star
32

gpx-updater

Retrieve new OSM GPS tracks as they are uploaded, and invalidate cached tiles
Perl
7
star
33

planetdump

Obsolete OpenStreetMap Planet Dump Generator - Replaced by https://github.com/zerebubuth/planet-dump-ng
C
6
star
34

splitter

Mirror of splitter's Subversion repository
Java
6
star
35

stateofthemap-2018

State of the Map 2018 website
HTML
6
star
36

beboj

Online OpenStreetMap editor (pre-alpha, discontinued)
Java
5
star
37

stateofthemap-website

State of the Map website resources
HTML
5
star
38

gpx-import

GPX Importer
C
4
star
39

stateofthemap-2016

State of the Map 2016
CSS
4
star
40

openstreetmap-license-change

Algorithm for OpenStreetMap ODbL transition.
Ruby
3
star
41

stateofthemap-2017

State of the Map 2017 website
HTML
3
star
42

stateofthemap-2024

State of the Map 2024 website
CSS
3
star
43

quad_tile

Native C implementation of quad_tile functions from OpenStreetMap bundled as a gem
Ruby
2
star
44

tilelog

Python
2
star
45

mediawiki-skins-osmf

OSMF Skin for MediaWiki
CSS
2
star
46

prometheus-exporters

Ruby
2
star
47

osmtaginfo

Mediawiki extension for taginfo.openstreetmap.org
PHP
2
star
48

irc-website

irc.openstreetmap.org website
HTML
2
star
49

svn-website

Minimal redirector for the svn.openstreetmap.org to the archive
Dockerfile
1
star
50

opengeodata-static

Historical OpenGeoData static content
1
star
51

hot.openstreetmap.org-website

container and builder for hot.openstreetmap.org website
Dockerfile
1
star
52

trac-website

Minimal redirector for the trac.openstreetmap.org to the archived tickets
Dockerfile
1
star
53

dmca-website

OpenStreetMap's DMCA notice website
PHP
1
star
54

stateofthemap-2021

State of the Map 2021 website
CSS
1
star