I recently started using neo4j db and its spatial plugin.
My data model consist of 4 different nodes: Building, Floor, Room and Device. All of them related by the relationship "HAS".
The node added to the spatial layer is Building.
This is how it looks at this moment:
To get all the Buildings that intersect in a given polygon I'm using the next cypher
WITH 'POLYGON((-6.342523097991944 39.47879396554205, -6.339948177337647
39.47879396554205, -6.339948177337647 39.478121118127696,
-6.342523097991944 39.478121118127696, -6.342523097991944
39.47879396554205))' as polygon
CALL spatial.intersects('geom',polygon) YIELD node
RETURN node
Particularity that returns one building:
Now, what I'm trying to do is to obtain the sub-graph holding from the intersected Building. Here is my try:
WITH 'POLYGON((-6.342523097991944 39.47879396554205, -6.339948177337647
39.47879396554205, -6.339948177337647 39.478121118127696, -6.342523097991944
39.478121118127696, -6.342523097991944 39.47879396554205))' as polygon
CALL spatial.intersects('geom',polygon) YIELD node
MATCH (node)-[:HAS]->(Floor)-[:HAS]->(Room)-[:HAS]->(Device)
RETURN *
That outputs the next graph:
That result is similar of what I want but not exactly. What I need is all the intersected building, all its floors, rooms and devices. This result is only giving my the floors that have rooms and the rooms that have devices. I don't know how to write the cypher to get what I need.
Apart from that, the previous cypher is taking around 7 seconds to output the results, is that time normal with the size of my actual graph? It seems a lot to me.
Thank you!
:
before the labels. aka(room:Room)
- Michael Hunger