【问题标题】:How to use GeoPandas Spatial Index with lines?如何将 GeoPandas 空间索引与线条一起使用?
【发布时间】:2016-10-27 08:33:56
【问题描述】:

我正在尝试找到离一堆点最近的线(大约 240 亿个点,400 万条线)。点存在于一个 GeoDataFrame 中,而线存在于另一个中。我试着按照这个:https://github.com/geopandas/geopandas/issues/140,然后这样做了:

lines_sidx = lines_df['geom'].sindex
[list(lines_sidx.intersection((points.loc[i,'geom'].y, points.loc[i,'geom'].x))) for i in range(len(points))]

这只是返回一个空的列表列表。这是怎么回事?

(请注意,我将其应用于两个数据集中的前 100 行和点)。

【问题讨论】:

    标签: python-3.x geopandas


    【解决方案1】:

    您的问题以您尝试执行最近邻查询的上下文开头,但您的问题本身询问的是 geopandas 交叉点代码块中发生了什么。我将尝试解决您的问题而不是它的序言,因为它们似乎不一致。看起来您的交集代码逻辑已关闭。将 rtree 与空间交集使用的要点是,您首先找到与索引的可能匹配项(一些误报,但没有误报),然后找到精确匹配项。

    类似这样的东西,正如geopandas r-tree tutorial 中所展示的那样:

    spatial_index = gdf.sindex
    possible_matches_index = list(spatial_index.intersection(polygon.bounds))
    possible_matches = gdf.iloc[possible_matches_index]
    precise_matches = possible_matches[possible_matches.intersects(polygon)]
    

    如果您尝试使用一组点和一组线进行最近邻搜索,则可能没有任何要素相交,这可能会返回您的空集结果。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2012-06-10
      • 2023-03-12
      • 2020-09-09
      • 1970-01-01
      • 2022-08-15
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多