I want to reclassify a raster (variable) in model builder in two classes. First class ist 0-treshold = NoData and second is treshold-max value = 1. It works fine if i use an existing raster file as input (where i can state and know the max value) but not for variables in ModelBuilder.

Any ideas how to do it in ModelBuilder, or with ArcPy?

This is my model in modelbuilder


Here is my edited model, but it's not running yet.

Edited model in modelbuilder

  • Please provide some code or a screenshot of your model... – dru87 Feb 22 '16 at 13:02
  • You're right, sorry for that. Model is attached now – geopea Feb 28 '16 at 10:48
  • There is a spelling error in the expression. The function name should be apply_threshold instead of apply _treshold. The name in the expression should match what is in the code block. – Nxaunxau Feb 29 '16 at 19:57
  • Ah that was obvious. Sorry for that stupid mistake and thanks for your reply. I corrected the spelling mistakes, but it is still not running. As soon as I connect the threshold Parameter and the rcls_flow_path as precondition (both data type any value, maybe here is the mistake?), the calculate value field can't be run anymore. Whats exactly the purpose of rcls_flow_path? – geopea Mar 1 '16 at 20:53
  • rcls_flow_path is a full path to where you want to save the reclassed flow accumulation raster – Nxaunxau Mar 2 '16 at 10:53

Try this:

Replace your reclassify step with the following steps:

  • Use the Get Raster Properties tool to retrieve the maximum value from your flow accummulation raster.
  • Use the Calculate Value tool and a python snippet to reclassify your flow accumulation raster.
  • Set the Data Type of the Calculate Value tool to "Raster Layer"
  • Define the following function in the code block

    def apply_threshold(flow_acc, max_flow,threshold, rcls_flow_path):
         rcls = arcpy.sa.Reclassify(flow_acc,"Value","0 {0} NODATA; {0} {1} 1".format(threshold,max_flow), "DATA")
         return rcls_flow_path

The function defined above accepts a flow accummulation raster, max flow value, a threshold and an output path. Values 0 - threshold are reclassed to NODATA and values from threshold to max value are reclassed to 1.

See sample model below. enter image description here

  • Connect the reclassed flow accumulation to the rest of your model....
  • Thanks for the answer. I got the raster properties, I filled in the Expression and Code Block field as said, but how can I connect the max_flow and other parameters to the model? – geopea Feb 29 '16 at 15:44
  • Connect them as preconditions to Calculate Tool. – Nxaunxau Feb 29 '16 at 19:51

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.