I have two shapefiles with different points (cities) in lat/lon, and I am running the Near Analysis tool to find the nearest point in the second shapefile for each point in the first one. However, I want to condition this such that both points in each dataset lie within the same polygon (e.g, an administrative region), or such that in the resulting near table I can at least see in which region each point is, along with the region of its corresponding nearest feature (so as to check if they match). I have a shapefile with the boundaries of all of said regions.
For instance: if I am looking at a point that happens to lie next to the boundary of the region it is in, the nearest point may be just outside of that boundary, in a different region. This is not useful for my purposes, as both points must lie within the same region
What would be the optimal strategy to proceed in this case? I am using ArcMap, and if necessary I can run ArcPy commands.
When I initially ran this without any sort of condition (e.g, simply using Near for points in the first .shp to the second one), while many points where correctly assigned a nearest point that lied in the same region (this was easy to check because their names were similar), many other points were matched to others in nearby (but not the same) regions, or even really far away regions (as there is far from perfect overlap in the coverage of each shapefile). This question, which I asked earlier, is related what I first did.
Please note that neither shapefile contains features that can be later compared after joining a generated NearTable, as suggested in the answer to this. To check, I would have to see in which region each of the initial points lie, and check whether each of the nearest ranked towns are in the same region or not. These regions' boundaries are in a separate shapefile. What I am asking is how to proceed with this.