Earth Engine 已推出
非商業用途的配額級別,以便保護共用運算資源,並確保所有使用者都能享有穩固效能。非商業用途的專案預設會使用「社群」級別,但您隨時可以變更專案級別。
Google uses AI technology to translate content into your preferred language. AI translations can contain errors.
ee.ImageCollection.toArrayPerBand
透過集合功能整理內容
你可以依據偏好儲存及分類內容。
將多張圖片串連成單一陣列圖片。
| 用量 | 傳回 |
|---|
ImageCollection.toArrayPerBand(axis, dropMasked) | 圖片 |
| 引數 | 類型 | 詳細資料 |
|---|
this: collection | ImageCollection | 要串連的圖片。每個波段都會進行個別串連,因此除了串連軸的長度外,所有圖片的每個波段都必須具有相同的維度和形狀。 |
axis | 整數,預設值為 0 | 要沿著串連的軸;必須至少為 0,且至多為集合中任何頻帶的最小維度。 |
dropMasked | 布林值,預設值為 false | 如果為 false (預設值),輸出像素的遮罩值是輸入像素遮罩的最小值。如果計算定界框內的集合中,有任何圖片的像素完全遮蓋,該輸出像素就會遮蓋。因此,每個未遮蓋的輸出像素陣列大小都會相同。
如果是 true,輸出像素的遮罩值就是輸入遮罩的最大值。系統會忽略該像素完全遮蓋的圖片,且不會將資料提供給輸出陣列。因此,每個像素的輸出陣列不一定會具有相同大小。 |
範例
程式碼編輯器 (JavaScript)
// A function to extract and print the array of a selected pixel.
function sampleArrayImage(arrImg) {
var point = ee.Geometry.Point([0, 0]);
return arrImg.sample(point, 1).first().get('b1');
}
// Define three single-band constant images with unified data types.
var img0 = ee.Image(0).byte().rename('b1');
var img1 = ee.Image(1).byte().rename('b1');
var img2 = ee.Image(2).byte().rename('b1');
// 1. Basic usage: concatenate fully valid images along axis 0.
var colSimple = ee.ImageCollection([img0, img1, img2]);
var arrayBasic = colSimple.toArrayPerBand();
print('Basic toArrayPerBand (pixel array):', sampleArrayImage(arrayBasic));
// Result: [0, 1, 2]
// 2. Masking behavior: introduce an image with a masked pixel.
// Update mask so img1 has no valid data at the sampled pixel.
var img1Masked = img1.updateMask(0);
var colMasked = ee.ImageCollection([img0, img1Masked, img2]);
// By default (dropMasked = false), if any input image is masked at a pixel,
// the output array is masked at that pixel. Since sampling a masked pixel
// returns no features, we inspect the output image's mask directly.
var arrayDefault = colMasked.toArrayPerBand();
print('Default masking behavior (pixel mask is 0):',
sampleArrayImage(arrayDefault.mask()));
// Result: 0
// With dropMasked = true, if any input image is masked at a specific pixel,
// its value is omitted from the output array at that pixel. As a result,
// array lengths can vary across different pixels.
var arrayDropped = colMasked.toArrayPerBand(0, true);
print('dropMasked=true (pixel array omits image-specific masked pixels):',
sampleArrayImage(arrayDropped));
// Result: [0, 2]
Python 設定
請參閱
Python 環境頁面,瞭解 Python API 和如何使用 geemap 進行互動式開發。
import ee
import geemap.core as geemap
Colab (Python)
# A function to extract and print the array of a selected pixel.
def sample_array_image(arr_img):
point = ee.Geometry.Point([0, 0])
return arr_img.sample(point, 1).first().get('b1')
# Define three single-band constant images with unified data types.
img0 = ee.Image(0).byte().rename('b1')
img1 = ee.Image(1).byte().rename('b1')
img2 = ee.Image(2).byte().rename('b1')
# 1. Basic usage: concatenate fully valid images along axis 0.
col_simple = ee.ImageCollection([img0, img1, img2])
array_basic = col_simple.toArrayPerBand()
display('Basic toArrayPerBand (pixel array):', sample_array_image(array_basic))
# Result: [0, 1, 2]
# 2. Masking behavior: introduce an image with a masked pixel.
# Update mask so img1 has no valid data at the sampled pixel.
img1_masked = img1.updateMask(0)
col_masked = ee.ImageCollection([img0, img1_masked, img2])
# By default (dropMasked = False), if any input image is masked at a pixel,
# the output array is masked at that pixel. Since sampling a masked pixel
# returns no features, we inspect the output image's mask directly.
array_default = col_masked.toArrayPerBand()
display(
'Default masking behavior (pixel mask is 0):',
sample_array_image(array_default.mask()),
)
# Result: 0
# With dropMasked = true, if any input image is masked at a specific pixel,
# its value is omitted from the output array at that pixel. As a result,
# array lengths can vary across different pixels.
array_dropped = col_masked.toArrayPerBand(0, True)
display(
'dropMasked=True (pixel array omits image-specific masked pixels):',
sample_array_image(array_dropped),
)
# Result: [0, 2]
除非另有註明,否則本頁面中的內容是採用創用 CC 姓名標示 4.0 授權,程式碼範例則為阿帕契 2.0 授權。詳情請參閱《Google Developers 網站政策》。Java 是 Oracle 和/或其關聯企業的註冊商標。
上次更新時間:2026-05-31 (世界標準時間)。
[[["容易理解","easyToUnderstand","thumb-up"],["確實解決了我的問題","solvedMyProblem","thumb-up"],["其他","otherUp","thumb-up"]],[["缺少我需要的資訊","missingTheInformationINeed","thumb-down"],["過於複雜/步驟過多","tooComplicatedTooManySteps","thumb-down"],["過時","outOfDate","thumb-down"],["翻譯問題","translationIssue","thumb-down"],["示例/程式碼問題","samplesCodeIssue","thumb-down"],["其他","otherDown","thumb-down"]],["上次更新時間:2026-05-31 (世界標準時間)。"],[],[]]