ee.Dictionary.select

傳回只含指定鍵的字典。

用量傳回
Dictionary.select(selectors, ignoreMissing)字典
引數類型詳細資料
這個:dictionary字典
selectors清單可供選取的鍵或規則運算式清單。
ignoreMissing布林值,預設值為 false忽略與至少 1 個鍵不符的選取器。

範例

程式碼編輯器 (JavaScript)

// A dictionary (e.g. results of ee.Image.reduceRegion of an S2 image).
var dict = ee.Dictionary({
  B1: 182,
  B2: 219,
  B3: 443
});

print('Select keys by name', dict.select(['B1', 'B2']));
print('Select keys by regex', dict.select(['B[1-2]']));
print('Set ignoreMissing as true to avoid an unmatched key error',
      dict.select({selectors: ['B1', 'B2', 'Region'], ignoreMissing: true}));

Python 設定

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

import ee
import geemap.core as geemap

Colab (Python)

# A dictionary (e.g. results of ee.Image.reduceRegion of an S2 image).
dic = ee.Dictionary({
    'B1': 182,
    'B2': 219,
    'B3': 443
})

print('Select keys by name:', dic.select(['B1', 'B2']).getInfo())
print('Select keys by regex:', dic.select(['B[1-2]']).getInfo())

dic_select = dic.select(**{'selectors': ['B1', 'B2', 'Region'],
                           'ignoreMissing': True})
print('Set ignoreMissing as true to avoid an unmatched key error:',
      dic_select.getInfo())