A similar question was posted here, but I have an additional problem that seems to make the answers there unlikely to work. I am interested in performing a spatial join between point feature class A (target) and point feature class B in order to get the feature in B that is closest to each feature in A. However, I would like it to be the case that a feature in B must be in the same country as feature in A in order for it to be joined. The difficulty, is that the closest feature in B to feature in A may in fact be in a different country, but the next closest feature in B may be in the same country, and this is the feature I'd like to have the spatial join return. While model builder seems to allow me to iterate through selection of one feature class (the "feature selection" iterator), it does not seem to allow me to iterate a feature selection that draws on attributes for two feature classes, so that I could set the country fields equal before performing the spatial join. (I'd like to avoid using python since I don't have any experience with it).
If you want to use model builder probably the simplest approach would be to expose some of your inputs as parameters and turn your whole model into a tool.
If it were me:
- I would expose the the
whereclauseof a select by attribute tool which allows you to enter the code for a county. Apply this selection process on feature class A and B.
- You now have two featureclass each with points select for a specific county, run the spatial join with these.
Most tools honour selections so only these points will be processed.