1

Is there a way to fix the pixel resolution of a dataset in Earth Engine?

I am using the USGS Mangrove layer image collection, which I reduce using the max() function. This gives me an image of 1s over the global extent of mangroves. This image was made with Landsat so its native resolution is 30m.

However, when I try to get the area of each pixel, it varies with the level of zoom I am using. If I zoom out the pixel area increases and if I zoom in, the pixel area value decreases. At the equator, the value should be approximately 900 m2 and it should change with increases in latitude.

I need to get the size of each pixel as I need to multiply it by another dataset (Hansen Forest cover) in order to get the tree cover area per pixel.

A link to my code is here: https://code.earthengine.google.com/a01b4889289544bf5cd761105d9d8caa

And a code snippet is:

Map.setCenter(9.5, 0.2, 10)

var MaxMangrove = Mangroves.max()
print('Pixel Size = ', MaxMangrove.projection().nominalScale())

Map.addLayer(MaxMangrove, {min:0,max:1}, 'Max Mangrove Value')

// not sure if it wants res in m or degrees here
var MangroveProj = MaxMangrove.setDefaultProjection('EPSG:4326', null, 30)

var PixelArea = MangroveProj.multiply(ee.Image.pixelArea())

// This runs fine and displays the image I want - an image where the
// pixel value is the pixel area. This should change with latitude
// but it changes with zoom
Map.addLayer(PixelArea, {min:0,max:100}, 'Pixel Area')
  • 1
    As you've discovered, GEE doesn't treat images as if they have a native scale, but selects the level specified by you. You will probably use a reducer (e.g. reduceRegion) to solve your problem, and it takes a scale parameter as input. When you zoom in and out, you are requiring a different scale, so the areas are different. – Jon Apr 25 at 22:41
  • @Jon Will using a reducer allow me to still get every pixel value, or will it only return one value (e.g. a mean, min or max value)? I have used it previously to get the total area of target pixels, but I need the area of each pixel, which will change with each pixel as latitude increases – Nathan Thomas Apr 26 at 13:53
1

what you want is to force the projection of pixel area raster.

So, If you do this and use it to calculate stuff

var pa = ee.Image.pixelArea().reproject({crs:'EPSG:4326',scale:30})

or simply add the layer to map and check, the values do not change based on zoom level. It does take a while though. If you want to confirm it quickly, you can use the inspector tab/tool to check for values.

  • This is great! I tried to reproject as a separate variable before I calculated the pixel area but I got a memory error. Doing it all on the fly like that works great! – Nathan Thomas Apr 26 at 15:04

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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