1

I'm trying to develop an application that accepts the latitude, longitude and direction (the direction that the phone is pointing in) from the user. I need to use the coordinates to find the first object (most likely a building) that is in the user's line of sight. This building will be stored as a polygon in the database. Is there a Neo4j query for this? I'm trying to answer a question similar to "Find all countries that are intersected by the Line of Capricon".

Thanks for reading. I appreciate the help.

jjulk
  • 51
  • 2

1 Answers1

1

If you application is written in Java with the embedded API, then Neo4j Spatial has all the tools you need because it makes use of JTS internally and so you can perform any JTS query you want. However, to benefit from the RTree index to make the query fast will require that you also limit the search scope somewhat. If you have an idea of a maximum distance you wish to search you could solve this in two ways:

  1. Either - do an initial distance search finding all geometries within the maximum distance, and then perform a refinement on the resulting dataset to get only geometries that intersect the line of sight.
  2. Or - create the LineString for the line of sight, with a length matching your max distance, then perform an intersections search for all geometries that intersect this LineString, and select the closest.

This second option would only work in the Java API, but would be the fastest since the search will only consider objects along the line of sight in the RTree, so the index search is more selective than the distance search option (which will search in all directions).

If, instead, the application is going to use the REST API, then this would be much harder to do, since that API only allows searching of points. I would recommend creating an unmanaged extension and doing the work in Java and exposing your own REST endpoint for this function.

Craig Taverner
  • 759
  • 4
  • 5