Good day,
I want to work with building geometries on a larger scale. For that purpose, I am importing geometry data from various sources (also shp-files) to an embedded neo4j database working with spring-data-neo4j. So far so good.
Where I am stuck:
In my domain, I define a Building
entity that has a shape Polygon wkt;
Is it possible to create a node having a Polygon
property via the CRUDRepository
?
With a Point
it would work just fine: e.g.
@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);
The problem is that there are no IndexTypes implemented for Lines
and Polygons
.
This is my first project with spring-data and neo4j so I am unsure which direction I should take.
Taking a look at the neo4j spatial documentation shows that using wkt's, it should be possible to store Polygon
s (see http://neo4j-contrib.github.io/spatial/#spatial-server-plugin)
https://stackoverflow.com/a/26567534 also proposes to create a spatial index via REST. Another suggestion is this one: https://stackoverflow.com/a/24741823.
I tried to manually create a spatial index like so:
Transaction tx = template.getGraphDatabaseService().beginTx();
template.getGraphDatabaseService().index().forNodes("building_wkt_index", MapUtil.stringMap(
IndexManager.PROVIDER, "spatial", "geometry_type", "polygon", "wkt", "wkt"));
tx.success();
and call the repository's save(). However, this doesn't seem to work. The wkt is not stored, it's null.
Is it possible to use this named index (is that even possible) in my Building
somehow - or is moving all the transactions over the neo4j spatial plugin's REST really the only way to do this.
Would it for example be possible to implement a new IndexType
?
all input is much appreciated!