MCPcopy Create free account
hub / github.com/shapely/shapely / STRtree

Class STRtree

shapely/strtree.py:31–550  ·  view source on GitHub ↗

A query-only R-tree spatial index. It is created using the Sort-Tile-Recursive (STR) [1]_ algorithm. The tree indexes the bounding boxes of each geometry. The tree is constructed directly at initialization and nodes cannot be added or removed after it has been created. All op

Source from the content-addressed store, hash-verified

29
30
31class STRtree:
32 """A query-only R-tree spatial index.
33
34 It is created using the Sort-Tile-Recursive (STR) [1]_ algorithm.
35
36 The tree indexes the bounding boxes of each geometry. The tree is
37 constructed directly at initialization and nodes cannot be added or
38 removed after it has been created.
39
40 All operations return indices of the input geometries. These indices
41 can be used to index into anything associated with the input geometries,
42 including the input geometries themselves, or custom items stored in
43 another object of the same length as the geometries.
44
45 Bounding boxes limited to two dimensions and are axis-aligned (equivalent to
46 the ``bounds`` property of a geometry); any Z values present in geometries
47 are ignored for purposes of indexing within the tree.
48
49 Any mixture of geometry types may be stored in the tree.
50
51 Note: the tree is more efficient for querying when there are fewer
52 geometries that have overlapping bounding boxes and where there is greater
53 similarity between the outer boundary of a geometry and its bounding box.
54 For example, a MultiPolygon composed of widely-spaced individual Polygons
55 will have a large overall bounding box compared to the boundaries of its
56 individual Polygons, and the bounding box may also potentially overlap many
57 other geometries within the tree. This means that the resulting tree may be
58 less efficient to query than a tree constructed from individual Polygons.
59
60 Parameters
61 ----------
62 geoms : sequence
63 A sequence of geometry objects.
64 node_capacity : int, default 10
65 The maximum number of child nodes per parent node in the tree.
66
67 References
68 ----------
69 .. [1] Leutenegger, Scott T.; Edgington, Jeffrey M.; Lopez, Mario A.
70 (February 1997). "STR: A Simple and Efficient Algorithm for
71 R-Tree Packing".
72 https://ia600900.us.archive.org/27/items/nasa_techdoc_19970016975/19970016975.pdf
73
74 """
75
76 def __init__(self, geoms: Iterable[BaseGeometry], node_capacity: int = 10):
77 """Create a new STRtree spatial index."""
78 # Keep references to geoms in a copied array so that this array is not
79 # modified while the tree depends on it remaining the same
80 self._geometries = np.array(geoms, dtype=np.object_, copy=True)
81
82 # initialize GEOS STRtree
83 self._tree = lib.STRtree(self.geometries, node_capacity)
84
85 def __len__(self):
86 """Return the number of geometries in the tree."""
87 return self._tree.count
88

Callers 14

treeFunction · 0.90
line_treeFunction · 0.90
poly_treeFunction · 0.90
test_initFunction · 0.90
test_referencesFunction · 0.90
test_flush_geometriesFunction · 0.90
test_geometries_propertyFunction · 0.90
test_pickle_persistenceFunction · 0.90
test_nearest_empty_treeFunction · 0.90

Calls

no outgoing calls

Tested by 14

treeFunction · 0.72
line_treeFunction · 0.72
poly_treeFunction · 0.72
test_initFunction · 0.72
test_referencesFunction · 0.72
test_flush_geometriesFunction · 0.72
test_geometries_propertyFunction · 0.72
test_pickle_persistenceFunction · 0.72
test_nearest_empty_treeFunction · 0.72

Used in the wild real call sites across dependent graphs

searching dependent graphs…