Archive | Code RSS for this section

OpenStreetMap data extraction

Many people have asked how they can extract data from the OpenStreetMap. Here is an example of how I got some locations I wanted out of the system.

I use PHP in my example but I geuss the method is transferrable. This solution is not the most ideal one but it gets the job done. I will update this example as I see fit to make it as good as possible. If you find a better way to do these things, please leave a comment.

The php and osm files used in this example can be found here (osm_example.rar).

There are many different sized files available at multiple sources but the ting is those files are huge so handling them requires good knowledge of the content of the file (because you can’t open it with a text editor and check it) but also massive, state-of-the-art hardware.

But since I know what I’m looking for and where to get it, I can export custom .osm file from OpenStreetMap.

First go to OpenStreetMap and hit the Export link at the top of the screen. Zoom and pan the map to select the area you want your information from. The maximum ammount of nodes the exported data can have is 50,000 so zoom close.

Select OpenStreetMap XML Data as the format you want to export and hit the Export-button. This should prompt a window where you can save the map.osm file containing the data of the selected area.

So now we have the file. Let’s jump to the .php-file. Read More…