The available Shapely user guide seems to be out of date, but since 2013/2014, Shapely has strtree.py with class STRtree. I used it and it works well.
Here is a snippet from docstring:
STRtree is an R-tree that is created using the Sort-Tile-Recursive algorithm. STRtree takes a sequence of geometry objects as an initialization parameter. After initialization, the query method can be used to create a spatial query on these objects.
>>> from shapely.geometry import Polygon >>> polys = [ Polygon(((0, 0), (1, 0), (1, 1))), Polygon(((0, 1), (0, 0), (1, 0))), Polygon(((100, 100), (101, 100), (101, 101))) ] >>> s = STRtree(polys) >>> query_geom = Polygon(((-1, -1), (2, 0), (2, 2), (-1, 2))) >>> result = s.query(query_geom) >>> polys[0] in result True
Phil Mar 29 '17 at 22:54 on 2017-03-29 22:54
source share