spatial
spatial copied to clipboard
possible feature request: WKB or WKT?
Hi,
Is it better ( e.g. faster ) to use WKB or WKT geometries??
If the first, consider:
` @Procedure("spatial.addBase64WKB") @PerformsWrites public Stream<NodeResult> addGeometryWKBToLayer(@Name("layerName") String name, @Name("geometry") String geometryBase64WKB) throws ParseException { EditableLayer layer = getEditableLayerOrThrow(name); WKBReader reader = new WKBReader(layer.getGeometryFactory()); return streamNode(addGeometryWkb(layer,reader,Base64.getDecoder().decode(geometryBase64WKB))); }
private Node addGeometryWkb(EditableLayer layer, WKBReader reader, byte[] geometryWKB) {
try {
Geometry geometry = reader.read(geometryWKB);
return layer.add(geometry).getGeomNode();
} catch (ParseException e) {
throw new RuntimeException("Error parsing geometry: "+geometryWKB,e);
}
} `
We have not done any benchmarking of WKB versus WKT, and would be curious to know if you have.
One option here is for you to make a PR with this code, and a matching test in SpatialProceduresTest for us to consider.
I start getting the feeling that this should be decided by the user. Which means, every WKT/WKB-based importer should have an optional binaryFormat flag, which would make the importer store data as WKB when set to true and as WKT when set to false. The defaults would be based on how things are handled currently, i.e. addGeometryToLayer(...) would have false as default, the ShapefileImporter would have the default true etc. This would be quite an effort, but it might be worth it.
Neo4j 3.1 introduces the ability to have optional and default values on procedures. We could certainly improve spatial procedures to use this for cases like this where it is nice to give the user the choice.
See https://github.com/neo4j/neo4j/pull/7424