I am working with two collections of satellite data. I want to select specific bands from "collection 1", join them to "collection 2", and then run a function. Unfortunately, the function does not work with the joined data, although it works for "collection 1".
Here is an example just using B10 of Sentinel-2
//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);
The error is: img.select(...).gt is not a function
How do I make this work?
Ok. I solved it. Thank you for your input. I needed to use a cast in the function. Now it works.