basemap readshapefile错误int()的无效文字

时间:2017-06-23 18:34:06

标签: python shapefile matplotlib-basemap fiona

我正在尝试通过以下方式处理底图中的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可能不干净,但我无法弄清楚如何解决这个问题。任何的想法?非常感谢提前。

3 个答案:

答案 0 :(得分:0)

好吧,不用担心,我刚用官方网站下载的另一个shp文件解决了这个问题。

答案 1 :(得分:0)

我有同样的错误。这是由于shapefile错误造成的。我尝试了QGIS Goeprocessing工具“检查有效性”和“多部分到单部分”。我以为我过去使用这些方法解决了问题,但是这次没有任何帮助。

我通过从头开始绘制一个shapefile并替换了损坏的文件解决了该问题。有趣的是,geodjango完美地读取了相同的shapefile,只有底图引起了错误。

答案 2 :(得分:0)

我刚用Qgis创建的shapefile遇到此错误,并试图在python中加载。我将其跟踪到正在读取属性表的mpl_toolskits.basemap库中。我没有真正进一步调试它,但是我拥有一堆能够删除的属性(因为我不再使用它们了)。完成此操作后,便能够在python中成功加载shapefile。