1

I'm trying to clip an image collection to the province of Alberta, but filterBounds is not working. Thank you for any help you can offer! I would like the image collection to be clipped, not just the layer on the map, so when I perform operations on the image collection they will only be performed for Alberta

var Admins = ee.FeatureCollection("FAO/GAUL/2015/level1");
var Alberta = Admins.filter(ee.Filter.eq('ADM1_NAME', 'Alberta'));
print(Alberta)
Map.addLayer(Alberta, {}, 'Alberta')
Map.centerObject(Alberta, 6)

//Load NTL data for 2018, find the median value for each pixel
var dataset = ee.ImageCollection('NOAA/VIIRS/DNB/MONTHLY_V1/VCMSLCFG')
                  .filter(ee.Filter.date('2018-12-01', '2018-12-31'))
                  .filterBounds(Alberta); //here I'm trying to clip the image collection
var nighttime = dataset.select('avg_rad');
var nighttimeVis = {min: 0.0, max: 60.0};
print(nighttime)
Map.addLayer(nighttime.median(), nighttimeVis, 'Nighttime'); //this layer still shows the whole world :-(
Carrie Ann Adams
  • 43
  • 1
  • 1
  • 5

2 Answers2

13

One simple way is:

var dataset = ee.ImageCollection('NOAA/VIIRS/DNB/MONTHLY_V1/VCMSLCFG')
                  .filter(ee.Filter.date('2018-12-01', '2018-12-31'))
                  .map(function(image){return image.clip(Alberta)});
HamiEbra
  • 310
  • 2
  • 7
1

I figured it out. I wrote a function to clip the images and applied it over the image collection.

//Create feature for Alberta Boundary
var Admins = ee.FeatureCollection("FAO/GAUL/2015/level1");
var Alberta = Admins.filter(ee.Filter.eq('ADM1_NAME', 'Alberta'));
print(Alberta)
Map.addLayer(Alberta, {}, 'Alberta')
Map.centerObject(Alberta, 6)


//Load NTL data for 2018, find the median value for each pixel
var dataset = ee.ImageCollection('NOAA/VIIRS/DNB/MONTHLY_V1/VCMSLCFG')
                  .filter(ee.Filter.date('2018-12-01', '2018-12-31'))
                  .filterBounds(Alberta); //here I'm trying to clip the image to Alberta

function clp(img) {
  return img.clip(Alberta)
}

var clippedVIIRS = dataset.map(clp)
print(clippedVIIRS)

var nighttime = clippedVIIRS.select('avg_rad');
var nighttimeVis = {min: 0.0, max: 60.0};
Map.addLayer(nighttime.median(), nighttimeVis, 'Nighttime');
Carrie Ann Adams
  • 43
  • 1
  • 1
  • 5