交叉点匹配通过密码?

时间:2015-01-09 17:27:55

标签: neo4j spring-data-neo4j neo4j-spatial

可以检查WKT几何体是否与另一块几何体相交(通过Cypher)?

例如,如何对它们进行空间搜索以返回与给定边界框相交的任何内容?

例如,如果我有空间索引节点:

@NodeEntity
class Route {
    @GraphId Long id;
    @Indexed(indexType = IndexType.POINT, indexName = "routeSpatial") String wkt
}

和两个这样的例子:

{ wkt: "LINESTRING (12 10, 14 12, 17 12, 18 10) }

{ wkt: LINESTRING (18 15, 18 12, 14 9, 14 6, 17 3, 20 3) }

似乎:

@Query("START n=node:routeSpatial('bbox:[15.000000, 20.000000, 9.000000, 16.000000]') RETURN n")
尽管与两条线相交,

也不会返回任何内容。

而边界框完全包围两个几何,

@Query("START n=node:routeSpatial('bbox:[7.000000, 24.000000, 2.000000, 17.000000]') RETURN n")

返回两者。

有人能帮助我吗?

1 个答案:

答案 0 :(得分:0)

好的,或许这里有一些问题的答案。

查看neo4j空间代码,我们在文件 SpatialPlugin.java

中找到以下内容
@PluginTarget(GraphDatabaseService.class)
@Description("search a layer for geometries in a bounding box. To achieve more complex CQL searches, pre-define the dynamic layer with addCQLDynamicLayer.")
public Iterable<Node> findGeometriesInBBox(
        @Source GraphDatabaseService db,
        @Description("The minimum x value of the bounding box") @Parameter(name = "minx") double minx,
        @Description("The maximum x value of the bounding box") @Parameter(name = "maxx") double maxx,
        @Description("The minimum y value of the bounding box") @Parameter(name = "miny") double miny,
        @Description("The maximum y value of the bounding box") @Parameter(name = "maxy") double maxy,
        @Description("The layer to search. Can be a dynamic layer with pre-defined CQL filter.") @Parameter(name = "layer") String layerName) {
//    System.out.println("Finding Geometries in layer '" + layerName + "'");
    SpatialDatabaseService spatialService = getSpatialDatabaseService(db);

    try (Transaction tx = db.beginTx()) {

        Layer layer = spatialService.getDynamicLayer(layerName);
        if (layer == null) {
            layer = spatialService.getLayer(layerName);
        }
        // TODO why a SearchWithin and not a SearchIntersectWindow?

        List<Node> result = GeoPipeline
                .startWithinSearch(layer, layer.getGeometryFactory().toGeometry(new Envelope(minx, maxx, miny, maxy)))
                .toNodeList();
        tx.success();
        return result;
    }
}

请注意“ TODO为什么SearchWithin而不是SearchIntersectWindow?”。看起来这个插件的原作者有类似的想法。