Head's Up! These forums are read-only. All users and content have migrated. Please join us at community.neo4j.com.
11-18-2019 07:45 AM
Hi,
I have bunch of cartesian-3D points. Is there a function/procedure to calculate center point, positioned after calculating distances from each node? I want to create a new node, that would represent the points it was calculated from.
Refer: https://neo4j.com/docs/cypher-manual/current/functions/spatial/#functions-point-cartesian-3d
Thanks!
12-02-2019 03:09 PM
There's no reason to calculate distances between points. Instead you can deconstruct each point and calculate the average of each individual dimension. Try out the code below. Put any number of points in there that you desire and it will provide you with the average of all 3 dimensions.
WITH [point({ x: 2.3, y: 4.5, z: 2 }), point({ x: 2.3, y: 4.5, z: 4 })] AS points
UNWIND points AS point
WITH avg(point.x) AS avgx, avg(point.y) AS avgy, avg(point.z) AS avgz
RETURN point({ x: avgx, y: avgy, z: avgz }) AS avgpoint;
09-22-2020 04:50 PM
That's doesn't work with spatial data near lat 180/0:
avg [179,-179] = 0
(the other side of the world).
09-26-2020 07:50 AM
@tony.chiboucas you are right that this does not work for geographic points, but it does work as @mojo2go said for 3D cartesian points.
For geographic data you would first need to define what is meant by the term 'center point', which could mean a point on the direct line through the earth, or a point on the surface of the earth. Two completely different definitions with two completely different mathematical solutiuons. For some cases the second definition leads to infinite solutions.
09-28-2020 11:17 AM
Thank you @craig.taverner, I ended up writing my own function which:
This leaves an opportunity to use the distance from earth-center to average cart3d point as a measure of how widely distributed the set is.
All the sessions of the conference are now available online