This is a static archive of our old OpenStreetMap Help Site. Please post any new questions and answers at community.osm.org.

How to count POI nodes around specific area using Python?

0

Hi, OSM crew. I'm newbie here. I try to count each POI nodes around specific GPS coordinates. This is my code for loading node around specific lat and lon using Python

overpass_url = "http://overpass-api.de/api/interpreter"
overpass_query = """
[out:json][timeout:25];
(
node(around:60.0,13.74567157,100.53371655);
);
out body;
    """
response = requests.get(overpass_url,
                        params={'data': overpass_query})
data = response.json()

From this code, I get every nodes around that specific area. But I have more than 50,000 place to find. I want to know how can I use some variables instead of typing every coordinates in my code.

Moreover, I just want to count every POI node separated by its amenity tag such as 'drinking_water' or 'cafe' but I can't find tag index in data

Thanks for any help.

asked 02 Oct '18, 11:41

Krawan's gravatar image

Krawan
11223
accept rate: 0%


One Answer:

1

Your current query is for all nodes, so most of them don't have tags. You probably want to restrict that a bit.

Something like this will only return nodes with an amenity tag or a tourism tag (they don't have to have both):

(
node(around:60.0,13.74567157,100.53371655)[amenity];
node(around:60.0,13.74567157,100.53371655)[tourism];
);

Generating the query is more a python question, there's lots of ways to do string substitution over there. In Python 3 I tend to use format strings anymore, so you could replace the coordinates in your query with some variables:

...
node(around:60.0,{lat},{lon});
...

Then you'd substitute in the values:

filled_query=overpass_query.format(lat="13.74567157",lon="100.53371655")

You might also consider using the nwr query operator (along with out center;) instead of node . Then your results will include POIs that are modeled as ways or relations instead of as nodes.

answered 02 Oct '18, 21:25

maxerickson's gravatar image

maxerickson
12.7k1083176
accept rate: 32%

Source code available on GitHub .