# Calculate the distance from pts to polygon centroids

4192
5
08-26-2015 06:18 AM
New Contributor II

I have a census boundary polygon layer and a point layer containing facilities, I would like to calculate the distance from each facility to the centroid of the polygon boundary layer it is contained by. The near function as far as I can tell will only give zeros for pts contained within the polygon so that won't work for me. Also, if I convert the boundary polygons to centroids I don't know how to calculate only the distance to polygon centroids that each facility is contained by.

Any suggestions?

I suspect this may be a multipart soloution.

1 Solution

Accepted Solutions
New Contributor II

So in the end I used the method that seemed the easiest and took the least steps

• made a spatial join between the facility points and the census boundary polygons to obtain the census polygon ID for each facility point
• joined attribute tables using the censusID to centroids layer
• calculated the distance between the facility XY to the census boundary centroid XY using field calculator (I actually took the attribute table out and did this calc in Excel as I need to reuse the model for many other census boundaries and faciilty point and I didn't know how to quickly change the Calc to reflect the field names).  =SQRT((CensusX-FacX)^2+(CensusY-FacY)^2)
5 Replies
MVP Frequent Contributor

I think if you use the point facilities layer and the centroids, Near would work.

Determines the distance from each feature in the input features to the nearest feature in the near features, within the search radius.

Near (Analysis)

Chris Donohue, GISP

New Contributor II

Except I need to calculate the distance from each facility point to only the centroid of the polygon that contains it, not the nearest polygon.

I'm going to try a spatial join between the facility points and the census boundary polygons to obtain the census polygon ID for each facility point, then in the attribute table I should be able to join using the ID to centroids layer and then calculate the distance between the facility XY to the census boundary centroid XY using field calculator. That's my plan anyway.

MVP Frequent Contributor

Besides Carls' suggestion of scripting, Modelbuilder could also be a means to accomplish your analysis.

ArcGIS Help (10.2, 10.2.1, and 10.2.2)

It would go something like this:

1. Iterate by record for your facility feature class.

Iteration examples:

ArcGIS Desktop

2. Select by location the Census polygon your facility is in.

3. Feature to Point of the Census polygon Selection.

4. Run Near

Note - you will probably want to use In-line Variable Substitution to name the Near outputs so as to keep them organized.  For example, you could have the outputs be named based on the facility ID's.

ArcGIS Help (10.2, 10.2.1, and 10.2.2)

Chris Donohue, GISP

New Contributor II

Hi Christina.  I looked at this for a while this morning and convinced myself that I could do something very clever with an intersect (facilities and block groups) and a join (facilities to centroids).  It didn't work.  I suspect that you will need a script which steps through your block groups, selects the facilities within the block group, runs the near tool to the previously created centroid,  and then moves on to the next block group record.  The Python technology is generically referred to as using cursors to access data.

Good luck.

New Contributor II

So in the end I used the method that seemed the easiest and took the least steps

• made a spatial join between the facility points and the census boundary polygons to obtain the census polygon ID for each facility point
• joined attribute tables using the censusID to centroids layer
• calculated the distance between the facility XY to the census boundary centroid XY using field calculator (I actually took the attribute table out and did this calc in Excel as I need to reuse the model for many other census boundaries and faciilty point and I didn't know how to quickly change the Calc to reflect the field names).  =SQRT((CensusX-FacX)^2+(CensusY-FacY)^2)