Search code examples
neo4jcypherneo4j-spatial

Creating geohash relationships in neo4j


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 ?


Solution

  • 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.