Skip to main content
Added links to GEE scripts
Source Link

I've been able to create a script that executes this task for a single polygon in this feature collection, posted below and link here.

My question is how do I take this script and scale it up to execute the task for my whole collection of polygons? Script I'm working on is also below and here.

I've been able to create a script that executes this task for a single polygon in this feature collection, posted below.

My question is how do I take this script and scale it up to execute the task for my whole collection of polygons? Script I'm working on is also below.

I've been able to create a script that executes this task for a single polygon in this feature collection, posted below and link here.

My question is how do I take this script and scale it up to execute the task for my whole collection of polygons? Script I'm working on is also below and here.

Tweeted twitter.com/StackGIS/status/1201924200782450690
Added scripts to post, removed links to GEE scripts.
Source Link

I've been able to create a script that executes this task for a single polygon in this feature collection, link here: https://code.earthengine.google.com/1bf8dce761366a138243fac15963f105posted below.

My question is how do I take this script and scale it up to execute the task for my whole collection of polygons? My script for thisScript I'm working on is here: https://code.earthengine.google.com/852538f4a82a518667ca3f5e01a9cdfdalso below.

Everything runs smoothly up until step 4 (mapping a reduceRegion/(s) function across the image collection), where earth engine returns a 'computation timed out' or an 'earth engine memory capacity exceeded' error. I've tried breaking both the image collection and the feature collection into smaller chunks with no success. I wonder if exporting a task to my google drive could be a solution, but I'm unsure of how to write the correct code for this.

Scripts:

  1. Mean EVI for a single polygon for each image in a collection (works):

    // 1. Filter 'polys' feature collection by property 'Name'. var NU009 = polys.filterMetadata('Name', 'equals', 'NU009');

    // 2. Get Landsat 8 EVI collection and filter to NU009. var l8 = ee.ImageCollection('LANDSAT/LC08/C01/T1_8DAY_EVI') .filterBounds(NU009) .filterDate('2014-01-01','2018-12-30');

    // 3. Clip each Landsat image to the area covered by NU009. var l8_clip = l8.map(function(image) { return image.clip(NU009); });

    // 4. Calculate mean EVI for NU009 in each image. //Define a function that calculates mean EVI for NU009. //Returns an image collection where each image has a new property, //'meanEVI'. var reducer = function(image) { var meanEVI = image.reduceRegion({ reducer: ee.Reducer.mean(), geometry: NU009.geometry(), scale: 30, bestEffort: true }); return image.set('meanEVI', meanEVI); };

    //Map the reducer function over the image collection. var l8_reduce = l8_clip.map(reducer); print(l8_reduce);

  2. Mean EVI for all polygons for each image in a collection (computation times out):

    // 1. Filter 'polys' by size.

    // Define a function that calculates area of each polygon. // New property 'GEE_Area' is in square meters. var feature_area = function(feature) { var area = feature.geometry().area(); return feature.set('GEE_Area', area); };

    polys = polys.map(feature_area);

    // Filter polys by their GEE_Area. // Must be greater than 30 square meters (900m) to be sufficiently //represented by a Landsat pixel. var polys_filtered = polys.filterMetadata('GEE_Area', 'not_less_than', 900);

    // 2. Get Landsat EVI image collection. var l8 = ee.ImageCollection('LANDSAT/LC08/C01/T1_8DAY_EVI') .filterBounds(polys_filtered) .filterDate('2014-01-01','2018-12-31');

    // 3. Clip each Landsat image to the area covered by all polygons. var l8_clip = l8.map(function(image) { return image.clipToCollection(polys_filtered); });

    // 4. Calculate mean EVI for each polygon in each image.

    // Define a function that calculates mean EVI for all polygons using //'reduceRegion' method. var reduceRegion = function(image) { var meanEVI = image.reduceRegion({ reducer: ee.Reducer.mean(), geometry: polys_filtered.geometry(), scale: 30, bestEffort: true }); return image.set('meanEVI', meanEVI); };

    var l8_reduceRegion = l8_clip.map(reduceRegion); print(l8_reduceRegion);

    // Alternative to above function: // Define a function that calculates mean EVI for all polygons using //'reduceRegions' method. var reduceRegions = function(image) { var meanEVI = image.reduceRegions({ collection: polys_filtered, reducer: ee.Reducer.mean(), scale: 30}); return meanEVI; };

    var l8_reduceRegions = l8_clip.map(reduceRegions); print(l8_reduceRegions);

I've been able to create a script that executes this task for a single polygon in this feature collection, link here: https://code.earthengine.google.com/1bf8dce761366a138243fac15963f105

My question is how do I take this script and scale it up to execute the task for my whole collection of polygons? My script for this is here: https://code.earthengine.google.com/852538f4a82a518667ca3f5e01a9cdfd

