Skip to content

Instantly share code, notes, and snippets.

@jsta
Created December 17, 2021 16:53
Show Gist options
  • Save jsta/4021c371febf7dcd0500dedbf7142b91 to your computer and use it in GitHub Desktop.
Save jsta/4021c371febf7dcd0500dedbf7142b91 to your computer and use it in GitHub Desktop.
Plot a featureCollection as a choropleth in Google Earth Engine (GEE)
// bottom-left, top-right
var aoi = ee.Geometry.Rectangle(43.1, 13, 47, 30);
var ecoregions = ee.FeatureCollection('RESOLVE/ECOREGIONS/2017')
.filterBounds(aoi);
var ecoregions_img = ecoregions
.filter(ee.Filter.notNull(['SHAPE_AREA']))
.reduceToImage({
properties: ['SHAPE_AREA'],
reducer: ee.Reducer.first()
});
var area_values = ecoregions
.filter(ee.Filter.greaterThan("SHAPE_AREA", 0))
.aggregate_array("SHAPE_AREA");
print(area_values) // 0 - 72
Map.centerObject(ecoregions, 4)
Map.addLayer(ecoregions_img, {
min: 0,
max: 73,
palette: ['FCFDBF', 'FDAE78', 'EE605E', 'B63679', '711F81', '2C105C']
});
Map.addLayer({eeObject: ecoregions.draw({color: 'black', strokeWidth: 1}), visParams: {}, opacity: 0.3});
@jsta
Copy link
Author

jsta commented Dec 17, 2021

image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment