Friday, October 14, 2011

Using OSM data in GeoServer: Part2 - osm2pgsql

For this part we have to:

  1. get the OpenStreetMap(OSM) data that are called planet files.
  2. download the import tool osm2pgsql.
  3. import the osm data.

The OSM wiki has a page that describes how to download their data.
We choose geofrabrik. In the folder osm/europe/germany wie click on hessen.osm.bz2. This file is not to big (121 MB) for this example. Germany would take the whole day to import.


For osm2pgsql exist a compiled version to download from here.

 osm2pgsql -U postgres -W -c -s -d osm -S default.style hessen.osm.bz2  

The parameters:
-U Postgresql user name.
-W Force password prompt.
-c Remove existing data from the database.
-s Store temporary data in the database. This greatly reduce the RAM usage but is much slower. You are running this on 32bit system, so at most 3GB of RAM will be used. If you encounter unexpected exceptions during import, you should try this switch.
-d The name of the PostgreSQL database to connect.
-S Location of the style file. Defaults to /usr/share/osm2pgsql/default.style.

The import takes around 30 minutes.

Have a look in the osm-db. 5 new tables are there.
planet_osm_line
planet_osm_point
planet_osm_polygon
planet_osm_roads

In the next part I will show you how to visualize the date with GeoServer.

No comments:

Post a Comment