TransWikia.com

Area Calculation doesn't work after reprojecting the Vector

Geographic Information Systems Asked by Simgis on August 1, 2021

I’m trying to change the projection of resolve ecoregions data to EPSG:32648.
Unfortunately, when I changed the projection, the command line for calculating the area doesn’t work.

Here is my code :

//** Center on the Region of Interest
Map.centerObject (roi,10);

//** Import Ecoregion
var ecoRegions_raw = ee.FeatureCollection("RESOLVE/ECOREGIONS/2017")
                .filterBounds(roi)

var filtered = ee.Filter (ee.Filter.noNull())
                
print ('--Dataset properties--',ecoRegions_raw);

//** Reproject dataset into EPSG:32648
var projection = 'EPSG:32648';

//** Apply Reprojection and transformation
var transformer = function(a_feature) {
  var transformed_feature = a_feature.transform(projection, 0.001);
  return transformed_feature;
};

var ecoRegions = ecoRegions_raw.map(transformer);

print(ecoRegions);

//** Set up color
var colorUpdates = [
                  {ECO_ID: 204, COLOR: '#B3493B'},
                  {ECO_ID: 245, COLOR: '#267400'},
                  {ECO_ID: 259, COLOR: '#004600'},
                  {ECO_ID: 286, COLOR: '#82F178'},
                  {ECO_ID: 316, COLOR: '#E600AA'},
                  {ECO_ID: 453, COLOR: '#5AA500'},
                  {ECO_ID: 317, COLOR: '#FDA87F'},
                  {ECO_ID: 763, COLOR: '#A93800'},
                  ];

//** loop over all other features and create a new style property for styling
//** later on
var ecoRegions = ecoRegions.map(function(f) {
  var color = f.get('COLOR');
  return f.set({style: {color: color, width: 0}});
});

//** make styled features for the regions we need to update colors for,
//** then strip them from the main asset and merge in the new feature
for (var i=0; i < colorUpdates.length; i++) {
  colorUpdates[i].layer = ecoRegions
      .filterMetadata('ECO_ID','equals',colorUpdates[i].ECO_ID)
      .map(function(f) {
        return f.set({style: {color: colorUpdates[i].COLOR, width: 0}});
      });

  ecoRegions = ecoRegions
      .filterMetadata('ECO_ID','not_equals',colorUpdates[i].ECO_ID)
      .merge(colorUpdates[i].layer);
}

//** Use style property to color shapes
var imageRGB = ecoRegions.style({styleProperty: 'style'});

//** Visualize the Ecoregion dataset
Map.addLayer(imageRGB, {}, 'RESOLVE/ECOREGIONS/2017');

//** Calculating area for each feature using function
var withArea = ecoRegions.map(function(f) {
  var clipped = f.geometry().intersection(roi)
  return f
    .set('Feature_Area_ha', f.area().divide(10000))
    .set('ROI_Area_ha', clipped.area().divide(10000))
})
print ('--Resolve Ecoregion 2017 by AOI--',withArea)

//** Extract ECO_NAME and set as property
//** within for each Feature collection
var Collection = withArea.map(function(feature) {
    var feature_id = feature.id();
    var eco_name = feature_id;
    return feature.set('id',eco_name);
});//end of map function

print(Collection)

//** Create List
//** The list of keys cannot contain duplicates so this is using 
var biome_names = ee.List(Collection.aggregate_array('BIOME_NAME'));
var area = ee.List(Collection.aggregate_array('ROI_Area_ha'));
var out_dict = ee.Dictionary.fromLists(biome_names,area);
print('--Area (Ha) by Biome Name--', out_dict);

Do you know why area calculation doesn’t work after reprojecting the vector?

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP