May 252013
 
Article MySQL

The “osmosis” tool can be used to import an XML OpenStreetMap dump file into a MySQL database, but the structure of the database needs to be created beforehand.

Create the database and the tables

To do it, download the zip file  osm_createdb.zip that contains a osm_createdb.sql script with the SQL sentences that create the OSM tables. Once uncompressed, execute the script:

$ mysql -u root -p < osm_createdb.sql

The script creates a database named ‘osm’, and inside this database create the tables ‘changesets’, ‘relations’, ‘ways’, ‘nodes’, etc… that will contain the different elements that are part of the OSM data.

Import the OSM file

To do the import, download the osmosis tool (written in Java).

The following example shows the command to import into the database the file “planet.osm.bz2”:

bunzip2 -c planet.osm.bz2 | osmosis/bin/osmosis --rx /dev/stdin \
                   enableDateParsing=no --buffer --write-apidb dbType="mysql" \
                   database=osm user=USUARIO password=PASSWORD validateSchemaVersion=no

 Posted by at 8:46 pm

 Leave a Reply

(required)

(required)