立交桥API:计算围绕LAT LONS的指定类型的便利性查询

发布于 2025-01-27 17:08:30 字数 933 浏览 4 评论 0原文

我正在尝试从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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

祁梦 2025-02-03 17:08:30

通常,您可以运行OUT COUNT;以从立交通道API查询返回计数。

不知道您的数据是如何专门构建的,但是使用区域来查看特定城市或区域,这是很难说的。

这是一个示例,返回俄勒冈州波特兰的所有节点的计数:

/* charging stations in portland */
area[name="Oregon"]->.state;
area[name="Portland"]->.city;
(
  node["amenity"="charging_station"](area.state)(area.city);
);
out count;

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:

/* charging stations in portland */
area[name="Oregon"]->.state;
area[name="Portland"]->.city;
(
  node["amenity"="charging_station"](area.state)(area.city);
);
out count;
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文