Creating geohash relationships in neo4j

486 views Asked by At

I've csv files that contains latitude/longitude fields, what i want is to convert this latitude/longitude into a geohash and then make a relationship between different location nodes based on their geohash values.
how to do that ?

2

There are 2 answers

13
logisima On BEST ANSWER

Neo4j has a spatial plugin, that creates a R-Tree for your geo-data. So instead of creating a geohash, you can directly use this plugin.

Moreover, the last version of Neo4j has introduced some new types for properties, and one of them is the point. Take a look at the documentation : https://neo4j.com/docs/developer-manual/3.4/cypher/functions/spatial/

Update for geohash with spatial plugin

Just create a geohash layer :

CALL spatial.addPointLayerGeohash('my_geohash_layer_name')

And then add your node to the layer :

CREATE (n:Node {latitude:60.1,longitude:15.2}) WITH n 
CALL spatial.addNode('my_geohash_layer_name',n) YIELD node 
RETURN node

Your nodes must have a latitude & longitude properties.

4
Craig Taverner On

If you are only working with Point data (latitude and longitude), you do not need to use the spatial plugin at all, and can use the built-in spatial features of Neo4j 3.4. The built-in index is a hilbert space-filling curve, which is a similar concept to a geohash, so I assume it will satisfy your needs. For information on how to use the new features, you can look at either the documentation, or some recent blogs:

If you specifically want to use the Neo4j Spatial library and you only want geohash, not the related, and better, hilbert curves, then you can use procedures like CALL spatial.addPointLayerGeohash('geom') and then add data with commands like CREATE (n:Node {latitude:60.1,longitude:15.2}) WITH n CALL spatial.addNode('geom',n) YIELD node RETURN node.