HOW TO

Conditonally process certain values of a raster on a row or column basis

Last Published: April 25, 2020

Summary

Instructions provided describe how to process only on rows or columns in a raster that contain a particular value.

For example, in a Grid with values from 1 to 10, make negative any values that are less than 5.

One approach is to create a custom application that loops through the raster by iterating an extent window through it, however this generates a lot of intermediate rasters that need to be collated into the final result.

A simpler approach is to incorporate the use of a Block function. The procedure is to identify the rows/columns that contain the threshold value and then conditionally restrict the operations to those rows/columns.

Procedure

This example looks for rows that contain a value of 5, and makes any values that are 4 or less on those rows negative.

The input grid 'a0':

 1  2  3  4
3 5 2 6
9 1 2 3
5 1 9 5


Note:
This procedure can be modified to operate on columns instead.
  1. Identify the threshold values:

    a1 = CON (a0 EQ 5, 1, 0)
    0 0 0 0
    0 1 0 0
    0 0 0 0
    1 0 0 1

  2. Populate the rows with an index value that is used to control where the values change.

    In the BlockMax function, the width of the neighborhood is the number of columns in the raster. The height of the neighborhood is 1, for one row. In Geoprocessing and ArcObjects, use the the Block Statistics function.

    a2 = BLOCKMAX (a1, rectangle, 4, 1)
    0 0 0 0
    1 1 1 1
    0 0 0 0
    1 1 1 1

  3. Apply a conditional statement that applies the following logic:

    · The True condition is if the value in the A2 raster is equal to 1, and the value in the original raster is less than the threshold of 5, the original value is made negative.

    · The False condition is if the value in the original raster is greater than the threshhold value, thet original value is retained.

    a3 = CON (a2 EQ 1 AND a0 < 5, a0 * -1, a0)
    1 2 3 4
    -3 5 -2 6
    9 1 2 3
    5 -1 9 5

Article ID:000009115

Software:
  • ArcMap 8 x
  • ArcMap 9 x
  • Legacy Products

Get help from ArcGIS experts

Contact technical support

Download the Esri Support App

Go to download options

Discover more on this topic