关于python:使用geopandas和geopy进行地理编码错误

Geocoding error with geopandas and geopy

根据geopandas文档,我试图对字符串列表进行geocode,但我得到了一个错误。

我的环境

1
2
3
4
5
6
7
8
9
10
11
12
13
import geopandas as gdp
from geopandas.geocode import geocode
import geopy
import sys

print(sys.version)
print (gdp.__version__)
print (geopy.__version__)

3.4.3 |Anaconda 2.2.0 (x86_64)| (default, Mar  6 2015, 12:07:41)
[GCC 4.2.1 (Apple Inc. build 5577)]
0.1.1
1.10.0

我正在努力

1
geocode(['boston, ma', '1600 pennsylvania ave. washington, dc'])

我得到以下错误

1
2
3
4
5
6
7
8
9
10
11
12
AttributeError                            Traceback (most recent call last)
<ipython-input-77-d7e5e2fb2b1d> in <module>()
----> 1 geocode(['boston, ma', '1600 pennsylvania ave. washington, dc'])

/Users/tbmh1/anaconda/envs/devData34/lib/python3.4/site-packages/geopandas-0.1.1-py3.4.egg/geopandas/geocode.py in geocode(strings, provider, **kwargs)
     70               'bing': geopy.geocoders.Bing,
     71               'yahoo': Yahoo,
---> 72               'mapquest': geopy.geocoders.MapQuest,
     73               'openmapquest': geopy.geocoders.OpenMapQuest,
     74               'nominatim' : geopy.geocoders.Nominatim}

AttributeError: 'module' object has no attribute 'MapQuest'

当文档说Googlev3是默认的提供者时,我不知道它为什么要尝试执行mapquest。我在python 2.7中得到同样的错误


不管它是否使用MapQuest,geopandas都不能建立字典,除非这个名字存在。Geopy在此提交中删除了该编码器:

MapQuest geocoder removed as the API it uses is now only available to
enterprise accounts. OpenMapQuest is a replacement for
Nominatim-sourced data.

同时,您可以通过将名称绑定到其他内容来解决此问题,因此字典至少可以工作:

1
2
3
4
5
6
7
8
9
>>> geopy.geocoders.MapQuest = None
>>> geocode(['boston, ma', '1600 pennsylvania ave. washington, dc'])
                                             address  \
0                                    Boston, MA, USA  
1  1600 Pennsylvania Avenue Southeast, Washington...  

                         geometry  
0  POINT (-71.0588801 42.3600825)  
1  POINT (-76.9816788 38.8786589)