In my below script, i am trying to export features which are having null or 0 values for some particular fields(listed in fieldList) from the GDB.I found that the problem is with update cursor.I tring for long time and still not able to solve. Could someone help me how to do it?
Code:
import arcpy,os
arcpy.env.overwriteOutput = True
targetGdb = arcpy.GetParameterAsText(0)
workFolder = os.path.dirname(targetGdb)
outFolder = workFolder + os.sep + "CheckforErrors"
if not arcpy.Exists(outFolder):
arcpy.CreateFolder_management(workFolder, "CheckforErrors")
attrErrPt = "AttributionError_Points"
attrErrL = "AttributionError_Lines"
attrErrP = "AttributionError_Polygons"
if not arcpy.Exists(attrErrPt):
arcpy.CreateFeatureclass_management(outFolder, attrErrPt, "POINT")
if not arcpy.Exists(attrErrL):
arcpy.CreateFeatureclass_management(outFolder, attrErrL, "POLYLINE")
if not arcpy.Exists(attrErrP):
arcpy.CreateFeatureclass_management(outFolder, attrErrP, "POLYGON")
outErrPt = outFolder + os.sep + "AttributionError_Points"
outErrL = outFolder + os.sep + "AttributionError_Lines"
outErrP = outFolder + os.sep + "AttributionError_Polygons"
fieldList = ['feattype','idarpt','name','source','ZV7','featsource','imagery','status','idthr','Z5M',
'idstd','tdze','tdzslope','brngtrue','brngmag','rwyslope','tora','toda','asda','lda','vasis',
'cat','thrtype','pntsttyp','marking','lighting','radius','height','material','idp','idrwy','idlin',
'color','style','direc','linsttyp','catstop','gsurftyp','idapron','idbase','ident','surftype','frq',
'station','idhot','jetway','surftype','width','length','idrwi','featbase','bridge','plysttyp']
arcpy.env.workspace = targetGdb
datasetList = arcpy.ListDatasets('','feature')
for dataset in datasetList:
fcs = arcpy.ListFeatureClasses('','', dataset)
for fc in fcs:
desc = arcpy.Describe(fc)
fcType = desc.ShapeType
arcpy.AddMessage(fc)
arcpy.AddMessage(fcType)
if fcType == "Point":
fields = arcpy.ListFields(fc)
for field in fields:
fname = field.name
arcpy.AddMessage(field.name)
if field.name in fieldList:
rows = arcpy.SearchCursor(fc)
newRows = arcpy.InsertCursor(outErrPt)
row = rows.next()
while row:
rVal = row.getValue(fname)
if rVal == None:
newRo = newRows.newRow()
newRo.shape = row.shape
newRows.insertRow(newRo)
row = rows.next()
del row, rows, newRows
elif fcType == "Polyline":
fields = arcpy.ListFields(fc)
newRows2 = arcpy.InsertCursor(outErrL)
for field in fields:
fname = field.name
arcpy.AddMessage(field.name)
if field.name in fieldList:
rows = arcpy.SearchCursor(fc)
row = rows.next()
while row:
rVal = row.getValue(fname)
if rVal == None:
newRow2 = newRows2.newRow()
newRow2.shape = row.shape
newRows2.insertRow(newRow2)
row = rows.next()
del row, rows
elif fcType == "Polygon":
fields = arcpy.ListFields(fc)
newRows3 = arcpy.InsertCursor(outErrP)
for field in fields:
fname = field.name
arcpy.AddMessage(field.name)
if field.name in fieldList:
rows = arcpy.SearchCursor(fc)
row = rows.next()
while row:
rVal = row.getValue(fname)
if rVal == None:
newRow3 = newRows3.newRow()
newRow3.shape = row.shape
newRows3.insertRow(newRow3)
row = rows.next()
del row, rows