如何在 OSM 上批量反转 lat/long

How batch reverse lat/long on OSM

我有一个 lat/long 坐标列表,需要获取每个坐标的状态。这可以用代码完成:

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

但对于我的 ~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,这是预期的。

我只需要处理一次,不介意花一整天。我通读了 OSM Acceptable Use Policy,它是:

所以..应该可以(?)

我尝试添加我的 API 密钥 (geocoder.osm([lat,lon], method='reverse', key=API_KEY)) 并在每次调用之前添加一个 time.sleep(1.1) 以确保确定,但并没有真正帮助。

想法?

Nominatim Usage Policy明确指出:

  • No heavy uses (an absolute maximum of 1 request per second).
  • Provide a valid HTTP Referer or User-Agent identifying the application (stock User-Agents as set by http libraries will not do).
  • 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).

您似乎没有将请求限制为每秒最多 1 次。此外,我不确定您是否传递了有效的 HTTP 引荐来源网址(又名用户代理)。

请注意,此使用政策仅适用于 OSM 的 public Nominatim 实例。你总是可以 install your own Nominatim service or switch to an alternative/commercial Nominatim instance.