使用 geopandas sindex 时是否可以绕过 pygeos?

Is it possible to bypass pygeos when using geopandas sindex?

我目前正在使用 Geopandas,我需要在数据框中高效地搜索 k 最近邻。根据 documentation, the implementation of sindex depends on wether or not pygeos is available. Unfortunatly, this change the api for nearest method, which only supports k-nearest when using rtree 实现而不是 pygeos。

有没有办法强制 geopandas 绕过 pygeos 并改用 rtree?

是的。来自 docs:

当 PyGEOS 可用时,您仍然可以通过以下方式切换使用:

  • 设置环境变量(USE_PYGEOS=0/1)。请注意,仅在首次导入 GeoPandas 时检查此变量。
  • 正在设置一个选项:geopandas.options.use_pygeos = True/False。请注意,尽管可以在交互式会话期间设置此变量,但只有在更改此值后创建了您使用的 GeoDataFrames(例如,使用 read_file 读取文件)时,它才会起作用。