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:
working="S:/Wind/"
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")
fc="farms_poly_lyr"
rows=arcpy.SearchCursor(fc)
for farm in rows:
farmName=farm.getValue("Name")
print farmName
arcpy.SelectLayerByLocation_management("turbines_lyr", "intersect", farm)
arcpy.MeanCenter_stats("turbines_lyr", "turbine_center_"+farmName)
Any help would be greatly appreciated!