dopple
dopple

Reputation: 92

How do I return coordinates of nodes in neo4j

I am looking at visualising neo4j graph data in Tableau but Tableau requires the coordinates to be included in the data before it can plot the nodes in a graph.

By coordinates I just mean an x & y value so that I can plot nodes and edges on a 2d graph. There aren't any geographic/address requirements

Is there any way to return coordinates in a result set using cypher? Something along the lines of

MATCH (j:Job)-[:PARENT_OF]->(w:Workflow)
RETURN j, coords(j), w, coords(w)

There is nothing obvious that I can see having searched the web and also stackoverflow. I have searched the APOC procedures with terms such as "spatial", "coordinates" and "position" but so far I've had no joy.

I'm using neo4j community 3.3.1

EDIT: Looking at howto graph visualization step by step this suggests that you need to use external libraries in order to do this rather than getting the information from neo4j. I appreciate the visualisations are fluid and can be moved about but I would have thought that given the neo4j server has crunched the geospatial algorithms already, it would be something that could somehow be output via a function or procedure.

Upvotes: 0

Views: 693

Answers (2)

dopple
dopple

Reputation: 92

When I asked this question I didn't understand that what actually happens is a frontend algorithm sorts and orders the nodes dynamically and therefore no coordinates are provided.

Upvotes: 0

cybersam
cybersam

Reputation: 66999

APOC does have a couple of procedures for getting the coordinates of an address: apoc.spatial.geocodeOnce and apoc.spatial.geocode.

For example, this query:

CALL apoc.spatial.geocodeOnce('21 rue Paul Bellamy 44000 NANTES FRANCE') YIELD location
RETURN location;

produces this result:

{
  "description": "21, Rue Paul Bellamy, Talensac - Pont Morand, Hauts-Pavés - Saint-Félix, Nantes, Loire-Atlantique, Pays de la Loire, France métropolitaine, 44000, France",
  "latitude": 47.2221667,
  "longitude": -1.5566625
}

Modifying the example in your question (assuming that j and w have address properties), this should work:

MATCH (j:Job)-[:PARENT_OF]->(w:Workflow)
CALL apoc.spatial.geocodeOnce(j.address) YIELD location AS jLoc
CALL apoc.spatial.geocodeOnce(w.address) YIELD location AS wLoc
RETURN j, jLoc, w, wLoc;

Upvotes: 2

Related Questions