1

再会,

我想在更大的范围内构建几何图形。为此,我将几何数据从各种来源(也是 shp 文件)导入使用 spring-data-neo4j 的嵌入式 Neo4j 数据库。到现在为止还挺好。

我被困在哪里:在我的域中,我定义了一个Building具有形状的实体Polygon wkt; 是否可以通过创建具有Polygon属性的节点CRUDRepository

有了Point它就可以了:例如

@NodeEntity
public class Building implements Serializable{
    @GraphId
    private Long id;
    @Indexed(indexType = IndexType.POINT, indexName = "building_wkt_index", unique = false)
    private Point wkt;
}

public interface BuildingRepository extends GraphRepository<Building>, SpatialRepository<Building>{
/**
 * CRUD
 */
}

Building b = new Building();        
b.setWkt(new Point(12,12));
buildingService.save(b);

问题是没有为Lines和实现 IndexTypes Polygons。这是我第一个使用 spring-data 和 neo4j 的项目,所以我不确定我应该采取哪个方向。查看 neo4j 空间文档显示使用 wkt 应该可以存储Polygons(参见http://neo4j-contrib.github.io/spatial/#spatial-server-plugin

https://stackoverflow.com/a/26567534还建议通过 REST 创建空间索引。另一个建议是:https ://stackoverflow.com/a/24741823 。

我尝试像这样手动创建空间索引:

Transaction tx = template.getGraphDatabaseService().beginTx();
template.getGraphDatabaseService().index().forNodes("building_wkt_index", MapUtil.stringMap(
IndexManager.PROVIDER, "spatial", "geometry_type", "polygon", "wkt", "wkt"));
tx.success();

并调用存储库的 save()。但是,这似乎不起作用。wkt 没有被存储,它是空的。

是否有可能以Building某种方式使用这个命名索引(甚至可能) - 或者将所有事务移动到 neo4j 空间插件的 REST 上真的是唯一的方法。

例如,是否可以实施一个新的IndexType? 非常感谢所有输入!

4

1 回答 1

0

对于任何对可能的解决方案感兴趣的人:

第一次我手动创建一个空间索引:

template.getGraphDatabaseService().index().forNodes("your_spatial_index", MapUtil.stringMap(
            IndexManager.PROVIDER, "spatial", "geometry_type","polygon","wkt", "wkt"));

在域实体中,wkt 存储为字符串:

String wkt;

然后我将存储库访问权限移至服务。保存新节点时,手动将该节点添加到空间索引中:

Transaction tx = template.getGraphDatabase().beginTx();
Node n = template.getNode(b.getId());
template.getGraphDatabase().getIndex("your_spatial_index").add(n,"id",b.getId());
tx.success();
tx.close();

至少,这是将多边形 wkt 添加到 R-Tree 的快速修复。但是,更新和删除索引节点必须手动处理。

于 2015-04-27T18:39:52.327 回答