Resampling and Reducing Resolution

As noted in the Projections doc, Earth Engine performs nearest neighbor resampling by default during reprojection. You can change this behavior with the resample() or reduceResolution() methods. Specifically, when one of these methods is applied to an input image, any required reprojection of the input will be done using the indicated resampling or aggregation method.


resample() causes the indicated resampling method ('bilinear' or 'bicubic') to be used at the next reprojection. Since inputs are requested in the output projection, an implicit reprojection may happen before any other operation on the input. For this reason, call resample() directly on the input image. Consider the following simple example:

// Load a Landsat image over San Francisco, California, UAS.
var landsat = ee.Image('LANDSAT/LC8_L1T_TOA/LC80440342016083LGN00');

// Set display and visualization parameters.
Map.setCenter(-122.37383, 37.6193, 15);
var visParams = {bands: ['B4', 'B3', 'B2'], max: 0.3};

// Display the Landsat image using the default nearest neighbor resampling.
// when reprojecting to Mercator for the Code Editor map.
Map.addLayer(landsat, visParams, 'original image');

// Force the next reprojection on this image to use bicubic resampling.
var resampled = landsat.resample('bicubic');

// Display the Landsat image using bicubic resampling.
Map.addLayer(resampled, visParams, 'resampled');

Note that the 'bicubic' resampling results in the output pixels appearing smooth relative to the original image (Figure 1).

nearest neighbor
Figure 1a. Landsat imagery resampled with nearest neighbor.
Figure 1b. Landsat imagery resampled with bicubic resampling.

The order of operations for this code sample is diagrammed in Figure 2. Specifically, the implicit reprojection to the maps mercator projection takes place with the resampling method specified on the input image.

Figure 2. Flow chart of operations when resample() is called on the input image prior to display in the Code Editor. Curved lines indicate the flow of information to the reprojection: specifically, the output projection, scale and resampling method to use.

Reduce Resolution

Suppose that instead of resampling during reprojection, your goal is to aggregate pixels to larger pixels in a different projection. This is useful when comparing image datasets at different scales, for example 30-meter pixels from a Landsat-based product to coarse pixels (higher scale) from a MODIS-based product. Control this aggregation process with the reduceResolution() method. As with resample(), call reduceResolution() on the input, in order to affect the next reprojection of the image. The following example uses reduceResolution() to compare forest cover data at 30-meters resolution to a vegetation index at 500-meters resolution:

// Load a MODIS EVI image.
var modis = ee.Image(ee.ImageCollection('MODIS/MOD13A1').first())

// Display the EVI image near La Honda, California.
Map.setCenter(-122.3616, 37.5331, 12);
Map.addLayer(modis, {min: 2000, max: 5000}, 'MODIS EVI');

// Get information about the MODIS projection.
var modisProjection = modis.projection();
print('MODIS projection:', modisProjection);

// Load and display forest cover data at 30 meters resolution.
var forest = ee.Image('UMD/hansen/global_forest_change_2015')
Map.addLayer(forest, {max: 80}, 'forest cover 30 m');

// Get the forest cover data at MODIS scale and projection.
var forestMean = forest
    // Force the next reprojection to aggregate instead of resampling.
      reducer: ee.Reducer.mean(),
      maxPixels: 1024
    // Request the data at the scale and projection of the MODIS image.
      crs: modisProjection

// Display the aggregated, reprojected forest cover data.
Map.addLayer(forestMean, {max: 80}, 'forest cover at MODIS scale');

In this example, note that the output projection is explicitly set with reproject(). During the reprojection to the MODIS sinusoidal projection, rather than resampling, the smaller pixels are aggregated with the specified reducer (ee.Reducer.mean() in the example). This sequence of operations is illustrated in Figure 3. Although this example uses reproject() to help visualize the effect of reduceResolution(), most scripts don't need to explicitly reproject; see the warning here.

Figure 3. Flow chart of operations when reduceResolution() is called on an input image prior to reproject(). Curved lines indicate the flow of information to the reprojection: specifically, the output projection, scale and pixel aggregation method to use.

Note that a second reprojection occurs (implicitly) to display the data on the Code Editor map. Visually inspect the results and observe the correspondence between the pixels from the MODIS layer and the forest cover data reprojected to MODIS scale and projection. In general, you should rarely need to explicitly reproject() in Earth Engine.

Send feedback about...

Google Earth Engine API