Domanda

So I am trying to read a shapefile in python for display in matplotlib basemap. I keep getting an error

ValueError: invalid literal for int() with base 10: '*'

From what I have read, it seems that the error is associated with some null values in some fields of the dbf file. I was wondering if there is any fix for this or any alternative way to resolve this problem?

I can't seem to send shapefiles to matplotlib or mpl_toolkits without using Basemap, but basemap keeps giving me these errors.

Here is some sample code.

from mpl_toolkits.basemap import Basemap
import matplotlib.pyplot as plt
fig = plt.figure(figsize=(12, 12))
map = Basemap(projection='lcc', resolution='h', area_thresh=None,
          lat_0=33.5130, lon_0=36.2920, llcrnrlon=36, llcrnrlat=33.2,
          urcrnrlon=36.5, urcrnrlat=33.7)
map.readshapefile('dmc_buildings', 'buildings', drawbounds=True)
fig.show()

The error trace looks like this.

Traceback (most recent call last):
File "dmc_gis_basemap.py", line 17, in <module>
map.readshapefile('dmc_roads', 'roads', drawbounds=True)
File "../anaconda/envs/py27env/lib/python2.7/site-packages/mpl_toolkits/basemap  /__init__.py", line 2146, in readshapefile
for shprec in shf.shapeRecords():
File "../anaconda/envs/py27env/lib/python2.7/site-packages/mpl_toolkits/basemap/shapefile.py", line 543, in shapeRecords
for rec in zip(self.shapes(), self.records())]
File "../anaconda/envs/py27env/lib/python2.7/site-packages/mpl_toolkits/basemap/shapefile.py", line 515, in records
r = self.__record()
File "../anaconda/envs/py27env/lib/python2.7/site-packages/mpl_toolkits/basemap/shapefile.py", line 480, in __record
value = int(value)
ValueError: invalid literal for int() with base 10: '***'

Nessuna soluzione corretta

Altri suggerimenti

I would recommend using a real python tool meant for shapefiles. Take a look at Fiona https://pypi.python.org/pypi/Fiona and Shapely https://pypi.python.org/pypi/Shapely

This blog post I wrote links to some examples using Fiona and Shapely https://www.openshift.com/blogs/using-open-source-gis-tools-for-spatial-data-qgis-gdal-python

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top