我使用以下 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)
}
一切看起来都很好
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" : []
}
怎么了?有什么遗漏吗?