Reclassification using Python Script

2631
1
07-04-2012 08:32 PM
PriyankaSharma1
New Contributor
Hi,

I am trying to perform reclassification on a shape file having several attributes. 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!
Tags (2)
0 Kudos
1 Reply
MarcinGasior
Occasional Contributor III
To preserve oryginal classification create new text Field eg. LC_RECL.
Then in Field Calculator select Python parser.
In Pre-Logic Script Code paste this code:
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


Then below:
LC_RECL =
reclass(!LANDCOVER!)
0 Kudos