首页 > 解决方案 > 如何在没有外部 API 的情况下通过坐标获取国家名称?

问题描述

我在寻找什么?

我正在寻找一个带有方法/模块的python库,该方法/模块无需连接到外部API即可获取坐标并返回国家名称

为什么?

我有一个带有很多行(更多 10000 行)的 pandas df,我不想为每一行发送请求。

这就是我现在正在做的事情:

from geopy.geocoders import ArcGIS
...
...
...

geolocator = ArcGIS(scheme='http')

    for index, row in df.iterrows():

        if math.isnan(row['latitude']) or math.isnan(row['longitude']):
            continue
        else:
            try:
                location = geolocator.reverse((row['latitude'], row['longitude']), timeout=30)
                # takes the country
                location = str(location)
                if len(location.split(",")) == 4:
                    country = location.split(",")[3][1:]
                    df.at[index, 'country'] = country

如果可以为所有行发送一个请求,它仍然可以

标签: pythonpandasgeogeopy

解决方案


似乎没有现成的库,但在没有外部 API 的情况下,一种可能的解决方案是:


推荐阅读