Euclidean distance between centroids

4207
2
08-24-2013 05:26 AM
Highlighted
New Contributor
Ok here is another question for my mapping project:

I've got two Layers - "A" and "B". Each layer contains one type of polygons.

What I'm trying to do is to calculate the average euclidean distance between every single polygon (or centroid of every single polygon) of "A" with every centroid of all polygons of "B" (and note in table). - I've attached a graphic to visualize my task.

I've tried so far the "Calculate Distance Band from Neighbor Count" tool but it's looking randomly at neighbors and its count is limited to 9.999.

What do you think I should do?

edit: the calculation of the average distance is not mandatory.
Reply
0 Kudos
2 Replies
Highlighted
New Contributor
In the dinosaur age I would have done something like select out one or a small subset of centroids in A and then calculate distance to all centroids in B. Repeat until have data for all points in A.

I am hoping somebody knows a clever modern way to do this.
Reply
0 Kudos
Highlighted
New Contributor II
Conrad87, I'm not sure if you are familiar with or able to use ArcObjects, but an adaptation of this code will do it for you. Note that you don't have necessarily have to use GeometryBags like in the example, since you aren't comparing feature classes to themselves. You just need to be able to access and loop over each feature class.

Do it like this:

For every polygon in A:
     For every polygon in B:
           Calculate distance from A to B (This is done in the linked example using the IProximityOperator.ReturnDistance() method
           Store distance in an array/list

          

You will want to store your distances in an array/list like in the example, though your data structure may be a bit more complicated because you aren't just looking for the minimum distance like in the example, you need them all to be able to calculate the average.

A data structure like this might work: [FeatureIDA, FeatureIDB, distance]

Then you simply query all distance from your list that have FeatureIDA in the first element and calculate the average from it.
Reply
0 Kudos