import arcpy import os, sys from xml.etree import cElementTree as ElementTree def addCoreFields(fc): arcpy.AddField_management(fc, "AssetObjectId", "LONG", "", "", "", "", "NULLABLE", "NON_REQUIRED", "") arcpy.AddField_management(fc, "AssetId", "LONG", "", "", "", "", "NULLABLE", "NON_REQUIRED", "") arcpy.AddField_management(fc, "AssetObjectStatus", "TEXT", "", "", "32", "", "NULLABLE", "NON_REQUIRED", "") arcpy.AddField_management(fc, "Status", "TEXT", "", "", "32", "", "NULLABLE", "NON_REQUIRED", "") arcpy.AddField_management(fc, "Feature", "TEXT", "", "", "32", "", "NULLABLE", "NON_REQUIRED", "") arcpy.AddField_management(fc, "SubFeature", "TEXT", "", "", "32", "", "NULLABLE", "NON_REQUIRED", "") arcpy.AddField_management(fc, "AssetCode", "TEXT", "", "", "32", "", "NULLABLE", "NON_REQUIRED", "") arcpy.AddField_management(fc, "LaneLocation", "TEXT", "", "", "32", "", "NULLABLE", "NON_REQUIRED", "") arcpy.AddField_management(fc, "Route", "TEXT", "", "", "32", "", "NULLABLE", "NON_REQUIRED", "") arcpy.AddField_management(fc, "FromMilepost", "LONG", "", "", "", "", "NULLABLE", "NON_REQUIRED", "") arcpy.AddField_management(fc, "FromOffset", "DOUBLE", "", "", "", "", "NULLABLE", "NON_REQUIRED", "") arcpy.AddField_management(fc, "ToMilepost", "LONG", "", "", "", "", "NULLABLE", "NON_REQUIRED", "") arcpy.AddField_management(fc, "ToOffset", "DOUBLE", "", "", "", "", "NULLABLE", "NON_REQUIRED", "") if __name__ == '__main__': scriptPath = sys.path[0] dataGDB = os.path.join(scriptPath, "data.gdb") if arcpy.Exists(dataGDB): arcpy.Delete_management(dataGDB) arcpy.CreateFileGDB_management(scriptPath, "data") sr = "PROJCS['NAD_1983_StatePlane_Arizona_Central_FIPS_0202_Feet_Intl',GEOGCS['GCS_North_American_1983',DATUM['D_North_American_1983',SPHEROID['GRS_1980',6378137.0,298.257222101]],PRIMEM['Greenwich',0.0],UNIT['Degree',0.0174532925199433]],PROJECTION['Transverse_Mercator'],PARAMETER['False_Easting',700000.0],PARAMETER['False_Northing',0.0],PARAMETER['Central_Meridian',-111.9166666666667],PARAMETER['Scale_Factor',0.9999],PARAMETER['Latitude_Of_Origin',31.0],UNIT['Foot',0.3048]];-17746700 -44067300 3048;-100000 10000;-100000 10000;3.28083989501312E-03;0.001;0.001;IsHighPrecision" for name in ['one', 'two', 'three']: fc = os.path.join(dataGDB, name) arcpy.CreateFeatureclass_management(dataGDB, name, "POINT", "", "DISABLED", "DISABLED", sr, "", "0", "0", "0") addCoreFields(fc)
Solved! Go to Solution.
with that extra second of execution time per added per field my geo proc just got a lot slower.
def addfields(): print "Adding fields" field_name_list = [field.name for field in arcpy.ListFields(calc_table)] add_fields = [ ("TYPE", "TEXT", "#", "#", 40), ("ORIGIN_SITE", "TEXT", "#", "#", 10), ("UTYPE", "TEXT", "#", "#", 40), ("U_ORIGIN_SITE", "TEXT", "#", "#", 10), ("DEC_PER", "SHORT", "#", "#", "#"), ("LEAD_CON", "TEXT", "#", "#", 2), ("COV_GRP", "TEXT", "#", "#", 2), ("STRATA", "SHORT", "#", "#", "#"), ("CON_PIECE", "FLOAT", "#", "#", "#"), ("DEC_PIECE", "FLOAT", "#", "#", "#"), ("CON_VOLHA", "FLOAT", "#", "#", "#"), ("DEC_VOLHA", "FLOAT", "#", "#", "#"), ("UDEC_PER", "SHORT", "#", "#", "#"), ("UCOV_GRP", "TEXT", "#", "#", 2), ("ULEAD_CON", "TEXT", "#", "#", 2), ("TDASTRATUM", "TEXT", "#", "#", 8), ("UTDASTRATUM", "TEXT", "#", "#", 8)] for field in add_fields: if field[0] not in field_name_list: arcpy.AddField_management( calc_table, field[0], field[1], field[2], field[3], field[4])
with that extra second of execution time per added per field my geo proc just got a lot slower.
in_memory workspace -- the Add Fields happen very fast with no file-locking issues
import arcpy import os, sys def addCoreFields(fc): arcpy.AddField_management(fc, "AssetObjectId", "LONG", "", "", "", "", "NULLABLE", "NON_REQUIRED", "") arcpy.AddField_management(fc, "AssetId", "LONG", "", "", "", "", "NULLABLE", "NON_REQUIRED", "") arcpy.AddField_management(fc, "AssetObjectStatus", "TEXT", "", "", "32", "", "NULLABLE", "NON_REQUIRED", "") arcpy.AddField_management(fc, "Status", "TEXT", "", "", "32", "", "NULLABLE", "NON_REQUIRED", "") arcpy.AddField_management(fc, "Feature", "TEXT", "", "", "32", "", "NULLABLE", "NON_REQUIRED", "") arcpy.AddField_management(fc, "SubFeature", "TEXT", "", "", "32", "", "NULLABLE", "NON_REQUIRED", "") arcpy.AddField_management(fc, "AssetCode", "TEXT", "", "", "32", "", "NULLABLE", "NON_REQUIRED", "") arcpy.AddField_management(fc, "LaneLocation", "TEXT", "", "", "32", "", "NULLABLE", "NON_REQUIRED", "") arcpy.AddField_management(fc, "Route", "TEXT", "", "", "32", "", "NULLABLE", "NON_REQUIRED", "") arcpy.AddField_management(fc, "FromMilepost", "LONG", "", "", "", "", "NULLABLE", "NON_REQUIRED", "") arcpy.AddField_management(fc, "FromOffset", "DOUBLE", "", "", "", "", "NULLABLE", "NON_REQUIRED", "") arcpy.AddField_management(fc, "ToMilepost", "LONG", "", "", "", "", "NULLABLE", "NON_REQUIRED", "") arcpy.AddField_management(fc, "ToOffset", "DOUBLE", "", "", "", "", "NULLABLE", "NON_REQUIRED", "") if __name__ == '__main__': scriptPath = sys.path[0] dataGDB = os.path.join(scriptPath, "data.gdb") if arcpy.Exists(dataGDB): arcpy.Delete_management(dataGDB) arcpy.CreateFileGDB_management(scriptPath, "data") for name in ['one', 'two', 'three']: fc = arcpy.CreateFeatureclass_management("in_memory", name, "POINT", "", "DISABLED", "DISABLED", "", "", "0", "0", "0") addCoreFields(fc) arcpy.CopyFeatures_management(fc, os.path.join(dataGDB, name)) arcpy.Delete_management(fc)