rtree icon indicating copy to clipboard operation
rtree copied to clipboard

A question when i want to find the closest segment in a set to a point

Open HanZhaang opened this issue 6 years ago • 1 comments

I tried to define a bounding box of a segment. for example: (0, 0), to (2, 2), bounding box is (0,0,2,2) minx,miny,maxx,maxy It worked perfectly. But when I met segment (0,2) to (2, 0) , its bounding box is same as the former one. but they are different segments. How should I define such segment?

HanZhaang avatar Dec 19 '19 13:12 HanZhaang

The entries in the R-tree index are minimum bounding rectangles (MBR) of point sets, not oriented line segments, and the intersection and nearest neightbour queries are point-MBR queries.

The MBR (min. bounding rectangle) of the line segment from (0, 2) to (2, 0) is given by (0, 0, 2, 2), using the (minx, miny, maxx, maxy) convention, same as for the line segment from (0, 0) to (2, 2). Geometrically, the two line segments have different orientation, but their MBRs are the same. You can check this.

In [1]: from shapely.geometry import Point, LineString                                                                            

In [2]: p00, p22 = Point(0, 0), Point(2, 2)                                                                                       

In [3]: l1 = LineString((p00, p22))                                                                                               

In [4]: l1.bounds                                                                                                                 
Out[4]: (0.0, 0.0, 2.0, 2.0)

In [5]: p02, p20 = Point(0, 2), Point(2, 0)                                                                                       

In [6]: l2 = LineString((p02, p20))                                                                                               

In [7]: l2.bounds                                                                                                                 
Out[7]: (0.0, 0.0, 2.0, 2.0)

sr-murthy avatar Feb 10 '20 19:02 sr-murthy