3

Does anyone know how the distance function of neo4j/cypher works exactly?

When i compare the evaluated distances between neo4j and postgis, i always get a difference of about 0.1-0.5%.

As postgis st_distance uses an srid i assume that the problem is the distance function from neo4j.

3

The Neo4j implementation is considering great circle distances (see distance calculation documentation). The earth radius is set to 6,371,000 meters (see implementation on GitHub).

The PostGIS documentation states that the ST_Distance function

returns the 2D Cartesian distance between two geometries in projected units (based on spatial ref). For geography type defaults to return minimum geodesic distance between two geographies in meters.

I am assuming you are using WGS84 coordinates and geography types in PostGIS. WGS84 (EPSG 4326) is defined with a radius of 6,378,137 meters (spatialreference.org) which explains the deviations. Deviations will grow with the actual distance of points.

  • 1
    The question needs to be clarified, but I would assume PostGIS data are not in EPSG:4326 because ST_Distance, as you describe, calculates a Cartesian distance in the SRID's coordinate units. So the distance from New York to Sao Paulo is 69.88 because the unit is decimal degrees. OTH, maybe OP is using the geography data type? – Lee Hachadoorian Oct 22 '16 at 14:27
  • You are right. I assume he is using the geography type and EPSG:4326 coordinates which provides results in meters (using the ST_Distance function). Otherwise ST_Distance_Sphere could be used for the geometry type and EPSG:4326 coordinates to get the distance in meters too. – Lars Oct 23 '16 at 12:36

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.