I have a sequence of points which are arranged in a 2D grid such as the drawing below:

These points are stored in NEO4J along with their respective cartesian location as:

{

"pid": "P001",

"location": point({srid:7203, x:0, y:0})

}

{

"pid": "P002",

"location": point({srid:7203, x:1, y:0})

}

{

"pid": "P004",

"location": point({srid:7203, x:3, y:0})

}

{

"pid": "P010",

"location": point({srid:7203, x:4, y:1})

}

and so on.

Points do not have a direct relationship to each other, but are connected to a node representing the whole grid:

(:Point {pid:"P001"}) -[:PART_OF]-> (:Grid {gid:"G01"}) <-[:pART_OF]-(:Point {pid:"P002"})

I know that I can calculate the distance between any arbitrary pair of points just doing

MATCH (p1:Point {pid:"P002"})

MATCH (p2:Point {pid:"P004"})

RETURN distance(p1.location,p2.location)

But, how can I automatically calculate the distances between pairs of neighbouring points? That is,

distance(p001,p002)

distance(p002,p004)

distance(p004, p010)

and so on? Please be aware that my dataset has hundreds of sequential points.

Thank you in advance for your help!