2

I am trying to download (export) WorldPop data (population count at 100m spatial resolution) for 2018 for the city of London, using Google Earth Engine (GEE). The WorldPop is a yearly dataset.

There is no example available so I tried this (among other things):

var dataset = ee.ImageCollection("WorldPop/GP/100m/pop")
  .filter(ee.Filter.date('2018-01-01', '2018-12-31'));
  
var bands = 'population'
  
var visualization = {
  bands: ['population'],
  palette: ['24126c', '1fff4f', 'd4ff50']
};

Map.addLayer(dataset, visualization, 'Population');
  
Export.image.toDrive({
  image: dataset,
  description: 'pop',
  scale: 100,
  region: table,
  maxPixels: 1000000000000,
  crs: 'EPSG:27700',
  folder: 'Landsat-5'
});

but I am getting this error:

Error: Image.setDefaultProjection, argument 'image': Invalid type. Expected type: Image<unknown bands>. Actual type: ImageCollection. (Error code: 3)

which means I am trying to export the entire image collection (I don't want that). How can I export the population of London for the year 2018?

Here is the link to my code and here is the link to the asset.

2
  • 1
    A filtered collection is still a collection. You want to take the .first() element of the collection and export that. Nov 28, 2022 at 18:42
  • var dataset = ee.ImageCollection("WorldPop/GP/100m/pop") .filter(ee.Filter.date('2018-01-01', '2018-12-31')) .filterBounds(table) .select('population') .first() .clip(table); It worked.
    – Nikos
    Nov 28, 2022 at 18:57

1 Answer 1

3

You need to select the image from the collection. What I do here is use the table to filter the collection spatially. Then I convert the image collection to an image list, and finally, I extract the image from the list to export it.

var dataset = ee.ImageCollection("WorldPop/GP/100m/pop")
  .filter(ee.Filter.date('2018-01-01', '2018-12-31')).filterBounds(table);

//Convert to collection list
var list_img = dataset.toList(dataset.size());

// Select the image on the collection list
var img = ee.Image(list_img.get(0)); // or any image of your preference

 var bands = 'population'
  
var visualization = {
  bands: ['population'],
  palette: ['24126c', '1fff4f', 'd4ff50']
};

 Map.addLayer(dataset, visualization, 'Population');
  
Export.image.toDrive({
  image: img,
  description: 'pop',
  scale: 100,
  region: table,
  maxPixels: 1000000000000,
  crs: 'EPSG:27700',
  folder: 'Landsat-5'
});

3
  • You should not convert the collection to list (or use collection.size() to determine how big the list should be). Both are potentially expensive and unnecessary. collection.first() is what you should use. Nov 29, 2022 at 19:18
  • After collection.filterBounds I get 3 images: features: List (3 elements) 0: Image WorldPop/GP/100m/pop/GRB_2018 (1 band) 1: Image WorldPop/GP/100m/pop/RUS_2018 (1 band) 2: Image WorldPop/GP/100m/pop/USA_2018 (1 band). Then, how to get image 1 or 2 without expensive and unnecessary computations? @Noel Gorelick
    – OscarBau
    Nov 30, 2022 at 8:04
  • You can mosaic() those together if you need them all (they're different regions). Dec 1, 2022 at 10:27

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.