GEE错误——Layer error: Image.reduceResolution: The input to reduceResolution does not have a valid defa

错误

HSR_RLS LST 201808: Layer error: Image.reduceResolution: The input to reduceResolution does not have a valid default projection. Use setDefaultProjection() first.

在GEE中,reduceResolution()函数用于降低图像的分辨率。然而,该函数必须应用于具有有效默认投影的图像。如果图像没有默认投影,则会出现上述错误。这通常发生在以下两种情况下:

1. 图像没有设置投影:在进行投影操作之前,必须为图像设置投影。可以使用setDefaultProjection()函数将图像设置为具有默认投影。

2. 图像有多个波段,但它们的投影不同:如果多个波段具有不同的投影,那么reduceResolution()函数无法确定要使用哪个投影。可以使用reproject()函数将所有波段重新投影为相同的投影,然后再应用reduceResolution()函数。

在使用reduceResolution()函数之前,确保图像具有有效的默认投影,并且所有波段具有相同的投影。这样可以避免以上错误的发生。

 

原始代码

var geometry = 
    /* color: #d63000 */
    /* shown: false */
    /* displayProperties: [
      {
        "type": "rectangle"
      }
    ] */
    ee.Geometry.Polygon(
        [[[-121.63428873522334, 40.9266151669724],
          [-121.63428873522334, 40.91487639908032],
          [-121.61489099962763, 40.91487639908032],
          [-121.61489099962763, 40.9266151669724]]], null, false);
Map.centerObject(geometry,15);
Map.addLayer(geometry, {color: 'blue'}, 'Flux tower region');


