neo4j-contrib / spatial

Neo4j Spatial is a library of utilities for Neo4j that faciliates the enabling of spatial operations on data. In particular you can add spatial indexes to already located data, and perform spatial operations on the data like searching for data within specified regions or within a specified distance of a point of interest. In addition classes are provided to expose the data to geotools and thereby to geotools enabled applications like geoserver and uDig.
http://neo4j-contrib.github.io/spatial
Other
778 stars 192 forks source link

Legacy index doesn't delete nodes properly. #236

Closed Infiniverse closed 8 years ago

Infiniverse commented 8 years ago

In LayerNodeIndex we add a node as follows:

public void add( Node geometry, String key, Object value ) { Geometry decodeGeometry = layer.getGeometryEncoder().decodeGeometry( geometry ); Node matchingNode = findExistingNode( geometry ); if (matchingNode == null) { SpatialDatabaseRecord newNode = layer.add( decodeGeometry, new String[] { "id" }, new Object[] { geometry.getId() } ); idLookup.add(newNode.getGeomNode(), "id", geometry.getId()); }

When it's subsequently deleted it happens like this:

public void remove( Node node ) { try { layer.removeFromIndex( node.getId() ); idLookup.remove(((SpatialDatabaseRecord) node).getGeomNode()); } catch (Exception e) { //could not remove } }

This fails because node isn't a SpatialDatabaseRecord, so the exception is thrown and the spatial description of the node isn't removed from the RTree.

Ought it not to say: idLookup.remove(findExistingNode(node));

ehx-v1 commented 8 years ago

they already noticed that, see #139

craigtaverner commented 8 years ago

I believe this is fixed by https://github.com/neo4j-contrib/spatial/commit/f24ef823c87721831e2d4a3273fe01eacb802ff6. I will close this issue, but if you have other failing tests, feel free to re-open with more details. My own fix does include a test case which failed before the fix and passes now.

Infiniverse commented 8 years ago

Thanks Craig - we appreciate your effort on this. ++owedbeer.

craigtaverner commented 8 years ago

I made a release of 0.15-neo4j-2.3 for 2.3.4 that includes this fix. It can be downloaded from https://github.com/neo4j-contrib/m2/blob/master/releases/org/neo4j/neo4j-spatial/0.15-neo4j-2.3.4/neo4j-spatial-0.15-neo4j-2.3.4-server-plugin.zip?raw=true