1

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?

Mik378
  • 21,881
  • 15
  • 82
  • 180

1 Answers1

1

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

William Lyon
  • 8,371
  • 1
  • 17
  • 22
  • Yes I know this subtility with the order, but I managed to handle it. I've just implemented the exact same calculation, but there's still a problem of accuracy. – Mik378 Dec 09 '15 at 00:28
  • I manage to refine the algorithm using the same method than the one used in cypher + reordering lat lon. It works now, thanks. – Mik378 Dec 09 '15 at 12:43