Open Google Earth Engine(OEEL)——oeel.plotly.plot绘制MODIS影像中土地分类的变化情况

简介: Open Google Earth Engine(OEEL)——oeel.plotly.plot绘制MODIS影像中土地分类的变化情况

利用OEEL中函数来绘制土地利用变化情况。

oeel.Element.addTimeProperties(...)

oeel.Element.addTimeProperties(sinceEpoch, timeVariable, timeZone, image, feature, collection)

addTimeProperties. Simply add some time metric (day, month, year ...) derived from system:time_start

Arguments:

  • sinceEpoch* booleandefine each property locally or the absolute cumulated since epoch (01.01.1970)
  • timeVariable* string|object Default:start.The name of the variable to use. ‘start’, ‘end’, or ‘both’ are using the system time any other name can be used too.
  • timeZone* string Default:UTC.The time zone.
  • image ee.ImageThe image on which to add the time properties.
  • feature ee.FeatureThe feature on which to add the time properties.
  • collection ee.CollectionThe collection on which to add the time properties

Return:

  • Returnfunction|ee.Image|ee.Feature|ee.Collection

Examples:

oeel.plotly.plot(...)

oeel.plotly.plot()

plot. Create a empty plot object to get Plotly plots

Arguments:

Return:

函数:

ee.Filter.inList(leftField, rightValue, rightField, leftValue)

Filter on metadata contained in a list.

Returns the constructed filter.

Arguments:

leftField (String, optional):

A selector for the left operand. Should not be specified if leftValue is specified.

rightValue (List<Object>|Object, optional):

The value of the right operand. Should not be specified if rightField is specified.

rightField (String, optional):

A selector for the right operand. Should not be specified if rightValue is specified.

leftValue (List<Object>|Object, optional):

The value of the left operand. Should not be specified if leftField is specified.

Returns: Filter

ee.Array(values, pixelType)

Returns an array with the given coordinates.

Arguments:

values (Object):

An existing array to cast, or a number/list of numbers/nested list of numbers of any depth to create an array from. For nested lists, all inner arrays at the same depth must have the same length, and numbers may only be present at the deepest level.

pixelType (PixelType, default: null):

The type of each number in the values argument. If the pixel type is not provided, it will be inferred from the numbers in 'values'. If there aren't any numbers in 'values', this type must be provided.

Returns: Array

reshape(shape)

Reshapes an array to a new list of dimension lengths.

Arguments:

this:array (Array):

Array to reshape.

shape (Array):

New shape to which arrays are converted. If one component of the shape is the special value -1, the size of that dimension is computed so that the total size remains constant. In particular, a shape of [-1] flattens into 1-D. At most one component of shape can be -1.

Returns: Array

ee.List.repeat(value, count)

Returns a new list containing value repeated count times.

Arguments:

value (Object)

count (Integer)

Returns: List

ee.Dictionary.fromLists(keys, values)

Construct a dictionary from two parallel lists of keys and values.

Arguments:

keys (List)

values (List)

Returns: Dictionary

代码:

var geometry = /* color: #d63000 */ee.Geometry.Polygon(
        [[[-60.270601562500005, -1.4604924790211367],
          [-60.270601562500005, -9.264255286247176],
          [-50.338960937500005, -9.264255286247176],
          [-50.338960937500005, -1.4604924790211367]]], null, false);
