在 Google Earth Engine 中,如何将一个图像集中的 select 像素对应于另一个图像集中的 selected 像素值?
In Google Earth Engine, How do I select pixels from one image collection which correspond to a selected pixel value from another image collection?
我想在名为 "table" 的几何区域内绘制 modis 燃烧面积产品的燃烧像素计数,仅用于农业像素(从 'lc' 图像收集中获得)。我在文档中找不到任何指示您可以在 2 个图像集合之间进行此类查询的内容。有人有什么建议吗?
我试过使用遮罩,但似乎这可能只适用于个人 ee.Image,不适用于不同的图像集。代码如下:
var modba = ee.ImageCollection('MODIS/006/MCD64A1').filterDate('2017-01-
01', '2017-12-31').select('BurnDate')
var modbaN = ee.ImageCollection('MODIS/006/MCD64A1').filterDate('2017-01-
01', '2017-12-31').select('Uncertainty')
var lc = ee.ImageCollection('MODIS/006/MCD12Q1').filterDate('2017-01-01',
'2017-12-31').select('LC_Type1')
var AgOnly = lc.map(function(img) {
var ag = img.select('LC_Type1');
return ag.eq(12);
//Would also like to maybe have 2 or 3 LC types to select here
});
var mask_ba = modba.map(function(img){
return img.updateMask(AgOnly);
});
var bats =
//ui.Chart.image.seriesByRegion(modba, table, ee.Reducer.count());
ui.Chart.image.seriesByRegion(mask_ba, table, ee.Reducer.count());
print(bats);
var unts =
ui.Chart.image.seriesByRegion(modbaN, table, ee.Reducer.mean());
print(unts);
据我了解,您要做的是用 modba
图像 collection 中的每张图像(有 12 张图像或每月一张)遮盖 [=] 中的相应图像12=] 图像 collection (全年只有 1 张图像)。这完全可行。
在您提供的代码中,您 updateMask
使用 AgOnly
(图像 collection),这是 GEE 不允许的。
您只需制作 AgOnly
图像,然后再将其用于 updateMask
。
试试这个:
var AgOnly = lc.map(function(img) {
var ag = img.select('LC_Type1');
return ag.eq(12);
//Would also like to maybe have 2 or 3 LC types to select here
}).max();
max()
方法会将您的图像 collection 转换为图像。如果愿意,您也可以使用 min()
或 mean()
,这都会给出相同的结果,因为 AgOnl
中只有一张图像。
它仍然适用于更广泛的日期范围和多种土地覆盖类型。
在那种情况下,只需保留计算 AgOnly
的旧代码,并修改计算 mask_ba
的代码如下:
var mask_ba = modba.map(function(img){
var img_year = img.date().format('YYYY');
var start_date = ee.Date(img_year.cat('-01-01'));
var end_date = start_day.advance(1, 'year');
var Agri_this_year = AgOnly.filterDate(start_date, end_date).max();
return img.updateMask(Agri_this_year);
});
基本上,上面的代码只是提取当前img
的年份,然后使用filterDate
方法从AgOnly
中select得到当年的土地覆盖类型图片合集,最后申请updateMask
.
同样的想法可以应用于其他土地覆盖类型。
希望对您有所帮助。
我想在名为 "table" 的几何区域内绘制 modis 燃烧面积产品的燃烧像素计数,仅用于农业像素(从 'lc' 图像收集中获得)。我在文档中找不到任何指示您可以在 2 个图像集合之间进行此类查询的内容。有人有什么建议吗?
我试过使用遮罩,但似乎这可能只适用于个人 ee.Image,不适用于不同的图像集。代码如下:
var modba = ee.ImageCollection('MODIS/006/MCD64A1').filterDate('2017-01-
01', '2017-12-31').select('BurnDate')
var modbaN = ee.ImageCollection('MODIS/006/MCD64A1').filterDate('2017-01-
01', '2017-12-31').select('Uncertainty')
var lc = ee.ImageCollection('MODIS/006/MCD12Q1').filterDate('2017-01-01',
'2017-12-31').select('LC_Type1')
var AgOnly = lc.map(function(img) {
var ag = img.select('LC_Type1');
return ag.eq(12);
//Would also like to maybe have 2 or 3 LC types to select here
});
var mask_ba = modba.map(function(img){
return img.updateMask(AgOnly);
});
var bats =
//ui.Chart.image.seriesByRegion(modba, table, ee.Reducer.count());
ui.Chart.image.seriesByRegion(mask_ba, table, ee.Reducer.count());
print(bats);
var unts =
ui.Chart.image.seriesByRegion(modbaN, table, ee.Reducer.mean());
print(unts);
据我了解,您要做的是用 modba
图像 collection 中的每张图像(有 12 张图像或每月一张)遮盖 [=] 中的相应图像12=] 图像 collection (全年只有 1 张图像)。这完全可行。
在您提供的代码中,您 updateMask
使用 AgOnly
(图像 collection),这是 GEE 不允许的。
您只需制作 AgOnly
图像,然后再将其用于 updateMask
。
试试这个:
var AgOnly = lc.map(function(img) {
var ag = img.select('LC_Type1');
return ag.eq(12);
//Would also like to maybe have 2 or 3 LC types to select here
}).max();
max()
方法会将您的图像 collection 转换为图像。如果愿意,您也可以使用 min()
或 mean()
,这都会给出相同的结果,因为 AgOnl
中只有一张图像。
它仍然适用于更广泛的日期范围和多种土地覆盖类型。
在那种情况下,只需保留计算 AgOnly
的旧代码,并修改计算 mask_ba
的代码如下:
var mask_ba = modba.map(function(img){
var img_year = img.date().format('YYYY');
var start_date = ee.Date(img_year.cat('-01-01'));
var end_date = start_day.advance(1, 'year');
var Agri_this_year = AgOnly.filterDate(start_date, end_date).max();
return img.updateMask(Agri_this_year);
});
基本上,上面的代码只是提取当前img
的年份,然后使用filterDate
方法从AgOnly
中select得到当年的土地覆盖类型图片合集,最后申请updateMask
.
同样的想法可以应用于其他土地覆盖类型。
希望对您有所帮助。