简体   繁体   English

如何在 OSM 上批量反向经纬度

[英]How batch reverse lat/long on OSM

I have a list of lat/long coordinates and need to obtain the state for each.我有一个经纬度坐标列表,需要获取每个坐标的状态。 That can be done with the code:这可以通过代码完成:

df = pd.read_csv('SOL_A.dsv', delimiter = '|', low_memory=False)
for index, row in df.iterrows(): 
    lat = row['LAT']
    lon = row['LONG']
    g = geocoder.osm([lat,lon], method='reverse')
    st = '_UN'
    if g.state != None:
        st = g.state
    geom_states.append(st)
df['STATE'] = geom_states

But for my ~5k records it eventually starts yielding Status code 429 from https://nominatim.openstreetmap.org/search: ERROR - 429 Client Error: Too Many Requests for URL: tps://nominatim.openstreetmap.org/search?q=0.0%2C+0.0&format=jsonv2&addressdetails=1&limit=1 which is expected.但是对于我的 ~5k 记录,它最终开始Status code 429 from https://nominatim.openstreetmap.org/search: ERROR - 429 Client Error: Too Many Requests for URL: tps://nominatim.openstreetmap.org/search?q=0.0%2C+0.0&format=jsonv2&addressdetails=1&limit=1产生Status code 429 from https://nominatim.openstreetmap.org/search: ERROR - 429 Client Error: Too Many Requests for URL: tps://nominatim.openstreetmap.org/search?q=0.0%2C+0.0&format=jsonv2&addressdetails=1&limit=1这是预期的。

I only have to process this once and don't mind if it takes a whole day.我只需要处理一次,不介意是否需要一整天。 I read through the OSM Acceptable Use Policy and it goes:我通读了 OSM可接受使用政策,内容如下:

  • No heavy uses (an absolute maximum of 1 request per second).没有大量使用(绝对最大每秒 1 个请求)。
  • Provide a valid HTTP Referer or User-Agent identifying the application (stock User-Agents as set by HTTP libraries will not do).提供一个有效的 HTTP Referer 或 User-Agent 标识应用程序(由 HTTP 库设置的库存 User-Agents 不会这样做)。
  • Clearly display attribution as suitable for your medium.清楚地显示适合您的媒体的归属。
  • Data is provided under the ODbL license which requires to share alike (although small extractions are likely to be covered by fair usage / fair dealing).数据是在 ODbL 许可下提供的,该许可需要相同的共享(尽管小型提取可能会被合理使用/公平交易所涵盖)。

So.. It should be possible (?)所以..应该是可能的(?)

I tried adding my API Key ( geocoder.osm([lat,lon], method='reverse', key=API_KEY) ) and also added a time.sleep(1.1) before each call to be sure, but didn't really help.我尝试添加我的 API 密钥( geocoder.osm([lat,lon], method='reverse', key=API_KEY) )并在每次调用之前添加一个time.sleep(1.1)以确保,但并没有真正帮助。

Ideas?想法?

Nominatim Usage Policy clearly states:提名使用政策明确规定:

  • No heavy uses (an absolute maximum of 1 request per second ).没有大量使用(绝对最大每秒 1 个请求)。
  • Provide a valid HTTP Referer or User-Agent identifying the application (stock User-Agents as set by http libraries will not do).提供一个有效的HTTP RefererUser-Agent标识应用程序(由 http 库设置的库存 User-Agents 不会这样做)。
  • Clearly display attribution as suitable for your medium.清楚地显示适合您的媒体的归属。
  • Data is provided under the ODbL license which requires to share alike (although small extractions are likely to be covered by fair usage / fair dealing).数据是在ODbL许可下提供的,该许可需要相同的共享(尽管小型提取可能会被合理使用/公平交易所涵盖)。

Looks like you don't limit your requests to a maximum of 1 per second.看起来您没有将请求限制为每秒最多 1 个。 Also I'm not sure if you pass a valid HTTP referer (aka user-agent).另外,我不确定您是否传递了有效的 HTTP 引用程序(又名用户代理)。

Note that this usage policy only applies to OSM's public Nominatim instance.请注意,此使用策略仅适用于 OSM 的公共 Nominatim 实例。 You can always install your own Nominatim service or switch to an alternative/commercial Nominatim instance .您始终可以安装自己的 Nominatim 服务或切换到替代/商业 Nominatim 实例

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM