cancel
Showing results for 
Search instead for 
Did you mean: 

Head's Up! These forums are read-only. All users and content have migrated. Please join us at community.neo4j.com.

spatial.withinDistance returning geoms further away than stated distance

The following query is returning many results much further than 0.01km from the point... Is there any reason why? I initially though it was returning the centroid of the geometry and some of a polygon may still be within 0.01km but when plotting the returned data that is not the case

CALL spatial.withinDistance('layer', {latitude: 54.904099672863794, longitude: -1.3702582511780292}, 0.01) yield node, distance return id(node), distance

4 REPLIES 4

I traced the code, and found the following line at https://github.com/neo4j-contrib/spatial/blob/master/src/main/java/org/neo4j/gis/spatial/pipes/proce...

// TODO check Geometry is a point? use Centroid?
Coordinate point = flow.getGeometry().getCoordinate();

It looks like this code will work only with Point geometries. The method getCoordinate() is defined in the JTS library at https://locationtech.github.io/jts/javadoc/org/locationtech/jts/geom/Geometry.html#getCoordinate() and claims the following:

Returns a vertex of this Geometry (usually, but not necessarily, the first one)

I would recommend you open this as a bug report in the issues of the github project at https://github.com/neo4j-contrib/spatial/issues

If the bug-fix is urgent, you could also submit a PR to fix it, replacing the call to getCoordinate() with something more sensible, like perhaps getCentroid().getCoordinate(). To get the PR accepted, you need to write tests and sign the CLA.

I thought more about this and noticed that you saw the option of using the centroid as a problem too. So I've made a new bug-fix and released version 0.25.7 of the Neo4j Spatial library built against Neo4j 3.4.9 (but should work on all Neo4j 3.4.x servers). This version makes two key changes to the withinDistance function relevant to your use case:

  • When looking at distances to non-Point geometries, it will use the JTS DistanceOps functions to find the nearest point of the complex geometry and calculate the distance to that instead
  • Previously a filter was only applied to remove results if the layer was a point-only layer, and this has been changed to filter out distances further than the threshold for all geometry types

Please can you try the new release at https://github.com/neo4j-contrib/spatial/releases/tag/0.25.7-neo4j-3.4.9 and let us know if this works for your use case.

I will get on this today, thank you!

Iam also having problems.
The query is:

CALL spatial.withinDistance('hikes',{lat:11.515159369999996, lon:64.4836848995831}, 1000000)
yield node, distance return id(node), distance

and the results are weird.

id(node)	distance
190	7142.979887242287
125	7143.036407397392
42	7143.45712742689
140	7143.498292525642
63	7143.518485761018
79	7143.518485761018
161	7143.518485761018
142	7143.5205202181405
146	7143.5439201608415
58	7143.551335359225
65	7143.574107399573
98	7143.618875394959
144	7143.618875394961

No matter the distance all of them are in this weird range.

A am using neo 3.4.9 and the version of spatial plugin you mentioned.