我拥有正确配置的空间层和索引,可以使用findGeometriesWithinDistance REST API调用成功查询节点。

POST /db/data/ext/SpatialPlugin/graphdb/findGeometriesWithinDistance {"layer":"geom","pointX":15.0,"pointY":60.0,"distanceInKm":100.0}

但是,当使用cypher进行查询时,我没有任何结果(我尝试将60.0和15.0的顺序反转,但是没有运气):
START n=node:geom('withinDistance:[60.0, 15.0, 500.0]') return n;

Cyper返回:
==> +---+
==> | n |
==> +---+
==> +---+
==> 0 row
==>
==> 13 ms

休息:
200 OK
==> [ {
==>   "paged_traverse" : "http://localhost:7474/db/data/node/14472/paged/traverse/{returnType}{?pageSize,leaseTime}",
==>   "outgoing_relationships" : "http://localhost:7474/db/data/node/14472/relationships/out",
==>   "data" : {
==>     "lon" : 15.2,
==>     "bbox" : [ 15.2, 60.1, 15.2, 60.1 ],
==>     "RaceName" : "Parador Es Muy Caliente",
==>     "lat" : 60.1,
==>     "gtype" : 1
==>   },
==>   "all_typed_relationships" : "http://localhost:7474/db/data/node/14472/relationships/all/{-list|&|types}",
==>   "traverse" : "http://localhost:7474/db/data/node/14472/traverse/{returnType}",
==>   "self" : "http://localhost:7474/db/data/node/14472",
==>   "all_relationships" : "http://localhost:7474/db/data/node/14472/relationships/all",
==>   "property" : "http://localhost:7474/db/data/node/14472/properties/{key}",
==>   "properties" : "http://localhost:7474/db/data/node/14472/properties",
==>   "outgoing_typed_relationships" : "http://localhost:7474/db/data/node/14472/relationships/out/{-list|&|types}",
==>   "incoming_relationships" : "http://localhost:7474/db/data/node/14472/relationships/in",
==>   "incoming_typed_relationships" : "http://localhost:7474/db/data/node/14472/relationships/in/{-list|&|types}",
==>   "extensions" : {
==>   },
==>   "create_relationship" : "http://localhost:7474/db/data/node/14472/relationships"
==> } ]

REST调用以重现:
创建图层:
POST /db/data/ext/SpatialPlugin/graphdb/addSimplePointLayer { "layer":"geom", "lat":"lat", "lon":"lon" }

创建索引:
POST /db/data/index/node/ {"name":"geom", "config":{"provider":"spatial", "geometry_type":"point","lat":"lat","lon":"lon"}}

创建节点:
POST /db/data/node {"lat":60.2,"lon":15.1,"RaceName":"Parador Es Muy Caliente"}

(作为响应,检查“自己”并找到nodeid)

inode :
POST /db/data/ext/SpatialPlugin/graphdb/addNodeToLayer {"layer":"geom", "node":"http://localhost:7474/db/data/node/###NEW_NODE_ID###"}

找:
POST /db/data/ext/SpatialPlugin/graphdb/findGeometriesWithinDistance {"layer":"geom","pointX":15.0,"pointY":60.0,"distanceInKm":100.0}

最佳答案

我对此进行了调查,这与我们几次见过的问题有关。空间库的设计存在不一致之处,因为有两种方法可以将节点添加到空间索引。一种是使用REST调用将其添加到Layer(使用addNodeToLayer REST),它使用底层Java API,该API将节点直接连接到RTree中,成为同一图的一部分。另一种方法是在索引图中创建一个代理节点,以便您的域图不连接到索引图。第二种方法仅由IndexProvider接口(interface)采用(使用/db/data/index/node/geom REST调用)。

如果您同时调用这两种方法,则将节点添加两次,一次直接添加,一次通过代理添加。问题在于,Cypher insideDistance索引查询仅访问IndexProvider接口(interface),并且只会返回未同时连接到索引的节点。因此,如果您以两种方式添加节点,将不会返回该节点。

因此,您只需要添加两种方法之一即可。我在您的原始电子邮件中没有看到关于addNodeToLayer的任何提及,因此我怀疑SDN可能正在调用addNodeToLayer(也许Michael可以发表评论),在这种情况下,您不能使用cypher调用。

在测试期间,我可以使用Cypher手动删除一个索引关系,如下所示:

开始n = node(13065)匹配(n)
将13065替换为原始节点的节点ID。

我在neo4j浏览器(在2.1.2中)执行了以下操作:

:POST /db/data/ext/SpatialPlugin/graphdb/addSimplePointLayer { "layer":"geom", "lat":"lat", "lon":"lon" }
:POST /db/data/index/node/ {"name":"geom", "config":{"provider":"spatial", "geometry_type":"point","lat":"lat","lon":"lon"}}
:POST /db/data/node {"lat":60.2,"lon":15.1,"RaceName":"Parador Es Muy Caliente"}
:POST /db/data/index/node/geom {"value":"dummy","key":"dummy", "uri":"http://localhost:7474/db/data/node/13071"}

这创建了一个节点未直接连接到索引的图形。在这种情况下,REST调用“findGeometriesWithinDistance”不起作用(使用标准Java API),而密码“withinDistance”起作用。我使用以下命令进行了测试:
start n = node:geom("withinDistance:[60.2,15.1,100.0]") return n

请注意,不幸的是,此API的订单顺序为lat,lon,而不是更标准的lon,lat。

然后,我还添加了该层(即直接添加到索引图):
:POST /db/data/ext/SpatialPlugin/graphdb/addNodeToLayer {"layer":"geom", "node":"http://localhost:7474/db/data/node/13071"}

现在,当我使用cypher命令进行搜索时,我仍然会得到相同的正确答案,但是当我使用REST命令进行搜索时:
:POST /db/data/ext/SpatialPlugin/graphdb/findGeometriesWithinDistance {"layer":"geom","pointX":15.0,"pointY":60.0,"distanceInKm":100.0}

我发现这将返回代理节点而不是原始节点。

关于Neo4j Spatial 'WithinDistance' Cypher查询返回空,而REST调用返回数据,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/17966722/

10-10 03:13