Shapely 2.0.0 中文文档

  1. 主页
  2. 文档
  3. Shapely 2.0.0 中文文档
  4. User Manual
  5. STR-packed R-tree(STR算法构建R树)

STR-packed R-tree(STR算法构建R树)

Shapely provides an interface to the query-only GEOS R-tree packed using the Sort-Tile-Recursive algorithm. Pass a list of geometry objects to the STRtree constructor to create a spatial index that you can query with another geometric object. Query-only means that once created, the STRtree is immutable. You cannot add or remove geometries.

Shapely提供了一个使用Sort-Tile-Recursive算法封装的GEOS R-tree的查询接口。将一个几何对象的列表传递给STRtree构造函数来创建一个空间索引,你可以用另一个几何对象来查询。仅限查询意味着一旦创建,STRtree是不可改变的。你不能添加或删除几何对象。

  • class strtree.STRtree(geometries)

The STRtree constructor takes a sequence of geometric objects.

STRtree构造函数接收一连串的几何对象。

References to these geometric objects are kept and stored in the R-tree.

这些几何对象的引用被保留并存储在R树中。

New in version 1.4.0.

  • strtree.query(geom)

Returns the integer indices of all geometries in the strtree whose extents intersect the extent of geom. This means that a subsequent search through the returned subset using the desired binary predicate (eg. intersects, crosses, contains, overlaps) may be necessary to further filter the results according to their specific spatial relationships.

返回strtree中所有extents与geom的extents相交的几何对象的整数索引。这意味着随后可能需要使用所需的二元谓词(例如: intersects, crosses, contains, overlaps)对返回的子集进行搜索,以根据其特定的空间关系进一步过滤结果。

>>> from shapely import STRtree
>>> points = [Point(i, i) for i in range(10)]
>>> tree = STRtree(points)
>>> query_geom = Point(2,2).buffer(0.99)
>>> [points[idx].wkt for idx in tree.query(query_geom)]
['POINT (2 2)']
>>> query_geom = Point(2, 2).buffer(1.0)
>>> [points[idx].wkt for idx in tree.query(query_geom)]
['POINT (1 1)', 'POINT (2 2)', 'POINT (3 3)']
>>> points[idx].wkt for idx in tree.query(query_geom, predicate="intersects")]
['POINT (2 2)']
  • strtree.nearest(geom)

Returns the nearest geometry in strtree to geom.

返回strtree中与geom最近的几何对象。

>>> points = [Point(i, i) for i in range(10)]
>>> tree = STRtree(points)
>>> idx = tree.nearest(Point(2.2, 2.2))
>>> points[idx]
<POINT (2 2)>
标签 ,
这篇文章对您有用吗?

我们要如何帮助您?

欢迎留下您的宝贵建议

Please enter your comment!
Please enter your name here