geopandas.GeoSeries.sindex#

property GeoSeries.sindex#

生成空间索引

基于以下内容创建R树空间索引 pygeos.STRtreertree.index.Index

请注意,空间索引可能要到第一次使用时才能完全初始化。

示例

>>> from shapely.geometry import box
>>> s = geopandas.GeoSeries(geopandas.points_from_xy(range(5), range(5)))
>>> s
0    POINT (0.00000 0.00000)
1    POINT (1.00000 1.00000)
2    POINT (2.00000 2.00000)
3    POINT (3.00000 3.00000)
4    POINT (4.00000 4.00000)
dtype: geometry

根据边界框使用单个几何图形查询空间索引:

>>> s.sindex.query(box(1, 1, 3, 3))
array([1, 2, 3])

基于谓词使用单个几何查询空间索引:

>>> s.sindex.query(box(1, 1, 3, 3), predicate="contains")
array([2])

使用基于边界框的几何体数组查询空间索引:

>>> s2 = geopandas.GeoSeries([box(1, 1, 3, 3), box(4, 4, 5, 5)])
>>> s2
0    POLYGON ((3.00000 1.00000, 3.00000 3.00000, 1....
1    POLYGON ((5.00000 4.00000, 5.00000 5.00000, 4....
dtype: geometry
>>> s.sindex.query_bulk(s2)
array([[0, 0, 0, 1],
       [1, 2, 3, 4]])

使用基于谓词的几何数组查询空间索引:

>>> s.sindex.query_bulk(s2, predicate="contains")
array([[0],
       [2]])