Google Earth Engine – How to Use FeatureCollection to Mask an Image Efficiently

google-earth-engine

I want to classify crop types using Sentinel-2 image in GEE. Before starting the classification, however, I want to update the mask of the image, so that water, urban areas, forest and other non-arable land is masked. For that purpose I uploaded a shape file with the arable land and imported it as a FeatureCollection.

My question is is it possible to use this FeatureCollection to update the mask of the image dataset. I know of the updateMask() function but it takes an image as its argument.

Best Answer

You could do something like:

var ic = ee.ImageCollection('...')
var fc = ee.FeatureCollection('....')
var mask = ee.Image.constant(1).clip(fc.geometry()).mask().not()

ic = ic.map(function(image){return image.updateMask(mask)})