Podobnie jak w przypadku obrazów, geometrii i elementów, kolekcje elementów można dodawać do mapy bezpośrednio za pomocą funkcji Map.addLayer()
. Domyślna wizualizacja wyświetla wektory za pomocą czarnych linii i półprzezroczystego czarnego wypełnienia. Aby renderować wektory w kolorze, określ parametr color
. Poniżej przedstawiono ekoregiony z mapy „RESOLVE” (Dinerstein et al., 2017) jako domyślną wizualizację w kolorze czerwonym:
Edytor kodu (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
Aby wyświetlić więcej opcji, kliknij featureCollection.draw()
. W szczególności parametry pointRadius
i strokeWidth
kontrolują odpowiednio rozmiar punktów i linii w wyrenderowanym FeatureCollection
:
Edytor kodu (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')
Wyjście funkcji draw()
to obraz z pasmami czerwonym, zielonym i niebieskim ustawionymi zgodnie z określonym parametrem color
.
Aby mieć większą kontrolę nad wyświetlaniem elementu FeatureCollection
, użyj funkcji image.paint()
z argumentem FeatureCollection
. W przeciwieństwie do funkcji draw()
, która generuje 8-bitowy obraz wyświetlania w 3 pasmach, funkcja image.paint()
generuje obraz z określonymi wartościami liczbowymi „namalowanymi” na nim. Możesz też podać nazwę właściwości w polu FeatureCollection
, która zawiera liczby do pomalowania. Parametr width
działa w taki sam sposób: może być stałą wartością lub nazwą właściwości z liczbą odpowiadającą szerokości linii. Na przykład:
Edytor kodu (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')
Pamiętaj, że przed naniesieniem funkcji na obraz musisz najpierw rzutować pusty obraz. Dzieje się tak, ponieważ obraz stały zachowuje się jak stała: jest ograniczony do wartości początkowej. Aby nadać krawędziom cech kolory odpowiadające wartościom ustawionym w właściwości tych cech, ustaw parametr color na nazwę właściwości z wartościami liczbowymi:
Edytor kodu (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')
Zarówno kolor, jak i szerokość linii, którymi narysowane są granice, można ustawić za pomocą właściwości. Na przykład:
Edytor kodu (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' )
Jeśli parametr width
nie jest podany, wnętrze elementów jest zamalowane:
Edytor kodu (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')
Aby wyrenderować zarówno wnętrze, jak i krawędzie obiektów, pomaluj pusty obraz dwukrotnie:
Edytor kodu (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', )