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 ?

- 1,809
- 4
- 26
- 51
-
What have you tried so far? – Cid Jun 11 '18 at 10:01
-
I loaded my csv in neo4j and i just made location nodes with latitude and longitude, i didn't find a way to make a location relationship between them – A.HADDAD Jun 11 '18 at 10:06
-
i found https://github.com/huashiyiqike/GeoHash_Neo4j but the build dosen't work for me – A.HADDAD Jun 12 '18 at 13:19
2 Answers
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.

- 7,340
- 1
- 18
- 31
-
thanks , but i didn't find a clear tutorial on how to do that with R-Tree !? – A.HADDAD Jun 11 '18 at 14:57
-
did you take a look at this page : http://neo4j-contrib.github.io/spatial/0.24-neo4j-3.1/index.html ? There are some references of tutorials. – logisima Jun 11 '18 at 15:01
-
yes i saw them, but since i am new with neo4j i didn't understand a big thing. is spatial neo4j plugin didn't work in the Basic Neo4j Browser ? do i need uDig in order to use it ? – A.HADDAD Jun 11 '18 at 15:55
-
i found [here](https://neo4j.com/blog/driving-predictive-analytics-neo4j/#comment-138831) that the plugin have a geohash capability. if you can help me ? – A.HADDAD Jun 13 '18 at 11:28
-
thanks for your effort,but what that would add ? would it organize the nodes based on their geohash ? – A.HADDAD Jun 13 '18 at 16:23
-
yes, you will have a geohash tree in your graph, linked to yours nodes. Just install the spatial plugin and try it ! – logisima Jun 13 '18 at 16:33
-
i try it. actually after adding the layer, two nodes are connected by a relationship named layer the rest of nodes(added to the layer) aren't connected by any relationship. if you can add a photo ? – A.HADDAD Jun 13 '18 at 16:39
-
-
this what your answer do => [geohash tree question](https://stackoverflow.com/questions/50913970/how-to-create-geohash-tree-in-neo4j) cordially – A.HADDAD Jun 18 '18 at 17:25
-
1FYI it was a guess, the plugin do a tree when you use an other layer, and my example comes from the unit test of the plugin. I have the same result as you. – logisima Jun 19 '18 at 08:33
-
hey @logisima did you know how to fix the length (1-12) for the geohash point layer ? – A.HADDAD Jul 13 '18 at 09:56
-
-
it's like a precision just type in google **geohash length** and you will find informations – A.HADDAD Jul 13 '18 at 10:11
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:
- https://neo4j.com/docs/developer-manual/current/cypher/syntax/spatial/
- https://medium.com/neo4j/working-with-neo4j-date-and-spatial-types-in-a-react-js-app-5475b5042b50
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
.

- 759
- 4
- 5
-
actually the geohash layer dosen't work (it creates unrelated nodes unlike in R-tree) you can see the issue [here](https://stackoverflow.com/questions/50913970/how-to-create-geohash-tree-in-neo4j?noredirect=1&lq=1) – A.HADDAD Jun 18 '18 at 21:27
-
-
i see you have released a [new version](https://github.com/neo4j-contrib/spatial/releases/tag/0.25.5-neo4j-3.4.1) , is the geohash layer is fixed in it ? – A.HADDAD Jul 01 '18 at 03:06
-
i want to ask how to fix the length of the geohash in the layer to 7 for example ?? – A.HADDAD Jul 10 '18 at 04:25