Convert osm2shp using OSMLibrary on Ubuntu

From OpenStreetMap

Jump to: navigation, search

Ruby OSM Library

The OSM Library is based on Ruby modules and classes developed by Jochen Topf, which are all released under Public Domain. Its rather new so its only available at Beta-Version at this time but it works fine. Because of the unstable release its intended to know that this Library aims only to Developers. It allows us to export OSM-data to most common GIS-Formats like Shapefile (shp), Google Earth (kml), comma separated values (csv) and preliminary gpx (GPS-Exchange Format).


Installation on Ubuntu

To get in touch with the functionality of the Ruby OSM Library, you've got to install the Ruby Developer Version and some other Libraries listed below. An essential part of the Ruby core (mkmf.rb, listet in the Ruby Standard Library is missing in the default installation of Ruby 1.8 on Ubuntu 7.04, because the full methods and classes of ruby are only available in the developer packages. Therefore its necessary to install these packages first from the universal repositories (have a look at your /etc/apt/sources.list) to get the libxml-ruby library run correctly. Its important for XML-Parsing the OSM Data. The required commands are:

sudo apt-get install ruby1.8-dev
sudo apt-get install libxml2-dev

Additionally we need rubygems, which is the package management system under ruby like adept under Ubuntu. So install it with

sudo apt-get install rubygems

if not already done. Its important to use the gem manager (command: 'gem install') because there's no guarantee that everything works properly when you use the apt manager to install the last hinging libraries libxml-ruby, GeoRuby (for Spatial Support), builder (for KML-Export) and osmlib-base (for basic OSM-data model support).

sudo gem install libxml-ruby
sudo gem install GeoRuby
sudo gem install builder
sudo gem install osmlib-base

Finally we can install and use the OSM Library.

sudo gem install osmlib-export

There is an executable File called 'osmexport' in /var/lib/gems/1.8/bin, which control the conversion process and this File should be globally referenced in PATH of Ubuntu to allow the access at any directory. To do this just add

PATH=${PATH}:/var/lib/gems/1.8/bin
export PATH

to the end of File ~/.bashrc, while ~ allocates to your home directory and .bashrc is hidden.


Conversion into Shapefile

Before you can start the conversion you've to specify, which kind of Information you're interested in. This is done by a Rulefile in Ruby Syntax. Please make yourself familiar with the OSM Library Documentation for further details. There's also a setup section for export notes into Shapefile.

Personal tools
recent changes