Neo4j Spatial仅返回一个节点 [英] Neo4j Spatial return only one node

查看:80
本文介绍了Neo4j Spatial仅返回一个节点的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在neo4j中创建了空间索引,但是当搜索附近的地方时,我只会得到一个结果.

I created a spatial index in neo4j but when searching for nearby places I only get one result.

我的查询是:

START n=node:geom('withinDistance:[63.36, 10.35, 50.0]') RETURN n

在这个坐标中,我在空间索引中有3个节点:

And I have 3 nodes in the spatial index with this coords:

  • 节点1纬度:63.3654、10.3578
  • 节点2纬度:63.3654、10.3577
  • 节点3纬度:63.3654、10.3578(相同的节点1)

理论上,这三个节点位于同一区域.

Theoretically the three nodes are in the same area.

有什么主意吗?

更新

我执行了这些步骤以使用空间(全部通过neo4j浏览器-> rest api执行)

I performed these steps to use spatial (all executed from neo4j browser -> rest api)

1)索引创建

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

2)节点创建(全部以相同的方式)

2) Nodes creation (all in the same way)

:POST /db/data/node
{
    "name":"Franciscatos Pizza",
    "lat": 63.3654,
    "lon": 10.3578
}

3)节点到空间的索引

3) Node to spatial index

:POST /db/data/index/node/geom
{
    "value":"dummy",
    "key":"dummy"
    "uri":"http://localhost:7474/db/data/node/8"
}

4)节点到层

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

任何API响应都可以,并且索引的所有节点都包含:RTREE_REFERENCE关系.

Any API response are OK and all nodes indexed contain the :RTREE_REFERENCE relationship.

根据查询中的distance参数,这会返回不同的节点,但总是一个...

Depending on the distance parameter in the query, this returns me different nodes, but always one...

推荐答案

达里奥斯,

首先,请不要执行第3步.步骤3)和4)在某种程度上是多余的,但是步骤3)在节点中复制了几何信息,并创建了第二个节点,该节点存储在该层中.相反,请执行此新步骤3).

First thing, don't do step 3). Steps 3) and 4) are somewhat redundant, but step 3) makes a copy of the geometry information in the node and creates a second node that is stored into the layer. Instead, do this new step 3).

START n = NODE(8)
SET n.id = ID(n)

此Cypher代码在包含Neo4j节点号的节点上添加"id"参数.完成此操作后,您可以使用Cypher空间索引查询.请注意,第一行每次都有一个不同的节点号.此"id"属性是自引用的.

This Cypher code adds an 'id' parameter on the node that contains the Neo4j node number. Once you do this, you can use the Cypher spatial index query. Note that the first line will have a different node number each time. This 'id' property is self-referential.

或者,执行步骤3),但不要执行步骤4).但是如果执行REST几何查询,您将无法获得期望的结果.

Alternatively, do your step 3), but don't do step 4). But then you won't get what you expect if you do a REST geometry query.

看看您的结果是否有所改善.

See if your results improve.

恩典与和平,

吉姆

PS.

迈克尔

目前,实际上有两种相互竞争的方法正在处理空间问题.如果使用addNodeToLayer将节点添加到图层(如步骤4所示),则该节点将直接链接到RTree图中,而Cypher查询将找不到该节点.如果您使用的是Java,则也是如此.您可以使用findGeometriesWithinDistance和findGeometriesInBBox通过REST查询.

There's actually two competing approaches in play with spatial right now. If you use addNodeToLayer to add your node to a layer (as in step 4), the node is linked into the RTree graph directly and Cypher queries won't find the node. This is also true if you are using Java. You can query via REST using findGeometriesWithinDistance and findGeometriesInBBox.

如果您使用将节点添加到空间索引"方法将节点添加到图层(如步骤3中所示),则实际上并不会将您的节点添加到图层.创建一个新节点,该节点包含原始节点上的几何属性的副本,以及一个"id"属性,其中包含原始节点的Neo4j节点号,并将此副本节点添加到RTree图中. 空间索引"实际上并不包含节点列表.它是空间扩展代码的访问点.当您执行Cypher空间查询时,空间扩展会找到满足查询条件的副本节点,然后在每个节点上取消引用'id'属性以构建原始节点的返回列表.

