# Set the necessary product code
# import arcinfo
# Import arcpy module
import arcpy
from arcpy import env
# Check out any necessary licenses
arcpy.CheckOutExtension("spatial")
###################### Script arguments
Input_Land_Cover__NLCD_2006_ = arcpy.GetParameterAsText(0)
#Input_Land_Cover__NLCD_2006_ = "D:\\DATA\\NLCD\\nlcd2006_cook" # provide a default value if unspecified
Output_Workspace = arcpy.GetParameterAsText(1)
#Output_Workspace = "D:\\DATA\\DELETE" # provide a default value if unspecified
# Set environment settings
env.workspace = Output_Workspace
Zone_values_you_want_to_shrink__LC_code_ = arcpy.GetParameterAsText(2)
#Zone_values_you_want_to_shrink__LC_code_ = "11" # provide a default value if unspecified
Land_Cover_Code_for_which_you_want_to_extract_distance_measure = arcpy.GetParameterAsText(3)
#Land_Cover_Code_for_which_you_want_to_extract_distance_measure = "[11,94,0],[95,95,1]" # provide a default value if unspecified
####################
# could try this: tmp3 = Reclassify(Int(EucDistance(inR, "", "1000", "")), "VALUE", "0 NODATA", "DATA")
# Process: Reclassify
remap = arcpy.sa.RemapRange([Land_Cover_Code_for_which_you_want_to_extract_distance_measure])
nlcd_ag = arcpy.sa.Reclassify(Input_Land_Cover__NLCD_2006_, "VALUE", remap, "DATA")
out_rc1 = Output_Workspace + "\\out1"
nlcd_ag.save(out_rc1)
Does anyone have an example on how to set this up in python (i'm using ArcGIS10) and how to set up the model parameters correctly?
listString = arcpy.GetParameterAsText(3) # "[11,94,0],[95,95,1]"
# compose a line of python code and run it with exec()
exec("remap = arcpy.sa.RemapRange(%s)" % listString)
# the variable remap now has your remap range for the Reclassify tool
# Set the necessary product code
# import arcinfo
# Import arcpy module
import arcpy
from arcpy import env
# Check out any necessary licenses
arcpy.CheckOutExtension("spatial")
###################### Script arguments
Input_Land_Cover__NLCD_2006_ = arcpy.GetParameterAsText(0)
#Input_Land_Cover__NLCD_2006_ = "D:\\DATA\\NLCD\\nlcd2006_cook" # provide a default value if unspecified
Output_Workspace = arcpy.GetParameterAsText(1)
#Output_Workspace = "D:\\DATA\\DELETE" # provide a default value if unspecified
# Set environment settings
env.workspace = Output_Workspace
Zone_values_you_want_to_shrink__LC_code_ = arcpy.GetParameterAsText(2)
#Zone_values_you_want_to_shrink__LC_code_ = "11" # provide a default value if unspecified
# In the tool interface you can set defaults
fromClass = arcpy.GetParameterAsText(3) # "11 94 0"
toClass = arcpy.GetParameterAsText(4) # "95 95 1"
# convert strings to lists of reclass values
# using try/except to handle any syntax problems that come up
try:
fromClassList = fromClass.split()
toClassList = toClass.split()
# convert values to integer
fromClassList = [int(k) for k in fromClassList]
toClassList = [int(k) for k in toClassList]
if len(fromClassList) <> len(toClassList): raise Exception
except:
raise Exception, "Invalid input for From and To Classes"
####################
# Process: Reclassify
remap = arcpy.sa.RemapRange([fromClassList,toClassList])
nlcd_ag = arcpy.sa.Reclassify(Input_Land_Cover__NLCD_2006_, "VALUE", remap, "DATA")
out_rc1 = Output_Workspace + "\\out1_f"
nlcd_ag.save(out_rc1)
rangeText = "0 1 99, 1 2 100"
temp = rangeText.split(",") # split to two strings at the comma
temp = [k.split() for k in temp] # split each remap group into strings
temp = [ [int(j) for j in k] for k in temp] # integerize values
>>> rangeText = "0 1 99, 1 2 100"
>>> temp = rangeText.split(",")
>>> temp
['0 1 99', ' 1 2 100']
>>> temp = [k.split() for k in temp]
>>> temp
[['0', '1', '99'], ['1', '2', '100']]
>>> temp = [ [int(j) for j in k] for k in temp]
>>> temp
[[0, 1, 99], [1, 2, 100]]
Hi,
I am trying to perform reclassification on a shape file having several attributes[ATTACH=CONFIG]15757[/ATTACH]. I am trying to call this attribute table and "LANDCOVER" column into my python script to perform reclassification.
I am using this python script to perform this:fc = "D:\Priyanka\Model_tests\Reclassify_LU_Del\LANDUSE4_prj.shp" fldName = 'LANDCOVER' def reclass(landcover): if landcover in ("Drain", "Lake", "River", "Water Body", "Canal"): return "Water" elif landcover in ("Green Area", "Open Space"): return "Green and Open Space" elif landcover in ("Island"): return "Miscellaneous" elif landcover in ("Others"): return "Public Space" else: return landcover
But, I am getting errors "Invalid Syntax". I am sure that I am doing something wrong but dont know what! It would be great if you can please let me know how to perform reclassification on this attribute table and then incorporate the same to ARC Tool!
Thanks!
fc = "D:\Priyanka\Model_tests\Reclassify_LU_Del\LANDUSE4_prj.shp"
fldName = 'LANDCOVER'
newFldName = 'LANDCOV1'
arcpy.AddField_management(fc,newFldName,"TEXT")
arcpy.CalculateField_management(fc,newFldName,"reclass(!%s!)" % fldName, "PYTHON",
"""
def reclass(landcover):
if landcover in ("Drain", "Lake", "River", "Water Body", "Canal"):
return "Water"
elif landcover in ("Green Area", "Open Space"):
return "Green and Open Space"
elif landcover in ("Island"):
return "Miscellaneous"
elif landcover in ("Others"):
return "Public Space"
else:
return landcover
"""