Select to view content in your preferred language

Average Distance between all Points in the same Polygon

8060
7
07-10-2018 01:35 PM
RobertSchmidt
New Contributor

Hello Everybody,

I would be happy, if you could help me with this one:

I have a point shape containing almost 30000 points and I have a polygon shape with thousands of polygons. Every Point that is within one of the polygons has already been spatially joined with the ID of the polygon.

What I want to do: For every point I want to calculate the average (euclidean) distance to every other point within the same polygon (same polygon ID in the table).

It doesn't necessarily have to be an ArcGIS solution, Excel f.ex. would be just as fine.

The idea is to have a variable that tells me how centrally located a retailer is inside a shopping area (central as in close to the other retailers of the same type).

Thank you,

Robert

0 Kudos
7 Replies
DanPatterson_Retired
MVP Emeritus

sample data?

As long as the points can be differentiated by a polygon id, then it is readily accomplisable

0 Kudos
JoeBorgione
MVP Emeritus

Have a look here for starters:  Proximity analysis—Help | ArcGIS Desktop  IIRC, the near tool gives you a distance to nearest point,with a little math you could find the average.

That should just about do it....
0 Kudos
DanPatterson_Retired
MVP Emeritus

Joe... most of those require origins and destinations.  Robert is looking for inter-point distances with point sets being defined by polygonal bounds.

Sort of like a 'standard distance' value within a polygon.  It is a measure of spread of point sets where you get a 'central location' and a standard distance(deviation) about the center).  See the link below

Standard Distance—ArcGIS Pro | ArcGIS Desktop 

but this has to be done on a polygon-by-polygon basis for the points therein

JoeBorgione
MVP Emeritus

I just used the Generate Near Table in ArcMap.  Here is what the output looks like:

This is what I was thinking of.  There are 2159 points in the feature class I used as test data (actually a shapefile someone just gave me today.) Notice IN_FID is the origin, while NEAR_FID is the nearest point to the IN_FID.  Consequently there are 2159 records in the new table.  After that, use the statistics tool to fine the mean distance...

Generate Near Table—Help | ArcGIS Desktop 

That should just about do it....
DanPatterson_Retired
MVP Emeritus

That is what I was referring to, there is an 'origin' for determining the distance.  I think the OP wants the interpoint distance of the points of points within each polygon.

using the standard distance approach you get the 'center' point of the points within the polygon and the 'standard distance' (think standard deviations of X and Y)

We await data 

DanPatterson_Retired
MVP Emeritus

The Standard Distance approach is shown below.

If you want an actual distance matrix, then this can be done using numpy to produce the inter-point distances.

If you don't have the Spatial Analyst extension, then it can also be accomplished using python and numpy (see after the figure).

 

And in python and numpy (I will leave the process for a blog if this is what you need).

So for the first grouping (ID_poly = 1 and Group 0), one can see that the centres and standard distance are the same.

A distance matrix was also produced.  A triangular 'distance matrix' for the interpoint distances was also created.  The diagonal is the distance between each point and itself.  The upper portion of the matrix is set to zero to obliviate reduncancy.  The code, takes all the non-zero distances and determines the mean, st. dev, min and max.  Others are possible

The Standard distance calculated by the tool was an unweighted version and the 1 std level was returned.  The 'mean' on line 7 is the actual mean for non-zero distances.

So depending on whether you need the actual mean distance or its representation as a standard distance will depend on whether you have the Spatial Statistics extension and/or you are comfortable working with scripts.

All code is available on my GitHub site if people are interested.  I will post a blog if people want to see more.

Group .... 0
center ... [ 304932.447  5029991.887]
standard distance ... 795.1178530213251
distance matrix...
None
distance results...
  mean 1007.3678550988518, std dev. 551.9146638939515
  min  101.17610884053616, max      2390.932849486734


Array... ndim: 2  shape: (12, 12)
. .     0.00    0.00    0.00    0.00    0.00    0.00    0.00    0.00    0.00    0.00    0.00    0.00
. .   812.74    0.00    0.00    0.00    0.00    0.00    0.00    0.00    0.00    0.00    0.00    0.00
. .   391.33  643.55    0.00    0.00    0.00    0.00    0.00    0.00    0.00    0.00    0.00    0.00
. .  1005.12  409.87  684.66    0.00    0.00    0.00    0.00    0.00    0.00    0.00    0.00    0.00
. .   993.58  487.05  647.33  106.07    0.00    0.00    0.00    0.00    0.00    0.00    0.00    0.00
. .   907.22  656.05  520.52  366.66  266.74    0.00    0.00    0.00    0.00    0.00    0.00    0.00
. .   986.74  610.91  611.61  261.82  155.89  130.31    0.00    0.00    0.00    0.00    0.00    0.00
. .  1412.86  720.89 1089.91  409.13  448.20  677.07  546.80    0.00    0.00    0.00    0.00    0.00
. .  1279.06  853.66  896.31  447.52  369.04  377.20  297.74  476.16    0.00    0.00    0.00    0.00
. .  1219.59 1066.13  834.18  721.09  616.09  414.75  465.26  873.02  401.06    0.00    0.00    0.00
. .  1590.81 1037.28 1219.36  642.71  611.39  710.86  607.75  397.82  345.04  692.24    0.00    0.00
. .  1974.80 1412.32 1598.21 1027.38  999.50 1081.79  988.51  719.41  705.05  966.16  388.12    0.00