Select to view content in your preferred language

Just got this working in python

850
0
08-19-2010 09:19 AM
ChrisMathers
Deactivated User
For any one who uses for loops to batch run tools in python, I just got this monster working this morning. Though I would share.

#the list holding the field data is formated like so:
#[fieldname, targetlayer, jointable, expression, fieldmap],
#the greater list is broken to a new line at the comma at the end of each list inside it
fieldList=[
    ['backup_table.Co_FLU', r"C:\GIS Projects\CRW\parce_test_FeatureToPoint.shp", r'C:\GIS Projects\CRW\TrakIt_Source_RS.gdb\Input_Data\flu', '[parce_test_spatial_join.FLU_CODE]', "A1RENUM 'A1RENUM' true true false 15 Text 0 0 ,First,#,C:\GIS Projects\CRW\parce_test_FeatureToPoint.shp,A1RENUM,-1,-1;RE_LABEL 'RE_LABEL' true true false 15 Text 0 0 ,First,#,C:\GIS Projects\CRW\parce_test_FeatureToPoint.shp,RE_LABEL,-1,-1;FLU_CODE 'FLU_CODE' true true false 15 Text 0 0 ,First,#,C:\\GIS Projects\\CRW\\TrakIt_Source_RS.gdb\\Input_Data\\flu,FLU_CODE,-1,-1"],
    [30 more lists go here but were cut for space reasons],
    ]
def dataLoad(field, targetlayer, jointable, expression, fieldmap):
    gp.spatialjoin_analysis(targetlayer, jointable, r"C:\GIS Projects\CRW\parce_test_spatial_join.shp", "JOIN_ONE_TO_ONE", "KEEP_ALL", fieldmap,"INTERSECTS","0 Unknown","#")
    gp.addjoin_management('parce_test', "A1RENUM", r"C:\GIS Projects\CRW\parce_test_spatial_join.shp", "A1RENUM", "KEEP_ALL")
    gp.calculatefield_management('parce_test', field, expression, "VB", "#")
    gp.removejoin_management("parce_test","parce_test_spatial_join")
    gp.delete_management(r"C:\GIS Projects\CRW\parce_test_spatial_join.shp")
 
for parameter in fieldList:
    dataLoad(parameter[0], parameter[1], parameter[2], parameter[3], parameter[4])
0 Kudos
0 Replies