AnsweredAssumed Answered

Error on Centroid from Polygon script

Question asked by mosquitogis on May 4, 2017
Latest reply on May 5, 2017 by mosquitogis

So, for the record, I don't know jack about Python!  And I am pretty sure this is a pretty basic question.


I want to create Centroids from polygon features.  I found some code that does this:


import arcpy
arcpy.env.overwriteOutput = True

input_fc = "N:\\GeoDatabase.gdb\\SpotHistory"
output_fc = "\\\\SERVER\\Send\\CentroidHist"

cursor = arcpy.da.SearchCursor(input_fc, "SHAPE@XY")
centroid_coords = []
for feature in cursor:

point = arcpy.Point()
pointGeometryList = []

for pt in centroid_coords:
point.X = pt[0]
point.Y = pt[1]

pointGeometry = arcpy.PointGeometry(point)

arcpy.CopyFeatures_management(pointGeometryList, output_fc)


The issue is it works on most of my polygon features no problem.  But on another, I get the following error:

Traceback (most recent call last):
  File "N:/", line 16 in <module>
    point.X = pt[0]
  File "C:\Program Files (x86)\ArcGIS\Desktop10.5\ArcPy\arcpy\arcobjets\", line 89, in _set
  return setattr(self._arc_object, attr_name, cval(val))
RuntimeError: Point: Input value is not numeric

What do I need to do to fix this?