Get Cell Value (Data Management)

Summary

Retrieves the value of a given pixel using its x, y coordinates.

Parameters

LabelExplanationData Type
Input Raster

The raster that you want to query.

Mosaic Dataset; Mosaic Layer; Raster Layer
Location

The X and Y coordinates of the pixel location.

Point
Bands
(Optional)

Specify the bands that you want to query. Leave blank to query all bands in a multiband dataset.

Value Table

Derived Output

LabelExplanationData Type
Pixel Value

The pixel value.

String

arcpy.management.GetCellValue(in_raster, location_point, {band_index})
NameExplanationData Type
in_raster

The raster that you want to query.

Mosaic Dataset; Mosaic Layer; Raster Layer
location_point

The X and Y coordinates of the pixel location.

Point
band_index
[band_index,...]
(Optional)

Specify the bands that you want to query. Leave blank to query all bands in a multiband dataset.

Value Table

Derived Output

NameExplanationData Type
out_string

The pixel value.

String

Code sample

GetCellValue example 1 (Python window)

This is a Python sample for the GetCellValue tool.

import arcpy
result = arcpy.GetCellValue_management("C:/data/rgb.img", "480785 3807335", "2;3")
cellvalue = int(result.getOutput(0))
print(cellvalue)
GetCellValue example 2 (stand-alone script)

This is a Python script sample for the GetCellValue tool.

'''====================================
Get Cell Value
Usage: GetCellValue_management in_raster location_point {ID;ID...}
'''   
   
import arcpy
arcpy.env.workspace = "C:/Workspace"

# Get the Band_2 and Band_3 cell value of certain point in a RGB image
result = arcpy.GetCellValue_management("rgb.img", "480785 3807335", "2;3")
cellvalue = int(result.getOutput(0))

# View the result in execution log
print(cellvalue)

Environments

This tool does not use any geoprocessing environments.

Related topics