0

I have a Feature class with 285k point features. I am running this code on it:

with arcpy.da.UpdateCursor(FeatClass, ["SHAPE@XY"]) as cursor:
    for row in cursor:
        cursor.updateRow([[row[0][0] + transformX,row[0][1] + transformY]])

transformX and transformY are floats. This code has worked previously but fails with the error:

Runtime error 
Traceback (most recent call last):
  File "<string>", line 3, in <module>
TypeError: unsupported operand type(s) for +: 'NoneType' and 'float'

There are no gaps in the ObjectID, so apparently this is saying one of the objects has geometry of NoneType? Does that even make sense? If so, how do I identify the problem?

  • You'll probably want to print the OBJECTID of the feature that yields that error so you can manually check it. Knowing the OBJECTID allows you also to create a cursor for just that feature and run some tests and gain some insights about the issue. – Marcelo Villa Aug 21 at 20:24
3

You have features in your feature class without geometry. "SHAPE@XY" returns (None, None) when a feature has no geometry. As @MarceloVilla suggested, you can print out the OBJECTID of the features without geometry if you're interested knowing these.

with arcpy.da.UpdateCursor(FeatClass, ["SHAPE@XY", "OID@"]) as cursor:
    for (x, y), oid in curs:
        if x == None or y == None:
            print "null geometry in oid {}".format (oid)
        else:
            row = ((x + transformX, y + transformY), oid)
            cursor.updateRow (row)
  • How is it possible for a feature to have no geometry? I suspect that there was geometry previously, and a user somehow was able to remove the geometry without removing the entire record. I'm not sure how that works because if I were to select a feature either in the table or on screen and delete it, the entire feature would be gone. – Craig T Aug 21 at 21:04
  • The geometry is a bit like at attribute (not quite that simple, but it's similar). You can have a <NULL> attribute (ie and attribute with no value). Similarly, you can have a feature with no geometry (at least in some databases). – Son of a Beach Aug 21 at 23:56

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.