Question

I'm not really interested in generating tiles if I can help it. Instead, what I'm looking for is a means of getting "what is near me" kind of information, specifically bodies of water and green space, or even civil services.

If I had the map tiles, I suppose I could parse them for the colours I want, but I'm thinking that there must be a better/smarter way. Isn't is possible to get a list of objects near lat,lng that belong to categories A and B?

I'm a competent Python programmer, but am completely new to OSM. I understand that I can download a Very Large XML file and have all the data, but accessing it, especially for this sort of purpose is totally foreign to me.

I should however that I have at my disposal complete access to a PostgreSQL database complete with PostGIS in a GeoDjango setup.

Was it helpful?

Solution

Tiles are not necessary for this, generating tiles is just one possible way of using OSM data.

Do you need an online or offline solution? For an online solution you don't even need a local copy of the data. Instead you can directly fetch the data around a specific position. Instead of using the official API which is mainly for editing and not for bulk querying, just use the Overpass API which is way faster and features a complex query language.

Here is an example Overpass API query for querying all shops and parking places inside the given bounding box 50.6,7.0,50.65,7.05:

(
  node
    ["shop"]
    (50.6,7.0,50.65,7.05);
  node
    ["amenity"="parking"]
    (50.6,7.0,50.65,7.05);
  way
    ["shop"]
    (50.6,7.0,50.65,7.05);
  way
    ["amenity"="parking"]
    (50.6,7.0,50.65,7.05);
  relation
    ["shop"]
    (50.6,7.0,50.65,7.05);
  relation
    ["amenity"="parking"]
    (50.6,7.0,50.65,7.05);
);
(
  ._;
  >;
);
out;

(The result can be downloaded as either XML or JSON. You can also visualize it using overpass turbo)

In order to understand the query you have to get familiar with OSM's basic elements (nodes, ways and relations) as well as the tagging system and the most common tags.

If you need an offline solution then you better set up a local database. For an instruction you can read the serving tiles howto on switch2osm and just skip the Apache/mod_tile/mapnik steps. Importing an extract instead of the whole planet will often suffice. Live-parsing a XML file instead will be very slow except you have a very small area, say a city, and you did some filtering beforehand.

OTHER TIPS

There is a very beautiful package OSMnx by Geoff Boeing https://geoffboeing.com/tag/osmnx/ You can easily get all the amenities near you by OSM.

import osmnx as ox
import geopandas as gpd
place_name = "" (geocoding of polygon)
tags = {'amenity': 'charging_station'}
ox.geometries_from_place(place_name, tags)
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top