Skip to content

Commit

Permalink
Improved STRtree docs (#623)
Browse files Browse the repository at this point in the history
* docstring for strtree query method

* note about immutability, slight reformatting

not sure if immutable is the correct term, might be misleading?

* let's call it a spatial index

* rewording strtree docstring

* reworded strtree doc

* explicitely mention "extents"!
* rewrote subsequent filtering part, I hope it became better, not worse
* Rename R-Tree to STRTree to avoid confusion with rtree module trees
* name-drop "spatial index"

* strtree doc: add example on testing for intersection

+use query_geom variable name to help readability

* strtree doc: note about monkey patching for extra attributes

added code inside a note, untested if this comes out correctly. also no clue if the links work. rst is weird.

Co-authored-by: Sean Gillies <sean.gillies@gmail.com>
  • Loading branch information
kannes and sgillies committed Mar 2, 2020
1 parent 990df80 commit e6065ed
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 5 deletions.
2 changes: 1 addition & 1 deletion docs/manual.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2745,4 +2745,4 @@ References
.. _frozenset: https://docs.python.org/library/stdtypes.html#frozenset
.. _Sorting HowTo: https://wiki.python.org/moin/HowTo/Sorting/
.. _Python geo interface: https://gist.github.com/2217756
.. _polylabel: https://github.com/mapbox/polylabel
.. _polylabel: https://github.com/mapbox/polylabel
13 changes: 9 additions & 4 deletions shapely/strtree.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,12 @@

class STRtree:
"""
STRtree is an R-tree that is created using the Sort-Tile-Recursive
algorithm. STRtree takes a sequence of geometry objects as initialization
parameter. After initialization the query method can be used to make a
spatial query over those objects.
STRtree is an R-tree spatial index that is created using the
Sort-Tile-Recursive algorithm.
STRtree takes a sequence of geometry objects as initialization
parameter. Once created, it is immutable. The query method can
be used to make spatial queries over the objects on the index.
>>> 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))) ]
Expand Down Expand Up @@ -48,6 +50,9 @@ def __del__(self):
self._tree_handle = None

def query(self, geom):
"""Returns a list of objects on the index whose extents
intersect the given geometry's extents.
"""
if self._n_geoms == 0:
return []

Expand Down

0 comments on commit e6065ed

Please sign in to comment.