Untitled
unknown
plain_text
2 years ago
3.0 kB
4
Indexable
const list = ee.List(['Ia', 'Ib', 'II', 'III', 'IV', 'V', 'VI', 'Not Reported', 'Not Applicable', 'Not Assigned', 'World Heritage Site (natural or mixed)', 'Ramsar Site, Wetland of International Importance']); let featureCollection = ee.FeatureCollection(imageCollectionName).filterBounds(geometry).map(function (feature) { var heritageIndex = list.indexOf(feature.get('DESIG_ENG')); var mappedFeature = ee.Algorithms.If(heritageIndex.eq(ee.Number(10)), feature.set('IUCN_NUM', ee.Number(10)), ee.Algorithms.If(heritageIndex.eq(ee.Number(11)), feature.set('IUCN_NUM', ee.Number(11)), feature.set('IUCN_NUM', ee.Number(list.indexOf(feature.get('IUCN_CAT')))))); return mappedFeature; }); const calculateArea = function (feature, first) { let area = feature.geometry().intersection(geometry, ee.ErrorMargin(1)).area(ee.ErrorMargin(1)).divide(1000 * 1000); return ee.Number(first).add(area); } const calculateUnion = function (feature, first) { return feature.geometry().intersection(geometry, ee.ErrorMargin(1)).union(first, ee.ErrorMargin(1)); } let areaList = []; for (let i = 0; i <= 11; i++) { let collection = featureCollection.filter(ee.Filter.eq('IUCN_NUM', i)); let area = collection.iterate(calculateArea, ee.Number(0)); areaList.push({ "value": area.getInfo(), "category": i }); } // since protected areas of different types partially overlap, we calculate union of all geometries and then the area of the union which then gives the total protected area. const unionGeometry = featureCollection.iterate(calculateUnion, featureCollection.first().geometry().intersection(geometry, ee.ErrorMargin(1))); const area = ee.Geometry(unionGeometry).area(ee.ErrorMargin(1)).divide(1000 * 1000); areaList.push({ "value": area.getInfo(), "category": 'totalProtectedArea' }); areaList.push({ "value": geometry.area(ee.ErrorMargin(1)).divide(1000 * 1000).getInfo(), "category": 'totalArea' }); const collect = function (feature, first) { let dict = ee.Dictionary({ "ORIG_NAME": feature.get('ORIG_NAME'), "DESIG": feature.get('DESIG'), "DESIG_ENG": feature.get('DESIG_ENG'), "DESIG_TYPE": feature.get('DESIG_TYPE'), "IUCN_CAT": feature.get('IUCN_CAT'), "GOV_TYPE": feature.get('GOV_TYPE'), "MANG_AUTH": feature.get('MANG_AUTH'), "MANG_PLAN": feature.get('MANG_PLAN'), "OWN_TYPE": feature.get('OWN_TYPE'), "STATUS": feature.get('STATUS'), "STATUS_YR": feature.get('STATUS_YR'), "REP_AREA": feature.get('REP_AREA'), "feature": feature }); return ee.List(first).add(dict); } const areas = featureCollection.iterate(collect, ee.List([])); // TODO: result is in { statistics: areaList, info: areas }
Editor is loading...