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
1112
accept rate: 0%


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.

permanent link

answered 02 Oct '18, 21:25

maxerickson's gravatar image

maxerickson
9.9k969140
accept rate: 31%

Your answer
toggle preview

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text](http://url.com/ "title")
  • image?![alt text](/path/img.jpg "title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported

Question tags:

×151
×139
×112
×41

question asked: 02 Oct '18, 11:41

question was seen: 240 times

last updated: 02 Oct '18, 21:25

powered by OSQA