0

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.

5
  • there's a behavior across the majority of gp tools which is: if input is a layer with a selection, only the selected features will be used. What you could do is loop over each admin boundary and use SelectLayerByLocation to select cities and points in the second shapefile, then run Near or GenerateNearTable on the cities.
    – gotchula
    Mar 3, 2022 at 1:20
  • What result did you get from running the analysis N times with selection sets for N administrative units?
    – Vince
    Mar 3, 2022 at 1:21
  • @Vince If you are referring to running the near analysis unconditional on points lying within the same boundary, I got mixed results. Some points matched accordingly, but others were clearly matched to points in a nearby, but not the same, region
    – Kamyen
    Mar 3, 2022 at 1:45
  • @gotchula I think this makes sense, so I will try to give it a go and see how it goes
    – Kamyen
    Mar 3, 2022 at 1:46
  • @gotchula Related to this, say I instead wanted to generate a NearTable with the top X nearest points in the second file, and the region they belong to, regardless of whether it is the same as the points in the first shapefile or not. How could I proceed? (This is because, for my purposes, it may be informative to see potential closest matches even if they are not within the boundaries)
    – Kamyen
    Mar 3, 2022 at 2:01

1 Answer 1

1

This is what you originally managed to produce using Near tool:

enter image description here

It's enough to assign admin. regions id to setA and setB:

enter image description here

Transfer regions' ID to output of Generate Near Table, delete non-matching rows:

enter image description here

delete identical in near table using IN_FID and to get this:

enter image description here

This is essentially duplicate of 2nd post you are referring to and this is why I closed it.

2
  • Thank you for the clarification. From reading the question I linked, I was not able to understand it the way you put it here. How would I go about assigning admin regions ID to set A and set B? Is this done following step 2, as described in Matt Goodman's explanation of your comment to that question?
    – Kamyen
    Mar 3, 2022 at 13:56
  • Try near between A and regions.
    – FelixIP
    Mar 3, 2022 at 18:55

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.