TransWikia.com

To get 'NA' instead of '0' band value while exporting clipped image on Google Earth Engine

Geographic Information Systems Asked on March 21, 2021

My problem is that I need to export images that are clipped using some shapefiles. But when I export the images, for the masked pixels I get 0 band value instead of NA. How can I get NA?

When I use Rodrigo E. Principe’s batch download tool I get the exact format that I needed (na for masked pixels) but I could not use the tool since it is not made for a single image & I could not change the name of the export which is needed in my case.

var geometry = ee.Geometry.Polygon([
    [[23.42929490686074, 34.69481738849795],
     [46.36874803186074, 34.69481738849795],
     [46.36874803186074, 43.44349138830614],
     [23.42929490686074, 43.44349138830614]]
]);

// Import country boundaries feature collection.
var dataset = ee.FeatureCollection("USDOS/LSIB_SIMPLE/2017")

// Apply filter where country name equals turkey.
var turkeyBorder = dataset.filter(ee.Filter.eq('country_na', 'Turkey'));

var cloudyImage = ee.Image('COPERNICUS/S2_SR/20190427T083601_20190427T083603_T36SVJ');

var cloudBitMask = ee.Number(2).pow(10).int();
var cirrusBitMask = ee.Number(2).pow(11).int();

var qa = cloudyImage.select('QA60');

//Map.addLayer(qa.bitwiseAnd(cloudBitMask).neq(0), {}, 'clouds');
//Map.addLayer(qa.bitwiseAnd(cirrusBitMask).neq(0), {}, 'cirrus');

function maskS2clouds(image) {
    var qa = image.select('QA60');
    // 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);
}

var collection = ee.ImageCollection(ee.ImageCollection("COPERNICUS/S2")
    .filterDate("2019-05-01", "2019-05-06")
    .filterBounds(turkeyBorder))

Map.addLayer(collection, {bands: ['B4', 'B3', 'B2'], max: 2000}, 'collection');
Map.addLayer(table)
////Image bu
var min = collection.min().clip(table)
Map.addLayer(min, {bands: ['B4', 'B3', 'B2'], max: 2000}, 'min');
Map.centerObject(geometry, 5)
var bands = min.bandNames().getInfo();
for (var i = 0; i < bands.length; i++) {
    print(bands[i])
    Export.image.toDrive({
        image: min.select(bands[i]),
        description: 'may1-5_' + bands[i],
        folder: "may",
        scale: 100,
        region: geometry.getInfo(),
        maxPixels: 300000000000
    })
}

This is the link for my code https://code.earthengine.google.com/020cfd1f9e7a49ac325d0552a64f9f56

One Answer

Image type should be float to get NA so I changed line 40 to

var min = collection.min().clip(table).toFloat()

and problem solved...

Answered by Elif Dnmz on March 21, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP