本文主要是介绍GEE APP:利用夜间灯光数据建立一个简易的逐年影像查看器,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
简介
很多时候我们可以通过简单的滑块进行逐年影像的查看,slider这个工具可以进行每一年的夜间灯光数据的查看,这里主需要设定其实和后续的年份,另外,并给每一年进行属性设定对应的影像即可。这里最关键的就是一个返回值函数的设定,也就是滑块中的onchange函数的设定,这里我们首先要初始化地图界面,然后设定每一年份的属性。
函数
ee.Date.fromYMD(year, month, day, timeZone)
Returns a Date given year, month, day.
Arguments:
year (Integer):
The year, 2013, for example.
month (Integer):
The month, 3, for example.
day (Integer):
The day, 15, for example.
timeZone (String, default: null):
The time zone (e.g., 'America/Los_Angeles'); defaults to UTC.
Returns: Date
ee.DateRange(start, end, timeZone)
Creates a DateRange with the given start (inclusive) and end (exclusive), which may be Dates, numbers (interpreted as milliseconds since 1970-01-01T00:00:00Z), or strings (such as '1996-01-01T08:00'). If 'end' is not specified, a 1-millisecond range starting at 'start' is created.
创建具有给定开始(包括)和结束(不包括)的Date Range,这些开始可能是日期、数字(解释为自1970-01- 01 T00:00 Z以来的毫秒)或字符串(例如“1996-01- 01 T08:00”)。如果未指定“end”,则会创建从“start”开始的1毫秒范围。
Arguments:
start (Object)
end (Object, default: null)
timeZone (String, default: null):
If start and/or end are provided as strings, the time zone in which to interpret them; defaults to UTC.
Returns: DateRange
ui.Slider(min, max, value, step, onChange, direction, disabled, style)
A draggable target that ranges linearly between two numeric values. The value of the slider is displayed as a label alongside it.
Arguments:
min (Number, optional):
The minimum value. Defaults to 0.
max (Number, optional):
The maximum value. Defaults to 1.
value (Number, optional):
The initial value. Defaults to 0.
step (Number, optional):
The step size for the slider. Defaults to 0.01.
onChange (Function, optional):
A callback to fire when the slider's state changes. The callback is passed the slider's current value and the slider widget.
direction (String, optional):
The direction of the slider. One of
'horizontal' or 'vertical'. Defaults to 'horizontal'.
disabled (Boolean, optional):
Whether the slider is disabled. Defaults to false.
style (Object, optional):
An object of allowed CSS styles with their values to be set for this widget. See style() documentation.
Returns: ui.Slider
代码
/*
收藏幻灯片
通过使用滑动块选择显示层来可视化集合中的更改
*/var roi = /* color: #d63000 *//* displayProperties: [{"type": "rectangle"}] */ee.Geometry.Polygon([[[30.077489497329147, -28.41003324023103],[30.077489497329147, -28.718802987087276],[30.635045649672897, -28.718802987087276],[30.635045649672897, -28.41003324023103]]], null, false);// 从带有silder的收藏中选择图像。 var collection = ee.ImageCollection('NOAA/DMSP-OLS/NIGHTTIME_LIGHTS').select('stable_lights')// 一个帮助器函数,用于在默认地图上显示给定年份的图像。
var showLayer = function(year) {Map.layers().reset();var date = ee.Date.fromYMD(year, 1, 1);var dateRange = ee.DateRange(date, date.advance(1, 'year'));var image = collection.filterDate(dateRange).first();Map.addLayer({eeObject: ee.Image(image),visParams: {min: 0,max: 63,palette:['000000', 'FFFF00', 'FFA500', 'FF4500', 'FF0000']},name: String(year)});
};// 创建标签和属性
var label = ui.Label('Light Intensity for Year');
var slider = ui.Slider({min: 1992,max: 2014,step: 1,onChange: showLayer,style: {stretch: 'horizontal'}
});// 创建一个包含滑动块和标签的面板。
var panel = ui.Panel({widgets: [label, slider],layout: ui.Panel.Layout.flow('vertical'),style: {position: 'top-center',padding: '7px'}
});// 添加面板
Map.add(panel);// 设定默认的滑块和年份设定地图中心店
slider.setValue(2007);
Map.setCenter(30, 45, 4);
结果
这篇关于GEE APP:利用夜间灯光数据建立一个简易的逐年影像查看器的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!