Come per le immagini, le geometrie e gli elementi, le raccolte di elementi possono essere aggiunte alla mappa
direttamente con Map.addLayer()
. La visualizzazione predefinita mostra i vettori con linee nere piene e riempimento nero semiopaco. Per visualizzare i vettori a colori,
specifica il parametro color
. Di seguito sono riportate le ecoregioni "RESOLVE"
(Dinerstein
et al. 2017) come visualizzazione predefinita e in rosso:
Editor di codice (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
Per altre opzioni di visualizzazione, utilizza featureCollection.draw()
. Nello specifico,
i parametri pointRadius
e strokeWidth
controllano le dimensioni di punti
e linee, rispettivamente, nel FeatureCollection
visualizzato:
Editor di codice (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')
L'output di draw()
è un'immagine con bande rosse, verdi e blu impostate in base al parametro color
specificato.
Per un maggiore controllo sulla modalità di visualizzazione di un FeatureCollection
, utilizza
image.paint()
con FeatureCollection
come argomento. A differenza di
draw()
, che genera un'immagine di visualizzazione a tre bande e 8 bit,
image.paint()
genera un'immagine con il valore numerico specificato "dipinto"
al suo interno. In alternativa, puoi fornire il nome di una proprietà in FeatureCollection
che contiene i numeri da dipingere. Il parametro width
si comporta allo stesso modo: può essere una costante o il nome di una proprietà con un
numero per la larghezza della linea. Ad esempio:
Editor di codice (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')
Tieni presente che l'immagine vuota in cui dipingi gli elementi deve essere eseguita prima della pittura. Questo perché un'immagine costante si comporta come una costante: viene limitata al valore di inizializzazione. Per colorare i bordi delle caratteristiche con i valori impostati da una proprietà delle caratteristiche, imposta il parametro di colore sul nome della proprietà con valori numerici:
Editor di codice (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')
Sia il colore sia la larghezza con cui vengono disegnati i confini possono essere impostati con le proprietà. Ad esempio:
Editor di codice (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' )
Se il parametro width
non viene fornito, l'interno delle funzionalità vieneEPINTO:
Editor di codice (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')
Per eseguire il rendering sia dell'interno che dei bordi degli elementi, dipingi l'immagine vuota due volte:
Editor di codice (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', )