2

I downloaded a full XML dump. While there are lots of nodes and ways, I want to filter out only the human-relevant data.

By human-relevant, I mean neighborhoods, restaurants and landmarks are prefered over telephone poles, junctions, survey artifacts etc which are included in the full result set.

For example, the nominatim.openstreetmap.org/reverse service returns homes and other human-relevant places for a given (lat,lon) coordinates, while a dataset may return ways, relationships or irrelevant data.

What is the right criteria for filtering human-relevant nodes from the XML? My best guess is to filter out only nodes and to check if they have attributes with addr: prefixes

1
  • 1
    You will have look at the data and tags to determine what attributes/values can be used to discriminate the data you are interested in. Commented Jul 6, 2012 at 12:39

3 Answers 3

4

If you haven't done so already you should take a look at the OSM features page. The OSM Features Page will help you decide which features to filter based on which tags you determine to be human relevant. That should get you started thinking about the query you will use to pull out the data. If you get stuck the OSM mailing lists are also a good resource. Good luck!

3

I think it would be much easier to import OSM dump into the PostgreSQL database. You can do it with OSMOSIS. Look at this link for further details. It is much easier to work with data in the database with SQL than filtering osm file.

2
  • Agreed. But even then, how do I filter such locations? Commented Jul 6, 2012 at 9:16
  • with imported osm dump into postgres db, every node, every way, every relation has a geometry field. Using PostGIS spatial function, you could create SQL queries that would return almost anything you need for some location. The example you gave, should be quite trivial to do with PostGIS functions. Example: select * from nodes where tags->'amenity'= 'restaurant' and st_dwithin(geom, ST_SetSRID(ST_Point(15.977082,45.809987),4326), 0.03) Do a internet search for more PostGIS examples. Commented Jul 6, 2012 at 10:29
0

Besides importing everything into a postgis db and then filtering through SQL queries there's a couple different tools to do this specifically with OSM data where you can input an osm file and select what you want to keep or ignore, and have .osm as an ouput.

As for your suggestion about filtering out everything except Addr: , you will miss out on a lot of amenities (e.g. restaurants, schools, etc) that you'd would probably want to keep because they do not have an address.

Osmosis is the tool that you're looking for.

Osmosis has a couple important /filters that you'll need:

  • --node-key-value (--nkv)

  • --node-key (--nk)

  • --way-key-value (--wkv)
  • --way-key (--wk)
  • --tag-filter (--tf)

You can learn how to use the first four filters that I mentioned above at the detailed usage page of osmosis on the OSM wiki,

As mentioned, go through the map features page linked above and find out which tags that you want to keep.

For example: you'll likely want to keep all objects that have the key amenity or highway, so you would issue:

osmosis --read-xml file="input.osm" --way-key keyList="highway,amenity" --used-node --write-xml file="output.osm"

However, some tags (like amenity) are both used as nodes and ways, so you'll have to run this again, using --node-key.

If you end up with multiple files after filtering, you can then merge them together.

It's been a couple months since I last used osmosis, so as I write this I'm thinking you maybe able to just run -tf once instead of using --node-key and --way-key, but I am NOT sure and didn't test this.

For example:

osmosis \
  --read-xml input.osm \
  --tf accept-ways highway=* \ 
   -tf accept-nodes amenity=* \ 
   -tf accept-ways amenity=* \ 
  --tf reject-ways amenity=graveyard \
  --tf reject-nodes amenity=graveyard,fire_hydrant \
  --tf reject-relations \
  --used-node \
  --write-xml output.osm

Also, check out the wiki and TAGINFO to see what tags are often used.

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.