Search code examples
neo4jcypherdistanceneo4j-spatial

withinDistance not accurate at all


I'm using neo4j-spatial 0.13 and Neo4J 2.1.8 in production.

I have those two points:

Point(48.89205f,2.373335f) 
Point(48.885464f,2.2808545f)

Using the haversine formula, the distance between those two points is: 6.8 kilometers.

I expect this query to return at least the other point:

START targetedPersons = node:personslocation("withinDistance:[2.373335,48.89205, 7.0]") 
return targetedPersons.id 

but it doesn't.

However, when I pass a slightly greater value, like 11.0 as third argument, it works.

Why? Is it a known serious bug?

I really suspect that the mathematic formula used by withinDistance is slightly different from the haversine formula...
May anyone confirm?


Solution

  • Note that the API for withinDistance in Cypher uses the order of lat,lon instead of the more common order of lon,lat. Verify that is what you are expecting. (I assume you are aware of it since you have switched the order in your examples)

    I believe this is the function Neo4j-spatial is using for distance calculation: https://github.com/neo4j-contrib/spatial/blob/769e87e02aa065971a4452a247f08eb0a38cce7c/src/main/java/org/neo4j/gis/spatial/pipes/processing/OrthodromicDistance.java#L77