---
title: "I need help scripting in Google Earth Engine"
url: "https://openforis.support/questions/487/i-need-help-scripting-in-google-earth-engine"
tags: ["earth", "collectearth"]
status: "accepted"
score: 0
answer_count: 1
asked: "2016-02-29T21:46:06"
last_activity: "2016-03-01T10:52:30"
source: "Open Foris Support - Q&A Forum"
license: "Copyright Open Foris, 2026. Some rights reserved under creative commons license."
---

# I need help scripting in Google Earth Engine

Asked by Nahas on 2016-02-29

**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!**


## Accepted answer (score 0, by Open Foris on 2016-03-01)

Link: https://openforis.support/questions/487/i-need-help-scripting-in-google-earth-engine/488

Dear Nahas,

For this kind of questions on Google Earth Engine you will probably find better feedback on the [Google Earth Engine support forum][1] 

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][2]

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][3]

Anyway, for this you will get better answers from the GEE support forum!


  [1]: https://groups.google.com/forum/#!forum/google-earth-engine-developers
  [2]: https://code.earthengine.google.com/ce4d422726ac088734d8b578a2eff436
  [3]: https://code.earthengine.google.com/2d5dd98c6d607bde2ddecd8c59e2b8e2
