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

问题描述 投票:1回答:3

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

python shapefile matplotlib-basemap fiona
3个回答
0
投票

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


0
投票

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

我通过从头开始绘制shapefile并替换损坏的文件来解决它。有趣的是,geodjango完全读取了相同的shapefile,只有底图导致了错误。


0
投票

我刚刚使用我用Qgis创建的shapefile并且尝试在python中加载时出现此错误。我将它跟踪到正在读取属性表的mpl_toolskits.basemap库中。我没有真正调试这个,但我有一堆属性,我能够删除(因为我不再使用它们)。在我这样做之后,我能够在python中成功加载shapefile。

© www.soinside.com 2019 - 2024. All rights reserved.