Spatial cypher queries don't work

折月煮酒 提交于 2019-12-11 00:54:48

问题


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)
}

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:


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.



来源:https://stackoverflow.com/questions/24349807/spatial-cypher-queries-dont-work

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!