Skip to main content

I have two point datasets, GPoints (~100 points) and OPoints (~1000 points), and I want to find the nearest neighbor for each GPoints entry. However, the nearest neighbor from OPoints must have an ID that matches the values from 2 possible columns in GPoints. In this case the column names are id1 and id2.

 

E.g.The first entry in GPoints has values of id1 = 9001 and id2 = 9005. Therefore the nearest neighbor from OPoints must have an id of 9001 or 9005 (whichever is closest to the entry in GPoints current being analyzed). In SQL this would be WHERE OPoints.id = GPoints.id1 OR OPoints.id = GPoints.id2.

Use a NeighborFinder without Number of Neighbors to Find (but you may want to set a Maximum Distance), and enable Generate List (select attribute ID). Next use 2 ListSearchers (one for ID1, one for ID2), and copy the found list element with prefix ID1_ and ID2_ respectively. Finally use an AttributeManager: if ID1_distance <= id2_distance copy the ID and distance of ID1, else copy the ID and distance of ID2.

NeighborFinder_OPoints


Use a NeighborFinder without Number of Neighbors to Find (but you may want to set a Maximum Distance), and enable Generate List (select attribute ID). Next use 2 ListSearchers (one for ID1, one for ID2), and copy the found list element with prefix ID1_ and ID2_ respectively. Finally use an AttributeManager: if ID1_distance <= id2_distance copy the ID and distance of ID1, else copy the ID and distance of ID2.

NeighborFinder_OPoints

Thanks geomancer, that works perfectly! Lists seem very powerful and versatile, I will have to look into them more.


Reply