I'm working on building a model in google earth engine that will estimate carrying capacities for bird species based off of a table I have of bird densities per land cover type and an image of land cover types.

I'm at a point in my process where I have an image of bird densities across my region of interest. I want to use reduceRegion() with an ee.Reducer.sum() to get the total carrying capacity across my region of interest. My code looks like this:

//Density_Image is the image of bird densities I want to reduce.
//ROI is a FeatureCollection of regions within my region of interest.    
    reducer: ee.Reducer.sum(), 
    geometry: ROI.geometry().geometries().get(3),
    maxPixels: 1e11,
    tileScale: 16}));

This code works when I feed in a single feature (~1e8 pixels), but fails when I try to feed in the area covered by my entire feature collection (~2e9 pixels) because the computation takes too long.

To get around this issue, and also because I would like to store the carrying capacity of each subregion, I'm trying to write a .map() function that will loop through each feature (region) in my ROI FeatureCollection, calculate carrying capacity for that feature, and then store carrying capacity in a new property I'll set within that feature, 'pop_est'. Here is my code for that:

var pop_est_table = table.map(function(f) {
    // line above throws an error that argref = null.
    Density_Image = ee.Image(remap2);
    var pop_est = Density_Image.reduceRegion({
        reducer: ee.Reducer.sum(), 
        geometry: f.geometry(),      
        bestTry: true, 
        maxPixels: 1e12, 
        tileScale: 16});
    return ee.Feature(f).set('pop_est', pop_est);

The code I've written has at least two things wrong with it.

1) The code will run and set a new property in each feature class called 'pop_est', but these values are always 0. Additionally, trying to print f throws an error:

Feature (Error) Failed to decode JSON. Error: Field 'value' of object '{"type":"ArgumentRef","value":null}' is missing or null. Object: {"type":"ArgumentRef","value":null}.

I believe this error occurs because I am trying to call print(), a client-side function inside a server-side function, map(). I have a hunch the first error is also a result of some client-side/server-side confusion and would love some help on how to fix my code.

2) Even if this code does work I am worried that calling a reduceRegion() on each feature will take too long, causing google earth engine to shut down the computation.

How do I allow for a longer runtime or devote more computing power to this operation?

I've read that exporting is one way to attain longer runtimes, but I'm unfamiliar with the procedure.

I've tried several other approaches at this point, like clipping each feature out of my Density_Image and then putting those in an ImageCollection and mapping through that. I also tried reduceRegions(), but neither worked because their computations took too long.

  • Yes, you cannot use print inside a map function. The error is not easy to reproduce for me, I don't have a density_image neither your feature collection Commented Mar 19, 2018 at 23:19
  • If you want to reduce over multiple regions (i.e. a FeatureCollection) at once why not use . reduceRegions()? This basically maps a .reduceRegion() call to each feature inside a FC.
    – Kersten
    Commented Mar 20, 2018 at 14:53
  • Thanks for your replies. @RodrigoE.Principe, how can I send you my image and feature collections? Kersten, I tried the reduceRegions() but my computation timed out. Another thing to note is that within each feature's geometry are sometimes several separate geometries. Would this complicate the map function?
    – jhack2
    Commented Mar 20, 2018 at 15:30
  • You can share the GEE working environment with the "Get Link" button in the code editor. If you have FusionTables or Assets in there those need to be set to "Share with everyone who has the link" - otherwise we won't be able to see them.
    – Kersten
    Commented Mar 21, 2018 at 16:04


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.