2

是否可以检查 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")

两者都返回。

有人能帮助我吗?

4

1 回答 1

0

好的,也许这是这个问题的一些答案。

查看 neo4j-spatial 代码,我们在文件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? ”。看起来插件的原作者也有类似的想法。

于 2015-01-09T20:59:10.153 回答