ee.Image.arrayProject
Projects the array in each pixel to a lower dimensional space by specifying the axes to retain. Dropped axes must be at most length 1.
Usage | Returns | Image.arrayProject(axes) | Image |
Argument | Type | Details | this: input | Image | Input image. |
axes | List | The axes to retain. Other axes will be discarded and must be at most length 1. |
Examples
Code Editor (JavaScript)
// A function to print arrays for a selected pixel in the following examples.
function sampArrImg(arrImg) {
var point = ee.Geometry.Point([-121, 42]);
return arrImg.sample(point, 500).first().get('array');
}
// Create a 2D array image with the 0-axis having length 6 and the 1-axis
// having length 1.
var arrayImg2D = ee.Image([0, 1, 2, 3, 4, 5]).toArray().toArray(1);
print('2D array image (pixel)', sampArrImg(arrayImg2D));
// [[0],
// [1],
// [2],
// [3],
// [4],
// [5]]
// Project the 2D array to a 1D array, retain the 0-axis (concatenate elements
// from the 1-axis into the 0-axis).
var arrayImg2Dto1D = arrayImg2D.arrayProject([0]);
print('2D array image (pixel)', sampArrImg(arrayImg2Dto1D));
// [0, 1, 2, 3, 4, 5]
Python setup
See the
Python Environment page for information on the Python API and using
geemap
for interactive development.
import ee
import geemap.core as geemap
Colab (Python)
# A function to print arrays for a selected pixel in the following examples.
def samp_arr_img(arr_img):
point = ee.Geometry.Point([-121, 42])
return arr_img.sample(point, 500).first().get('array')
# Create a 2D array image with the 0-axis having length 6 and the 1-axis
# having length 1.
array_img_2d = ee.Image([0, 1, 2, 3, 4, 5]).toArray().toArray(1)
print('2D array image (pixel):', samp_arr_img(array_img_2d).getInfo())
# [[0],
# [1],
# [2],
# [3],
# [4],
# [5]]
# Project the 2D array to a 1D array, retain the 0-axis (concatenate elements
# from the 1-axis into the 0-axis).
array_img_2d_to_1d = array_img_2d.arrayProject([0])
print('2D array image (pixel):', samp_arr_img(array_img_2d_to_1d).getInfo())
# [0, 1, 2, 3, 4, 5]
Except as otherwise noted, the content of this page is licensed under the Creative Commons Attribution 4.0 License, and code samples are licensed under the Apache 2.0 License. For details, see the Google Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.
Last updated 2023-10-06 UTC.
[null,null,["Last updated 2023-10-06 UTC."],[[["`arrayProject` reduces the dimensionality of an array image by projecting it onto specified axes."],["Dropped axes must have a maximum length of 1, meaning they can't contain more than one element along that dimension."],["This operation effectively reshapes the array within each pixel of the image, retaining data from the specified `axes`."],["It's useful for operations like concatenating elements from different axes or reducing the complexity of an array image."]]],[]]