### System Tools import arcpy, os from arcpy.sa import * from arcpy import env, sa arcpy.CheckOutExtension("Spatial") ### Declarations------------------------------- arcpy.env.overwriteOutput = True ### Definitions------------------------------------- ## areaTab1 = "X:\\DATA\\Temp.gdb\\trees11_ward_tab" areaTab2 = "X:\\DATA\\Temp.gdb\\trees06_ward_tab" geog1_sub= "X:\\DATA\\Target_Geog.gdb\\WardPly" geog1= "X:\\DATA\\Temp.gdb\\WardPly_utm" cs= "C:\\Program Files (x86)\\ArcGIS\\Desktop10.0\\Coordinate Systems\\Projected Coordinate Systems\\UTM\\NAD 1983\\NAD 1983 UTM Zone 18N.prj" Lc06 = "X:\\DATA\\C_2006\\LandCover_2006.img" trees06 = "X:\\DATA\\trees_06" trees_in= "X:\\DATA\\Tree.gdb\\Tree_merged_022912" trees_vec= "X:\\DATA\\Tree.gdb\\Tree_merged_022912_1" trees_ras = "X:\\DATA\\Tree.gdb\\Tree_raster_022912" ##Processes trees06 = Reclassify(Lc06, "Value", RemapValue([[0, "NODATA"], [1, 10], [2, "NODATA"], [3,"NODATA"], [4,"NODATA"], [5,"NODATA"],[6,"NODATA"], [7,"NODATA"]])) ##FAILED: Assuming code doesn't like .img- But, ran perfectly using Reclassify tool. trees06.save("X:\\DATA\\Working\\trees_06") arcpy.Project_management(geog1_sub, geog1, cs) # Ran successfully arcpy.FeatureClassToFeatureClass_conversion(trees_in, os.path.dirname(str(trees_in)), trees_vec) ## Making a backup copy of data: Failed. Ran in python after adding actual pathname. arcpy.AddField_management(trees_vec, "Ras", "SHORT") #Success arcpy.CalculateField_management(trees_vec, "Ras", 1) # Success arcpy.FeatureToRaster_conversion(trees_vec, "Ras", trees_ras, 1) # Success TabulateArea(geog1, "OBJECTID", trees_in, "Value", areaTab1, 1) #FAILED: "Field OBJECTID does not exist". Um, yes it does, and tool ran fine using exact parameters from Tabulate Area tool. print "Tab 1 done" TabulateArea(geog1, "OBJECTID", trees06, "Value", areaTab2, 1)#FAILED: "Field OBJECTID does not exist". Um, yes it does, and tool ran fine using exact parameters from Tabulate Area tool. ## arcpy.JoinField_management(geog1, "OBJECTID", areaTab1, "OBJECTID", "VALUE_1") #This line failed first time through, then passed after restart. (?) arcpy.JoinField_management(geog1, "OBJECTID", areaTab2, "OBJECTID", "VALUE_10")# Succes ## FieldList = ["UTC11_Acres", "UTC11_Pct", "UTC06_Acres", "UTC06_Pct", "Chng_Acres", "Chng_Pct"] ## for field in FieldList: arcpy.AddField_management(geog1, field, "DOUBLE") rows = arcpy.UpdateCursor(geog1) for row in rows: row.UTC11_Acres = (row.VALUE_1 * 0.0002471054) rows.updateRow(row) row.UTC11_Pct = (row.VALUE_1 / row.Shape_Area) * 100 rows.updateRow(row) row.UTC06_Acres = (row.VALUE_10 * 0.0002471054) rows.updateRow(row) row.UTC06_Pct = (row.VALUE_10 / row.Shape_Area) * 100 rows.updateRow(row) row.Chng_Acres = (row.UTC11_Acres - row.UTC06_Acres) rows.updateRow(row) row.Chng_Pct = (row.UTC11_Pct - row.UTC06_Pct) rows.updateRow(row) arcpy.DeleteField_management(geog1, ["VALUE_1", "VALUE_10"])
Solved! Go to Solution.
arcpy.Reclassify_sa(Lc06, "Value","0 NODATA;1 10;2 NODATA;3 NODATA;4 NODATA;5 NODATA;6 NODATA;7 NODATA", trees06,"DATA")
trees06 = Reclassify(Lc06, "Value", RemapValue([[0, "NODATA"], [1, 10], [2, "NODATA"], [3,"NODATA"], [4,"NODATA"], [5,"NODATA"],[6,"NODATA"], [7,"NODATA"]])) trees06.save("X:\\DATA\\Working\\trees_06")
I wonder why the snippet code looks so different than the way Help describes how to write?
The snippet code fails, btw: "AttributeError: 'module' object has no attribute 'Reclassify_sa'"
I'm trying to convince my boss that python is a lot more efficient than clicking or modeling in ModelBuilder. It's a hard sell when i have to restart a script 8 times to get it to run.
Lc06 = r"X:\DATA\C_2006\LandCover_2006.img"
I think this may be a bug in the copy as python snippet.
You are correct the Copy As Python Snippet for the Con tool is not generating the correct syntax. I have submitted a software bug report on your behalf for this issue. The reference number and subject line for this bug is as follows:
[#NIM078805 The Spatial Analyst > Conditional > Con Python snippet from Results window uses incorrect syntax.]