for (var year = 2018; year < 2019 ; year++) {
  for (var m = 8; m < 9; m++) {
    
/* Convert to temporal frame */
var start = new Date(year + "-" + m + "-01");
var end = new Date(year + "-" + m + "-28");
var year2 = year-3;

var system =  year + ""+ "0" + m;
    
/* Landsat image assessment*/
    // Load Landsat 8 SR data
    var landsat8 = ee.ImageCollection('LANDSAT/LC08/C02/T1_L2')
           .filterDate(start, end)
           .map(maskL8sr)
           .map(function(image) {
              return image
            .select(['SR_B2', 'SR_B3', 'SR_B4', 'SR_B5', 'SR_B6', 'SR_B7', 'ST_B10'])
            .rename(['SR_B2', 'SR_B3', 'SR_B4', 'SR_B5', 'SR_B6', 'SR_B7', 'ST']);
    });

    // Cloud masking
    function maskL8sr(image) {
      // Bits 3 and 4 are cloud shadow and cloud, respectively.
      var cloudShadowBitMask = (1 << 3);
      var cloudsBitMask = (1 << 4);
      // Get the pixel QA band.
      var qa = image.select('QA_PIXEL');
      // Both flags should be set to zero, indicating clear conditions.
      var mask = qa.bitwiseAnd(cloudShadowBitMask).eq(0)
                     .and(qa.bitwiseAnd(cloudsBitMask).eq(0));
      return image.updateMask(mask);
    }
    
    // Calculate median and applies scaling factors
    function applyScaleFactors(image) {
      var opticalBands = image.select('SR_B.').multiply(0.0000275).add(-0.2);
      var thermalBands = image.select('ST').multiply(0.00341802).add(149.0);
      return image.addBands(opticalBands, null, true)
                  .addBands(thermalBands, null, true);
    }
    
    var l8m = landsat8.map(applyScaleFactors);
                        //.reproject(median.select('SR_B2').projection(), null, 30);
    
    var median = l8m.median();
    
    // Map results
    var visualization = {
      bands: ['SR_B4', 'SR_B3', 'SR_B2'],
      min: 0.0,
      max: 0.3,
    };
    

    //Map.addLayer(median, visualization, 'Landsat-8 RGB'+ ' Date: '+ year + m, false);
    
    // LST median
    // Conversion between Kelvin and Celsius
    var conv = 273.15;
    
    var LSTm = median.select('ST').subtract(conv)
              .reproject(median.select('SR_B2').projection(), null, 30);
    
    var visParams = {min: -10, max: 40, palette: [
        '040274', '040281', '0502a3', '0502b8', '0502ce', '0502e6',
        '0602ff', '235cb1', '307ef3', '269db1', '30c8e2', '32d3ef',
        '3be285', '3ff38f', '86e26f', '3ae237', 'b5e22e', 'd6e21f',
        'fff705', 'ffd611', 'ffb613', 'ff8b13', 'ff6e08', 'ff500d',
        'ff0000', 'de0101', 'c21301', 'a71001', '911003'
      ],};
            
    
    // Map result
    Map.addLayer(LSTm.clip(geometry),visParams,'Landsat-8 LST '+ system);
    
    // Export a cloud-optimized GeoTIFF.
    Export.image.toDrive({
      image: LSTm,
      description: 'L8_LST_' + system,
      scale: 30,
      region: geometry,
      fileFormat: 'GeoTIFF',
      maxPixels: 1e10,
      formatOptions: {
        cloudOptimized: true
      }
    });

/* NAIP image assessment*/
 
// Map the function over one year of data and take the median.
// Load NAIP TOA reflectance data.
var collection = ee.ImageCollection('USDA/NAIP/DOQQ')
    .filter(ee.Filter.date(year2 + '-01-01', year + '-12-31'))
    .filterBounds(geometry);

// Calculate median
var naipm = collection.median();

// Define the visualization parameters.
var trueColor = naipm.select(['R', 'G', 'B']);
var trueColorVis = {
  min: 0.0,
  max: 255.0,
};

// Map results
Map.addLayer(trueColor.clip(geometry),trueColorVis,'True Color '+ system);

/* Bandpass adjustment */
  // Create a new images that is the concatenation of two bands from two sensors
var red = ee.Image.cat(naipm.select('R'),median.select('SR_B4'));
var green = ee.Image.cat(naipm.select('G'),median.select('SR_B3'));
var blue = ee.Image.cat(naipm.select('B'),median.select('SR_B2'));
var nir = ee.Image.cat(naipm.select('N'),median.select('SR_B5'));

// Calculate regression coefficients for the set of pixels
var linearFitr = red.reduceRegion({
  reducer: ee.Reducer.linearFit(),
  geometry: geometry,
  scale: 30,
  tileScale: 16,
});

// Extract the y-intercept and slope.
var b0r = linearFitr.get('offset'); // y-intercept
var b1r = linearFitr.get('scale'); // slope

var new_nr = naipm.select('R').multiply(ee.Number(b1r)).add(ee.Number(b0r))
          .reproject(median.select('SR_B2').projection(), null, 1);

//Map.addLayer(new_nr,{max: 5000, min: 0}, 'Sentinel-2 RGB');

// Calculate regression coefficients for the set of pixels
var linearFitg = green.reduceRegion({
  reducer: ee.Reducer.linearFit(),
  geometry: geometry,
  scale: 30,
  tileScale: 16,
});

// Extract the y-intercept and slope.
var b0g = linearFitg.get('offset'); // y-intercept
var b1g = linearFitg.get('scale'); // slope

var new_ng = naipm.select('G').multiply(ee.Number(b1g)).add(ee.Number(b0g))
          .reproject(median.select('SR_B2').projection(), null, 1);

// Calculate regression coefficients for the set of pixels
var linearFitb = blue.reduceRegion({
  reducer: ee.Reducer.linearFit(),
  geometry: geometry,
  scale: 30,
  tileScale: 16,
});

// Extract the y-intercept and slope.
var b0b = linearFitb.get('offset'); // y-intercept
var b1b = linearFitb.get('scale'); // slope

var new_nb = naipm.select('B').multiply(ee.Number(b1b)).add(ee.Number(b0b))
          .reproject(median.select('SR_B2').projection(), null, 1);

// Calculate regression coefficients for the set of pixels
var linearFitn = nir.reduceRegion({
  reducer: ee.Reducer.linearFit(),
  geometry: geometry,
  scale: 30,
  tileScale: 16,
});

// Extract the y-intercept and slope.
var b0n = linearFitn.get('offset'); // y-intercept
var b1n = linearFitn.get('scale'); // slope

var new_nn = naipm.select('N').multiply(ee.Number(b1n)
  • 20
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

打赏作者

此星光明

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

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

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

打赏作者

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

抵扣说明:

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

余额充值