Rank (Spatial Analyst)

Available with Spatial Analyst license.

Summary

Ranks on a cell-by-cell basis the values from a set of input rasters and determines which values are returned based on the value of the rank input raster.

Illustration

Example Rank tool input and output values
OutRas = Rank(ConstRas, [InRas1, InRas2, InRas3])

Usage

  • In the list of input rasters, the order is irrelevant. However, the raster that defines the rank must precede these.

  • An arbitrary number of rasters can be specified in the input rasters list.

  • If a cell location contains NoData on any of the input rasters, that location will be assigned NoData on the output.

  • If all of the input values are the same for any cell location, regardless of the specified rank, the output for that cell location will be that value.

  • If the rank raster value is greater than the number of input rasters, each cell location in the output will be assigned NoData.

  • If any of the input rasters are floating point, the output is floating point; otherwise, it is integer.

  • If the Process as multiband parameter is unchecked (process_as_multiband is set to SINGLE_BAND in Python), only the first band of a multiband Input rank raster or constant value (in_rank_raster_or_constant in Python) will be used. Each band from a multiband Input rasters (in_rasters in Python) will be processed separately as a single-band raster.

  • If the Process as multiband parameter is checked (process_as_multiband is set to MULTI_BAND in Python), each multiband raster input will be processed as a multiband raster.

    The number of bands in the output depends on the Input rank raster or constant value. If the rank raster is a single band, the number of bands on the output raster will be the same as the maximum number of bands of all multiband rasters from the input rasters. If the rank raster is a multiband, the output raster will have the same number of bands as the rank raster.

    If any of the Input rasters is a raster with a smaller number of bands than the output raster, the missing bands will be interpreted as a band filled with NoData. If the cell value of the rank raster picks value one from the missing band, the output raster will receive NoData. If any of the input rasters is a constant, it will be interpreted as a multiband raster in which the cell values of all bands are the same as the constant and have the same number of bands as the output raster.

  • If all inputs are multidimensional raster data with the same number of variables, the tool will perform the operation for all slices with the same dimension value. The output will be a multidimensional raster in CRF format. The variables in the inputs must have at least one common dimension and one common dimensional value for this tool to process, otherwise an error will occur.

    If all of the inputs have one variable but different names, uncheck the Match Multidimensional Variable geoprocessing environment (set arcpy.env.matchMultidimensionalVariable = False in Python) before performing the operation.

    If one or more of the inputs are multidimensional rasters and the other inputs are constant, the tool will perform the operation for all slices for all variables using the constant value, and the output will be a multidimensional raster.

  • See Analysis environments and Spatial Analyst for additional details on the geoprocessing environments that apply to this tool.

Parameters

LabelExplanationData Type
Input rank raster or constant value

The input raster that defines the rank position to be returned.

A number can be used as an input; however, the cell size and extent must first be set in the environment.

Raster Layer; Constant
Input rasters

The list of input rasters from which the cell value of the raster at the specified rank position will be obtained.

For example, consider a particular location where the cell values in the three input rasters are 17, 8 and 11. The rank value for that location is defined as 3. The tool will first sort the input values. Since the rank value being requested is 3, the output value will be 17.

Raster Layer
Process as multiband
(Optional)

Specifies how the input multiband raster bands will be processed.

  • Unchecked—Each band from a multiband raster input will be processed separately as a single band raster. This is the default.
  • Checked—Each multiband raster input will be processed as a multiband raster. The operation will be performed for each band from one input using the corresponding band number from the other inputs.
Boolean

Return Value

LabelExplanationData Type
Output raster

The output raster.

For each cell on the output raster, the values on the input rasters are sorted from lowest to highest, and the input rank raster's value is used to select which will be the output value.

Raster

Rank(in_rank_raster_or_constant, in_rasters, {process_as_multiband})
NameExplanationData Type
in_rank_raster_or_constant

The input raster that defines the rank position to be returned.

A number can be used as an input; however, the cell size and extent must first be set in the environment.

Raster Layer; Constant
in_rasters
[in_raster,...]

The list of input rasters from which the cell value of the raster at the specified rank position will be obtained.

For example, consider a particular location where the cell values in the three input rasters are 17, 8 and 11. The rank value for that location is defined as 3. The tool will first sort the input values. Since the rank value being requested is 3, the output value will be 17.

Raster Layer
process_as_multiband
(Optional)

Specifies how the input multiband raster bands will be processed.

  • SINGLE_BANDEach band from a multiband raster input will be processed separately as a single band raster. This is the default.
  • MULTI_BANDEach multiband raster input will be processed as a multiband raster. The operation will be performed for each band from one input using the corresponding band number from the other inputs.
Boolean

Return Value

NameExplanationData Type
out_raster

The output raster.

For each cell on the output raster, the values on the input rasters are sorted from lowest to highest, and the input rank raster's value is used to select which will be the output value.

Raster

Code sample

Rank example 1 (Python window)

This example performs a rank operation on several input Grid rasters and outputs the result as a TIFF raster.

import arcpy
from arcpy import env
from arcpy.sa import *
env.workspace = "C:/sapyexamples/data"
outRank = Rank("cost", ["degs", "negs", "fourgrd"])
outRank.save("C:/sapyexamples/output/outrank.tif")
Rank example 2 (stand-alone script)

This example performs a rank operation on several input Grid rasters and outputs the result as a Grid raster.

# Name: Rank_Ex_02.py
# Description: Returns the value of a set of rasters based on
#              a rank level specified by another raster 
# Requirements: Spatial Analyst Extension

# Import system modules
import arcpy
from arcpy import env
from arcpy.sa import *

# Set environment settings
env.workspace = "C:/sapyexamples/data"

# Set local variables
inRankRaster = "cost"
inRaster01 = "degs"
inRaster02 = "negs"
inRaster03 = "fourgrd"

# Execute Rank
outRank = Rank(inRankRaster, [inRaster01, inRaster02, inRaster03])

# Save the output 
outRank.save("C:/sapyexamples/output/outrank")

Related topics