I'm trying to delete a row from a coverage
I'm using arcpy 10.3.1
the code that i am using is (to be able to reproduce the issue)
import arcpy
def count_row(data):
i = 0
for row in data:
i += 1
data.reset()
return i
arcpy.env.workspace = 'C:/Data/cea01apr'
feature = 'point'
fidfilter= 'fid = 1'
featureClassList = arcpy.ListFeatureClasses()
fieldList = arcpy.ListFields(feature)
fieldString = [str(x.name) for x in fieldList]
with arcpy.da.UpdateCursor(feature, fieldString, fidfilter) as cursorupdate:
print('Number of rows:' + str(count_row(cursorupdate)))
rowupdate = cursorupdate.next()
print(rowupdate[12])
rowupdate[12] += 'h'
cursorupdate.updateRow(rowupdate)
with arcpy.da.SearchCursor(feature, fieldString, fidfilter) as cursorupdate:
print('Number of rows:' + str(count_row(cursorupdate)))
rowupdate = cursorupdate.next()
if rowupdate:
print(rowupdate[12])
with arcpy.da.UpdateCursor(feature, fieldString, fidfilter) as cursorupdate1:
print('Number of rows:' + str(count_row(cursorupdate1)))
for row in cursorupdate1:
cursorupdate1.deleteRow()
raw_input('Press the <ENTER> key to exit')
the output of that script is
C:\Data>test.py
Number of rows:1
hhhhhhhhhhhhhhhh
Number of rows:1
hhhhhhhhhhhhhhhhh
Number of rows:1
Traceback (most recent call last):
File "C:\Data\test.py", line 39, in <module>
cursorupdate1.deleteRow()
SystemError: error return without exception set
I have tried this
arcpy.MakeTableView_management(feature, 'test')
arcpy.SelectLayerByAttribute_management('test', 'NEW_SELECTION', fidfilter)
arcpy.DeleteRows_management('test')
and i'm getting this error
Traceback (most recent call last):
File "C:\Data\test.py", line 41, in <module>
arcpy.DeleteRows_management('test')
File "C:\***\cots\ArcGIS\Desktop10.3\ArcPy\arcpy\management.py", line 15352, in DeleteRows
raise e
arcgisscripting.ExecuteError: ERROR 999999: Error executing function.
Failed to execute (DeleteRows).
trying the old arcpy.UpdateCursor
cursorupdate2 = arcpy.UpdateCursor(feature)
#print('Number of rows:' + str(count_row(cursorupdate2)))
row = cursorupdate2.next()
print('delete')
cursorupdate2.deleteRow(row)
will result into
C:\Data>test.py
ArcInfo
Number of rows:1
hhhhhhhhhhhhhhhhhhhh
Number of rows:1
hhhhhhhhhhhhhhhhhhhhh
delete
Traceback (most recent call last):
File "C:\Data\test.py", line 56, in <module>
cursorupdate2.deleteRow(row)
File "C:\***\cots\ArcGIS\Desktop10.3\ArcPy\arcpy\arcobjects\arcobjects.py", line 110, in deleteRow
return convertArcObjectToPythonObject(self._arc_object.DeleteRow(*gp_fixargs(args)))
RuntimeError: ERROR 999999: Error executing function.
uncommenting the line for the number of rows will actually crash python.exe
I answered your aml to arcpy question in the other thread is it possible to convert this AML into python? (arcedit)
Basically, my suggestion if you are just trying to select certain features that you want to keep is to not use a cursor or arcedit, just use the arcpy.Reselect_arc to select and copy the features to a new coverage. Based on the code you had in the other thread, I was able to get everything but the correct syntax for the"infoExpress", which is the process of RES, NSEL, RES, etc to get the set you will push out to the new coverage. Here is the code again, but I am getting an error on the last line. I have the help pages for Reselect_arc in a comment
import arcpy
inCover = r"C:\Workspace\test\bl01"
# inCover = r"c:\Data\cea01apr" # this assumes cea01apr is the Coverage name
arcpy.env.workspace = inCover
featureType = 'point' # this is the feature type
recCountIn = int(arcpy.GetCount_management(featureType).getOutput(0))
print("Number of {0} records in {1}: {2}".format(featureType, inCover, recCountIn))
# these aren't used, but good info
featureClassList = arcpy.ListFeatureClasses()
fieldList = arcpy.ListFields(inCover, "", featureType)
fieldString = [str(x.name) for x in fieldList]
print(fieldString)
tempCover = r"C:\Workspace\test\cl01testIn"
try:
arcpy.Copy_management(inCover, tempCover)
print("\nCopy worked")
except:
print("\nCopy didnt work, may already exist")
tempCoverOut = r"C:\Workspace\test\cl01Out"
fidfilter= 'fid < 16' # just for the sake of showing 15 vs one record...
# take a look at http://resources.arcgis.com/en/help/main/10.1/index.html#/Select/001300000005000000/
# or http://desktop.arcgis.com/en/arcmap/10.3/tools/coverage-toolbox/select.htm
print("\nReselect {0} from {1} then nselect for the other {2} and save to new coverage".format(fidfilter, recCountIn, (recCountIn - int(fidfilter[-3:]))))
infoExpress = ["RESELECT FID LT 16",
"NSELECT"]
print("\n my test infoExpress: {0}\n but doesn't work".format(infoExpress))
"""
# sample from help pages
infoExpress = ["RESELECT stream_name CN 'AQUEDUCT'",
"NSELECT",
"RESELECT stream_order > 3",
"ASELECT length > 10000"]
"""
# Execute Reselect
arcpy.Reselect_arc(tempCover, tempCoverOut, infoExpress, featureType, "", "")
This doesn't look like anything that you were trying to do in this thread, but I'm assuming that what you were trying to do is in the other.....bad assumption??? anyway, that's all I can do tonight. Hopefully that is enough to get you going. Have fun!
i'm trying to delete rows from feature class based on some condition, this could have worked but like you i can't make the infoexpress work.