0

I wanted to export an imagery data from GEE, based on its doc. I needed to retrieve the projection information from a band of the original image. I used following codes:

var geometry = ee.Geometry.Rectangle([-114.3461, 51.2335, -113.8015, 50.8140]);
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 S2_collection = ee.ImageCollection("COPERNICUS/S2_SR_HARMONIZED").filterDate('2019-08-01', '2019-08-30').filterBounds(geometry)
.filter(ee.Filter.lt('CLOUDY_PIXEL_PERCENTAGE',20)).map(maskS2clouds);


var S2_bands = ['B4', 'B3', 'B2'];
var S2_mosaic = S2_collection.median().select(S2_bands).clip(geometry);
var S2_display = {bands: S2_bands, min: 0, max: 0.3};
Map.addLayer(S2_mosaic, S2_display, "S2_Image");
Map.centerObject(geometry);


var projection = S2_collection.select('B2').projection().getInfo();

But error: Line 28: S2_collection.select(...).projection is not a function

Would you please help?

1 Answer 1

0

The projection() function works on a single image variable. There is no need of getInfo(). You can select the band and store it in another variable and then use the function.

var image= S2_collection.select('B2')
var projection= image.projection()

[Edited after Justin's comment]

1
  • 1
    The default projection of a collection reduction is 1-degree pixel scale in WGS84 EPSG:4326 projection. I don't think that is what you want. You should get the projection from an unaltered image in the original collection. See this for more info on GEE's default projection: developers.google.com/earth-engine/guides/… Oct 18, 2022 at 19:30

Your Answer

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

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