1.Importing Table Data:https://developers.google.com/earth-engine/guides/table_upload
需要注意在导入shp文件时,需要将包含.shp, .dbf, .shx, .prj四个文件压缩成zip文件再导入。
当导入的shp文件含有多个polygon,可以利用fiterMetadata函数筛选出某个polygon。
之前使用的ee.Filter.eq(), ee.Filter.gte(),这些函数现在不能使用了。
var shp1 = table.filterMetadata('ID','equals','1')// filter ID = 1 polygon
2.矢量数据裁剪影像
(1)裁剪影像集
先定义一个对单幅影像裁剪的函数,后对数据集运用这个函数。
//shp
var tp = ee.FeatureCollection(table)
// show jrc monthly history dataset
var dataset = ee.ImageCollection('JRC/GSW1_3/MonthlyHistory')
.filterDate('2010-01-01','2020-12-31')
.filterBounds(tp);
//use shp file to clip the jrc dataset
//define clip function to clip a image
function clipImg(image){
return image.clipToCollection(tp);
}
var clipCol=dataset.map(clipImg);
var visParams={
bands: ['water'],
min: 0.0,
max: 2.0,
palette: ['ffffff', 'fffcb8', '0905ff']
};
print(clipCol);
Map.addLayer(clipCol,visParams,"clip ImgCol");
(2)裁剪单幅影像
利用矢量数据裁剪单幅影像就比较简单,直接利用裁剪函数:clipToCollection
var clip=data.clipToCollection(shp_file);