3

On Google Earth Engine I'm trying to download some display images using the method image.getThumbURL. The image shows well in Map.addLayer, but when I pass it through getThumbURL I only get a blank image. Here an example of this behavior:

var point = ee.Geometry.Point([11.300422012780208, 44.50570009326473])
var pngArea =
    ee.Geometry.Polygon(
        [[[10.966712295983333, 44.65340259358304],
          [10.966712295983333, 44.24754759759594],
          [11.738501846764583, 44.24754759759594],
          [11.738501846764583, 44.65340259358304]]], null, false)

var s2coll = ee.ImageCollection("COPERNICUS/S2")
s2coll = s2coll.filterBounds(point)
        .filterDate('2018-07-15', '2018-07-30')
print(s2coll)
var img = s2coll.mosaic()
print(img)
var visualization = {
  min: 0.0,
  max: 2000,
  bands: ['B4', 'B3', 'B2'],
}
var outImg = img.visualize(visualization)
Map.addLayer(outImg)

print(outImg.getThumbURL({region: pngArea, format: 'png'}))

https://code.earthengine.google.com/89afe6e672f63d2245ef438288f78f55

What am I doing wrong?

6

You did not specify a scale, and provided a region whose coordinate system is in degrees. Thus, you got a very small image (2 × 1 pixels).

If you specify a scale, you'll get an image:

print(outImg.getThumbURL({region: pngArea, scale: 200, format: 'png'}));

Scale 200

You can also specify explicit dimensions, but that may get you a distorted image if the dimensions don't match the region's aspect ratio:

print(outImg.getThumbURL({
  region: pngArea,
  dimensions: '150x150',
  format: 'png',
}))

150x150

Another option you may be interested in is crs to use the image's projection (or any projection) instead of the region's projection:

print(outImg.getThumbURL({
  region: pngArea,
  crs: s2coll.first().select('B4').projection(),
  scale: 200,
  format: 'png',
}))

Used image's projection

This version does not have a slanting right edge because the exported image rectangle is using the same coordinate system as (at least one of) the original images.

It's also generally a good idea to use a projection intended for mapping (whether it's the image's projection or another one), rather than the degrees longitude & latitude you're using for your region (which is what Earth Engine defaulted to in absence of a better idea), which will have distorted pixels as you get closer to the poles. Notice that this image is closer to the aspect ratio of your original rectangle on the map, whereas the first one that only specifies scale is stretched wider than it should be.

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.