Get Cell Value (Data Management)

License Level:BasicStandardAdvanced

Summary

Retrieves the pixel value at a specific x,y coordinate. For multiband raster datasets you can specify from which bands to retrieve the cell value. If you do not specify any bands, the pixel value for all the bands will be returned for the input location.

Usage

Syntax

GetCellValue_management (in_raster, location_point, {band_index})
ParameterExplanationData Type
in_raster

The input raster dataset.

Mosaic Dataset; Mosaic Layer; Raster Layer
location_point

Type the x and y coordinates of the pixel location.

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

Define which bands for which you would like to get the pixel value. If you do not define any bands, a pixel value for all the bands in the x,y location will be returned.

Value Table

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")
cellSize = int(result.getOutput(0))
print cellSize
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...}
'''   
   
try:
    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")
    cellSize = int(result.getOutput(0))
    
    # View the result in execution log
    print cellSize

except:
    print "Get Cell Value exsample failed."
    print arcpy.GetMessages()

Environments

Related Topics

Licensing Information

ArcGIS for Desktop Basic: Yes
ArcGIS for Desktop Standard: Yes
ArcGIS for Desktop Advanced: Yes
5/7/2015