Simple way to extract areas from features and image

Simple way to extract areas from features and image

//Set a feature
var roi = ee.FeatureCollection('put your asset here')
Map.centerObject(roi, )
Map.addLayer(roi, {color:'Green'},'NAME')
print('data',roi)

//Calculate the feature area
var area = roi.geometry().area()//m2 - default
var area_km = ee.Number(area).divide(1e6).round()
print('area (km2)', area_km)

//========================================================================//to run this example of area calculation, I will use: 
//"Dynamic World V1"
//Dynamic World is a 10m near-real-time (NRT) Land Use/Land Cover (LULC) //dataset that includes class probabilities and label information for nine //classes.
//========================================================================

var classification = ee.ImageCollection("GOOGLE/DYNAMICWORLD/V1")
                    .filterDate('2023-12-01','2024-01-01')
                    .max()//pode ser mean ou min
                    .clip(roi)

// Define list pairs of label and color.
var CLASS_NAMES = [
    'water', 'trees', 'grass', 'flooded_vegetation', 'crops',
    'shrub_and_scrub', 'built', 'bare', 'snow_and_ice'];

var VIS_PALETTE = [
    '419bdf', '397d49', '88b053', '7a87c6', 
    'e49635', 'dfc35a', 'c4281b','a59b8f', 
    'b39fe1'];


var classification = classification
                     .select('label')


Map.addLayer(classification,{min: 0, max: 8, palette: VIS_PALETTE},'classific')

//========================================================================
//Calculate the area by selecting only one label
//in this example I would calculate the label "tree"
//========================================================================

//select only the label to be used. I'm using terms and color palette //provided by DW
var trees = classification.eq(2).selfMask()
Map.addLayer(trees, {palette: '397d49'},'Trees')

//Area in m2
var areaImage = trees.multiply(ee.Image.pixelArea())

//Accumulating the pixels of area in m2
var area = areaImage.reduceRegion({
  reducer: ee.Reducer.sum(),
  geometry: roi.geometry(),
  scale: 10,
  maxPixels: 1e13,
  })
print('Forested area in m2',area)

//Area in km2
var treeAreaSqKm = ee.Number(
  area.get('label')).divide(1e6).round()
print('área florestada em m2',treeAreaSqKm)

        
an example is the Chapada do Araripe protection area.



        
Lindemberg Vidal

PhD student | People Analytics | HRIS | Business Intelligence | Data Quality

1 年

Have you ever tried to use GEE queries through Python?

要查看或添加评论,请登录

Lucas Barreira的更多文章

社区洞察

其他会员也浏览了