HOW TO
Feature centroids can be calculated in several ways. Depending on how the centroid needs to calculated, there are several possible methods: calculate the features' central XY coordinates, use the Feature to Point tool, or use Python to retrieve centroid coordinates. Instructions provided below describe these methods.
Note: The Feature To Point tool is only available at the Advanced Desktop or ArcInfo, license level.
The Feature To Point tool is used to create a new feature class containing points generated from the representative locations of input features. The algorithms for the specific calculation are proprietary, but there are two basic concepts used.
The tool calculates the centroid of multipoint, line, or polygon input using a center of gravity-based algorithm. The center of gravity calculation uses the geometric center model to output the new point feature class. For lines, polygons, or three-dimensional features, it is the center of mass (center of gravity) and may fall inside or outside the feature. For multipoint, polylines, or polygons with multiple parts, it is computed using the weighted mean center of all feature parts.
Within the tool parameters there is an option to calculate the centroid that falls within the feature boundaries; this option can be enabled by checking the box for 'inside'. Enabling this parameter forces the tool to calculate a centroid that is inside the feature boundaries, if it originally falls outside the boundaries the point will be adjusted to what is considered the center of gravity within the boundaries.
Note: The Data Access cursors are available only at ArcGIS 10.1 and higher. See Reading Geometries and Writing Geometries for alternative workflows for version 10.x.
import arcpy
input_fc = "C:\\temp\\geodatabase.gdb\\states"
output_fc = "C:\\temp\\geodatabase.gdb\\state_centroids"
cursor = arcpy.da.SearchCursor(input_fc, "SHAPE@XY")
centroid_coords = []
for feature in cursor:
centroid_coords.append(feature[0])
point = arcpy.Point()
pointGeometryList = []
for pt in centroid_coords:
point.X = pt[0]
point.Y = pt[1]
pointGeometry = arcpy.PointGeometry(point)
projectedPointGeometry = pointGeometry.projectAs("WGS 1984")
pointGeometryList.append(projectedPointGeometry)
arcpy.CopyFeatures_management(pointGeometryList, output_fc)
Article ID: 000011754
Get help from ArcGIS experts
Start chatting now