If you use the 'add the node to the spatial index' method to add your node to a layer (as in step 3), it doesn't actually add your node to the layer. A new node is made that contains a copy of the geometry properties on the original node and an 'id' property that contains the Neo4j node number of the original node, and this copy node is added to the RTree graph. The 'spatial index' does not actually contain a list of nodes. It is an access point for the spatial extension code. When you do a Cypher spatial query, the spatial extension finds the copy nodes that satisfy the query, then dereferences the 'id' properties on each to build a return list of original nodes.

如果仅使用步骤4)将节点添加到图层,则是由于缺少'id'属性来取消引用导致Cypher空间索引查询失败.通过添加'id'属性,解除引用成功,您将从查询中获得结果.

It's the lack of the 'id' property to dereference that causes Cypher spatial index queries to fail if you add a node to a layer using step 4) alone. By adding the 'id' property, the dereference succeeds, and you get results from your query.

shapefile导入器将节点直接链接到RTree,如果您希望能够进行Cypher空间索引查询,则需要按照我的描述向每个节点添加'id'属性. OSM导入器可建立相关的域"和几何节点,但我认为它不会使基于Cypher的查询可以访问它们.如果您将"id"属性添加到每个几何节点,则它们将是.

The shapefile importer links nodes directly into the RTree, and if you want to be able to do Cypher spatial index queries, you need to add the 'id' property to each node as I described. The OSM importer builds related 'domain' and geometry nodes, but I don't think it makes them accessible to Cypher-based queries. If you add the 'id' property to each geometry node, then they will be.

我可能会错过它,但是我还没有看到有人指出,如果您使用将节点添加到空间索引"方法,那么您将拥有的节点数增加了一倍,并且将数据库中存储的几何属性的数量.由于原始节点和复制节点之间没有建立关系,因此无法访问复制节点中的几何属性,因此您无法真正从原始节点删除几何属性.

I may have missed it, but I haven't seen anyone point out that if you use the 'add the node to the spatial index' method, that you just doubled the number of nodes you have, as well as doubled the number of geometry properties stored in your database. Since there is no relationship built between the original nodes and the copy nodes, there is no way to access the geometry properties in the copy nodes, so you can't really delete the geometry properties from the original nodes.

结果,我发现更希望将节点直接添加到RTree图,并通过添加自指代'id'属性使它们通过Cypher空间索引可查询(可查询?).

As a result, I find it more desirable to add my nodes to the RTree graph directly and make them queryable (queriable?) through the Cypher spatial index by adding self-referential 'id' properties.

对于删除节点,没有用于从层中删除节点的REST SpatialPlugin方法.如果使用REST空间索引方法将节点添加到RTree图,则REST调用

As for deleting nodes, there is no REST SpatialPlugin method for removing a node from a layer. If you add the node to the RTree graph using the REST spatial index method, then the REST call

:DELETE /db/data/index/node/geom/{ID}

将从RTree中删除该节点,但是有一个陷阱.您必须获取复制节点的Neo4j节点号,此功能才能起作用!您不能以任何直接的方式.如果您设法获取复制节点的节点号,它将从RTree中删除它,但是复制节点不会被删除.

will remove the node from the RTree, but there is a catch. You must get the Neo4j node number of the copy node in order for this to work! Which you can't in any straightforward way. If you manage to obtain the node number of the copy node, it will remove it from the RTree, but the copy node is not deleted.

具有讽刺意味的是,如果使用addNodeToLayer将节点添加到RTree而不添加'id'属性,则从索引中删除节点的调用将从RTree中删除该节点.如果添加自指代"id"属性,然后从索引中删除该节点,则该节点将被删除.因此,每种方法都有缺陷.

Somewhat ironically, if you add the node to the RTree using addNodeToLayer and don't add the 'id' property, the call to remove the node from the index removes the node from the RTree. If you add the self-referential 'id' property and then remove the node from the index, the node is deleted. So every approach is flawed.

这篇关于Neo4j Spatial仅返回一个节点的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