Google Earth Engine(GEE)——当加载图表的时候出现错误No features contain non-null values of “system:time_start“.

文章指出,由于在处理MODISNDVI图像系列时未正确保留system:time_start属性,导致生成图表时出现错误。解决方案是在映射函数中使用.copyProperties()方法来保持时间属性,以便图表能正确地以时间为x轴进行绘制。
摘要由CSDN通过智能技术生成

 

错误:

Error generating chart: The image collection is empty.


No features contain non-null values of "system:time_start".


The image collection is empty.

原始代码:


var geometry = /* color: #d63000 */ee.Geometry.Polygon(
        [[[-81.14573791618602, 25.335453210591712],
          [-80.90953186149852, 25.32924702619973],
          [-81.03312805290477, 25.5190118912932],
          [-81.1992962657954, 25.50537864099872]]]),
    Mang = ee.FeatureCollection("users/selenachav5/mangrove_vector");
var WSC1050 = /* color: #98ff00 */ee.Geometry.Point([-81.11963534, 25.42344856]);

var mask = Mang
var mangroveImg = ee.Image(0).paint(mask, 1);
Map.addLayer(mangroveImg, {min:0, max:1}, 'mangroveImg')
function maskNonMangrove(i){
  return i.updateMask(mangroveImg).copyProperties(i);
}

var col = ee.ImageCollection('MODIS/061/MOD13Q1')
                  .map(function(im) {return im.select(['NDVI']).multiply(0.0001)})
                  .filter(ee.Filter.date('2013-01-01', '2023-05-01'))
                  .map(maskNonMangrove) 
                  ;




var ndvi = col.select('NDVI');
var ndviVis = {
  min: 0.0,
  max: 8000.0,
  palette: [
    'FFFFFF', 'CE7E45', 'DF923D', 'F1B555', 'FCD163', '99B718', '74A901',
    '66A000', '529400', '3E8601', '207401', '056201', '004C00', '023B01',
    '012E01', '011D01', '011301'
  ],
};
Map.setCenter(6.746, 46.529, 2);
Map.addLayer(ndvi, ndviVis, 'NDVI');

var ndviChart = ui.Chart.image.series(ndvi, WSC1050, ee.Reducer.mean(), 250);
  ndviChart.setOptions({
    title: 'MODIS NDVI',
    vAxis: {title: 'NDVI', maxValue: 9000},
    hAxis: {title: 'date', format: 'MM-yy', gridlines: {count: 7}},
  });
  
print(ndviChart)

解析:

出现这个的主要原因是,我们在对影像集合进行映射计算的出现了掩盖掉时间属性的东西,所以我们需要在进行映射函数之后要进行属性的追加,也就是及逆行属性的copy,从而保留这个时间属性,因为在默认状态下chart中是需要进行时间属性的来作为横轴进行加载的,所以这里我们必须要保留原有的影像时间信息。

关键代码:

.copyProperties(i,['system:time_start'])

图表函数:

ui.Chart.image.series(imageCollection, region, reducerscalexProperty)

Generates a Chart from an ImageCollection. Plots derived values of each band in a region across images. Usually a time series.

  • X-axis: Image, labeled by xProperty value.

  • Y-axis: Band value.

  • Series: Band names.

Returns a chart.

Arguments:

imageCollection (ImageCollection):

An ImageCollection with data to be included in the chart.

region (Feature|FeatureCollection|Geometry):

The region to reduce.

reducer (Reducer, optional):

Reducer that generates the values for the y-axis. Must return a single value. Defaults to ee.Reducer.mean().

scale (Number, optional):

Scale to use with the reducer in meters.

xProperty (String, optional):

Property to be used as the label for each image on the x-axis. Defaults to 'system:time_start'.

Returns: ui.Chart

修改后的代码:

var WSC1050 = /* color: #98ff00 */ee.Geometry.Point([-81.11963534, 25.42344856]);

var mask = Mang
var mangroveImg = ee.Image(0).paint(mask, 1);
Map.addLayer(mangroveImg, {min:0, max:1}, 'mangroveImg')
function maskNonMangrove(i){
  return i.updateMask(mangroveImg).copyProperties(i,['system:time_start']);
}

var col = ee.ImageCollection('MODIS/061/MOD13Q1')
                  .map(function(i) {return i.select(['NDVI']).multiply(0.0001).copyProperties(i,['system:time_start'])})
                  .filter(ee.Filter.date('2013-01-01', '2023-05-01'))
                  .map(maskNonMangrove) 
                  ;


var ndvi = col.select('NDVI');
var ndviVis = {
  min: 0.0,
  max: 8000.0,
  palette: [
    'FFFFFF', 'CE7E45', 'DF923D', 'F1B555', 'FCD163', '99B718', '74A901',
    '66A000', '529400', '3E8601', '207401', '056201', '004C00', '023B01',
    '012E01', '011D01', '011301'
  ],
};
Map.setCenter(6.746, 46.529, 2);
Map.addLayer(ndvi, ndviVis, 'NDVI');

var ndviChart = ui.Chart.image.series(ndvi, WSC1050, ee.Reducer.mean(), 250);
  ndviChart.setOptions({
    title: 'MODIS NDVI',
    vAxis: {title: 'NDVI', maxValue: 1},
    hAxis: {title: 'date', format: 'MM-yy', gridlines: {count: 7}},
  });
  
print(ndviChart)

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

此星光明

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值