【问题标题】:Add NodeEntity directly into Neo4j-Spatial layer?将 NodeEntity 直接添加到 Neo4j-Spatial 层?
【发布时间】:2014-07-01 03:02:45
【问题描述】:

我有一个类 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类型的节点中存在)。

【问题讨论】:

    标签: playframework neo4j neo4j-spatial


    【解决方案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));
    }
    

    【讨论】:

      【解决方案2】:

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

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

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

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2013-06-08
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多