2

I'm starting to use the GEE Python API and I'm struggling with the translation of some instructions from JavaScript to Python.

I'm using the following code in JS:

var all_alerts  = ee.ImageCollection('projects/glad/alert/UpdResult')
var country     = ee.FeatureCollection('USDOS/LSIB_SIMPLE/2017').filter(ee.Filter.eq('country_co', 'CG'));
var alerts_2020 = all_alerts.select('conf20').mosaic().clip(country);  

Export.image.toDrive({
  image:alerts_2020,
  description:'alerts_rdc_2020',
  scale: 30,
  region:country,
  maxPixels: 1e10
})

and it work like a charm.
Naive I'd like to make the same with the python API:

def get_alerts(country_code, year):
    country = ee.FeatureCollection('USDOS/LSIB_SIMPLE/2017').filter(ee.Filter.eq('country_co', country_code))
    all_alerts  = ee.ImageCollection('projects/glad/alert/UpdResult')
    alerts = all_alerts.select(year).mosaic().clip(country);
    
    file_name = 'alerts_' + country_code + '_' + year
    task_config = {
        'image':alerts,
        'description':file_name,
        'scale': 30,
        'region':country,
        'maxPixels': 1e10
    }
    
    task = ee.batch.Export.image.toDrive(**task_config)
    task.start()

country_code = 'CG'
year= 'conf20'
get_alerts(country_code, year)

The task start on my GEE taskboard but rise the following error :

Error: GeometryConstructors.LineString, argument 'coordinates': Invalid type. Expected type: List. Actual type: FeatureCollection.

which I don't understand because it the exact same call I was making (or so I think).

4

I think adding .geometry() after country will work:

task_config = {
    'image':alerts,
    'description':file_name,
    'scale': 30,
    'region':country.geometry(),
    'maxPixels': 1e10

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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