Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Line / box intersections? #264

Open
Quafadas opened this issue May 26, 2021 · 6 comments
Open

Line / box intersections? #264

Quafadas opened this issue May 26, 2021 · 6 comments
Labels
question Further information is requested

Comments

@Quafadas
Copy link

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?

@plokhotnyuk plokhotnyuk added the question Further information is requested label May 26, 2021
@plokhotnyuk
Copy link
Owner

plokhotnyuk commented May 26, 2021

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

@Quafadas
Copy link
Author

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 ?

@plokhotnyuk
Copy link
Owner

plokhotnyuk commented May 27, 2021

@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?

@Quafadas
Copy link
Author

Quafadas commented May 27, 2021

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 :-/

@plokhotnyuk
Copy link
Owner

plokhotnyuk commented May 27, 2021

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.

@Quafadas
Copy link
Author

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants