TransWikia.com

Don't add empty images to GEE ImageCollection

Geographic Information Systems Asked by Thummper on December 27, 2020

Given 2 dates I want to output all satellite images that 100% fill a given region (region is an imported shape file of a UK county boundary).

Initially I was just getting all images, but sometimes they would not fill the whole county and I could not figure out a method to make sure they fill the whole region with filters.

To solve this I decided to get weekly composite images instead. My reasoning was that if the satellite took a photo of half a county, it probably captured the other half after (I really didn’t want to spend time meshing images together to get a full county images, so I thought the composite would be a quick fix).

Now my issue is as follows: when there are no images taken in a given week, my code adds an empty image to the image collection – I don’t want it to do this, I only want images with actual content added to my collection – is there an easy way to do this?

My code is as follows:

function addNDVI(image) {
  var ndvi = image.normalizedDifference(['B5', 'B4']);
  return image.addBands(ndvi);
}

var clipArea = function(image){
  // table is my imported shapefile
  return image.clip(table)
}

function getWeeklySentinelComposite(date, product){
  var sentinelWeek = ee.ImageCollection(product)
  .filterBounds(table)
  .filterDate(date, date.advance(1, 'week'))
  .filter(ee.Filter.lt('CLOUDY_PIXEL_PERCENTAGE', 20))
  .map(clipArea)
  .map(addNDVI)
  .mean()
  .set('system:time_start', date.millis(), 'dateYMD', date.format('YYYY-MM-dd'));
  return sentinelWeek;
}


var startDate = "2018-01-01";
var endDate   = "2018-12-31";

var weekDifference = ee.Date(startDate).advance(1, 'week').millis().subtract(ee.Date(startDate).millis());
var listMap = ee.List.sequence(ee.Date(startDate).millis(), ee.Date(endDate).millis(), weekDifference);

var weeklySentinel = ee.ImageCollection.fromImages(listMap.map(
  function(dateMillis){
    var date = ee.Date(dateMillis);
    var image = getWeeklySentinelComposite(date, "COPERNICUS/S2");
    return image 
  }
));

At this point weeklySentinel is an image collection of weekly image composites, some images are understandably empty. Is there a way to only add images with content to my collection, or do I have to try fortnightly / monthly composites and adjust my cloud cover filter to get a full dataset?

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP