2

我使用以下 REST API 调用为 Neo4j 配置了空间插件:

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

我使用以下 Scala 代码(嵌入在 Play 应用程序中)添加空间节点:

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

Neo4j 浏览器中显示的 Graph

一切看起来都很好

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

返回一些 Location 节点(以及来自空间索引本身的一些节点 - 这是正常的吗?)但是

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

只返回

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

怎么了?有什么遗漏吗?

4

1 回答 1

1

您正在将图层与索引混合在一起。密码查询仅适用于索引。所以甚至不要创建图层。只需创建一个空间索引,并将节点添加到空间索引,然后 cypher 就会看到它们。

例如,请参阅http://maxdemarzi.com/2014/01/31/neo4j-spatial-part-1/

于 2014-06-22T16:30:16.930 回答