import arcpy from arcpy import env arcpy.env.overwriteOutput = True in_path =r"Database Connections/Sun120 - 5151.sde/CONVERSION." in_feature = "CPTESTPOINTINSPECTION" out_path = r"E:/Rich Anderson/CP_ReChecks/" FileGDBName = "Test.gdb" infc1 = in_path + in_feature try: fieldmappings = arcpy.FieldMappings() fieldmappings.addTable(infc1) fldmap_READING = arcpy.FieldMap() fldmap_READING.addInputField(infc1, "READING") fld_READING = fldmap_READING.outputField fld_READING.name = "READING" fldmap_READING.outputField = fld_READING fieldmappings.addFieldMap(fldmap_READING) arcpy.FeatureClassToFeatureClass_conversion(in_path + in_feature, out_path + FileGDBName, "Max_CP_Inspection_Date_Test", " \"READING\" > 85 ", fieldmappings) except Exception as e: print e
Solved! Go to Solution.
start = datetime.datetime.now() droplst = ["xxx","rings_ok","rings_nok","lpoly#","rpoly#", "fnode#","tnode#","length","area","perimeter", "multi","case1","case2","case3", "$SCALE","$ANGLE","PAR-ID","OTHR#","OTHR-ID",] sr = arcpy.SpatialReference() sr.factoryCode = 2193 # NZTM sr.create() arcpy.env.outputCoordinateSystem = sr ws = "e:/lib/nztm/tile" arcpy.env.workspace = ws+"/t1001/data" dictCov = { "add_all":"address/point", "emf":"emf/point", "fename":"fename/point", "hydro":"hydro/polygon", "titledif":"titledif/point", "up":"up/point", "uparcel":"uparcel/point" } l # lstFC = ["uparcel"] for outFCName in lstFC : cov = dictCov[outFCName] fds = cov.split("/")[0] print "Processing",outFCName,cov arcpy.AddMessage(outFCName) if not arcpy.Exists(gdb+"/"+outFCName) : lstSrc = [] for ld in range(12) : tile = "t%d" % (ld + 1001) srcCov = ws+"/"+tile+"/data/"+cov if arcpy.Exists(srcCov) : lstSrc.append(srcCov) else : arcpy.AddError(srcCov+'not found') print srcCov,"NOT FOUND" # Create FieldMappings object to manage merge output fields fieldMappings = arcpy.CreateObject("FieldMappings") # Add all fields from sources for src in lstSrc: fieldMappings.addTable(src) # hide fields print " removing ", for fld in [fds+"#",fds+"-ID"] + droplst: #include cov# and cov-id pos = fieldMappings.findFieldMapIndex(fld.upper()) # print pos,fld if pos >= 0 : fieldMappings.removeFieldMap(pos) print fld.upper(), print print " keeping ", for x in range(fieldMappings.fieldCount): print fieldMappings.getFieldMap(x).outputField.name, print arcpy.Merge_management(lstSrc, gdb+"/"+outFCName,fieldMappings ) print outFCName,"merged" arcpy.AddMessage(outFCName+" merged") else : print "Skipping load of",outFCName arcpy.AddWarning("Skipping load of "+outFCName)
start = datetime.datetime.now() droplst = ["xxx","rings_ok","rings_nok","lpoly#","rpoly#", "fnode#","tnode#","length","area","perimeter", "multi","case1","case2","case3", "$SCALE","$ANGLE","PAR-ID","OTHR#","OTHR-ID",] sr = arcpy.SpatialReference() sr.factoryCode = 2193 # NZTM sr.create() arcpy.env.outputCoordinateSystem = sr ws = "e:/lib/nztm/tile" arcpy.env.workspace = ws+"/t1001/data" dictCov = { "add_all":"address/point", "emf":"emf/point", "fename":"fename/point", "hydro":"hydro/polygon", "titledif":"titledif/point", "up":"up/point", "uparcel":"uparcel/point" } l # lstFC = ["uparcel"] for outFCName in lstFC : cov = dictCov[outFCName] fds = cov.split("/")[0] print "Processing",outFCName,cov arcpy.AddMessage(outFCName) if not arcpy.Exists(gdb+"/"+outFCName) : lstSrc = [] for ld in range(12) : tile = "t%d" % (ld + 1001) srcCov = ws+"/"+tile+"/data/"+cov if arcpy.Exists(srcCov) : lstSrc.append(srcCov) else : arcpy.AddError(srcCov+'not found') print srcCov,"NOT FOUND" # Create FieldMappings object to manage merge output fields fieldMappings = arcpy.CreateObject("FieldMappings") # Add all fields from sources for src in lstSrc: fieldMappings.addTable(src) # hide fields print " removing ", for fld in [fds+"#",fds+"-ID"] + droplst: #include cov# and cov-id pos = fieldMappings.findFieldMapIndex(fld.upper()) # print pos,fld if pos >= 0 : fieldMappings.removeFieldMap(pos) print fld.upper(), print print " keeping ", for x in range(fieldMappings.fieldCount): print fieldMappings.getFieldMap(x).outputField.name, print arcpy.Merge_management(lstSrc, gdb+"/"+outFCName,fieldMappings ) print outFCName,"merged" arcpy.AddMessage(outFCName+" merged") else : print "Skipping load of",outFCName arcpy.AddWarning("Skipping load of "+outFCName)