繁体   English   中英

从 Google 地球引擎中的资产导入不同的 shapefile 后如何创建特征集合?

[英]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 像这样的东西。 (同一图表上两个州的时间序列)。

同一图表上的不同区域时间序列

图表来源URL

这里需要做两件事。 首先,在合并两个 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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM