4

I have a FeatureCollection with my study area, and an image with urban areas. I want to remove the areas in my FeatureCollection where the image has urban areas. How can this be done?

var studyArea = ee.FeatureCollection('USDOS/LSIB_SIMPLE/2017')
  .filter(ee.Filter.eq('country_na', 'Japan'));
Map.addLayer(studyArea, {}, "studyArea");

var mask = ee.Image("Tsinghua/FROM-GLC/GAIA/v10").clip(studyArea);
Map.addLayer(mask, {}, "mask");

https://code.earthengine.google.com/8cce1074c07cea956fe9aee77a98c336

enter image description here

1 Answer 1

0

This is possible in theory, but not necessarily a good idea. EE is great at working with large amount of pixels but less good at working with complicated features. To do this, you turn your image mask into a FeatureCollection, using reduceToVectors(). This works for simple and small images, but will be problematic for more complicated ones, resulting in a large amount of features.

I would suggest that you try to find a different way to attack your use-case, find away where you don't need to turn your image into features.

That said, here's how you could go about if your image was simpler - it will almost certainly not work with yours:

var mask = ee.Image(1)
  .clip(ee.Geometry.Point([139.8647, 35.9642]).buffer(10000))

var scale = 1000 // Tweak this
var vectors = mask.reduceToVectors({
  geometry: studyArea.geometry(),
  scale: scale,
  // Will increase the scale of processing to fit within maxPixels. 
  // You might want to drop this if you need to know the exact scale you've worked with
  bestEffort: true, 
  maxPixels: 1e6 // Tweak this
})

var filtered = studyArea.geometry()
  .difference(vectors, scale)
  
Map.addLayer(vectors, null, 'vectors', false)
Map.addLayer(filtered, null, 'filtered')

https://code.earthengine.google.com/d9f69229ca8f88586f731de8c65d72db

Your Answer

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

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