0

I downloaded .osm file from openstreetmap, map of our place, my question is how can i import this data to my mysql database?

user3027366
  • 1
  • 1
  • 1
  • Is there any particular reason why you have to use MySQL instead of PostgreSQL? PostgreSQL with PostGIS is far better suited. See [switch2osm](http://switch2osm.org/serving-tiles/manually-building-a-tile-server/) for detailed instructions. – scai Nov 24 '13 at 15:47
  • This question is a duplicate of http://stackoverflow.com/questions/20125242/import-openstreetmap-data-osm-file-to-a-mysql-database-sql-file - please close – Dan Stowell Nov 25 '13 at 12:23

2 Answers2

2

When I was implementing such functionality - I user Osmosis tool to convert database to XML file. http://wiki.openstreetmap.org/wiki/Osmosis . Than I created my own tool to parse the file and insert to records to database. The structure was similar to OSM primitives http://wiki.openstreetmap.org/wiki/Elements .

As a result I got a very huge mysql database. And also I had to create difficult queries to retrieve data.

My advice is NOT TO USE MySQL to store this data. MySQL - is a very bad solution to store such kind of data. PostgreSQL - is better. You can use Osmosis tool to generate the database quickly.

If you need to get map data only - you can use http://overpass-api.de/ service. It works perfectly.

Mykyta Karpyshyn
  • 198
  • 2
  • 13
0

You can use - ogr2ogr in GDAL (http://www.gdal.org/ogr2ogr.html)

Here's an example:

ogr2ogr -F MySQL MySQL:osm_data,host=localhost,user=root,password=mypass -nln test -nlt MULTIPOLYGON -update -overwrite -lco engine=InnoDB -lco MYSQL_FID=ogr_fid -lco cp1252 path\to\file.shp -skipfailures
codejunkie
  • 908
  • 2
  • 21
  • 34