1.关于查看空间上覆盖研究区的影像有多少张(非时间尺度)
var tiles = ee.ImageCollection("COPERNICUS/S2")
.filterBounds(region) //研究区范围
.filterDate('2017-01-01', '2017-12-01')
.distinct("MGRS_TILE")
.size()
print(tiles)
2.黑色风底图
var style = require('users/gena/packages:style')
style.SetMapStyleDark()
效果图:

3.通过时间戳选择精确时间的影像
var times = [
1412296596534,
1412296660684,
1412296720683,
1412308443226,
]
var filtered = ee.ImageCollection('COPERNICUS/S1_GRD')
.filter(ee.Filter.inList('system:time_start', times))
print(filtered)
4.选择离给定一系列时间范围最近影像
/***
* Filter collection by times, given max time diference
*/
function filterByTimes(collection, times, maxDiferenceSeconds) {
var features = times.map(function(t) {
return ee.Feature(null)
.set('system:time_start', ee.Date(t).millis()) //z这里.millis()为生成时间戳
})
// Define a max difference filter to compare timestamps.
var filter = ee.Filter.maxDifference({ //检查是否在允许的时间容差范围内
difference: maxDiferenceSeconds * 1000,
leftField: 'system:time_start',
rightField: 'system:time_start'
});
// Define the join. //通过maxDifference(filter对象)来创建join对象,给满足要求的匹配结果附加‘match’字段
var join = ee.Join.saveBest({ matchKey: 'match', measureKey: 'difference' });
// Apply the join. //执行join操作
var result = join.apply(features, collection, filter);
return ee.ImageCollection.fromImages(result.aggregate_array('match')) //统计并选择'match'字段的图像列表
}
// test
var filtered = filterByTimes(images, dates, 60)
print(filtered)
5.矢量缓冲区(两侧不同的缓冲距离)
var buffer2 = function(f, size1, size2) {
var buffer1 = f.buffer(size1) //buffer 1
var buffer2 = f.buffer(size2) //buffer 2
//define a box
var boxCoordinates = size1 > size2 ? ee.List(ee.List(buffer1.bounds().coordinates()).get(0)) : ee.List(ee.List(buffer2.bounds().coordinates()).get(0))
var srcCoordinates = ee.List(f.coordinates())
var leftAoi = ee.Geometry.Polygon(srcCoordinates.add(boxCoordinates.get(1))
.add(boxCoordinates.get(0))
.add(boxCoordinates.get(3))
.add(srcCoordinates.get(0)))
var rightAoi = ee.Geometry.Polygon(srcCoordinates.add(boxCoordinates.get(1))
.add(boxCoordinates.get(2))
.add(boxCoordinates.get(3))
.add(srcCoordinates.get(0)))
var a = buffer1.intersection(leftAoi)
var b = buffer2.intersection(rightAoi)
return a.union(b).dissolve(15)
}
Map.addLayer(buffer2(geometry, 10*1000, 15*1000));
6.一些色带代码整理
6.1 NDVI

var palette = [
'FFFFFF', 'CE7E45', 'DF923D', 'F1B555', 'FCD163', '99B718',
'74A901', '66A000', '529400', '3E8601', '207401', '056201',
'004C00', '023B01', '012E01', '011D01', '011301'];