Alpha Shapes with GeoPandas报错处理

我跟着github上的Alpha Shape Toolbox运行Alpha Shapes with GeoPandas中的示例代码,出现了以下异常:

  1. 生成空白图片
import cartopy.crs as ccrs
gdf.crs = 'epsg:4269'
gdf_proj = gdf.to_crs(ccrs.AlbersEqualArea().proj4_init)
gdf_proj.plot()

解决:ccrs.AlbersEqualArea().proj4_init可能没有办法正常获取crs参数,直接调取确定的crs参数即可

import cartopy.crs as ccrs
gdf_proj = gdf.to_crs('EPSG:4269')  # 使用 Albers Equal Area 的 EPSG 代碼
gdf_proj.plot()
  1. ValueError: could not convert string to float: ‘Adak Apt’
import alphashape
alpha_shape = alphashape.alphashape(gdf_proj)
alpha_shape.plot()

出现这个报错之后,我跟着deepseek或gpt4-o的建议改了好几次,但是每次都会出现新的报错,如:
ValueError: could not convert string to float: ‘Adak Apt’
TypeError: ‘MultiPoint’ object is not iterable
AttributeError: ‘Polygon’ object has no attribute ‘plot’

最后从github的issues中查到可能是alphashape版本本身的问题。
先卸载已安装的alphashape
Alpha Shapes with GeoPandas报错处理_第1张图片
再通过下面的命令安装有修复的alphashape

pip install git+https://github.com/bellockk/alphashape.git

再运行上述命令,能顺利输出转换后的plot
Alpha Shapes with GeoPandas报错处理_第2张图片

你可能感兴趣的:(python)