ee.String.getInfo

Pobiera wartość tego obiektu z serwera.

Jeśli nie podasz funkcji wywołania zwrotnego, żądanie zostanie wysłane synchronicznie. Jeśli podano wywołanie zwrotne, żądanie jest wysyłane asynchronicznie.

Tryb asynchroniczny jest preferowany, ponieważ tryb synchroniczny zatrzymuje cały inny kod (np. interfejs Edytora kodu EE) podczas oczekiwania na serwer. W przypadku żądania asynchronicznego zalecamy użycie funkcji evaluate() zamiast getInfo().

Zwraca obliczoną wartość tego obiektu.

WykorzystanieZwroty
String.getInfo(callback)Obiekt
ArgumentTypSzczegóły
to: computedobjectComputedObjectInstancja ComputedObject.
callbackFunkcja (opcjonalnie)opcjonalne wywołanie zwrotne. Jeśli nie zostanie podany, wywołanie zostanie wykonane synchronicznie.

Przykłady

Edytor kodu (JavaScript)

// After getInfo(), the instance is a local JavaScript string.
// Regular JavaScript string manipulations are then available.
//
// Note: getInfo() fetches results from Earth Engine immediately, and may freeze
// the browser or lead to poor performance.  Use evaluate() to avoid this.

print(ee.String('abc').getInfo().charAt(1));  // b
print(ee.String('abc').getInfo()[2]);         // c

// Using + with ee.String has unexpected results
print(ee.String('abc') + 'def');  // ee.String("abc")def

// Fetch string using getInfo
print(ee.String('abc').getInfo() + 'def');  // abcdef

// Improved solution: cat is available on ee.String
print(ee.String('abc').cat('def'));  // abcdef

Konfiguracja Pythona

Informacje o interfejsie Python API i używaniu geemap do interaktywnego programowania znajdziesz na stronie Środowisko Python.

import ee
import geemap.core as geemap

Colab (Python)

# After getInfo(), the instance is a local Python string.
# Regular Python string manipulations are then available.

# Note: getInfo() fetches results from Earth Engine synchronously;
# later expressions will not be evaluated until it completes.

print(ee.String('abc').getInfo()[-2])  # b
print(ee.String('abc').getInfo()[2])  # c

# Fetch string using getInfo
print(ee.String('abc').getInfo() + 'def')  # abcdef