立交桥API:计算围绕LAT LONS的指定类型的便利性查询
我正在尝试从OSM立交桥API查询数据。具体来说,我试图确定一个给定类型的设施的计数(使用“围绕”语法)。在为许多位置(LAT,LONS)运行此操作时,我会遇到ToomanyRequests错误。
我试图通过设置睡眠时间停顿并使用超时标题和重试时间来解决,但我遇到了同一问题。我正在尝试找到一种调整查询的方法,以便它只是在每个点附近返回(指定类型的)便利设施,而不是更密集的数据的完整节点。我当前的脚本如下;
# Running Overpass query for each point
results = {}
for n in range(0, 200):
name = df.loc[n]['city']
state = df.loc[n]['state_name']
rad = df.loc[n]['radius_m']
lat = df.loc[n]['lat']
lon = df.loc[n]['lng']
# Overpass query for amenities
start_time = time.time()
api = overpy.Overpass(max_retry_count=None, retry_timeout=2)
r = api.query(f"""
[out:json][timeout:180];
(node["amenity"="charging_station"](around:{rad}, {lat}, {lon});
);
out;
""")
print("query time for "+str(name)+", number "+str(n)+" = "+str(time.time() - start_time))
results[name] = len(r.nodes)
time.sleep(2)
任何帮助其他立交桥用户都非常感谢!
谢谢
I'm trying to query data from the OSM Overpass API. Specifically I'm trying to determine the count of amenities of a given type around a point (using the 'around' syntax). When running this for many locations (lat, lons) I'm running into a TooManyRequests error.
I have tried to work around by setting sleep time pauses and playing with the timeout header and retry time, but I'm running into the same issue. I'm trying to find a way to adapt the query so that it just returns the count of amenities (of specified type) around each point, rather than the full json of nodes which is more data intensive. My current script is as follows;
# Running Overpass query for each point
results = {}
for n in range(0, 200):
name = df.loc[n]['city']
state = df.loc[n]['state_name']
rad = df.loc[n]['radius_m']
lat = df.loc[n]['lat']
lon = df.loc[n]['lng']
# Overpass query for amenities
start_time = time.time()
api = overpy.Overpass(max_retry_count=None, retry_timeout=2)
r = api.query(f"""
[out:json][timeout:180];
(node["amenity"="charging_station"](around:{rad}, {lat}, {lon});
);
out;
""")
print("query time for "+str(name)+", number "+str(n)+" = "+str(time.time() - start_time))
results[name] = len(r.nodes)
time.sleep(2)
Any help is much appreciated from other Overpass users!
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
通常,您可以运行
OUT COUNT;
以从立交通道API查询返回计数。不知道您的数据是如何专门构建的,但是使用
区域
来查看特定城市或区域,这是很难说的。这是一个示例,返回俄勒冈州波特兰的所有节点的计数:
In general, you can run
out count;
to return a count from an overpass API query.It's hard to say without knowing how your data is specifically structured, but you might have better luck using
area
to look at specific cities, or regions.Here is an example that returns the count of all nodes tagged as charging station in Portland, Oregon: