javascriptgoogle-earth-enginelandsat

Google Earth Engine: Region of Landsat Image


I have some manipulation in Google Earth Engine, for example:

// Load a cloudy Landsat scene and display it.
var cloudy_scene = ee.Image('LANDSAT/LC8_L1T_TOA/LC80440342014269LGN00');
Map.centerObject(cloudy_scene);
Map.addLayer(cloudy_scene, {bands: ['B4', 'B3', 'B2'], max: 0.4}, 'TOA', false);

// Add a cloud score band.  It is automatically called 'cloud'.
var scored = ee.Algorithms.Landsat.simpleCloudScore(cloudy_scene);

// Create a mask from the cloud score and combine it with the image mask.
var mask = scored.select(['cloud']).lte(20);

// Apply the mask to the image.
var masked = cloudy_scene.updateMask(mask);

And now I want to export result (masked) to google drive using method Export.image.toDrive, but I don't known how to specify parameter region to meet the same as original image LANDSAT/LC8_L1T_TOA/LC80440342014269LGN00 is.

Please help me construct this region.


Solution

  • I think that's what you're looking for:

    Export.image.toDrive({
    
      image:masked.select('B3'),
      description: 'Masked_Landsat_Image',
      region:masked.geometry(),
      scale:mask.projection().nominalScale().getInfo()
    
    })
    

    In this case I'm using the image's footprint ( with image.geometry() ) to define my export region.

    Note that I'm using the function mask.projection().nominalScale().getInfo() to derive the scale (resolution) of your export. This makes sure I'm using the native resolution of the image (in this case 30m). You need to add getInfo to the function to actually retrieves the integer from the server. You could also just specify 30 or any other desired resolution in meters.

    HTH


    Edit:

    Just a visual aid to what I've written in the comment below:

    3 Images:

    1. Top left corner of original LS image (downloaded from EarthExplorer) - Red indicates NoData

    Image 1

    1. LS image from GEE on top of original image (GEE image has redish pixels) - You can clearly see that there's still the NoData part of the original image which is missing in the GEE version. The thing I would be concerned about is that the pixels don't line up nicely.

    Image 2

    1. The top right corner of both images: Here you can see how far the 2 images are apart

    enter image description here