-1

I am new to GEE. I'm working with Landsat images. First, visualizing them in the map, then downloading them and working with them afterwards in QGis 3.6 to obtain certain indexes (NDVI, NDWI, Wetness) for some dates.

They sent me a code to do this with Landsat 8 images, and it works perfect for the dates > 2013. I can visualize the Landsat images and then download them to me Drive, after making sure cloud cover is < 10.

The code is this one:

var L8 = ee.ImageCollection("LANDSAT/LC08/C01/T1_RT"),
    Zona = 
    /* color: #ff0000 */
    /* displayProperties: [
      {
        "type": "rectangle"
      }
    ] */
    ee.Geometry.Polygon(
        [[[-69.65662957471234, -19.253174496773713],
          [-69.65662957471234, -19.86525490862596],
          [-68.83402825635297, -19.86525490862596],
          [-68.83402825635297, -19.253174496773713]]], null, false);

//AGREGAR MANUALMENTE:
// Polígono que incluya la zona cuyas imágenes se quieren 
// descargar (dibujar con el mouse)

// Parámetros visualización para el mapa
var imageVisParam = {bands: ["B7","B5","B2"], max: 18241, min: 6422}

//Fechas (ir modificando manualmente)
var date1 = ee.Date('2019-08-01');
var date2 = ee.Date('2019-08-30');

// Filtrar para la fecha requerida y para cobertura de nubes 
var L8_d1 = L8
  .filterBounds(Zona)
  .filterDate(date1, date2)
  .filterMetadata("CLOUD_COVER", "less_than", 10);
print(L8_d1)

// Cortar al área de estudio
var mask = function(image){
  var cortada = image.clip(Zona);
  return cortada 
};

var L8clipped = L8_d1.map(mask)
var newr = L8clipped.max()

Map.addLayer(newr, imageVisParam, "landsat")

// Exportar la imagen, especificando escala y región.
Export.image.toDrive({
  image: newr,
  description: 'Landsat_01',
  folder: 'GoogleEngine', //cambiar según su carpeta
  scale: 30,
  region: Zona
});

The problem is now I need more old images (~ 1985-2013), so I want to do the exact same thing, but with Landsat 5. But when I try to modify the original code in order to do this, I can't visualize the images. All I get is a redder square.

The code I'm trying for this last thing is this one:

var L5 = ee.ImageCollection("LANDSAT/LT05/C01/T1"),
    Zona = 
    /* color: #ff0000 */
    /* displayProperties: [
      {
        "type": "rectangle"
      }
    ] */
    ee.Geometry.Polygon(
        [[[-69.89558221143109, -19.73992297777349],
          [-69.89558221143109, -20.35013752032207],
          [-68.78458977979047, -20.35013752032207],
          [-68.78458977979047, -19.73992297777349]]], null, false);

// AGREGAR MANUALMENTE:
// Polígono que incluya la zona cuyas imágenes se quieren 
// descargar (dibujar con el mouse)

// Parámetros de visualización para el mapa
var imageVisParam = {bands: ["B7","B4","B1"], max: 20000, min: 6000}

// Fechas (ir modificando manualmente)
var date1 = ee.Date('2006-07-01');
var date2 = ee.Date('2006-07-31');

// Filtrar para la fecha requerida y para cobertura de nubes 
var L5_d1 = L5
  .filterBounds(Zona)
  .filterDate(date1, date2)
  .filterMetadata("CLOUD_COVER", "less_than", 10);
print(L5_d1);

// Cortar al área de estudio
var mask = function(image){
  var cortada = image.clip(Zona);
  return cortada 
};

var L5clipped = L5_d1.map(mask);
var newr = L5clipped.max();

Map.addLayer(newr, imageVisParam, "landsat");

// Exportar la imagen, especificando escala y región.
Export.image.toDrive({
  image: newr,
  description: 'Landsat_Sept06',
  folder: 'GoogleEngine', //cambiar según su carpeta
  scale: 30,
  region: Zona
});

I've tried modifying the dates, the cloud cover, and the visualization parameters (bands, max and min) and nothing. And when I try downloading them, the following error appears:

Error: Exported bands must have compatible data types; found inconsistent types: Byte and UInt16.

I don't quite understand the max and min from the visualization, I think the error might be there.

Can someone explain what they mean and how to get them for different images (to learn how to do it in the future)?

Do you have recommendations for images sets to work with?

I don't know which sets are available for this kind of work in GEE.

1

OK I edited your code slightly but this should work in a similar fashion to the code you used for Landsat 8.

The min and max in the visualization parameters specify a valid range of values to show in the map console. If your range is too high or too low, you will get an all white or all black image in the map display. In this case, Landsat 5 values are 8-bit integers and can only be from 0-255, so I adjusted the min and max values to values within that range. This only controls what you see on the map, not what is exported.

For the export issue, I used .select() to select the 7 bands of similar pixel type.

var L5 = ee.ImageCollection("LANDSAT/LT05/C01/T1"),
    Zona = 
    /* color: #ff0000 */
    /* displayProperties: [
      {
        "type": "rectangle"
      }
    ] */
    ee.Geometry.Polygon(
        [[[-69.89558221143109, -19.73992297777349],
          [-69.89558221143109, -20.35013752032207],
          [-68.78458977979047, -20.35013752032207],
          [-68.78458977979047, -19.73992297777349]]], null, false);

// AGREGAR MANUALMENTE:
// Polígono que incluya la zona cuyas imágenes se quieren 
// descargar (dibujar con el mouse)

// Parámetros de visualización para el mapa
var imageVisParam = {bands: ["B7","B4","B1"], max: 150, min: 0}

// Fechas (ir modificando manualmente)
var date1 = ee.Date('2006-07-01');
var date2 = ee.Date('2006-07-31');

// Filtrar para la fecha requerida y para cobertura de nubes 
var L5_d1 = L5
  .filterBounds(Zona)
  .filterDate(date1, date2)
  .filterMetadata("CLOUD_COVER", "less_than", 10);
print(L5_d1);

// Cortar al área de estudio
var mask = function(image){
  var cortada = image.clip(Zona);
  return cortada 
};

var L5clipped = L5_d1.map(mask);
var newr = L5clipped.max().select(['B*.']);


Map.addLayer(newr, imageVisParam, "landsat");
| improve this answer | |
  • Hi! Thank you very much. I edited the post to add my code. I'm new here so I didn't know how to do it. – AlbertoH Aug 12 at 15:56
  • Not a problem. Thanks for adding your code here. I edited my original response which should work to visualize and export the landsat 5 image. – rpr_mt Aug 12 at 17:56
  • Thank you so much, I tried it and it works. Can I ask you what's the difference between the work with Landsat 8 (max: 18241, min: 6422) and Landsat 5? What would change if I added the .select() (or what I'm losing by not doing it) to the Landsat 8 code? – AlbertoH Aug 13 at 0:40
  • That .select() just allows you to select which bands you want in the images, in this case for exporting. You wouldn't lose anything in the Landsat 8 images as all of the bands start with 'B' and would therefore be selected by the above .select() call. Hope this helps! – rpr_mt Aug 31 at 18:12
  • I'm sorry to bother again, but I've been using the code for Landsat 5 images and found that for some months I need it shows the following error: landsat: Layer error: Image.select: Pattern 'B*.' did not match any bands. I don't know what it means or how to correct it. I thought it just meant that there were no images available for that month, but I think it's no it. Could you help me solve it please? – AlbertoH Oct 16 at 14:14

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.