Vector to Raster Conversion

Vector to raster conversion in Earth Engine is handled by the featureCollection.reduceToImage() method. This method assigns pixels under each feature the value of the specified property. This example uses the counties data to create an image representing the land area of each county:

// Load a collection of US counties.
var counties = ee.FeatureCollection('TIGER/2018/Counties');

// Make an image out of the land area attribute.
var landAreaImg = counties
  .filter(ee.Filter.notNull(['ALAND']))
  .reduceToImage({
    properties: ['ALAND'],
    reducer: ee.Reducer.first()
});

// Display the county land area image.
Map.setCenter(-99.976, 40.38, 5);
Map.addLayer(landAreaImg, {
  min: 3e8,
  max: 1.5e10,
  palette: ['FCFDBF', 'FDAE78', 'EE605E', 'B63679', '711F81', '2C105C']
});

Specify a reducer to indicate how to aggregate properties of overlapping features. In the previous example, since there is no overlap, an ee.Reducer.first() is sufficient. As in this example, pre-filter the data to eliminate nulls that can not be turned into an image. The output should look something like Figure 1, which maps a color gradient to county size. Like all image-outputting reducers in Earth Engine, the scale is dynamically set by the output. In this case, the scale corresponds to the zoom level in the Code Editor.

reduceToImage output
Figure 1. The result of reduceToImage() using the ‘ALAND’ (land area) property of the 'TIGER/2018/Counties' FeatureCollection.

Send feedback about...

Google Earth Engine API