【问题标题】:GEE joined collection is not working in a functionGEE 加入的集合在函数中不起作用
【发布时间】:2021-01-27 08:49:26
【问题描述】:

我正在处理两个卫星数据集合。我想从“集合 1”中选择特定波段,将它们加入“集合 2”,然后运行一个函数。不幸的是,该函数不适用于连接的数据,尽管它适用于“集合 1”。

这是一个仅使用 Sentinel-2 的 B10 的示例

//identifying area and date
var geometry = ee.Geometry.Point([4,45]);

Map.centerObject(geometry,10);
var start = '2019-03-10';
var end   = '2019-05-10';


//my function
function testing(img){
  img = img.updateMask(img.select(['B10']).gt(200).focal_min(2).focal_max(2).not());
  return img;
}

//my two collections
var collection1 = ee.ImageCollection('COPERNICUS/S2').filterDate(start,end)
                  .filterBounds(geometry);
  
var B10s=collection1.select('B10');
//print('B10s',B10s);


var collection2 = ee.ImageCollection('COPERNICUS/S2_SR')
                  .filterDate(start,end)
                  .filterBounds(geometry);
                  
// joining the collections
var filtering = ee.Filter.equals({
  leftField: 'system:time_start',
  rightField: 'system:time_start'
});

var simpleJoin = ee.Join.inner();
var innerJoin = simpleJoin.apply(collection2, B10s, filtering);
var joined = innerJoin.map(function(feature) {
  return ee.Image.cat(feature.get('primary'), feature.get('secondary'));
});

print('Joined', joined);

//just to visualize one image
//var coll1 = ee.Image(collection1.first());
//Map.addLayer(coll1, {bands:['B2'], min:0, max:5000},'B2Coll1 test');

//running the function for collection 1 works
var test = collection1.map(testing);
var tess = ee.Image(test.first());
Map.addLayer(tess, {bands:['B2'], min:0, max:5000},'B2 test');

//here when running with the joined collection, there is a problem
var TestingJoined = joined.map(testing);

错误是:img.select(...).gt is not a function

我该如何进行这项工作?

【问题讨论】:

  • 请在代码问题中给出minimal reproducible example--cut & paste & runnable code,包括最小的代表性示例输入作为代码;期望和实际输出(包括逐字错误消息);标签和版本;明确的规范和解释。给出尽可能少的代码,即您显示的代码可以通过您显示的代码扩展为不正常的代码。 (调试基础。)对于包含 DBMS 和 DDL(包括约束和索引)的 SQL,并以表格式作为代码输入。 How to Ask 暂停总体目标的工作,将代码砍到第一个表达式,没有给出你期望的内容,说出你期望的内容和原因。
  • 你为什么希望 gt 在那里可以访问? (有理由参考权威文档。)

标签: join inner-join google-earth-engine image-masking sentinel2


【解决方案1】:

调试时,连接是否按预期工作?日期时间太精确而无法完全加入是否存在任何问题?

我要走的第二条路线是确保连接的对象与集合相同。我怀疑如果没有你投射它或其他东西(尽管我不熟悉这个库),情况会是这样。您映射到这些集合的“测试”功能可能仅适用于未连接的集合。如果您提供实际的“问题”或错误输出,将会非常有帮助。

【讨论】:

    【解决方案2】:

    好的。我解决了。谢谢您的意见。 我需要在函数中使用强制转换。现在可以了。

    function testing(img){
      img = ee.Image(img).updateMask(ee.Image(img).select(['B10']).gt(200).focal_min(2).focal_max(2).not());
      return img;
    }
    

    【讨论】:

      猜你喜欢
      • 2020-04-15
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-08-02
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多