Al igual que con las imágenes, las geometrías y los componentes, las colecciones de componentes se pueden agregar al mapa directamente con Map.addLayer()
. La visualización predeterminada mostrará los vectores con líneas negras sólidas y relleno negro semiopaco. Para renderizar los vectores en color,
especifica el parámetro color
. A continuación, se muestran las ecorregiones de "RESOLVE" (Dinerstein et al. 2017) como la visualización predeterminada y en rojo:
// 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
# 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
Para obtener opciones de visualización adicionales, usa featureCollection.draw()
. Específicamente, los parámetros pointRadius
y strokeWidth
controlan el tamaño de los puntos y las líneas, respectivamente, en el FeatureCollection
renderizado:
Map.addLayer(ecoregions.draw({color: '006600', strokeWidth: 5}), {}, 'drawn');
import ee import geemap.core as geemap
m.add_layer(ecoregions.draw(color='006600', strokeWidth=5), {}, 'drawn')
El resultado de draw()
es una imagen con bandas rojas, verdes y azules configuradas según el parámetro color
especificado.
Para tener más control sobre cómo se muestra un FeatureCollection
, usa image.paint()
con FeatureCollection
como argumento. A diferencia de draw()
, que genera una imagen de visualización de tres bandas y 8 bits, image.paint()
genera una imagen con el valor numérico especificado “pintado” en ella. Como alternativa, puedes proporcionar el nombre de una propiedad en el FeatureCollection
que contiene los números que se pintarán. El parámetro width
se comporta de la misma manera: puede ser una constante o el nombre de una propiedad con un número para el ancho de línea. Por ejemplo:
// 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
# 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')
Ten en cuenta que la imagen vacía en la que pintas las características debe transmitirse antes de la pintura. Esto se debe a que una imagen constante se comporta como una constante: se ajusta al valor de inicialización. Para colorear los bordes de los componentes con valores establecidos a partir de una propiedad de los componentes, establece el parámetro de color en el nombre de la propiedad con valores numéricos:
// 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
# 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')
Tanto el color como el ancho con los que se dibujan los límites se pueden establecer con propiedades. Por ejemplo:
// 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
# 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' )
Si no se proporciona el parámetro width
, el interior de los componentes se pinta de la siguiente manera:
// 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
# 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')
Para renderizar el interior y los bordes de los componentes, pinta la imagen vacía dos veces:
// 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
# 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', )