[英]How to subset an image collection in Google Earth Engine based on their position?
[英]How to create a feature collection after importing different shapefiles from assets in Google Earth Engine?
我正在将 2 个不同的 shapefile 从资产导入到 plot MODIS 的时间序列图
但我无法从这些 shapefile 中收集特征
怎么做?
var Haryana_state = ee.FeatureCollection('users/abhilashaanu92/HaryanaBoundary');
Map.addLayer(Haryana_state);
var Punjab_state = ee.FeatureCollection('users/abhilashaanu92/punjab_state_boundary');
Map.addLayer(Punjab_state);
// Combine features into a feature collection.
var both_states = ee.FeatureCollection([Haryana_state, Punjab_state]).flatten();
Map.addLayer(both_states);
// Load MODIS vegetation indices data and subset annual images.
var vegIndices = ee.ImageCollection('MODIS/006/MOD13A1')
.filter(ee.Filter.date('2019-01-01', '2020-01-01'))
.select(['NDVI', 'EVI']);
// Define the chart and print it to the console.
var chart =
ui.Chart.image
.seriesByRegion({
imageCollection: vegIndices,
band: 'NDVI',
regions: both_states,
reducer: ee.Reducer.mean(),
scale: 500,
seriesProperty: 'label',
xProperty: 'system:time_start'
})
.setOptions({
title: 'Average NDVI Value by Date',
hAxis: {title: 'Date', titleTextStyle: {italic: false, bold: true}},
vAxis: {
title: 'NDVI (x1e4)',
titleTextStyle: {italic: false, bold: true}
},
lineWidth: 5,
colors: ['f0af07', '0f8755', '76b349'],
});
print(chart);
如果我将单个 shapefile 变量的名称放在区域中,那么它可以工作,但是当我将 2 个 shapefile 组合到一个特征集合中时,它会显示错误。
如何纠正这种情况?
我想要 output 像这样的东西。 (同一图表上两个州的时间序列)。
这里需要做两件事。 首先,在合并两个 FeatureCollections 之后添加.flatten()
。
这样,您可以创建所需的特征集合 (FeatureCollection)。 否则,您最终会得到一个 FeatureCollections 集合,这会提示错误。
其次, seriesProperty
需要与您的 FeatureCollection 的 label 相匹配。 在这种情况下,“STATE_NAME”。 您可以通过添加 print(both_states) 来检查新 FeatureCollection 的外观。 我已经更新了代码。
var Haryana_state = ee.FeatureCollection('users/abhilashaanu92/HaryanaBoundary');
Map.addLayer(Haryana_state);
var Punjab_state = ee.FeatureCollection('users/abhilashaanu92/punjab_state_boundary');
Map.addLayer(Punjab_state);
// Combine features into a feature collection.
var both_states = ee.FeatureCollection([Haryana_state, Punjab_state]).flatten();
print('Check the properties; this will tell you what seriesProperty to use', both_states)
Map.addLayer(both_states);
// Load MODIS vegetation indices data and subset annual images.
var vegIndices = ee.ImageCollection('MODIS/006/MOD13A1')
.filter(ee.Filter.date('2019-01-01', '2020-01-01'))
.select(['NDVI', 'EVI']);
// Define the chart and print it to the console.
var chart =
ui.Chart.image
.seriesByRegion({
imageCollection: vegIndices,
band: 'NDVI',
regions: both_states,
reducer: ee.Reducer.mean(),
scale: 500,
seriesProperty: 'STATE_NAME',
xProperty: 'system:time_start'
})
.setOptions({
title: 'Average NDVI Value by Date',
hAxis: {title: 'Date', titleTextStyle: {italic: false, bold: true}},
vAxis: {
title: 'NDVI (x1e4)',
titleTextStyle: {italic: false, bold: true}
},
lineWidth: 5,
colors: ['f0af07', '0f8755', '76b349'],
});
print(chart);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.