ee.Dictionary.get

تستخرج هذه الدالة قيمة مسماة من قاموس. إذا لم يحتوي القاموس على المفتاح المحدّد، يتم عرض defaultValue، ما لم تكن القيمة فارغة.

الاستخدامالمرتجعات
Dictionary.get(key, defaultValue)عنصر
الوسيطةالنوعالتفاصيل
هذا: dictionaryالقاموس
keyسلسلة
defaultValueكائن، القيمة التلقائية: null

أمثلة

محرّر الرموز البرمجية (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('Value for "B1" key', dict.get('B1'));

// Set a default value for the case where the key does not exist.
print('Value for nonexistent "Band_1" key',
      dict.get({key: 'Band_1', defaultValue: -9999}));

إعداد Python

راجِع صفحة بيئة Python للحصول على معلومات حول واجهة برمجة التطبيقات Python واستخدام 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('Value for "B1" key:', dic.get('B1').getInfo())

# Set a default value for the case where the key does not exist.
print('Value for nonexistent "Band_1" key:',
      dic.get(**{'key': 'Band_1', 'defaultValue': -9999}).getInfo())