Select to view content in your preferred language

Error on Centroid from Polygon script

2362
11
Jump to solution
05-04-2017 01:09 PM
MosquitoGIS
Frequent Contributor

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:
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)
pointGeometryList.append(pointGeometry)

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:/Script.py", line 16 in <module>
    point.X = pt[0]
  File "C:\Program Files (x86)\ArcGIS\Desktop10.5\ArcPy\arcpy\arcobjets\_base.py", 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?

0 Kudos
11 Replies
IanMurray
Honored Contributor

I would run the check geometry and it will tell what the geometry problem is.  You can repair the geometry using the repair geometry tool on the input dataset.  You may wish to make a duplicate dataset to test the repair on first(not that it should cause an issue, but just in case as it does edit your existing dataset).

I haven't directly run into reasons for bad geometries being created, but you can read this help on checking and repairing geometries that should take care of things.

http://desktop.arcgis.com/en/arcmap/10.3/tools/data-management-toolbox/checking-and-repairing-geomet...

MosquitoGIS
Frequent Contributor

Thanks found a few other issues using the tools that I didn't even know I had!

0 Kudos