0

I am running analysis on forest area MultiPolygons to calculate tree cover loss using the Hansen et al dataset (ee.Image('UMD/hansen/global_forest_change_2020_v1_8')).

I am running into problems because the MultiPolygon I am using is made up of 5000 Polygons. If I try to run the pass the whole thing through a function then GEE times out and I get the error: 'EEException: Request payload size exceeds the limit: 10485760 bytes.'

Is there a way to manage this efficiently?

I can run the analysis in segments like this (hansen_map(forest_multipolygon[500:1000])) but I then end up with only a section of the forest area on the map and I would like to visualise the total project area in one go.

The function and Python code I am using is below:

def hansen_map(coord):
    Map = geemap.Map()
    forest_threshold = 30
    proj = ee.Projection('EPSG:3857')
    
    loc = ee.Geometry.MultiPolygon(coord)#.MultiPolygon(coord)

    # Import Hansen dataset with it clipped for the specific loc based upon project coordinates

    hansen_dataset = ee.Image('UMD/hansen/global_forest_change_2020_v1_8').clip(loc)

    # Add map layers with visual parameters

    treeCoverVisParam = {
        'bands': ['treecover2000'],
        'min': 0,
        'max': 100,
        'palette': ['black', 'green']
    }
    Map.addLayer(hansen_dataset, treeCoverVisParam, 'tree cover')

    treeLossVisParam = {
      'bands': ['lossyear'],
      'min': 0,
      'max': 20,
      'palette': ['yellow', 'red']
    }
    Map.addLayer(hansen_dataset, treeLossVisParam, 'tree loss year')

    visParams_forest21 = {'palette': 'green'}


    ##-----------------------------------------------------------------------------
    ## Define the forest extent using Hansen tree cover and forest definition
    ##-----------------------------------------------------------------------------

    # Get the various image from Hansem - select loss and tree cover bands - reproject the raster

    tree00 = hansen_dataset.select(['treecover2000']).reproject(proj,None, 30)
    landmask = hansen_dataset.select(['datamask']).reproject(proj,None,30)
    gainImage = hansen_dataset.select(['gain']).reproject(proj,None,30)

    # mask the area only the non-deforested and define the forest extent

    tree21_reclass_proj = tree00.updateMask(lossImage.eq(0)).gte(forest_threshold)

    # produce the forest extent area

    tree21 = tree21_reclass_proj.updateMask(tree21_reclass_proj.eq(1))

    # display results on map

    Map.addLayer(tree21.clip(loc),visParams_forest21, 'Forest Extent 2021')
    
    return Map

1 Answer 1

1

If I try to run the pass the whole thing through a function then GEE times out and I get the error: 'EEException: Request payload size exceeds the limit: 10485760 bytes.'

coords is too much data to pass through the API in a single call not meant for that purpose. Upload your geometry as a table asset; manually if the data set is static, or using ee.data.startTableIngestion if it needs to be automated.

Then use that as the loc value:

loc = ee.FeatureCollection('users/me/my_region_of_interest')

After you do that, it's also good practice to replace .clip(loc) with .clipToCollection(loc) (because the latter avoids a potentially expensive geometry union operation), but that will make no difference if the table asset contains exactly one feature (geometry). Note that sufficiently large geometries may be split into multiple features when uploaded.

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.