question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

docs: Clarification of STRTree documentation

See original GitHub issue

I would like to (slightly) improve the documentation for the STRTree.

http://shapely.readthedocs.io/en/stable/manual.html#str-packed-r-tree says

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 an R-tree that you can query with another geometric object.

The example then shows two queries that return Geometry objects.

I was hoping I could use STRTree just like the rtree module: passing index numbers to be able to match geometries to (Fiona) features but that seems not to be the case. STRTree simply takes a list of Geometry objects and on a query, returns the intersecting Geometry objects it knows about. There is no order or indices. Is that correct?

If so, I would just add one sentences about what the query method returns. For class descriptions (e.g. Point) the attributes are presented in prose, but if this should get a new .. method:: entry, just say so. 😃

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:10 (8 by maintainers)

github_iconTop GitHub Comments

6reactions
kannescommented, Aug 8, 2018
6reactions
sgilliescommented, Jul 30, 2018

@kannes we’re not flexible right now about what gets stored, but we do store the geometry object as well as all its attributes. You can add attributes to a geometry object after it has been created because these geometry objects store their attributes in a __dict__ member (geom.myattr gets read as geom.__dict__['myattr']). We’re not going to change this behavior of Shapely any time soon, so the following code should work at least until a hypothetical Shapely 2.0:

>>> from shapely.strtree import STRtree
>>> from shapely.geometry import Point
>>> pt = Point(0.0, 0.0)
>>> pt.name = 'foo'
>>> tree = STRtree([pt])
>>> tree.query(Point(1.0, 1.0).buffer(2.0))
[<shapely.geometry.point.Point object at 0x109254208>]
>>> results = tree.query(Point(1.0, 1.0).buffer(2.0))
>>> respt = results[0]
>>> respt
<shapely.geometry.point.Point object at 0x109254208>
>>> respt.name
'foo'

There is some related discussion in #615.

Read more comments on GitHub >

github_iconTop Results From Across the Web

docs: Clarification of STRTree documentation #618 - GitHub
STRTree simply takes a list of Geometry objects and on a query, returns the intersecting Geometry objects it knows about. There is no...
Read more >
STRTree — Shapely 2.0.0 documentation - Read the Docs
A query-only R-tree spatial index created using the Sort-Tile-Recursive (STR) [1] algorithm. The tree indexes the bounding boxes of each geometry. The tree...
Read more >
Shapely Documentation - Read the Docs
Shapely is a BSD-licensed Python package for manipulation and analysis of planar geometric objects. It is using.
Read more >
shapely geometry - how to preserve refrence to original feature
Ie. After creating STRtree and getting some result from it, there is no direct way to access feature f from which this geometry...
Read more >
sf.pdf
The reference for the STR tree algorithm is: Leuteneg- ... set st_use_s2() to FALSE See postgis.net/docs/ST_Buffer.html for details.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found