NSW-OEH-EMS-KST / grid-garage

ArcGIS python toolbox supporting table-based processing
4 stars 2 forks source link

raster - reclass by threshold #267

Open TomWaterat opened 5 years ago

TomWaterat commented 5 years ago

@byezy can you remind me how this tool works? I've forgotten! Screen Shot 2019-07-22 at 11 19 03 pm

byezy commented 5 years ago

@TomWaterat

Mate, pretty sure this tool was added to help me do a job for Mal quite some time go. Quite a handy tool I think. Looking at the code, I will try to explain:

Reclassifies (or changes) the values in a raster

ArcGIS Help for Reclassify3d

image

For this tool, the thresholds are specified as per: "0 5 1;5.01 7.5 2;7.5 10 3" in this case values from 0-10 are assigned 1-3

which are sets of value range reclassification (or think of it as a reclass by table row) in the form of "from_value to_value new_value"

i.e. condition: from_value <= VALUE <= to_value operation: VALUE = new_value

Peeking at the code,

minv = float(arcpy.GetRasterProperties_management(ras, "MINIMUM").getOutput(0))
maxv = float(arcpy.GetRasterProperties_management(ras, "MAXIMUM").getOutput(0))
mean = float(arcpy.GetRasterProperties_management(ras, "MEAN").getOutput(0))
std = float(arcpy.GetRasterProperties_management(ras, "STD").getOutput(0))

remap = data["thresholds"].replace("MIN", str(minv)).replace("MAX", str(maxv))

self.info("Reclassifying...")

arcpy.Reclassify_3d(ras, "Value", remap, ras_out, "NODATA")

It seems that you can use MIN, MAX keywords. I suspect that a threshold spec could then look like this:

"MIN 5 1;5.01 7.5 2;7.5 MAX 3"

Looking at it in comparison to "Reclass by Table", it seems to do the same thing but with a lightweight way of speccing reclass, a string rather than 3 table columns.

Note that they are actually two different ArcGIS tools being used, arcpy.Reclassify_3d & arcpy.ReclassByTable_3d although I think the end result should be the same... but there may be different tool options I have only skimmed help so far(?)

Clear as mud?