I have 150 feature classes in a file geodatabase. Each consist of a few polygons with a different label class. I want to make a selection on Label "1E-06", but some feature classes do not have this label, only for instance label 1E-01 to 1E-05. Is it possible to make some if statement, so if label 1E-06 does not exist in feature class, add row with label = "1E-06". It doesnt have to have geometry. I want to merge all 1e-06 labels later. For statistics purposes I need the empty ones too.
EDIT: I tried it myself (with help of answer below), but still get stuck. Right now, it can find all the shapefiles and put it in a database. It can search for rows with my expression, but I want to add a row for all features without the expression. I tried this with for row not in scursor: but this gives an error. How can I add a row in the features who do not have a row with the stated expression?
import arcpy
import os
count = 0
ws = "N:\Documents\Project\data"
dst654 = "N:\Documents\Project\Contour654.gdb"
dst800 = "N:\Documents\Project\Contour800.gdb"
expression654 = "Label = '1E-06 654'"
expression800 = "Label = '1E-06 800'"
for dirpath, dirnames, filenames in arcpy.da.Walk(ws,datatype="FeatureClass"):
count += 1
for file in filenames:
filepath = os.path.join(dirpath,file)
file_nice = file.replace('-', '_')
file_nice = file_nice.replace(' ', '_')
file_nice= file_nice.replace('.', '_')
if '654' in file_nice:
outpath1 = os.path.join(dst654,file_nice[:-4])
arcpy.CopyFeatures_management(filepath,outpath1)
arcpy.AddField_management(outpath1, "gid", "DOUBLE", "", "", "", "", "NULLABLE", "", "")
arcpy.CalculateField_management(outpath1, "gid", count, "PYTHON", "")
with arcpy.da.SearchCursor(outpath1, ['Shape', 'Label'],
where_clause=expression654) as scursor:
for row in scursor:
print "yes"
print outpath1
else:
outpath2 = os.path.join(dst800,file_nice[:-4])
arcpy.CopyFeatures_management(filepath,outpath2)
arcpy.AddField_management(outpath2, "gid", "DOUBLE", "", "", "", "", "NULLABLE", "", "")
arcpy.CalculateField_management(outpath2, "gid", count, "PYTHON", "")
with arcpy.da.SearchCursor(outpath2, ['Shape', 'Label'],
where_clause=expression800) as scursor:
for row in scursor:
print "yes"
print outpath2