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({
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!

asked 29 Feb '16, 21:46

Nahas's gravatar image

accept rate: 0%

Dear Nahas,

For this kind of questions on Google Earth Engine you will probably find better feedback on the Google Earth Engine support forum

From the top of my head maybe it is better that you present the information using a histogram chart, something like this :

Slope on a plot

Or even how the percentage of days a plot has an NDVI over a threshold is shown in our standard GEE script :

Standard Collect Earth GEE script

Anyway, for this you will get better answers from the GEE support forum!

permanent link

answered 01 Mar '16, 10:52

Open%20Foris's gravatar image

Open Foris ♦♦
accept rate: 6%

Your answer
toggle preview

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here



Answers and Comments

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text](http://url.com/ "title")
  • image?![alt text](/path/img.jpg "title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported

Question tags:


question asked: 29 Feb '16, 21:46

question was seen: 4,676 times

last updated: 01 Mar '16, 10:52