首页 > 解决方案 > Cartopy 正在崩溃谷歌代码实验室

问题描述

我正在使用 Cartopy 和 Metpy 创建新图形。当我尝试在我的地图上设置范围时使用谷歌代码实验室时:

track_line_gdf = geopandas.read_file('/content/al112017-020_5day_lin.shp')
cone_gdf = geopandas.read_file('/content/al112017-020_5day_lin.shp')
points_gdf = geopandas.read_file('/content/al112017-020_5day_pts.shp')

map_crs = ccrs.LambertConformal(central_latitude=35, central_longitude=100, 
standard_parallels=(30, 60))

data_crs = ccrs.PlateCarree()

fig = plt.figure(figsize=(14 , 12))

ax = plt.subplot(1, 1, 1, projection=map_crs)

ax.set_extent([-90,-72, 20, 55]) #Problem line

我收到警告:“几何必须是点或线串”然后我的笔记本崩溃了。我尝试更改 ax.set_extent() 中的值,但仍然遇到“几何必须是点或线串”的相同问题,然后我的笔记本因“未知”原因而崩溃。我使用的数据也是飓风艾尔玛的形状文件。有没有人见过这个问题?感谢您的帮助!

PS我目前住在关岛,所以与美国大陆相比,我可能会在奇怪的时间做出回应。再次感谢你的帮助!

标签: pythonpython-3.xgoogle-colaboratorycartopymetpy

解决方案


我在 Google Colab 上也发生了这种情况,同样的错误以 Point 或 Linestring 结尾。那条信息似乎很关键。我注意到常规的 apt-get to install cartopy 似乎没有做任何事情——因为它已经安装了,所以我卸载并重新安装了它。但是,我怀疑唯一必要的步骤是之前的帖子发现的: Geometry must be a Point or LineString error using Cartopy

也就是说:在您的 Cartopy 使用前加上:

!apt-get -V -y -qq 安装 python-cartopy python3-cartopy

!pip 匀称卸载 -y

!pip install shapely --no-binary shapely


推荐阅读