AnsweredAssumed Answered

How can I calculate the centroid of all point features contained in each polygon feature (search cursor)?

Question asked by kristenm37 on Nov 28, 2016
Latest reply on Nov 28, 2016 by dkwiens

I have a polygon feature class and a point feature class. For each polygon, I would like to:

(1) Select the points contained in that polygon and 

(2) Calculate the centroid of those selected points


Ideally, I would end up with a new point feature class called "centroids", for example, that would have a centroid for each polygon (they are named with "Name").


I'm a beginner in ArcPy, especially with search cursors. So far, I've tried writing something to iterate over each polygon (farm), select the points(turbines) within the farm, calculate the centroid of those points, and create a layer named "turbine_center"+the name of the farm. I'm running into an error in the SelectLayerByLocation tool:


turbines= working + "Turbines_eastern.shp"
farms_poly= working + "Farms_polygons.shp"

arcpy.MakeFeatureLayer_management(farms_poly, "farms_poly_lyr")
arcpy.MakeFeatureLayer_management(turbines, "turbines_lyr")

for farm in rows:
    print farmName
    arcpy.SelectLayerByLocation_management("turbines_lyr", "intersect", farm)
    arcpy.MeanCenter_stats("turbines_lyr", "turbine_center_"+farmName)


Any help would be greatly appreciated!