【问题标题】:Geopandas and Google Colab issue: Spatial indexes require either `rtree` or `pygeos`Geopandas 和 Google Colab 问题:空间索引需要 `rtree` 或 `pygeos`
【发布时间】:2021-12-08 05:17:57
【问题描述】:

我正在尝试使用 Google Colab 上的 gdf.overlay 函数与 2 GeoDataFrame 进行交集。请看下面的代码

!sudo apt install libspatialindex-dev
!sudo pip3 install rtree
!pip install pygeos

overlap = gpd.overlay(gdf1,gdf2, how='intersection')
overlap.plot(figsize=(10,10), cmap='jet')

我收到以下错误消息

ImportError: Spatial indexes require either `rtree` or `pygeos`. See installation instructions at https://geopandas.org/install.html

是什么导致了这里的问题?

【问题讨论】:

  • 您同时使用了pippip3。他们可能在不同的 python 安装上运行
  • 使用conda 安装rtree 并使用conda-forge 将您的python 更新为cpython
  • 尝试使用 venv (python3 -mvenv your-virtual-env),然后避免(总是!)sudo pip。 pip 安装包,一旦你激活了我们的虚拟环境,应该以更可靠的方式产生一个连贯的库生态系统。

标签: python google-colaboratory geopandas


【解决方案1】:

我在 colab 上运行它时遇到了同样的问题,这是由于依赖关系,请遵循以下建议的相同顺序: https://geopandas.org/getting_started/install.html

对我来说,第一次安装依赖项时错误消失了:

!pip install pandas fiona shapely pyproj rtree

然后:

!pip install geopandas

【讨论】:

  • 对我来说,这不起作用。
猜你喜欢
  • 2021-10-20
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2019-04-29
  • 1970-01-01
  • 2020-07-12
相关资源
最近更新 更多