Google Earth Engine Authors 8fee1d9e26 v0.1.386
PiperOrigin-RevId: 597577360
2024-01-18 18:09:09 +00:00

28 lines
661 B
Python

"""Reverse mask a region.
Create an image that masks everything except for the specified polygon.
"""
import ee
import ee.mapclient
ee.Initialize()
ee.mapclient.centerMap(-115, 39, 5)
fc = (ee.FeatureCollection('RESOLVE/ECOREGIONS/2017')
.filter(ee.Filter().eq('ECO_NAME', 'Great Basin shrub steppe')))
# Start with a black image.
empty = ee.Image(0).toByte()
# Fill and outline the polygons in two colors
filled = empty.paint(fc, 2)
both = filled.paint(fc, 1, 5)
# Mask off everything that matches the fill color.
result = both.mask(filled.neq(2))
ee.mapclient.addToMap(result, {
'palette': '000000,FF0000',
'max': 1,
'opacity': 0.5
})