Everything runs smoothly up until step 4 (mapping a reduceRegion/(s) function across the image collection), where earth engine returns a 'computation timed out' or an 'earth engine memory capacity exceeded' error. I've tried breaking both the image collection and the feature collection into smaller chunks with no success. I wonder if exporting a task to my google drive could be a solution, but I'm unsure of how to write the correct code for this.

I've been able to create a script that executes this task for a single polygon in this feature collection, posted below.

My question is how do I take this script and scale it up to execute the task for my whole collection of polygons? Script I'm working on is also below.

Everything runs smoothly up until step 4 (mapping a reduceRegion/(s) function across the image collection), where earth engine returns a 'computation timed out' or an 'earth engine memory capacity exceeded' error. I've tried breaking both the image collection and the feature collection into smaller chunks with no success. I wonder if exporting a task to my google drive could be a solution, but I'm unsure of how to write the correct code for this.

Scripts:

  1. Mean EVI for a single polygon for each image in a collection (works):

    // 1. Filter 'polys' feature collection by property 'Name'. var NU009 = polys.filterMetadata('Name', 'equals', 'NU009');

    // 2. Get Landsat 8 EVI collection and filter to NU009. var l8 = ee.ImageCollection('LANDSAT/LC08/C01/T1_8DAY_EVI') .filterBounds(NU009) .filterDate('2014-01-01','2018-12-30');

    // 3. Clip each Landsat image to the area covered by NU009. var l8_clip = l8.map(function(image) { return image.clip(NU009); });

    // 4. Calculate mean EVI for NU009 in each image. //Define a function that calculates mean EVI for NU009. //Returns an image collection where each image has a new property, //'meanEVI'. var reducer = function(image) { var meanEVI = image.reduceRegion({ reducer: ee.Reducer.mean(), geometry: NU009.geometry(), scale: 30, bestEffort: true }); return image.set('meanEVI', meanEVI); };

    //Map the reducer function over the image collection. var l8_reduce = l8_clip.map(reducer); print(l8_reduce);

  2. Mean EVI for all polygons for each image in a collection (computation times out):

    // 1. Filter 'polys' by size.

    // Define a function that calculates area of each polygon. // New property 'GEE_Area' is in square meters. var feature_area = function(feature) { var area = feature.geometry().area(); return feature.set('GEE_Area', area); };

    polys = polys.map(feature_area);

    // Filter polys by their GEE_Area. // Must be greater than 30 square meters (900m) to be sufficiently //represented by a Landsat pixel. var polys_filtered = polys.filterMetadata('GEE_Area', 'not_less_than', 900);

    // 2. Get Landsat EVI image collection. var l8 = ee.ImageCollection('LANDSAT/LC08/C01/T1_8DAY_EVI') .filterBounds(polys_filtered) .filterDate('2014-01-01','2018-12-31');

    // 3. Clip each Landsat image to the area covered by all polygons. var l8_clip = l8.map(function(image) { return image.clipToCollection(polys_filtered); });

    // 4. Calculate mean EVI for each polygon in each image.

    // Define a function that calculates mean EVI for all polygons using //'reduceRegion' method. var reduceRegion = function(image) { var meanEVI = image.reduceRegion({ reducer: ee.Reducer.mean(), geometry: polys_filtered.geometry(), scale: 30, bestEffort: true }); return image.set('meanEVI', meanEVI); };

    var l8_reduceRegion = l8_clip.map(reduceRegion); print(l8_reduceRegion);

    // Alternative to above function: // Define a function that calculates mean EVI for all polygons using //'reduceRegions' method. var reduceRegions = function(image) { var meanEVI = image.reduceRegions({ collection: polys_filtered, reducer: ee.Reducer.mean(), scale: 30}); return meanEVI; };

    var l8_reduceRegions = l8_clip.map(reduceRegions); print(l8_reduceRegions);

Source Link

Calculate mean EVI for multiple polygons across an image collection in Google Earth Engine

My goal is to calculate mean EVI for a collection of polygons for each image in an image collection.

My collection of polygons is a GEE feature collection (called 'polys') and I'm using the Landsat 8 EVI image collection.

I've been able to create a script that executes this task for a single polygon in this feature collection, link here: https://code.earthengine.google.com/1bf8dce761366a138243fac15963f105

My question is how do I take this script and scale it up to execute the task for my whole collection of polygons? My script for this is here: https://code.earthengine.google.com/852538f4a82a518667ca3f5e01a9cdfd

Everything runs smoothly up until step 4 (mapping a reduceRegion/(s) function across the image collection), where earth engine returns a 'computation timed out' or an 'earth engine memory capacity exceeded' error. I've tried breaking both the image collection and the feature collection into smaller chunks with no success. I wonder if exporting a task to my google drive could be a solution, but I'm unsure of how to write the correct code for this.