I'm new to scripting so I need some help.
So I used the following script:
var geometry : Polygon, 15 vertices
// define the var
var Catchment = /* color: 98ff00 */geometry;
var landcover = ee.Image('*LINK TO A LAND COVER IMAGE*').select('b1');
// Clip the image to the polygon geometry and add it to the map
var landcover_clip = landcover.clip(Catchment);
var sld_intervals =
'< RasterSymbolizer>' +
'< ColorMap type="intervals" extended="false" >' +
'< ColorMapEntry color="#FFFF00" quantity="1" label="Agriculture"/>' +
'< ColorMapEntry color="#00FF00" quantity="2" label="Grassland and Shrubland"/>' +
'< ColorMapEntry color="#008000" quantity="3" label="Forest"/>' +
'< ColorMapEntry color="#00FFFF" quantity="4" label="Flooded"/>' +
'< ColorMapEntry color="#FF00FF" quantity="5" label="Urban areas"/>' +
'< ColorMapEntry color="#808080" quantity="6" label="Bare areas"/>' +
'< ColorMapEntry color="#0000FF" quantity="7" label="Water"/>' +
'< ColorMapEntry color="#FFFFFF" quantity="8" label="Permanent snow and ice"/>' +
'< /ColorMap>' +
'< /RasterSymbolizer>';
Map.addLayer(landcover_clip.sldStyle(sld_intervals), {}, 'IGBP classification styled');
// Print out the frequency of landcover occurrence for the polygon.
var frequency = landcover.reduceRegion({
reducer:ee.Reducer.frequencyHistogram(),
geometry:Catchment,
scale:300
});
print('landcover frequency', frequency.get('b1'));
To get the following console output:
1: 13401
2: 58801
3: 338570
4: 1141
5: 1120
6: 81
7: 35860
So my question is : How can I have a percentage instead of a frequency? or in other words : *Is there a percentage equivalent to ee.Reducer.frequencyHistogram() ?*
And while we're at it, I have another question : *How can I change the labels in the legend to have "Agriculture", "Grass and Shrubland", "Forest", "Flooded", "Urban areas", "Bare areas", "Water", and "Permanent snow and ice" instead of "1", "2", "3", "4", "5", "6", "7", and "8"?*
Thank you very much!