gpt4 book ai didi

python - 在读取 shapefile 时从 dbf 文件中删除空值以解决 Matplotlib Basemap 中的错误

转载 作者:行者123 更新时间:2023-11-28 19:22:24 25 4
gpt4 key购买 nike

所以我试图在 python 中读取一个 shapefile 以在 matplotlib basemap 中显示。我一直收到错误

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

根据我的阅读,该错误似乎与 dbf 文件的某些字段中的某些空值有关。我想知道是否有解决此问题的方法或解决此问题的其他方法?

如果不使用 Basemap,我似乎无法将 shapefile 发送到 matplotlib 或 mpl_toolkits,但 basemap 一直给我这些错误。

这是一些示例代码。

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()

错误轨迹如下所示。

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

最佳答案

我建议使用真正的 python 工具来处理 shapefile。看看菲奥娜https://pypi.python.org/pypi/Fiona身材匀称https://pypi.python.org/pypi/Shapely

我写的这篇博文链接指向一些使用 Fiona 和 Shapely 的示例 https://www.openshift.com/blogs/using-open-source-gis-tools-for-spatial-data-qgis-gdal-python

关于python - 在读取 shapefile 时从 dbf 文件中删除空值以解决 Matplotlib Basemap 中的错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22138816/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com