0

I use the GEE API in a Python environment and I want to upload numerous small image to my local machine. I try to implement the solution suggested here. Before upgrading my code I wanted to do some test in EE code editor but I cannot make it work.

So I tried to use the ee method getDownloadUrl to retrieve multiband images on very small surface using the following code:


function maskS2clouds(image) {
  var qa = image.select('QA60');

  // Bits 10 and 11 are clouds and cirrus, respectively.
  var cloudBitMask = 1 << 10;
  var cirrusBitMask = 1 << 11;

  // Both flags should be set to zero, indicating clear conditions.
  var mask = qa.bitwiseAnd(cloudBitMask).eq(0)
      .and(qa.bitwiseAnd(cirrusBitMask).eq(0));

  return image.updateMask(mask).divide(10000);
}

var aoi = ee.FeatureCollection('users/bornToBeAlive/FRA_Grid_2')
var dataset = ee.ImageCollection('COPERNICUS/S2_SR')
  .filterDate('2020-01-01', '2020-01-30')
  // Pre-filter to get less cloudy granules.
  .filter(ee.Filter.lt('CLOUDY_PIXEL_PERCENTAGE',20))
  .map(maskS2clouds)

var visualization = {
  min: 0.0,
  max: 0.3,
  bands: ['B4', 'B3', 'B2'],
};


//clip the dataset on the aoi 
var clip = dataset.mean().clip(aoi)

// get the first tile 
Map.addLayer(clip, visualization, 'S2')
Map.addLayer(aoi.first().geometry(), {}, "france")
Map.centerObject(aoi.first())

The displayd image is very snowy but I manage to see things.

now to upload this image I want to get a downloadable link:

var link = clip.select(['B4', 'B3', 'B2']).getDownloadURL({
    'name': 'toto',
    'region': aoi.first().geometry(),
    'filePerBand': false
});

print(link)

Unfortunately the link I get is giving me an image that is not scaled properly (the square is way too big) and I only get the same value for each pixel on each band.

Did I do something wrong? Does anyone knows how to use this function?

0

In the proposed code, you forgot the scale parameter.

here is a proper implementation for at 10 meters for sentinel 2 data :

var link = clip.select(['B4', 'B3', 'B2']).getDownloadURL({
    'name': 'toto',
    'region': aoi.first().geometry(),
    'filePerBand': false,
    'scale': 10
});

print(link)

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.