Select to view content in your preferred language

Using Reclassify in Python

595
3
09-13-2023 06:42 AM
SoratoMarques
Emerging Contributor

Hi,

I have one raster and would like to transform all values between -0,9 - 0 like 1 value, and 0 - 0,9 like NoData.

How can I to this in python?

Thank´s

0 Kudos
3 Replies
DanPatterson
MVP Esteemed Contributor

Reclassify (Spatial Analyst)—ArcGIS Pro | Documentation

See the code examples for the spatial analyst extension.

 


... sort of retired...
0 Kudos
HaydenWelch
Frequent Contributor

Have you used the arcpy.ddd.Reclassify tool yet?

From the docs:

 

import arcpy
# Set Environment
arcpy.env = r"<PATH TO ENVIRONMENT>"

# Set local variables
inRaster = "landuse"
field = "VALUE"
remapString = "1 9;2 8;3 1;4 6;5 3;6 2;7 1"
outRaster = "C:/output/reclass3d"

# Execute Reclassify
arcpy.ddd.Reclassify(inRaster, field, remapString, outRaster, "DATA")

 

In your case you would do something like this:

 

import arcpy

arcpy.env = r"<PATH TO ENVIRONMENT>"

remap = "-0.9 0 1"
raster = r"<PATH TO RASTER>"
field = "<RECLASS FIELDNAME>"
out_raster = r"<PATH TO OUTPUT RASTER>"

arcpy.ddd.Reclassify(raster, field, remap, out_raster, "NODATA")

 

The "NODATA" flag at the end will write any values outside the provided remap range with NoData instead of the original values, so in your case you only define the remap for the lower end and just don't map the values over 0

0 Kudos
mody_buchbinder
Frequent Contributor

If you want ESRI to set the classes for you using some good algorithms you can try Slice  https://pro.arcgis.com/en/pro-app/latest/tool-reference/spatial-analyst/slice.htm 

0 Kudos