tecznotes
Michal Migurski's notebook, listening post, and soapbox. Subscribe to this blog. Check out the rest of my site as well.
Aug 13, 2015 6:15am
the other openstreetmap churches post
Scott Murray wrote the other day asking about getting Church data out of OpenStreetMap:
What is the easiest way to extract a list of a specific type of features from OSM for a particular area? For example, say I want all of the churches ( feature type: building / church ) in London, and the name, lat, and lon for each. Ideally all of this would end up in a simple CSV. This would be a one-time extract, and I don’t need to update it again later.
It was a pretty quick process, so I wrote it up for him and asked his permission to re-post here. I figured others might run into the same need. Today, Steven Vance in Chicago posted a response to a near-identical question with a different approach. There are many ways to skin this cat, and possibly not enough guides on this kind of retail data extraction from OpenStreetMap.
This is what I sent to Scott:
Since you’re asking for a major urban area, I would expect that London is part of the Mapzen metro extracts.
I downloaded a copy of the London OSM2PGSQL SHP data, because I know that it tends to be a closer (and often messier) representation of what’s in the OSM source database. If I was looking for roads or something else that I felt confident was already a defined and separate layer, I would download the IMPOSM SHP data. If I was looking for something outside a covered city, then I’d need to go digging in the Planet and I would be sad (edit: I’d follow Steven’s advice).
Next I looked on the OSM wiki to see how churches are tagged. The suggested tag is amenity = place_of_worship.
Then I used ogr2ogr, a tool in the GDAL family, to quickly peel out all the tag matches. I could do this interactively in QGIS as well, but I find the command line to be a speedier way to get what I want. ogr2ogr can be a pain in the butt to install, but I’ve found that it’s something of a secret hidden easter egg in Postgres.app, so if you install that you can find ogr2ogr hidden inside.
Here’s the conversion to get the OSM ID and the name for all places of worship:
ogr2ogr \ -select 'osm_id, name' \ -where "amenity = 'place_of_worship’” \ london_england_osm_point-amenity-place_of_worship.shp \ london_england_osm_point.shp
At this point I opened the shapefile in QGIS to see what’s there, and saw this this:
That looks right, so I convert it to a CSV preserving the geometry in (Y, X) fields, also using ogr2ogr:
ogr2ogr \ -f CSV -lco GEOMETRY=AS_YX \ london_england_osm_point-amenity-place_of_worship.csv \ london_england_osm_point-amenity-place_of_worship.shp