Hello everyone,
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[0] datetimeVal = rowYesterday[4] #print rowYesterday[1] #print rowYesterday[2] #print rowYesterday[3] #print rowYesterday[4] #print rowYesterday[5] #print rowYesterday[0] 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[4] == rowYesterday[4]: 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.
get the shapefieldName explicitly from the featureclass describe object
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.
Hi dkwiens, this is a piece of the code not the whole script. I delete the cursors at the end.
Hi Dan, if I understand correctly I need to use "Shape@" to populate all shape fields when creating a polygon.
writing geometries
InsertCursor—Help | ArcGIS for Desktop
Writing geometries—Help | ArcGIS for Desktop
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.
Hi all,
I just harcoded the list of fields:
fieldnames = ['AGMID', 'MODBY', 'MODDATE', 'CRTBY', 'CRTDATE', 'SHAPE@']
and it works