Hi All - I am trying to use dissolve_management applying it to obtain a field statistic {MAX} from the field [TIME]. The format of the field 'Time' is numeric (float). I am doing this for a set of FCs running through a For-loop. When I remove the field statistic option/constraint from the code it runs perfectly, but I need that Time statistic, as well as other statistics from other fields, but I figured if I get it for one I could get them for the others later.
The code gets stuck on the first FC of the loop. Thanks much for any insight on this !!
# Import system modules
import arcpy, os
from arcpy import env
# Set environment settings
env.workspace = r"C:\GIS\Track1\1_Orig\T_shp\shp"
# Set local variables
folder = r"C:\GIS\Track1\1_Orig\T_dis"
dissolveFields = ""
wildcard = ""
fctype = ""
try:
infcs = arcpy.ListFeatureClasses(wildcard, fctype)
print infcs
for fc in infcs:
outfcs = folder + os.sep + fc
print outfcs
#outfcs = os.path.join(folder, fc)
arcpy.Dissolve_management (fc, outfcs, dissolveFields, ["TIME",{MAX}],
"SINGLE_PART","DISSOLVE_LINES")
except:
print arcpy.GetMessages(2)
Cheers,
Gabriel
Solved! Go to Solution.
Hi, try this:
arcpy.Dissolve_management(fc, outfcs, dissolveFields, [["TIME","MAX"]], "SINGLE_PART","DISSOLVE_LINES")
The curly brackets in the documentation mean that the parameter is optional.
[[field, {statistic_type}],...] means that you can supply a list lists and of strings (although that's not obvious). The first item of the list is the field name as string, the second item is and optional string specifying the statistic.
Hope this will work.
Filip.
Hi Gabriel,
I think the MAX in your Dissolve tool should be in quotes.
What error message did you get?
Russell
Hi Russell - thanks for your response. I tried both 'MAX' and "MAX" and didn't work, when I removed { }, I get an error saying that the Statistical method is empty.
I don't get any errors, I am just not getting any results. The 'print outfcs' helps me visualize by only printing the first output FC that the loop is stalled. When I remove the field statistics option, I get the entire list of output FCs, showing that the loop went through successfully. Otherwise no error, only at the bottom bar of the PythonWin a message saying that the Script 'returned exit code 0'.
Any ideas? thanks
Gabriel
Hi, try this:
arcpy.Dissolve_management(fc, outfcs, dissolveFields, [["TIME","MAX"]], "SINGLE_PART","DISSOLVE_LINES")
The curly brackets in the documentation mean that the parameter is optional.
[[field, {statistic_type}],...] means that you can supply a list lists and of strings (although that's not obvious). The first item of the list is the field name as string, the second item is and optional string specifying the statistic.
Hope this will work.
Filip.
Thanks Filip !
It worked.
Regards,
Gabriel