1

I'm trying to process a shapefile in basemap by:

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)

Although the code worked well with another shapefile, with this shapefile, I'm getting the error:

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: '***********'

I think the issue is somehow that the shapefile is maybe not clean, but I can't figure out how to solve that. Any idea? Many thanks in advance.

fahrradlaus
  • 197
  • 1
  • 3
  • 13

3 Answers3

0

Ok no worries, I just solved it with another shp file from an downloaded from an official website.

fahrradlaus
  • 197
  • 1
  • 3
  • 13
0

I had the same error. It is caused by a faulty shapefile. I tried the QGIS Goeprocessing tools "check validity" and "multiparts to singleparts". I thought I solved it in the past using these methods, but this time nothing helped.

I solved it by drawing a shapefile from scratch and replacing the corrupt one. Interestingly, the same shapefile was read by geodjango perfectly, only basemap caused the error.

MarMat
  • 790
  • 8
  • 12
0

I just had this error with a shapefile that I created with Qgis and was trying to load in python. I tracked it into the mpl_toolskits.basemap library where the attribute table was being read. I didn't really debug this any further, but I had a bunch of attributes that I was able to delete (because I wasn't using them anymore). After I did this, I was able to successfully load the shapefile in python.