Feature and FeatureCollection Visualization

As with images, geometries and features, feature collections can be added to the map directly with Map.addLayer(). The default visualization will display the vectors with solid black lines and semi-opaque black fill. To render the vectors in color, specify the color parameter. The following displays the ‘Global 200’ ecoregions (Olson et al. 1998) as the default visualization and in red:

// Load a FeatureCollection from a Fusion Table: 'global 200' ecoregions.
var g200 = ee.FeatureCollection('ft:11SfWB6oBS1iWGiQxEOqF_wUgBJL7Bux-pWU-mqd5');

// Display as default and with a custom color.
Map.addLayer(g200, {}, 'default display');
Map.addLayer(g200, {color: 'FF0000'}, 'colored');
    

For additional display options, use featureCollection.draw(). Specifically, parameters pointRadius and strokeWidth control the size of points and lines, respectively, in the rendered FeatureCollection:

Map.addLayer(g200.draw({color: '006600', strokeWidth: 5}), {}, 'drawn');
    

The output of draw() is an image with red, green and blue bands set according to the specified color parameter.

For more control over how a FeatureCollection is displayed, use image.paint() with the FeatureCollection as an argument. Unlike draw(), which outputs a three-band, 8-bit display image, image.paint() outputs an image with the specified numeric value ‘painted’ into it. Alternatively, you can supply the name of a property in the FeatureCollection which contains the numbers to paint. The width parameter behaves the same way: it can be a constant or the name of a property with a number for the line width. For example:

// 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: g200,
  color: 1,
  width: 3
});
Map.addLayer(outline, {palette: 'FF0000'}, 'edges');
    

Note that the empty image into which you paint the features needs to be cast prior to painting. This is because a constant image behaves as a constant: it is clamped to the initialization value. To color the feature edges with values set from a property of the features, set the color parameter to the name of the property with numeric values:

// Paint the edges with different colors, display.
var outlines = empty.paint({
  featureCollection: g200,
  color: 'G200_NUM',
  width: 4
});
var palette = ['FF0000', '00FF00', '0000FF'];
Map.addLayer(outlines, {palette: palette}, 'different color edges');
    

Both the color and width with which the boundaries are drawn can be set with properties. For example:

// Paint the edges with different colors and widths.
var outlines = empty.paint({
  featureCollection: g200,
  color: 'G200_NUM',
  width: 'G200_BIOME'
});
Map.addLayer(outlines, {palette: palette}, 'different color, width edges');
    

If the width parameter is not provided, the interior of the features is painted:

// Paint the interior of the polygons with different colors.
var fills = empty.paint({
  featureCollection: g200,
  color: 'G200_NUM',
});
Map.addLayer(fills, {palette: palette}, 'colored fills');
    

To render both the interior and edges of the features, paint the empty image twice:

// Paint both the fill and the edges.
var filledOutlines = empty.paint(g200, 'G200_NUM').paint(g200, 0, 2);
Map.addLayer(filledOutlines, {palette: ['000000'].concat(palette)}, 'edges and fills');
    

发送以下问题的反馈:

此网页
Google Earth Engine API