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

Intersection between two routes (linestrings) #159

Open
SebaSOFT opened this issue Mar 23, 2018 · 6 comments
Open

Intersection between two routes (linestrings) #159

SebaSOFT opened this issue Mar 23, 2018 · 6 comments
Labels

Comments

@SebaSOFT
Copy link

Hi
I'm really sorry for asking such a noob question, but is this library the correct one to estimate:

  • If a route is within distance of a point (I have a bunch of routes)
  • If two routes intersect each other
  • Get all intersecting routes for a given route (this may be pre-calculated)
  • Points of intersection (there may be many! or inifnite if routes go together)

I plan to use this on Android /offline

@dsmiley
Copy link
Contributor

dsmiley commented Mar 23, 2018

If a route is within distance of a point (I have a bunch of routes)

Yes. Each route is a LineString, and you could test intersection against a circle (point-radius).

If two routes intersect each other

Yes.

Get all intersecting routes for a given route (this may be pre-calculated)

This is the same as the previous question? At least, in Spatial4j, you can test routes against each other. This is O(N) with the number of routes to test if you want to know the intersecting routes for a particular route. If you have many, you'll have to look elsewhere for some persistent indexing approach (e.g. Lucene/Solr).

Points of intersection (there may be many! or inifnite if routes go together)

No, sorry. The primary geometry/shape feature in Spatial4j is computing a relationship between a pair of shapes. There is no further information on where shapes touch/intersect.

@SebaSOFT
Copy link
Author

Thanks, at least if I know to be interacting I can test for segments and apply simple math to that
( https://github.com/MartinThoma/algorithms/tree/master/crossingLineCheck/Geometry/src )

there are about 60 tracks with no more than 20 points each so a pre-calculation would not be that much of a burden and it can be cached.

Regards

@ChangooLee
Copy link

Hello,
I'm using this for flight route calculation. Thanks in advance.

Could you show me an example that test intersection of LineString against a circle?

Best regards

@dsmiley
Copy link
Contributor

dsmiley commented Apr 16, 2018

Could you show me an example that test intersection of LineString against a circle?

Ouch; I was wrong! Anything can be intersected against a rectangle or point, but relations that don't involve either (circle, line, polygon) are not universally supported. It would be really nice if circle-line intersection was supported; ah well.

As an alternative, consider using JTS. JTS has a LineString. For a circle you can approximate it. JTS has a utility somewhere for producing a polygonal circle given a center point and radius.

@ChangooLee
Copy link

Thanks for your information.
I don't know why but, somehow, it worked... you can check with radius 7 and 8.

org.locationtech.jts.io.WKTReader wktReader = new org.locationtech.jts.io.WKTReader();
Shape line = ctxNotGeo.makeShape(wktReader.read("LINESTRING(5 10, -10 -20, 20 10)"));
System.out.println(line.relate(ctxNotGeo.makeCircle(10, -10, 8)));

@dsmiley
Copy link
Contributor

dsmiley commented Apr 19, 2018

Oops; I was wrong; that was embarrassing. I was looking at the Spatial4j-native BufferedLineString shape but forgot that the JtsGeometry wrapper is in play here which does relate with a Circle. Just be aware that this logic works in a cartesian space, so will be inaccurate if you're using it in a "geo" context ("geo" is Spatial4j's lingo for a spherical world model). Thus if your points are decimal degrees lat/lon, this relation will become increasingly inaccurate away from the equator.

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

No branches or pull requests

3 participants