Spatial cypher queries don't work

143 views Asked by At

I configured the spatial plugin for Neo4j with the following REST API Calls:

POST http://localhost:7474/db/data/ext/SpatialPlugin/graphdb/addSimplePointLayer
{
 "layer" : "geom",
 "lat" : "lat",
 "lon" : "lon"
}

POST http://localhost:7474/db/data/index/node/
{
  "name" : "geom",
  "config" : {
    "provider" : "spatial",
    "geometry_type" : "point",
    "lat" : "lat",
    "lon" : "lon"
  }
}

I add spatial nodes with the following Scala code (embedded in a Play application):

val mergeStatement = Cypher(
  """
    MERGE (location: Location {placesID: {id}, name: {name}, lat: {lat}, lon: {lon}})
    RETURN id(location)
  """
).on("id" -> id, "name" -> name, "reference" -> reference, "lat" -> latitude, "lon" -> longitude)
val nodeID = mergeStatement().head[Long]("id(location)")

val bodyA = JsObject(Seq(("value",JsString("dummy")),("key",JsString("dummy")),("uri", JsString(Neo4jREST.baseURL + "node/" + nodeID.toString))))

WS.url(Neo4jREST.baseURL + "index/node/geom").withHeaders("Accept" -> "application.json").post(bodyA) map { response =>

    val bodyB = JsObject(Seq(("layer",JsString("geom")),("node", JsString(Neo4jREST.baseURL + "node/" + nodeID.toString))))

    WS.url(Neo4jREST.baseURL + "ext/SpatialPlugin/graphdb/addNodeToLayer").withHeaders("Accept" -> "application.json").post(bodyB)
}

the Graph displayed in the Neo4j browser

Everything looks fine and

POST http://neo4jurl/db/data/ext/SpatialPlugin/graphdb/findGeometriesWithinDistance`
{
  "layer" : "geom",
  "pointX" : 8.5,
  "pointY" : 47.3,
  "distanceInKm" : 10
}

returns some Location nodes (and some nodes from the spatial index itself - is this normal?) but

POST http://neo4jurl//db/data/cypher
{
 "query" : "start node = node:geom('withinDistance:[8.5,47.3, 10.0]') return node"
}

only returns

{
  "columns" : [
    "node"
  ],
  "data" : []
} 

What is wrong? Is something missing?

1

There are 1 answers

1
Max De Marzi On BEST ANSWER

You are mixing up Layers with Indexes. The cypher query only works off indexes. So don't even create a layer. Just create a spatial index, and add nodes to the spatial index, then cypher will see them.

See http://maxdemarzi.com/2014/01/31/neo4j-spatial-part-1/ for example.