rtree2d icon indicating copy to clipboard operation
rtree2d copied to clipboard

Line / box intersections?

Open Quafadas opened this issue 4 years ago • 6 comments

I'm not sure if I'm missing something obvious, but is it possible to calculate the intersections of a line (specified by lat/long start) with a box on a spherical earth?

I can only see point / box interactions?

Quafadas avatar May 26 '21 12:05 Quafadas

The library currently supports limited number of operations on the spherical earth (just a bare minimum to build R-tries and to support nearest and bounding box requests on them):

  • creation of R-tree entries (or bounding boxes with values) by line with start and end points or by circles defined by a center point and a distance from the center
  • calculation of distance from a point to an R-tree entry

plokhotnyuk avatar May 26 '21 13:05 plokhotnyuk

Hmmmm... then I guess this would be a feature request!

I did have a dig to see if this was something which would be easy to add... and concluded it was either quite easy (add an RLineEntry which extends REntry and override the methods)?

Or quite hard... because you'd have to implement any actual functionality required for each geometry?

I ended up leaning toward the "hard" ... given that I don't know much about R Trees in general, I concluded this was probably beyond my skills. Would you have any hint here ?

Quafadas avatar May 27 '21 10:05 Quafadas

@Quafadas I'd keep the project focused on R-trees.

I'll be happy to help you find the most efficient solution but need know the context to avoid XY-problem trap.

Could you please describe your initial challenge that you are going to solve?

plokhotnyuk avatar May 27 '21 11:05 plokhotnyuk

Sure, so I have a curiosity project, where I'm noodling around with Hurricane data.

https://www.aoml.noaa.gov/hrd/hurdat/Data_Storm.html

It's freely available (I have some scala which converts the original data format into "nicer" case classes, but that's not so relevant). The point is that a Hurricane has a "track". NOAA measure this as a series of points, for which Lat Long is available. The "track" is effectively the line(s) interpolated between the points.

The idea, was to look for intersections of Hurricane tracks with "boxes" or "circles" on the earth. I think an RTree can do this, but it would need a "line" concept... hence the question...

Hope that clarifies? I like the XY-trap reference, I hadn't come across that before.

Actually, I can do even better, NOAA already have this; https://coast.noaa.gov/hurricanes/#map=8.56/18.2255/-66.467&search=eyJzZWFyY2hTdHJpbmciOiIxOC4yMjMxNDYsIC02Ni40NjY5NjUiLCJzZWFyY2hUeXBlIjoiY2VudGVyIiwibWF0Y2giOiJleGFjdCIsIm9zbUlEIjoiNTMwNjAiLCJsYXQiOjE4LjIyMzE0NiwibG9uIjotNjYuNDY2OTY1LCJjYXRlZ29yaWVzIjpbIkg1Il0sInllYXJzIjpbXSwibW9udGhzIjpbXSwiZW5zbyI6W10sInByZXNzdXJlIjp7InJhbmdlIjpbMCwxMTUwXSwiaW5jbHVkZVVua25vd25QcmVzc3VyZSI6dHJ1ZX0sImJ1ZmZlciI6MTAwLCJidWZmZXJVbml0IjpbIktpbG9tZXRlcnMiXSwic29ydFNlbGVjdGlvbiI6eyJ2YWx1ZSI6InllYXJzX25ld2VzdCIsImxhYmVsIjoiWWVhciAoTmV3ZXN0KSJ9LCJhcHBseVRvQU9JIjpmYWxzZSwiYmFzZW1hcCI6InNhdGVsbGl0ZSIsImlzU3Rvcm1MYWJlbHNWaXNpYmxlIjp0cnVlfQ==

which is almost exactly what I want to do (no fancy graphics for me, mind you). In the spirit of the XY reference, I want to then be able to customise / search for dependancies with external variables / do some downstream calculations on the data at those points... the last part isn't 100% defined yet :-/

Quafadas avatar May 27 '21 11:05 Quafadas

Great! I think R-trees can speed up searching of intersections of hurricane tracks with other geometric figures (circles, polygons of city borders, etc.). You can create an RTree instance for the hurricane track where entries will be bounding boxes for lines between points of the track. Then using rtree.searchAll call you can filter only those bounding boxes which intersect with a bounding box of the search call (rtree.searchAll parameters). Having those filtered entries you can check linked lines if they cross the circle. For example, you can calculate the minimal distance from the circle center to the line using these calculations and then check if it is greater or less than the radius of the circle.

plokhotnyuk avatar May 27 '21 13:05 plokhotnyuk

I think I understand... thankyou for the tip. I'll give it a whirl...

Quafadas avatar May 27 '21 13:05 Quafadas