我使用以下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" : []
}
有什么问题?缺少什么?
答案 0 :(得分:1)
您正在将图层与索引混合在一起。密码查询仅适用于索引。所以,甚至不要创建一个图层。只需创建一个空间索引,并将节点添加到空间索引,然后密码就会看到它们。
例如,请参阅http://maxdemarzi.com/2014/01/31/neo4j-spatial-part-1/。