Wie bei Bildern, Geometrien und Elementen können auch Funktionssammlungen der Karte direkt mit Map.addLayer()
hinzugefügt werden. In der Standardvisualisierung werden die Vektoren mit durchgezogenen schwarzen Linien und einer halbtransparenten schwarzen Füllung dargestellt. Wenn Sie die Vektoren in Farbe rendern möchten, geben Sie den Parameter color
an. Im Folgenden sind die RESOLVE-Ekoregionen (Dinerstein et al. 2017) als Standardvisualisierung und in Rot zu sehen:
Code-Editor (JavaScript)
// Load a FeatureCollection from a table dataset: 'RESOLVE' ecoregions. var ecoregions = ee.FeatureCollection('RESOLVE/ECOREGIONS/2017'); // Display as default and with a custom color. Map.addLayer(ecoregions, {}, 'default display'); Map.addLayer(ecoregions, {color: 'FF0000'}, 'colored');
import ee import geemap.core as geemap
Colab (Python)
# Load a FeatureCollection from a table dataset: 'RESOLVE' ecoregions. ecoregions = ee.FeatureCollection('RESOLVE/ECOREGIONS/2017') # Display as default and with a custom color. m = geemap.Map() m.set_center(-76.2486, 44.8988, 8) m.add_layer(ecoregions, {}, 'default display') m.add_layer(ecoregions, {'color': 'FF0000'}, 'colored') m
Über featureCollection.draw()
können Sie weitere Anzeigeoptionen aufrufen. Insbesondere steuern die Parameter pointRadius
und strokeWidth
die Größe der Punkte bzw. Linien in der gerenderten FeatureCollection
:
Code-Editor (JavaScript)
Map.addLayer(ecoregions.draw({color: '006600', strokeWidth: 5}), {}, 'drawn');
import ee import geemap.core as geemap
Colab (Python)
m.add_layer(ecoregions.draw(color='006600', strokeWidth=5), {}, 'drawn')
Die Ausgabe von draw()
ist ein Bild mit roten, grünen und blauen Bändern, die gemäß dem angegebenen color
-Parameter festgelegt sind.
Wenn Sie die Darstellung einer FeatureCollection
genauer steuern möchten, verwenden Sie image.paint()
mit der FeatureCollection
als Argument. Im Gegensatz zu draw()
, das ein dreibandiges 8‑Bit-Displaybild ausgibt, gibt image.paint()
ein Bild mit dem angegebenen numerischen Wert aus. Alternativ können Sie in FeatureCollection
den Namen einer Property angeben, die die zu zeichnenden Zahlen enthält. Der Parameter width
funktioniert genauso: Er kann eine Konstante oder der Name einer Property mit einer Zahl für die Linienbreite sein. Beispiel:
Code-Editor (JavaScript)
// Create an empty image into which to paint the features, cast to byte. var empty = ee.Image().byte(); // Paint all the polygon edges with the same number and width, display. var outline = empty.paint({ featureCollection: ecoregions, color: 1, width: 3 }); Map.addLayer(outline, {palette: 'FF0000'}, 'edges');
import ee import geemap.core as geemap
Colab (Python)
# Create an empty image into which to paint the features, cast to byte. empty = ee.Image().byte() # Paint all the polygon edges with the same number and width, display. outline = empty.paint(featureCollection=ecoregions, color=1, width=3) m.add_layer(outline, {'palette': 'FF0000'}, 'edges')
Das leere Bild, in das Sie die Elemente malen, muss vor dem Malen gecastet werden. Das liegt daran, dass sich ein konstantes Bild wie eine Konstante verhält: Es wird auf den Initialisierungswert begrenzt. Wenn Sie die Featurekanten mit Werten aus einem Attribut der Features färben möchten, legen Sie den Farbparameter auf den Namen des Attributs mit numerischen Werten fest:
Code-Editor (JavaScript)
// Paint the edges with different colors, display. var outlines = empty.paint({ featureCollection: ecoregions, color: 'BIOME_NUM', width: 4 }); var palette = ['FF0000', '00FF00', '0000FF']; Map.addLayer(outlines, {palette: palette, max: 14}, 'different color edges');
import ee import geemap.core as geemap
Colab (Python)
# Paint the edges with different colors, display. outlines = empty.paint(featureCollection=ecoregions, color='BIOME_NUM', width=4) palette = ['FF0000', '00FF00', '0000FF'] m.add_layer(outlines, {'palette': palette, 'max': 14}, 'different color edges')
Sowohl die Farbe als auch die Breite, mit der die Grenzen gezeichnet werden, können mithilfe von Attributen festgelegt werden. Beispiel:
Code-Editor (JavaScript)
// Paint the edges with different colors and widths. var outlines = empty.paint({ featureCollection: ecoregions, color: 'BIOME_NUM', width: 'NNH' }); Map.addLayer(outlines, {palette: palette, max: 14}, 'different color, width edges');
import ee import geemap.core as geemap
Colab (Python)
# Paint the edges with different colors and widths. outlines = empty.paint( featureCollection=ecoregions, color='BIOME_NUM', width='NNH' ) m.add_layer( outlines, {'palette': palette, 'max': 14}, 'different color, width edges' )
Wenn der Parameter width
nicht angegeben ist, wird das Innere der Elemente ausgemalt:
Code-Editor (JavaScript)
// Paint the interior of the polygons with different colors. var fills = empty.paint({ featureCollection: ecoregions, color: 'BIOME_NUM', }); Map.addLayer(fills, {palette: palette, max: 14}, 'colored fills');
import ee import geemap.core as geemap
Colab (Python)
# Paint the interior of the polygons with different colors. fills = empty.paint(featureCollection=ecoregions, color='BIOME_NUM') m.add_layer(fills, {'palette': palette, 'max': 14}, 'colored fills')
Wenn Sie sowohl die Innenräume als auch die Ränder der Elemente rendern möchten, malen Sie das leere Bild zweimal:
Code-Editor (JavaScript)
// Paint both the fill and the edges. var filledOutlines = empty.paint(ecoregions, 'BIOME_NUM').paint(ecoregions, 0, 2); Map.addLayer(filledOutlines, {palette: ['000000'].concat(palette), max: 14}, 'edges and fills');
import ee import geemap.core as geemap
Colab (Python)
# Paint both the fill and the edges. filled_outlines = empty.paint(ecoregions, 'BIOME_NUM').paint(ecoregions, 0, 2) m.add_layer( filled_outlines, {'palette': ['000000'] + palette, 'max': 14}, 'edges and fills', )