Reputation: 13
We are developing a project in Neo4j with spatial plugin but we can't filter on label of nodes obtained after the call. The query we want to realize has to connect 2 nodes of type 'Street' that are within 0.1 of distance. The following code works with every node, but we can't use a filter.
MATCH (s1:Street) with s1
CALL spatial.withinDistance('streets',{latitude: s1.latitude, longitude: s1.longitude},0.1)
yield node as s2
WHERE s1.id<s2.id AND s2
CREATE (s1)-[:NEXT_TO]->(s2)
RETURN s1,s2
Obviously here relation NEXT_TO is built between every node (even not Street) that is near s1. We don't know how to filter on s2 to catch only nodes with label Street. We tryed many solution but none worked. Can u help us? Thank you
EDIT:
The solution is
MATCH (s1:Street) with s1
CALL spatial.withinDistance('layer',{latitude: s1.latitude, longitude: s1.longitude},0.1)
yield node as s2
WHERE s1.id<s2.id AND 'Street' in labels(s2)
CREATE (s1)-[:NEXT_TO]->(s2)
return s1,s2
I simply forgot to load Street nodes when i loaded all other nodes, my mistake
Upvotes: 1
Views: 59
Reputation: 31
MATCH (s1:Street) with s1
CALL spatial.withinDistance('streets',{latitude: s1.latitude, longitude: s1.longitude},0.1)
yield node as s2
WHERE s1.id<s2.id AND s2:Street
CREATE (s1)-[:NEXT_TO]->(s2)
RETURN s1,s2
I added the where clause s2:Street, have you tried that? Maybe I didnät udnerstand the question properly.
Upvotes: 1