如何将 latitude/longitude 映射到特定的美国县?

how to map latitude/longitude to a specific US county?

我有一个包含 U.S 的数据框。 latitudelongitude 坐标。

我想创建一个显示相应 U.S 的变量。包含这些坐标的县。

我如何在 R/Python 中做到这一点?

谢谢!

你可以使用 geopy.

文档中使用 Nominatim(开放街道地图)的示例:

>>> from geopy.geocoders import Nominatim
>>> geolocator = Nominatim(user_agent="http")
>>> location = geolocator.reverse("52.509669, 13.376294")
>>> print(location.address)
Potsdamer Platz, Mitte, Berlin, 10117, Deutschland, European Union
>>> print((location.latitude, location.longitude))
(52.5094982, 13.3765983)
>>> print(location.raw)
{'place_id': '654513', 'osm_type': 'node', ...}

原始输出有一个字典键 country,如果可以找到的话。