1

I need to extract restaurants from a planet.osm.pbf file. I assume the best way to do this is with Osmosis, however I need to save this data in my own database format. (Not something standard like Postgres or something else with existing plugins). Therefore, I need to write a Java application to do this, yet the Osmosis documentation seems very confusing to me. What I need to do is this:

Pseudocode:

while(file.hasNext("amenity=restaurant"))
{
     Amenity restaurant = this.amenity;
     String street = restaurant.street;
     String city = restaurant.city;
     String region = restaurant.region;
     String name = restaurant.name;
     String cuisine = restaurant.cuisine;
     // I do my own thing with this information here...
}

I can read the file in with FileInputStream, etc... I just don't understand how to parse and extract data specifically.

This information would be extremely valuable, allowing people to extract this type of data with ease, so they don't have to scour the internet as I did.

1 Answer 1

4

Well this question includes multiple points that I try to answer step by step:

1. Amount of data
A full planet dump is giant and will break every not well designed application. So I highly recommend to rely on existing solutions at least for filtering the full planet dump.
On the other hand I don't know your exact usecase, but I'm pretty sure that you will need updates from time to time. So maybe setup and syncing a local DB or calling an API like overpass is a wise design decision:
http://wiki.openstreetmap.org/wiki/Data

2. Parsing XML data
Parsing the data depends on fileformat as well. You can use XML of course, but most devs say it's slow compared to protobuf. You might recycle existing solutions from osmosis or JOSM:
http://wiki.openstreetmap.org/wiki/Frameworks
http://wiki.openstreetmap.org/wiki/Elements
Maybe it's easier to learn by example who already did the job, e.g. OSM2World:
https://github.com/tordanik/OSM2World

3. Undestanding XML tags
Beside the parsing, you will need to get an feeling about the use of certain tags.
Not all restaurants have a cuisine tag. Some nodes are only placed within building outlines so you might need to copy the address from shape to your POI. Also sometimes the restaurant is tagged at the building itself (here: a closed OSM way) and you might need to calculate the center (what about multipolygones? ;) for a virtual node. All in all this needs time to learn about how the community collects and tags data and you need to be patient till you will get clean results.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.