0

I'm trying to export an image using a FeatureCollection as region. My code is as follow:

params = {
    'description': 'ndviChange_to_gtiff',
    'scale': 30,
    'region': AOI
  }
ee.batch.Export.image.toDrive(ndviChange, **params)

the AOI is a FeatureCollection defined earlier in my code:

AOI = ee.FeatureCollection("users/..../AOI")

I'm getting this error:

TypeError: Object of type FeatureCollection is not JSON serializable

Note that I'm running the code in QGIS GEE plugin.

1 Answer 1

2

You need to use getInfo() to extract the geometry information and then provide that to the region argument.

params = {
    'description': 'ndviChange_to_gtiff',
    'scale': 30,
    'region': AOI.geometry().getInfo()['coordinates']
  }
ee.batch.Export.image.toDrive(ndviChange, **params)

This should be able to solve the issue.

Another solution that I found from this post is to use geotools package and specify the region as:

tools.geometry.getRegion(AOI)

To upload the results to drive, you also need to start the task. Following snippet starts and logs the task status every 30 seconds:

task = ee.batch.Export.image.toDrive(ndviChange, **params)
task.start()

## get the status of task while it runs every 30 sec
import time
while task.active():
    time.sleep(30)
    print(task.status())
2
  • Thanks @shahryar, that works. But nothing is getting uploaded to my Google Drive. Am I missing something ? Commented Apr 11, 2020 at 14:58
  • Edited my answer to show the fix.
    – shahryar
    Commented Apr 11, 2020 at 16:00

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.