0

我在GIS StackExchange上问过这个问题,但到目前为止还没有运气。我想也许它属于这里。

我使用了以下脚本:

// define the var
var Catchment = /* color: 98ff00 */geometry;
var landcover = ee.Image('users/roynahas/ESACCI-LC-L4-LCCS-Map-300m-P5Y-2010-v161_RECLASS').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'));

在此处输入图像描述

要获得以下控制台输出:

在此处输入图像描述

所以我的问题是:我怎样才能有一个百分比而不是一个频率?或者换句话说:是否有相当于 ee.Reducer.frequencyHistogram() 的百分比?

4

1 回答 1

1

我在另一个论坛上得到了答案。这里是:

// Import variables
var globcover = ee.Image("ESA/GLOBCOVER_L4_200901_200912_V2_3"),
    geometry = /* color: d63000 */ee.Geometry.Polygon(
        [[[-71.466064453125, 48.763431137917955],
          [-71.378173828125, 48.89000369970676],
          [-72.674560546875, 49.38952445158216],
          [-73.179931640625, 49.106241774469055],
          [-73.575439453125, 48.27588152743497],
          [-72.83935546875, 48.10743118848039],
          [-71.4935302734375, 48.17341248658084],
          [-71.455078125, 48.56024979174331],
          [-71.5374755859375, 48.68370757165362]]]);
// Extract the landcover band
var landcover = globcover.select('landcover');
// Clip the image to the polygon geometry
var landcover_roi = landcover.clip(geometry);
// Add a map layer of the landcover clipped to the polygon.
Map.addLayer(landcover_roi);
// Print out the frequency of landcover occurrence for the polygon.
var frequency = landcover.reduceRegion({
  reducer:ee.Reducer.frequencyHistogram(),
  geometry:geometry,
  scale:1000
});
var dict = ee.Dictionary(frequency.get('landcover'));
var sum = ee.Array(dict.values()).reduce(ee.Reducer.sum(),[0]).get([0]);
var new_dict = dict.map(function(k,v) {
  return ee.Number(v).divide(sum).multiply(100);
});
print('Land Cover (%)',new_dict);

当然,输入(土地覆盖图像和多边形层)可以不同。

于 2016-03-08T17:39:01.267 回答