1

I am working on a classification problem on agricultural fields. To make things easier, I first identified road, cities, water, fields, and etc. I am planning to eliminate road, cities, and water out of the image to improve my model. I got all these areas as polygons in a .shp file and I want to mask out these areas.

Wherever I check, all applications are for clipping a polygon.

Is there a method to mask the polygons I provided in GEE code editor?

1

There may be many ways to do that, but when I had to do it I did:

var maskInside = function(image, geometry) {
  var mask = ee.Image.constant(1).clip(geometry).mask().not()
  return image.updateMask(mask)
}

And put that function in a package (geetools for the code editor) that you can use in this way:

var tools = require('users/fitoprincipe/geetools:tools')  
var i = ee.Image.random(1)
var masked = tools.geometry.maskInside(i, geometry)
Map.addLayer(masked)
  • Thanks! I can't try now since it's quite late here in Turkey and I'm out of office. It looks this solves the problem. It seems an easy task but I couldn't find anyone does it. Thanks a lot – Batuhan Kavlak Jun 7 at 23:29

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.