1

I'm trying to find the area of a classified land cover across the study area using the Google Earth Engine's Python API. I am trying to do this by mapping a .reduceRegion function across the image collection using the approach below.

# Salt marsh extents are images where pixels = 1 if salt marsh has been detected

salt_marsh_area = salt_marsh_extents.map(lambda image:
                                      image.reduceRegion(
                                          reducer=ee.Reducer.sum(),
                                          geometry=whole_estuary.geometry(),
                                          scale=30
                                      ))

However, when I try and export this to my Google Drive or use a .getInfo() to inspect the result I get an error of ee.ee_exception.EEException: Collection.map: A mapped algorithm must return a Feature or Image.

How do you convert this into a table format for export?

1 Answer 1

1

.reduceRegion() returns an ee.Dict. You can use this, wrap it into an ee.Feature without setting a geometry and return that feature. In the end you can export this Feature Collection as a CSV to get a table with your values. This is how you would do it:

def reduce_salt(image):
  reduced = image.reduceRegion(
              reducer=ee.Reducer.sum(),
              geometry=whole_estuary.geometry(),
              scale=30)
  return ee.Featue(None, reduced)

salt_marsh_area = salt_marsh_extents.map(reduce_salt)

task = ee.batch.Export.table.toDrive(
  collection=salt_marsh_area,
  description='reduced',
  fileFormat='CSV'
);

task.start()
2
  • Hi thanks for the response, I've just given it a try and it works perfectly. I'm just curious, what is the role of the None statement here?
    – joe_agate1
    Commented Mar 4, 2021 at 11:04
  • The first argument given to an ee.Feature is the geometry. So you could also give it whole_estuary.geometry() instead of None. With None it simply doesn't get a geometry, it only gets the properties. In Python you could probably also skip the None altogether and supply it with a keyword, like this ee.Feature(properties=reduced)
    – JonasV
    Commented Mar 5, 2021 at 7:25

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.