AI-generated Key Takeaways
-
The
ee.data.getPixelsfunction fetches pixels from an image asset and returns them as raw image data. -
The function accepts an object of parameters, including the asset ID, file format, grid details, region, band IDs, and visualization options.
-
The
fileFormatparameter can specify various image formats as well as Python data object formats likeNUMPY_NDARRAY. -
Visualization options can be applied to return an 8-bit RGB visualization instead of raw data.
Returns: The pixels as raw image data.
| Usage | Returns |
|---|---|
ee.data.getPixels(params)
|
Object|Value |
| Argument | Type | Details |
|---|---|---|
params
|
Object | An object containing parameters with the following possible values:assetId
- The asset ID for which to get pixels. Must be an image asset.fileFormat
- The resulting file format. Defaults to png. See ImageFileFormat
for the available formats. There are additional formats that convert
the downloaded object to a Python data object. These include: NUMPY_NDARRAY
, which converts to a structured NumPy
array.grid
- Parameters describing the pixel grid in which to fetch data.
Defaults to the native pixel grid of the data.region
- If present, the region of data to return, specified as a GeoJSON
geometry object (see RFC 7946).bandIds
- If present, specifies a specific set of bands from which to get
pixels.visualizationOptions
- If present, a set of visualization options to apply
to produce an 8-bit RGB visualization of the data,
rather than returning the raw data. |
Examples
import ee import geemap.core as geemap
Colab (Python)
# Region of interest. coords = [ - 121.58626826832939 , 38.059141484827485 , ] region = ee . Geometry . Point ( coords ) # Get a Sentinel-2 image. image = ( ee . ImageCollection ( 'COPERNICUS/S2' ) . filterBounds ( region ) . filterDate ( '2020-04-01' , '2020-09-01' ) . sort ( 'CLOUD_COVERAGE_ASSESSMENT' ) . first ()) image_id = image . getInfo ()[ 'id' ] # Make a projection to discover the scale in degrees. proj = ee . Projection ( 'EPSG:4326' ) . atScale ( 10 ) . getInfo () # Get scales out of the transform. scale_x = proj [ 'transform' ][ 0 ] scale_y = - proj [ 'transform' ][ 4 ] # Make a request object. request = { 'assetId' : image_id , 'fileFormat' : 'PNG' , 'bandIds' : [ 'B4' , 'B3' , 'B2' ], 'grid' : { 'dimensions' : { 'width' : 640 , 'height' : 640 }, 'affineTransform' : { 'scaleX' : scale_x , 'shearX' : 0 , 'translateX' : coords [ 0 ], 'shearY' : 0 , 'scaleY' : scale_y , 'translateY' : coords [ 1 ] }, 'crsCode' : proj [ 'crs' ], }, 'visualizationOptions' : { 'ranges' : [{ 'min' : 0 , 'max' : 3000 }]}, } image_png = ee . data . getPixels ( request ) # Do something with the image...

