ee.FeatureCollection.map

Mapuje algorytm na kolekcję.

Zwraca zmapowaną kolekcję.

WykorzystanieZwroty
FeatureCollection.map(algorithm, dropNulls)Kolekcja
ArgumentTypSzczegóły
to: collectionKolekcjaInstancja kolekcji.
algorithmFunkcjaOperacja mapowania obrazów lub elementów kolekcji. Funkcja JavaScript, która przyjmuje obraz lub funkcje i zwraca jeden z nich. Funkcja jest wywoływana tylko raz, a wynik jest zapisywany jako opis, więc nie może wykonywać operacji imperatywnych ani polegać na stanie zewnętrznym.
dropNullsWartość logiczna, opcjonalnaJeśli ma wartość „true”, zmapowany algorytm może zwracać wartości null, a elementy, dla których zwraca wartości null, zostaną usunięte.

Przykłady

Edytor kodu (JavaScript)

// FeatureCollection of power plants in Belgium.
var fc = ee.FeatureCollection('WRI/GPPD/power_plants')
            .filter('country_lg == "Belgium"');

// Function to convert power plant capacity from megawatts to gigawatts and
// add the value as a new feature property.
var mwToGw = function(feature) {
  var megawatt = feature.getNumber('capacitymw');
  var gigawatt = megawatt.divide(1000);
  return feature.set('capacitygw', gigawatt);
};

// Apply the function to each feature in the collection.
fc = fc.map(mwToGw);

print('Note the new "capacitygw" property in each feature', fc);

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)

# FeatureCollection of power plants in Belgium.
fc = ee.FeatureCollection('WRI/GPPD/power_plants').filter(
    'country_lg == "Belgium"')

# Function to convert power plant capacity from megawatts to gigawatts and
# add the value as a new feature property.
def mw_to_gw(feature):
  megawatt = feature.getNumber('capacitymw')
  gigawatt = megawatt.divide(1000)
  return feature.set('capacitygw', gigawatt)

# Apply the function to each feature in the collection.
fc = fc.map(mw_to_gw)

print('Note the new "capacitygw" property in each feature:', fc.getInfo())