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
780 stars 192 forks source link

Updating a node creates new RTREE_REFERENCE relationship #229

Open Alex-Wauters opened 8 years ago

Alex-Wauters commented 8 years ago

The nodes in our geospatial index can change location (frequently). At the moment, we modify the properties in the node and add it to the index anew by posting to:

/db/data/ext/SpatialPlugin/graphdb/addNodeToLayer

with

{"layer": "geom", "node", "nodeID"}

Which updates the bounding boxes of the geospatial index, but creates a new RTREE_REFERENCE relationship. Is there a way to update the geospatial location of a node, without creating a new relationship after each update operation?

Alternatively we can create a batch job which reduces X references (X > 1) to 1; or delete the first reference in the same transaction, but preferably we would like to avoid it.

ehx-v1 commented 8 years ago

from what I get, frequently moving things are not supposed to be modeled as geospatial nodes... I mean, you wouldn't call a cow a geospatial landmark, would you? (not meant to offend anyone, just making an example, same with cars and stuff) or, hang on... are you implementing a Sims City-styled virtual building reality with Spatial? that would be an interesting use case the creators certainly haven't thought of! I'd add a "like" to this idea!

Alex-Wauters commented 8 years ago

Sorry to disappoint you, we are not implementing a Sims City-styled virtual building reality. We have neo4j entities with location properties, and would like to use the Neo4j Spatial library for Geospatial operations on Neo4j entities, to perform a geospatial operation (withinDistance) on these entities.

ehx-v1 commented 8 years ago

so it's kind of how far cars are away from each other?

Alex-Wauters commented 8 years ago

Correct, from a certain location. In case anyone is interested, our current approach cleans up the database at regular moments with the following commands:

Clean double relationships

match s-[r:RTREE_REFERENCE]->e 
with s,e,type(r) as typ, tail(collect(r)) as coll 
foreach(x in coll | delete x)

Clean empty bounding boxes:

match (x)-[r:RTREE_CHILD]->(n)
WHERE NOT (n)-[]->()
delete r,n

The latter query would be cleaner if the bounding box nodes had a label, like the RTREE metadata node.