Friday 7 February 2020

Google Earth Engine - filter landsat by cloud cover over multiple polygons


I want to make a Landsat image collection that is totally cloud free over a SET of polygons. I have about 300 polygons (all within a single Landsat tile). I found this question, which is doing exactly what I want over a single polygon, but I can't figure out how to get it to work over a set of polygons (which are loaded as a feature class).


Here is what I tried to do to modify the solution from the question posted above, where imgcollection is my Landsat TOA Image Collection and fc is my feature class of polygons. I was trying to use map and clip together to select all the polygons in the feature class for each image (based on the answers in this related question).



  var combine = imgcollection.map(function(imgcollection) { return 
imgcollection.clip(fc); });

After this line, I tried to continue with the solution from the first question, but it doesn't work. The error I get is as follows, which confuses me. I'm trying to use the variable "combine" as the geometry - am I misunderstanding this and actually using something else?


  ImageCollection (Error)
Image.reduceRegion, argument 'geometry': Invalid type. Expected:
Geometry. Actual: ImageCollection.

EDIT: full code


  var fc = ee.FeatureCollection('ft:omit');


var imgcollection = ee.ImageCollection("LANDSAT/LC08/C01/T1_RT_TOA");

var combine = imgcollection.map(function(img) { return img.clip(fc); });

var withCloudiness = combine.map(function(image) {
var cloud = ee.Algorithms.Landsat.simpleCloudScore(image).select('cloud');
var cloudiness = cloud.reduceRegion({
reducer: 'mean',
geometry: combine,

scale: 30,
});
return image.set(cloudiness);
});

var filteredCollection = withCloudiness.filter(ee.Filter.lt('cloud', 10));
print(filteredCollection);

Answer



The error is quite clear. Parameter geometry of function reduceRegion must be a Geometry. In the documentation says:




geometry (Geometry, default: null): The region over which to reduce data. Defaults to the footprint of the image's first band.



So, if you want to reduce over fc:


var fc = ee.FeatureCollection('ft:omit');

var imgcollection = ee.ImageCollection("LANDSAT/LC08/C01/T1_RT_TOA");

var combine = imgcollection.map(function(img) { return img.clip(fc); });

var withCloudiness = combine.map(function(image) {

var cloud = ee.Algorithms.Landsat.simpleCloudScore(image).select('cloud');
var cloudiness = cloud.reduceRegion({
reducer: 'mean',
geometry: fc.geometry(),
scale: 30,
maxPixels: 1e13,
});
return image.set(cloudiness);
});


var filteredCollection = withCloudiness.filter(ee.Filter.lt('cloud', 10));
print(filteredCollection);

No comments:

Post a Comment

arcpy - Changing output name when exporting data driven pages to JPG?

Is there a way to save the output JPG, changing the output file name to the page name, instead of page number? I mean changing the script fo...