Open TomMRiddleJr opened 3 years ago
This kind of capability certainly exists inside this library, but is not exposed in the procedures, and therefor you would have to write a procedure for this. On the other hand, you mention that you are dealing with arrays of Neo4j point
objects, which would make this quite suitable to the newer library at https://github.com/neo4j-contrib/spatial-algorithms. That library is more focused on just the basic algorithms, including graph intersection. However, I do remember it does have some bugs in graph intersection.
There are already two user-defined functions in that library that sound appropriate:
spatial.algo.intersection
as defined at https://github.com/neo4j-contrib/spatial-algorithms/blob/master/neo4j/src/main/java/org/neo4j/spatial/neo4j/UserDefinedFunctions.java#L403spatial.algo.intersection.sweepline
as defined at https://github.com/neo4j-contrib/spatial-algorithms/blob/master/neo4j/src/main/java/org/neo4j/spatial/neo4j/UserDefinedFunctions.java#L419I've not tried those functions myself. Hopefully they work for you.
If you specifically want to use the spatial
library, then you will need to write a procedure that does this. There already exists one that is close:
spatial.intersects
at https://github.com/neo4j-contrib/spatial/blob/master/src/main/java/org/neo4j/gis/spatial/procedures/SpatialProcedures.java#L856This currently returns a list of geometries that intersect the geometry provided. You could, for example, copy it and enhance the copy to return a list ordered by overlap area. The underlying library uses a concept called a GeoPipeline
which allows chaining of operators, so you would need one operator to convert geometries to pairs of geometry and overlap area, and then another to sort that.
Actually, you would not need to write the sorting, as you could do this in Cypher afterwards:
MATCH (n:Geometry) WHERE n.id = $selected
CALL spatial.intersects.area('mylayer',n.geom) YIELD area, node, geometry
RETURN area, geometry ORDER BY area DESC LIMIT 1
Of course, you still need to write the procedure spatial.interests.area
, but that is probably quite similar to the existing spatial.interests
function.
Thanks for your reply. I was wondering if I could deploy our user defined procedure in a managed Neo4j service like Aura? Please let us know! @craigtaverner
Aura currently does not support custom plugins, but I presume that might be a feature sometime in the future. I believe some of our enterprise customers have custom plugins, but that was always done on a case-by-case basis, and is not part of the standard service.
In fact, none of the spatial plugins are currently available for Aura at all. APOC, on the other hand, is available on all Aura instances. I once considered adding the spatial-algorithms
library to APOC, but it requires more work for that.
I have this use case where: -
Polygon here is list of Points, of course.
For instance, in the image shown below: -
I could not find an example to calculate area of intersection, let alone iterating and finding the maximum. Could you please help me with this problem statement? @craigtaverner