ee.Image.clipToCollection

將圖片裁剪為 FeatureCollection。輸出頻帶與輸入頻帶完全對應,但系統會遮蓋至少一個特徵幾何圖形未涵蓋的資料。輸出圖片會保留輸入圖片的中繼資料。

用量傳回
Image.clipToCollection(collection)圖片
引數類型詳細資料
這個:input圖片要剪輯的圖片。
collection物件要剪輯的 FeatureCollection。

範例

程式碼編輯器 (JavaScript)

// A digital elevation model.
var dem = ee.Image('NASA/NASADEM_HGT/001');

// A FeatureCollection defining Southeast Asia boundary.
var fc = ee.FeatureCollection('USDOS/LSIB_SIMPLE/2017')
             .filter('wld_rgn == "SE Asia"');

// Clip the DEM by the Southeast Asia boundary FeatureCollection.
var demClip = dem.clipToCollection(fc);
print('Clipped image retains metadata and band names', demClip);

// Add layers to the map.
Map.setCenter(110.64, 9.16, 4);
Map.addLayer(dem, {bands: 'elevation', min: 0, max: 2500}, 'Original DEM');
Map.addLayer(fc, {color: 'blue'}, 'FeatureCollection');
Map.addLayer(demClip,
 {bands: 'elevation', min: 0, max: 2500, palette: ['green', 'yellow', 'brown']},
 'Clipped DEM');

Python 設定

請參閱 Python 環境頁面,瞭解 Python API 和如何使用 geemap 進行互動式開發。

import ee
import geemap.core as geemap

Colab (Python)

# A digital elevation model.
dem = ee.Image('NASA/NASADEM_HGT/001')

# A FeatureCollection defining Southeast Asia boundary.
fc = ee.FeatureCollection('USDOS/LSIB_SIMPLE/2017').filter(
    'wld_rgn == "SE Asia"'
)

# Clip the DEM by the Southeast Asia boundary FeatureCollection.
dem_clip = dem.clipToCollection(fc)
display('Clipped image retains metadata and band names', dem_clip)

# Add layers to the map.
m = geemap.Map()
m.set_center(110.64, 9.16, 4)
m.add_layer(dem, {'bands': 'elevation', 'min': 0, 'max': 2500}, 'Original DEM')
m.add_layer(fc, {'color': 'blue'}, 'FeatureCollection')
m.add_layer(
    dem_clip,
    {
        'bands': 'elevation',
        'min': 0,
        'max': 2500,
        'palette': ['green', 'yellow', 'brown'],
    },
    'Clipped DEM',
)
m