question 1
First you need to initialize the layer and create a spatial index using REST calls:
POST /db/data/ext/SpatialPlugin/graphdb/addSimplePointLayer HTTP/1.1 Host: localhost:7474 Accept: application/json Content-Type: application/json Cache-Control: no-cache { "layer" : "geom", "lat" : "lat", "lon" : "lon" }
and
POST /db/data/index/node/ HTTP/1.1 Host: localhost:7474 Accept: application/json Content-Type: application/json Cache-Control: no-cache { "name" : "geom", "config" : { "provider" : "spatial", "geometry_type" : "point", "lat" : "lat", "lon" : "lon" } }
Create a node with lon / lat properties using Cypher via a transactional endpoint:
POST /db/data/transaction/commit HTTP/1.1 Host: localhost:7474 Accept: application/json Content-Type: application/json Cache-Control: no-cache { "statements" : [ { "statement" : "create (city:City {data}) return id(city)", "parameters" : { "data" : { "name" : "MyTown", "lon": 15.2, "lat": 60.1 } } } ] }
and add it to the spatial index - be sure to accept the node identifier with the node identifier returned from the previous query:
POST /db/data/ext/SpatialPlugin/graphdb/addNodeToLayer HTTP/1.1 Host: localhost:7474 Accept: application/json Content-Type: application/json Cache-Control: no-cache { "layer": "geom", "node": "http://localhost:7474/db/data/node/<my_nodeid_goes_here>" }
To enable Spatial play with Cypher, you need to hack: each geo-indexed node must have a property with the name id with the value id node. This can be done using a simple cypher statement (the example below does this for all nodes in the city):
POST /db/data/transaction/commit HTTP/1.1 Host: localhost:7474 Accept: application/json Content-Type: application/json Cache-Control: no-cache { "statements" : [ { "statement" : "match (n:City) set n.id=id(n)" } ] }
Using this place, you can use Cypher for geoinformation, for example:
POST /db/data/transaction/commit HTTP/1.1 Host: localhost:7474 Accept: application/json Content-Type: application/json Cache-Control: no-cache { "statements" : [ { "statement" : "start city = node:geom('withinDistance:[60.1,15.2, 100.0]') return city", "parameters" : {} } ] }
NB: for withinDistance you need to specify lat , lon , distanceInKm .
question 2
As described above, you need to have a separate REST call to add the node to the spatial index. This is currently not possible for Cypher. As a workaround, use LOAD CSV to create nodes with lon / lat properties. At the preprocessing stage, execute a statement of the type MATCH (n:City) where not has(n.id) set n.id = id(n) return id(n) as id . This sets the id properties (the hack described above) and returns a list of identifiers for the new nodes. For each of them, we emit a REST call to add node to the geo-index.
question 3
The answer was already given above :-)