1

我有一个类NodeA,用@NodeEntity注释。它有很多领域,包括:

@Indexed
public Double lat;

@Indexed
public Double lon;

请注意,NodeA 已经能够通过latlon字段存储足够的位置信息。我想将 NodeA 类型的节点添加到空间层中,以便可以使用GeoPipeline运行空间查询。

  1. 如何将 NodeA 对象直接添加到空间层中?目前,我只能将点等添加new Coordinate(13.766, 55.566)到空间层中。(如果没有解决方案,如何将 NodeA 节点与其对应的 Coordinate 节点关联?)
  2. 我需要将节点单独 添加到空间索引中吗?

我在用:

  • Java in Play!Framework 2.2.2(可更新)
  • 嵌入式Neo4j-Spatial 0.13-neo4j-2.0.1(可更新)

编辑:当我将 NodeA 类型的现有节点连接到 RTREE_ROOT 时,GeoPipeline抱怨缺少NodeA 节点的bbox 属性。(果然NodeA中没有bbox属性,但在其他Coordinate类型的节点中存在)。

4

2 回答 2

1

我在这里找到了解决方案:http:
//www.markhneedham.com/blog/2013/03/10/neo4jcypher-finding-football-stadiums-near-a-city-using-spatial/

我们只需要将节点添加到空间索引中。节点应该有一个包含坐标信息的wkt属性。添加到此索引的所有节点也将自动添加到空间层。

IndexProviderTest.java 提供了一个更新的实现:
https ://github.com/mneedham/spatial/blob/master/src/test/java/org/neo4j/gis/spatial/IndexProviderTest.java#L251

@Test
public void testWithinDistanceIndex() {
Map<String, String> config = SpatialIndexProvider.SIMPLE_WKT_CONFIG;
IndexManager indexMan = db.index();
Index<Node> index = indexMan.forNodes("layer2", config);
Transaction tx = db.beginTx();
Node batman = db.createNode();
String wktPoint = "POINT(41.14 37.88 )";
batman.setProperty("wkt", wktPoint);
String batman1 = "batman";
batman.setProperty("name", batman1);
index.add(batman, "dummy", "value");
Map<String, Object> params = new HashMap<String, Object>();
Double[] point = {37.87, 41.13};
params.put(LayerNodeIndex.POINT_PARAMETER,
        point);
params.put(LayerNodeIndex.DISTANCE_IN_KM_PARAMETER, 2.0);
IndexHits<Node> hits = index.query(
        LayerNodeIndex.WITHIN_DISTANCE_QUERY, params);
tx.success();
tx.finish();
Node node = hits.getSingle();
assertTrue(node.getId() == batman.getId());
assertTrue(node.getProperty("name").equals(batman1));
}
于 2014-07-01T17:21:22.180 回答
0

使用Neo4j Spatial 和 Spring Data Neo4j 3.0.1 查找您旁边的梵高的作品

http://inserpio.wordpress.com/2014/04/03/artworks-spatial-search/

完全符合我的要求。@NodeEntity 包含一个wkt属性,并且节点被添加到SpatialRepository

于 2014-07-04T00:37:03.237 回答