我正在尝试通过以下方式处理底图中的 shapefile:
shp = fiona.open('Wien_test2.shp')
bds = shp.bounds
shp.close()
extra = 0.01
ll = (float(bds[0]), float(bds[1]))
ur = (float(bds[2]), float(bds[3]))
coords = list(chain(ll, ur))
w, h = coords[2] - coords[0], coords[3] - coords[1]
m = Basemap(
projection='tmerc',
lon_0=16.,
lat_0=48.,
ellps = 'WGS84',
llcrnrlon=coords[0] - extra * w,
llcrnrlat=coords[1] - extra + 0.01 * h,
urcrnrlon=coords[2] + extra * w,
urcrnrlat=coords[3] + extra + 0.01 * h,
lat_ts=0,
resolution='i',
suppress_ticks=True)
m.readshapefile(
'Wien_test2',
'Wien_test2',
color='none',
zorder=2)
虽然代码与另一个 shapefile 配合得很好,但使用这个 shapefile,我得到了错误:
Traceback (most recent call last):
File "maps.py", line 104, in <module>
zorder=2)
File "/usr/lib/python2.7/dist-packages/mpl_toolkits/basemap/__init__.py", line 2146, in readshapefile
for shprec in shf.shapeRecords():
File "/usr/lib/python2.7/dist-packages/mpl_toolkits/basemap/shapefile.py", line 543, in shapeRecords
for rec in zip(self.shapes(), self.records())]
File "/usr/lib/python2.7/dist-packages/mpl_toolkits/basemap/shapefile.py", line 515, in records
r = self.__record()
File "/usr/lib/python2.7/dist-packages/mpl_toolkits/basemap/shapefile.py", line 480, in __record
value = int(value)
ValueError: invalid literal for int() with base 10: '***********'
我认为问题在于shapefile可能不干净,但我不知道如何解决这个问题。任何想法?提前谢谢了。