在 GEE 中屏蔽具有不同分辨率的数据集
Masking datasets with different resolutions in GEE
我根据 MCD43A4(空间分辨率 500m)collection 计算了存在各种水体的区域的 NDMI 指数。
我想做的是根据 Landsat Global Inland Water 数据集(空间分辨率 30m)从我的 collection 中屏蔽掉这些水体,
但我不知道该怎么做。
我必须做的第一件事是改变 Landsat 的空间分辨率,以便与 MODIS 相匹配,但我不明白
怎么办,我应该使用一种 Reduce 吗?
谢谢
var geometry = /* color: #d63000 */ee.Geometry.Polygon(
[[[69.75758392503599, 50.151303763817786],
[71.60328705003599, 40.18192251959151],
[93.70777923753599, 41.54446477874571],
[91.86207611253599, 51.09912927236651]]]);
var dataset = ee.ImageCollection('GLCF/GLS_WATER')
.filterBounds(geometry)
.map(function(image){return image.clip(geometry)}) ;
var water = dataset.select('water');
var imageCollection = ee.ImageCollection("MODIS/006/MCD43A4")
.filterBounds(geometry)
.map(function(image){return image.clip(geometry)})
.filter(ee.Filter.calendarRange(6,8,'month'));
var modNDMI = imageCollection.select("Nadir_Reflectance_Band2","Nadir_Reflectance_Band6","BRDF_Albedo_Band_Mandatory_Quality_Band2","BRDF_Albedo_Band_Mandatory_Quality_Band6");
/////////////////////////////////////////////////
var quality = function(image){
var mask1 = image.select("BRDF_Albedo_Band_Mandatory_Quality_Band2").eq(0);
var mask2 = image.select("BRDF_Albedo_Band_Mandatory_Quality_Band6").eq(0);
return image.updateMask(mask1).updateMask(mask2);
};
var clean_collection = modNDMI.map(quality);
var addNDMI = function(image) {
var ndmi = image.normalizedDifference(['Nadir_Reflectance_Band2', 'Nadir_Reflectance_Band6']).rename('NDMI');
return image.addBands(ndmi);
};
var ndmi = clean_collection.map(addNDMI);
var NDMI=ndmi.select('NDMI')
print(water)
//And from this point, I have no idea how to mask the water bodies based on the
//Landsat collection
"mask the waterbodies," 的意思不是很明显,但如果这不是您想要的,那么只需使用 water_mask.not()
。
var gsw = ee.Image('JRC/GSW1_0/GlobalSurfaceWater');
var occurrence = gsw.select('occurrence');
// Create a water mask layer, and set the image mask so that non-water areas
// are opaque.
var water_mask = occurrence.gt(90).unmask(0);
Map.addLayer(water_mask)
var dataset = ee.ImageCollection('GLCF/GLS_WATER')
var water = dataset.select('water');
var imageCollection = ee.ImageCollection("MODIS/006/MCD43A4")
.filterDate('2017-01-01', '2018-12-31')
.filter(ee.Filter.calendarRange(6,8,'month'));
var modNDMI = imageCollection.select("Nadir_Reflectance_Band2","Nadir_Reflectance_Band6","BRDF_Albedo_Band_Mandatory_Quality_Band2","BRDF_Albedo_Band_Mandatory_Quality_Band6");
var quality = function(image){
var mask1 = image.select("BRDF_Albedo_Band_Mandatory_Quality_Band2").eq(0);
var mask2 = image.select("BRDF_Albedo_Band_Mandatory_Quality_Band6").eq(0);
return image.updateMask(mask1).updateMask(mask2);
};
var clean_collection = modNDMI.map(quality);
var addNDMI = function(image) {
var ndmi = image.normalizedDifference(['Nadir_Reflectance_Band2', 'Nadir_Reflectance_Band6']).rename('NDMI');
return image.addBands(ndmi).updateMask(water_mask);
};
var ndmi = clean_collection.map(addNDMI);
var NDMI=ndmi.select('NDMI')
Map.addLayer(NDMI)
另见 this tutorial。
我根据 MCD43A4(空间分辨率 500m)collection 计算了存在各种水体的区域的 NDMI 指数。 我想做的是根据 Landsat Global Inland Water 数据集(空间分辨率 30m)从我的 collection 中屏蔽掉这些水体, 但我不知道该怎么做。 我必须做的第一件事是改变 Landsat 的空间分辨率,以便与 MODIS 相匹配,但我不明白 怎么办,我应该使用一种 Reduce 吗?
谢谢
var geometry = /* color: #d63000 */ee.Geometry.Polygon(
[[[69.75758392503599, 50.151303763817786],
[71.60328705003599, 40.18192251959151],
[93.70777923753599, 41.54446477874571],
[91.86207611253599, 51.09912927236651]]]);
var dataset = ee.ImageCollection('GLCF/GLS_WATER')
.filterBounds(geometry)
.map(function(image){return image.clip(geometry)}) ;
var water = dataset.select('water');
var imageCollection = ee.ImageCollection("MODIS/006/MCD43A4")
.filterBounds(geometry)
.map(function(image){return image.clip(geometry)})
.filter(ee.Filter.calendarRange(6,8,'month'));
var modNDMI = imageCollection.select("Nadir_Reflectance_Band2","Nadir_Reflectance_Band6","BRDF_Albedo_Band_Mandatory_Quality_Band2","BRDF_Albedo_Band_Mandatory_Quality_Band6");
/////////////////////////////////////////////////
var quality = function(image){
var mask1 = image.select("BRDF_Albedo_Band_Mandatory_Quality_Band2").eq(0);
var mask2 = image.select("BRDF_Albedo_Band_Mandatory_Quality_Band6").eq(0);
return image.updateMask(mask1).updateMask(mask2);
};
var clean_collection = modNDMI.map(quality);
var addNDMI = function(image) {
var ndmi = image.normalizedDifference(['Nadir_Reflectance_Band2', 'Nadir_Reflectance_Band6']).rename('NDMI');
return image.addBands(ndmi);
};
var ndmi = clean_collection.map(addNDMI);
var NDMI=ndmi.select('NDMI')
print(water)
//And from this point, I have no idea how to mask the water bodies based on the
//Landsat collection
"mask the waterbodies," 的意思不是很明显,但如果这不是您想要的,那么只需使用 water_mask.not()
。
var gsw = ee.Image('JRC/GSW1_0/GlobalSurfaceWater');
var occurrence = gsw.select('occurrence');
// Create a water mask layer, and set the image mask so that non-water areas
// are opaque.
var water_mask = occurrence.gt(90).unmask(0);
Map.addLayer(water_mask)
var dataset = ee.ImageCollection('GLCF/GLS_WATER')
var water = dataset.select('water');
var imageCollection = ee.ImageCollection("MODIS/006/MCD43A4")
.filterDate('2017-01-01', '2018-12-31')
.filter(ee.Filter.calendarRange(6,8,'month'));
var modNDMI = imageCollection.select("Nadir_Reflectance_Band2","Nadir_Reflectance_Band6","BRDF_Albedo_Band_Mandatory_Quality_Band2","BRDF_Albedo_Band_Mandatory_Quality_Band6");
var quality = function(image){
var mask1 = image.select("BRDF_Albedo_Band_Mandatory_Quality_Band2").eq(0);
var mask2 = image.select("BRDF_Albedo_Band_Mandatory_Quality_Band6").eq(0);
return image.updateMask(mask1).updateMask(mask2);
};
var clean_collection = modNDMI.map(quality);
var addNDMI = function(image) {
var ndmi = image.normalizedDifference(['Nadir_Reflectance_Band2', 'Nadir_Reflectance_Band6']).rename('NDMI');
return image.addBands(ndmi).updateMask(water_mask);
};
var ndmi = clean_collection.map(addNDMI);
var NDMI=ndmi.select('NDMI')
Map.addLayer(NDMI)
另见 this tutorial。