2

I tried to clip using a loaded shapefile. It enables me to download but crushes at few seconds not completing the downloading task.

var clipToCol = function(image){
  return image.clip(export_geometry_2);
};

var dataset = ee.ImageCollection("WorldPop/GP/100m/pop").map(clipToCol)
                .filterDate('2017');
var worldPop = dataset.select('population');

var populationVis = {
  min: 0.0,
  max: 50.0,
  palette: ['24126c', '1fff4f', 'd4ff50'],
};

Map.addLayer(worldPop, populationVis, 'Population');

var export_geometry_2 = ee.FeatureCollection("users/gabiklm01/polyMosaic");

Export.image.toDrive({
image: dataset.select('population'),
description: 'worldPop',
scale: 100,
region: export_geometry_2
})
4
  • You can't export an imageCollection, only an image. Use something like dateset.mean() or dataset.mosaic() to transform to an image.
    – Kuik
    Feb 19, 2020 at 4:45
  • I tried the dataset.mea() and worked I could download the image, but my question: am I getting the image values or just a mean--average-- of the values?
    – Gab
    Feb 19, 2020 at 7:19
  • If there are overlapping pixels in that image collection, they will be averaged. But as said there is one image for every country, so that shouldn't affect your analysis.
    – Kuik
    Feb 19, 2020 at 7:21
  • I'm selecting only one year 2017 in such case using mean will just convert to an image without altering values right?
    – Gab
    Feb 19, 2020 at 7:26

1 Answer 1

1

Without your geometry, I used one stored in my GEE assets and the following version of your code ran but, the downloading task also crushes at few seconds as you said.

var clipToCol = function(image){
  return image.clip(export_geometry_2);
};

var export_geometry_2 = ee.FeatureCollection("users/joseguerreroa/utah/utah_bounds");

var dataset = ee.ImageCollection("WorldPop/GP/100m/pop").map(clipToCol)
                .filterDate('2017');

var worldPop = dataset.select('population');

var populationVis = {
  min: 0.0,
  max: 50.0,
  palette: ['24126c', '1fff4f', 'd4ff50'],
};

Map.addLayer(worldPop, populationVis, 'Population');

Export.image.toDrive({
image: dataset.select('population'),
description: 'worldPop',
scale: 100,
region: export_geometry_2
});

So, I printed worldPop for evaluating its properties and, I found out that this Image Collection has 248 images (one for each country). I think that it's too much for being handled by Google Drive when you try to export it. As my clip area is located in USA (country code 233 in the Image Collection), I modified above code as follows and, in this case, the downloading task was completed without any problem (after downloading the image stored in Google Drive, it was also visualized in QGIS as expected).

var clipToCol = function(image){
  return image.clip(export_geometry_2);
};

var export_geometry_2 = ee.FeatureCollection("users/joseguerreroa/utah/utah_bounds");

var dataset = ee.ImageCollection("WorldPop/GP/100m/pop").map(clipToCol)
                .filterDate('2017');

var worldPop = dataset.select('population');

var listOfImages = worldPop.toList(worldPop.size());

var utah_lake = ee.Image(listOfImages.get(233)) //code for USA
                  .select('population');

var populationVis = {
  min: 0.0,
  max: 50.0,
  palette: ['24126c', '1fff4f', 'd4ff50'],
};

Map.addLayer(utah_lake, populationVis, 'Population');

Export.image.toDrive({
image: utah_lake,
description: 'utah_lake',
scale: 100,
region: export_geometry_2 
});

Editing Note:

I created a rectangle geometry in that zone and ran following script that includes Israel, Jordan, Syria, and Lebanon.

var export_geometry_2 = 
    /* color: #d63000 */
    /* displayProperties: [
      {
        "type": "rectangle"
      }
    ] */
    ee.Geometry.Polygon(
        [[[31.362499999999955, 34.50062471333177],
          [31.362499999999955, 30.27182796010966],
          [43.315624999999955, 30.27182796010966],
          [43.315624999999955, 34.50062471333177]]], null, false);

var clipToCol = function(image){
  return image.clip(export_geometry_2);
};

var dataset = ee.ImageCollection("WorldPop/GP/100m/pop")
                .filterDate('2017');

var worldPop = dataset.select('population');

print(worldPop);

var listOfImages = worldPop.toList(worldPop.size());

var israel = ee.Image(listOfImages
                  .get(108)) //code for Israel
                  .select('population');

var jordan = ee.Image(listOfImages
                  .get(112)) //code for Jordan
                  .select('population');

var lebanon = ee.Image(listOfImages
                  .get(124)) //code for Lebanon
                  .select('population');

var syria = ee.Image(listOfImages
                  .get(213)) //code for Syria
                  .select('population');

// Create a collection by giving a list.
var collection = ee.ImageCollection([israel, jordan, lebanon, syria])
                 .select('population');

print('collection: ', collection.getInfo());

var populationVis = {
  min: 0.0,
  max: 50.0,
  palette: ['24126c', '1fff4f', 'd4ff50'],
};

Map.addLayer(collection, populationVis, 'Population');

var listOfImages2 = collection.toList(collection.size());

var israel_clip = ee.Image(listOfImages2.get(0)).clip(export_geometry_2);

Export.image.toDrive({
image: israel_clip,
description: 'israel_clip',
scale: 100,
region: export_geometry_2 
});

After running the script, layers look as follows:

enter image description here

In my case, exporting task to my Google Drive took 21 minutes only for israel clipped image by export_geometry_2. For this reason I didn't export the rest of images (but, if it works for one it should work for remaining images).

After downloading israel_clip image, it looks as expected in QGIS:

enter image description here

4
  • I have a shapefile rectangle (I can sent it to you or post it here don't know how to do that...) it has part of 3 different countries: Israel, Jordan, Syria, and Lebanon. How can I adapt your code to make it useful for my case?
    – Gab
    Feb 19, 2020 at 7:20
  • maybe if I modify this part: var listOfImages = worldPop.toList(worldPop.size()); var utah_lake = ee.Image(listOfImages.get(233)) //code for USA .select('population'); to my case it will work ... how could I do that?
    – Gab
    Feb 19, 2020 at 7:31
  • @Gab Please, see my Editing Note.
    – xunilk
    Feb 19, 2020 at 16:53
  • use dataset.filterBounds(YOURGEOMETRY).mosaic() and export that image
    – Kuik
    Feb 20, 2020 at 19: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.