Map.setOptions('SATELLITE')
var oeel=require('users/OEEL/lib:loadAll')
var color= ['000000',
  '05450a', '086a10', '54a708', '78d203', '009900', 'c6b044', 'dcd159',
  'dade48', 'fbff13', 'b6ff05', '27ff87', 'c24f44', 'a5a5a5', 'ff6d4c',
  '69fff8', 'f9ffa4', '1c0dff'
];
var igbpLandCover = ee.ImageCollection('MODIS/006/MCD12Q1').select("LC_Type1").map(oeel.Element.addTimeProperties());
var igbpLandCoverVis = {
  min: 0.0,
  max: 17.0,
  palette:color,
};
  
  
function getPlot(igbpLandCover,step, geometry){
  igbpLandCover=ee.ImageCollection(igbpLandCover).filter(ee.Filter.inList("oeel:start_year", ee.List.sequence(2000,2021,step)));
  
  var size=igbpLandCover.size();
  var scale=500;
  
  var NoC=17;
  
  var reducer=ee.Reducer.fixed2DHistogram({
    xMin:1,
    xMax:NoC+1,
    xSteps:NoC,
    yMin:1,
    yMax:NoC+1,
    ySteps:NoC,
  });
  
  function hist2DtoList(data,index,numberClass){
    return ee.Array.cat([
      ee.Array(data.get('histogram')),
      ee.Array(data.get('xBuckets')).add(index.multiply(numberClass)).reshape([1,-1]).repeat(0,ee.Array(data.get('yBuckets')).toList().size()),
      ee.Array(data.get('yBuckets')).add(index.add(1).multiply(numberClass)).repeat(1,ee.Array(data.get('xBuckets')).toList().size()),
      ],
      2).reshape([-1,3]);
  }
  
  
  var data=ee.List.sequence(0,size.subtract(2),1).map(function(index){
    index=ee.Number(index);
    return hist2DtoList(ee.Dictionary(igbpLandCover.toBands().select([index,index.add(1)]).reduceRegion(reducer,geometry,scale)),
    index,NoC+1);
  });
  
  data=ee.Array.cat(data,0).transpose();
  
  data=ee.Array.cat([data,data.slice(0,0,1).sqrt()],0);
  data=data.toList();
  
  var colors=ee.List.repeat(color,size).flatten();
  var labels=ee.List.repeat(igbpLandCover.aggregate_array("oeel:start_year"),NoC+1).unzip().flatten();
  
  var col=igbpLandCover.toList(size);
  
  // genration of custom plot
  return {
    type: "sankey",
    orientation: "h",
    node: {
      pad: 10,
      thickness: 25,
      line: {
        color: "black",
        width: 0.1
      },
     label: labels,
     color: colors
        },
  
    link:ee.Dictionary.fromLists(["label","source", "target","value"], data)
  };
}
var plot=oeel.plotly.plot();
// add custom plot
plot.addCustom(getPlot(igbpLandCover,1,geometry))
plot.layout.autosize=true;
Map.centerObject(geometry, 6);
//empty layer, to be used in onclick
var sourceMap=Map.addLayer(ee.Image(), igbpLandCoverVis, 'IGBP Land Cover source');
var destMap=Map.addLayer(ee.Image(), igbpLandCoverVis, 'IGBP Land Cover dest');
var maskMap=Map.addLayer(ee.Image(), {opacity:0.8}, 'mask');
// on click on the plot
plot.on('click',function(event){
  var srcImage=igbpLandCover.filter(ee.Filter.eq('oeel:start_year',event.points[0].source.label)).first();
  var dstImage=igbpLandCover.filter(ee.Filter.eq('oeel:start_year',event.points[0].target.label)).first();
  var srcMak=srcImage.eq(color.indexOf(event.points[0].source.color));
  var destMak=dstImage.eq(color.indexOf(event.points[0].target.color));
  var mask=srcMak.and(destMak)
  sourceMap.setEeObject(srcImage.updateMask(srcMak))
  destMap.setEeObject(dstImage.updateMask(destMak))
  maskMap.setEeObject(ee.ImageCollection([ee.Image.constant(0).eq(0),mask.eq(0)]).select([0],['mask']).mosaic().selfMask().not())
})
ui.root.insert(0,plot.widget({stretch:'horizontal',margin:0}))
ui.root.setLayout(ui.Panel.Layout.flow('vertical'))
var step=1;
// add a slider 
Map.add(ui.Slider({
min:1,
max:5,
value:1,
step:1,
  onChange:function(val){
    step=val;
    plot.data=[getPlot(igbpLandCover,step,Map.drawingTools().toFeatureCollection('id').geometry(1000))];
    plot.update()
  },
  direction:'vertical',
  style:{position:'middle-right'},
}))
// get geoemtry change
Map.drawingTools().onEdit(ui.util.throttle(function(){
  plot.data=[getPlot(igbpLandCover,step,Map.drawingTools().toFeatureCollection('id').geometry(1000))];
  plot.update()
},1000))
// print all OEEL function used
print('list of functions used',oeel.refs());

 

相关文章
|
3月前
|
数据可视化 定位技术 Sentinel
如何用Google Earth Engine快速、大量下载遥感影像数据?
【2月更文挑战第9天】本文介绍在谷歌地球引擎(Google Earth Engine,GEE)中,批量下载指定时间范围、空间范围的遥感影像数据(包括Landsat、Sentinel等)的方法~
544 0
如何用Google Earth Engine快速、大量下载遥感影像数据?
|
3月前
|
机器学习/深度学习 算法 数据可视化
基于Google Earth Engine云平台构建的多源遥感数据森林地上生物量AGB估算模型含生物量模型应用APP
基于Google Earth Engine云平台构建的多源遥感数据森林地上生物量AGB估算模型含生物量模型应用APP
106 0
|
2月前
|
存储 编解码 数据可视化
Google Earth Engine获取随机抽样点并均匀分布在栅格的不同数值区中
【2月更文挑战第14天】本文介绍在谷歌地球引擎(Google Earth Engine,GEE)中,按照给定的地表分类数据,对每一种不同的地物类型,分别加以全球范围内随机抽样点自动批量选取的方法~
260 0
Google Earth Engine获取随机抽样点并均匀分布在栅格的不同数值区中
|
3月前
|
编解码 人工智能 算法
Google Earth Engine——促进森林温室气体报告的全球时间序列数据集
Google Earth Engine——促进森林温室气体报告的全球时间序列数据集
26 0
|
3月前
|
编解码 人工智能 数据库
Google Earth Engine(GEE)——全球道路盘查项目全球道路数据库
Google Earth Engine(GEE)——全球道路盘查项目全球道路数据库
45 0
|
3月前
|
编解码
Open Google Earth Engine(OEEL)——matrixUnit(...)中产生常量影像
Open Google Earth Engine(OEEL)——matrixUnit(...)中产生常量影像
21 0
|
3月前
Google Earth Engine(GEE)——导出指定区域的河流和流域范围
Google Earth Engine(GEE)——导出指定区域的河流和流域范围
45 0
|
3月前
|
传感器 编解码 数据处理
Open Google Earth Engine(OEEL)——哨兵1号数据的黑边去除功能附链接和代码
Open Google Earth Engine(OEEL)——哨兵1号数据的黑边去除功能附链接和代码
23 0
|
3月前
Google Earth Engine(GEE)——当加载图表的时候出现错误No features contain non-null values of “system:time_start“.
Google Earth Engine(GEE)——当加载图表的时候出现错误No features contain non-null values of “system:time_start“.
43 0
|
3月前
|
编解码 定位技术
Google Earth Engine(GEE)——导出后的影像像素不同于原始Landsat影像的分辨率(投影差异)
Google Earth Engine(GEE)——导出后的影像像素不同于原始Landsat影像的分辨率(投影差异)
24 0

热门文章

最新文章