1

I'm trying to create a reduced resolution version of a categorical image using mode to reduce. The code is below and also at https://code.earthengine.google.com/0f433401de49c18cc48ff9c52eed5bf0. In the center of the reduced resolution image, there are a couple cells with a value in black (11) which does not exist in the full resolution version, nor does it look like it should be calculated by the reducer (especially considering I'm using mode). One thing is that at some point in the steps that created the full resolution image there may have been a value of 11 there!

Full resolution: enter image description here

Reduced resolution: enter image description here

This looks like a bug to me, but thought I'd ask for any insight.


I think @kkrao is onto something. This question was a bit of a simplification for demonstration purposes. Ultimately I want to export the image at reduced resolution, and in its native projection (EPSG:4326). Unfortunately the same error occurs when I export, and unless I'm missing something, there should not be a second reprojection happening if I do that? See updated code below and at link.

var lc_10 = ee.Image('users/jesse/reducer_test');

var lc_sld =
'<RasterSymbolizer>' +
 ' <ColorMap  type="intervals" extended="false" >' +
    '<ColorMapEntry color="#02682c" quantity="1" label=""/>' +
    '<ColorMapEntry color="#61aa36" quantity="2" label=""/>' +
    '<ColorMapEntry color="#e2c85f" quantity="3" label=""/>' +
    '<ColorMapEntry color="#ac9e8d" quantity="4" label=""/>' +
    '<ColorMapEntry color="#564F46" quantity="5" label=""/>' +
    '<ColorMapEntry color="#601818" quantity="6" label=""/>' +
    '<ColorMapEntry color="#75a8ea" quantity="7" label=""/>' +
    '<ColorMapEntry color="#e2e2d5" quantity="8" label=""/>' +
    '<ColorMapEntry color="#d8d7a9" quantity="9" label=""/>' +
    '<ColorMapEntry color="#f2f1dc" quantity="10" label=""/>' +
    '<ColorMapEntry color="#ab3c09" quantity="12" label=""/>' +
    '<ColorMapEntry color="#000000" quantity="11" label=""/>' +
    '<ColorMapEntry color="#e18c2c" quantity="1101" label=""/>' +
    '<ColorMapEntry color="#e18c2c" quantity="1102" label=""/>' +
    '<ColorMapEntry color="#e18c2c" quantity="1103" label=""/>' +
    '<ColorMapEntry color="#e18c2c" quantity="1104" label=""/>' +
    '<ColorMapEntry color="#e18c2c" quantity="1105" label=""/>' +
    '<ColorMapEntry color="#601818" quantity="1106" label=""/>' +
    '<ColorMapEntry color="#75a8ea" quantity="1107" label=""/>' +
    '<ColorMapEntry color="#e2e2d5" quantity="1108" label=""/>' +
    '<ColorMapEntry color="#d8d7a9" quantity="1109" label=""/>' +
    '<ColorMapEntry color="#e18c2c" quantity="1110" label=""/>' +
    '<ColorMapEntry color="#ab3c09" quantity="1112" label=""/>' +
  '</ColorMap>' +
'</RasterSymbolizer>';

Map.addLayer(lc_10,{},'10 meter', 0);
Map.addLayer(lc_10.sldStyle(lc_sld), {},'10 meter');


var lc_120 = lc_10.reduceResolution(ee.Reducer.mode(), true, 150).reproject({crs:'EPSG:4326', scale:120});
Map.addLayer(lc_120,{},'120 meter', 0);
Map.addLayer(lc_120.sldStyle(lc_sld),{}, '120 meter');
Map.setCenter(-94.718173, 48.796361, 16);

// native projection is EPSG:4326
print(lc_10.projection().getInfo());

// Should stay in native projection, right?
Export.image.toDrive({ image: lc_120, scale:120});

1 Answer 1

1

You are unintentionally reprojecting twice following the .reduceResolution() command which results in unexpected behaviour. The two reprojections happen when:

  1. Once explicitly by calling .reproject({crs:'EPSG:4326', scale:120}) and
  2. Once implicitly by calling Map.addLayer() on the layer. When you call Map.addLayer() the layer is reprojected again from EPSG:4326 to maps mercator using the same rule as you set in .reduceResolution(). Information about this is available here under the red warning ribbon.

To avoid this behaviour (and the unintended black squares in the middle) reproject straight to mercator projection using .reproject({crs:'EPSG:3857', scale:120}). This will fix your error with no other changes required to the script.

Link to corrected code with one reprojection.

If for some reason, you do want to have the 2 reprojections (for e.g., you want to do some intermediate computations on lc_120 in EPSG:4326 projection then add lc_120 onto the map in mercator projection), then just decrease the maxPixels to something smaller like 64 because reprojecting twice with ee.Reducer.mode() over 150 large pixels will likely include many pixels out of the extent of the current image. So replace this line:

var lc_120 = lc_10.reduceResolution(ee.Reducer.mode(), true, 150).reproject({crs:'EPSG:4326', scale:120});

with:

var lc_120 = lc_10.reduceResolution(ee.Reducer.mode(), true, 64).reproject({crs:'EPSG:4326', scale:120});

Link to corrected code with 2 reprojections.

Using any of the 2 solutions from above will result in an image with no black squares as shown below.

enter image description here

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.