The goal is to find all the records that were deleted comparing yesterday and today versions of the same feature class.
I am running a python script that uses cursors. With the curosr I am able to identigy the record that was deleted because it was in the featuer class yesterday but not today.
When I insert a new record using "arcpy.da.InsertCursor", "curAppend.insertRow( rowYesterday)", two fields SHAPE_length and SHAPE_Area are equal to 0. ArcCatalog does not show any shape information in the preview, but shows only attributes in the Table view. It looks like features were created witout spatial data, only attributes.
dsc = arcpy.Describe(Layer_DEFAULT) fields = dsc.fields # # List all field names except the OID field # fieldnames = [field.name for field in fields if field.name != dsc.OIDFieldName] curYesterday = arcpy.da.SearchCursor(Layer_DEFAULT, fieldnames) curToday = arcpy.da.SearchCursor(Layer_PREPROD, fieldnames) curAppend = arcpy.da.InsertCursor(Layer_D,fieldnames) for rowYesterday in curYesterday: # # layerID = layerID # datetimeVal = CRTDATE # layerID = rowYesterday datetimeVal = rowYesterday #print rowYesterday #print rowYesterday #print rowYesterday #print rowYesterday #print rowYesterday #print rowYesterday if datetimeVal is not None: whereClause = '"AGMID" = %s' % (layerID) srcToday = arcpy.da.SearchCursor(Layer_PREPROD, fieldnames, whereClause) count = 0 for rowToday in srcToday: if rowToday == rowYesterday: count = count + 1 if count == 0: print "Record for Delete :", layerID logging.info('Delete ' + whereClause) curAppend.insertRow( rowYesterday)
The thing that jumps out to me is that you start several cursors, never use one of them, and never delete them. You should use 'with' syntax, which cleans up your cursors even if they error out, and avoid seemingly random errors - which you seem to be experiencing.
You are running into a couple different issues:
Joshua you can use Shape@ to return the shape, then get its area/perimeter/length for poly* features. The advantage of retrieving the shape field directly, is that it works wih shapefile which have no auto-calculated shape properties.
Dan, I agree. My comments to the OP were to point out that he is likely not retrieving what he thinks he is in terms of geometry. The OP used arcpy.Describe to retrieve the name of the shape field, but he did not add the @ symbol. I may be incorrect, but the code and description of the problem made me think he wanted to retrieve the actual geometry and not a tuple of a feature's centroid.
require special attention. The area and length (for polygons) will be populated once the geometry is created and the editing is done. If you want a point representation of the polygon, then use the appropriate option in the first link.