admin管理员组文章数量:1405379
I am working with Google Earth Engine (GEE) and need to perform a left join operation between two image collections:
- collection1 (lstDataset), which has 365 elements.
- collection2 (NTTempdataset), which has 320 elements.
I want to join the two collections based on the timestamp (system:time_start), keeping all images from collection1 (lstDataset) and adding the bands from collection2 (NTTempdataset) where the dates match. For the 45 dates in collection1 that do not have a corresponding match in collection2, I want to add null values for the bands from collection2. I am getting this error
ImageCollection (Error)
Parameter 'value' is required and may not be null.
Link:
var point = ee.Geometry.Point([-94.73665965557193, 35.915990354302]);
print('Point Geometry:', point);
var startDate = ee.Date('2016-01-01');
var endDate = ee.Date('2016-12-31');
var lstDataset = ee.ImageCollection('OREGONSTATE/PRISM/AN81d')
.select('tmean')
.filterDate(startDate, endDate)
.filterBounds(point)
.map(function(image) { return image.clip(point); });
print("lstDataset", lstDataset)
var NTTempdataset = ee.ImageCollection('NASA/VIIRS/002/VNP21A1N')
.select("LST_1KM") // Select the LST_1KM band
.filterDate(startDate, endDate) // Filter by date
.filterBounds(point) // Filter by region
.map(function(image) {
return image
.clip(point) // Clip to the region
.rename("LST_1KM_Night"); // Rename the band to LST_1KM_Night
});
print("NTTempdataset", NTTempdataset)
var leftJoin = function(collection1, collection2, dateProperty) {
// Get the band names of collection2
var collection2Bands = collection2.first().bandNames();
return collection1.map(function(image) {
var date = image.get(dateProperty); // Get the date of the current image in collection1
// Find the image in collection2 with the same date
var sameDateImage = collection2
.filter(ee.Filter.eq(dateProperty, date)) // Filter for the same date
.first(); // Get the first image (if any)
// If no image is found, sameDateImage will be null.
var mergedImage = ee.Algorithms.If({
condition: ee.Algorithms.IsEqual(sameDateImage, null), // Check if no matching image is found
trueCase: image.addBands(ee.Image.constant(null).rename(collection2Bands)), // Add null bands if no match
falseCase: image.addBands(sameDateImage) // Add bands from collection2 if a match is found
});
return ee.Image(mergedImage); // Return the merged image
});
};
// Example usage
var dateProperty = 'system:time_start'; // Use 'system:time_start' as the default date property
// Left join with missing values filled with null
var leftJoinedCollection = leftJoin(lstDataset, NTTempdataset, dateProperty);
print("Left Joined Collection", leftJoinedCollection);
I am working with Google Earth Engine (GEE) and need to perform a left join operation between two image collections:
- collection1 (lstDataset), which has 365 elements.
- collection2 (NTTempdataset), which has 320 elements.
I want to join the two collections based on the timestamp (system:time_start), keeping all images from collection1 (lstDataset) and adding the bands from collection2 (NTTempdataset) where the dates match. For the 45 dates in collection1 that do not have a corresponding match in collection2, I want to add null values for the bands from collection2. I am getting this error
ImageCollection (Error)
Parameter 'value' is required and may not be null.
Link: https://code.earthengine.google/53320bc6a2c7711b62fea1e7762195bb
var point = ee.Geometry.Point([-94.73665965557193, 35.915990354302]);
print('Point Geometry:', point);
var startDate = ee.Date('2016-01-01');
var endDate = ee.Date('2016-12-31');
var lstDataset = ee.ImageCollection('OREGONSTATE/PRISM/AN81d')
.select('tmean')
.filterDate(startDate, endDate)
.filterBounds(point)
.map(function(image) { return image.clip(point); });
print("lstDataset", lstDataset)
var NTTempdataset = ee.ImageCollection('NASA/VIIRS/002/VNP21A1N')
.select("LST_1KM") // Select the LST_1KM band
.filterDate(startDate, endDate) // Filter by date
.filterBounds(point) // Filter by region
.map(function(image) {
return image
.clip(point) // Clip to the region
.rename("LST_1KM_Night"); // Rename the band to LST_1KM_Night
});
print("NTTempdataset", NTTempdataset)
var leftJoin = function(collection1, collection2, dateProperty) {
// Get the band names of collection2
var collection2Bands = collection2.first().bandNames();
return collection1.map(function(image) {
var date = image.get(dateProperty); // Get the date of the current image in collection1
// Find the image in collection2 with the same date
var sameDateImage = collection2
.filter(ee.Filter.eq(dateProperty, date)) // Filter for the same date
.first(); // Get the first image (if any)
// If no image is found, sameDateImage will be null.
var mergedImage = ee.Algorithms.If({
condition: ee.Algorithms.IsEqual(sameDateImage, null), // Check if no matching image is found
trueCase: image.addBands(ee.Image.constant(null).rename(collection2Bands)), // Add null bands if no match
falseCase: image.addBands(sameDateImage) // Add bands from collection2 if a match is found
});
return ee.Image(mergedImage); // Return the merged image
});
};
// Example usage
var dateProperty = 'system:time_start'; // Use 'system:time_start' as the default date property
// Left join with missing values filled with null
var leftJoinedCollection = leftJoin(lstDataset, NTTempdataset, dateProperty);
print("Left Joined Collection", leftJoinedCollection);
Share
Improve this question
edited Mar 8 at 14:52
ryan
asked Mar 8 at 14:51
ryanryan
12 bronze badges
1 Answer
Reset to default 0How about using a ee.Join
to do a join?
var point = ee.Geometry.Point([-94.73665965557193, 35.915990354302]);
print('Point Geometry:', point);
var startDate = ee.Date('2016-01-01');
var endDate = ee.Date('2016-12-31');
var lstDataset = ee.ImageCollection('OREGONSTATE/PRISM/AN81d')
.select('tmean')
.filterDate(startDate, endDate)
.filterBounds(point)
.map(function(image) { return image.clip(point); });
print("lstDataset", lstDataset)
var NTTempdataset = ee.ImageCollection('NASA/VIIRS/002/VNP21A1N')
.select("LST_1KM") // Select the LST_1KM band
.filterDate(startDate, endDate) // Filter by date
.filterBounds(point) // Filter by region
.map(function(image) {
return image
.clip(point) // Clip to the region
.rename("LST_1KM_Night"); // Rename the band to LST_1KM_Night
});
print("NTTempdataset", NTTempdataset)
var joined = ee.Join.saveBest({
matchKey: 'other',
measureKey: 'garbage',
outer: true
}).apply({
primary: lstDataset,
secondary: NTTempdataset,
condition: ee.Filter.maxDifference({
difference: 100000000,
leftField: 'system:time_start',
rightField: 'system:time_start'})
})
// Do something to these:
var withMatches = joined.filter(ee.Filter.neq('other', null))
print(withMatches.size())
// Do something else to these:
var withoutMatches = joined.filter(ee.Filter.eq('other', null))
print(withoutMatches.size())
本文标签:
版权声明:本文标题:null - how to fill the variable with missing value when the join fails to find a match in google earth engine - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744893273a2630912.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论