1. 需要遮掉fc以外的地方。
varmask = ee.Image.constant(1).clip(fc.geometry()).mask().not()

2. difference 相当于arcgis pro的erase擦除功能,但是geometry collection和geometry
参考 https://gis.stackexchange.com/questions/300725/difference-between-two-polygons-in-earth-engine

3. Mask 用法 掩膜
ee.image.mask
updatemask
unmask
4. 矢量转栅格
ImageCollection.reduceToImage(properties, reducer)
示例: //将矢量转为栅格,选择属性‘value’的平均值作为像元值 reduction reaction
var image_reduced=fc.reduceToImage(['value'],'mean');
示例:
var seamask = sea.reduceToImage({properties: ['rec'], reducer: ee.Reducer.first()});
5. Reduce
参考:https://geohackweek.github.io/GoogleEarthEngine/04-reducers/
reducer“还原剂”,reduce减少的意思,还原反应: reduction reaction
Temporal Reducer: Get Image Statistics Over Time 时间上的reduce,可以用sum等算法

6. 展示imagecollection内所有图像的YMD

function ymdList(imgcol){
var iter_func = function(image, newlist){
var date = ee.Number.parse(image.date().format("YYYYMMdd"));
newlist = ee.List(newlist);
return ee.List(newlist.add(date).sort())
};
return imgcol.iterate(iter_func, ee.List([]));
}
var ymd = ymdList(collection)
print(ee.List(ymd).reduce(ee.Reducer.frequencyHistogram()))
7. colorramp如何分段赋颜色
(参考https://gis.stackexchange.com/questions/304141/setting-values-for-palette-in-google-earth-engine)

varsetPalletes =function(image){
image = image.select('NDVI');
varimage02 = image.gte(0.2);
varimage04 = image.gte(0.4);
varimage06 = image.gte(0.6);
varimage08 = image.gte(0.8);
returnimage02.add(image04).add(image06).add(image08);
};
varnewImages = series.map(setPalletes);
Map.addLayer(newImages.first(), {bands: ['NDVI'],min:0,max:4,palette: ['black','red','orange','yellow','green']},'first');
代码示例:https://code.earthengine.google.com/05d07373354e0de70684dc7dbb4efab6
附:CSS3.0 colorhttps://www.w3.org/TR/2018/REC-css-color-3-20180619/
8. JavaScript 的函数虽然不能返回多个值,但是可以凑成一个数组再返回。
function create(year){
return [year,year+1,year+2]
}
var x = create(yrd);
a = x[0];
b = x[1];
c = x[2];

9. 如何提取image的boundaries(暂未解决,谁有好方法欢迎留言)
现在image的 边界可以通过var tmpImgPol = tmpImg.get('system:footprint'); 获取footprint属性得到一个geometry属性的变量,但是这个变量不能获得geometry的任何方法,比较了一下,图中上面的polygon是手动构建的,下面的是读取footprint获取的,两个polygon还是有一些不一样的。
不然可以通过coordinates的方法获取
var tmpImgPol = ee.Geometry.Polygon(tmpImg.get('system:footprint'));

当然也可以通过reduceToVectors的方法,但是需要图像是integeral的,所以要做几步处理。
网友评论