0

This function returns me the longitude and latitude of the pixels. The code works fine when I only do it for the "date" band, but when I do it for the "dates" and "NDVI" bands I get this error: Error in map(ID=LT04_009055_19880921): Array: Parallel arrays must have the same length. I'm not quite sure why this happens. This is my code:


var bands = ['dates', 'NDVI']

function extractPixels(image) {
  var pixels = image
    .clip(roi)
    .select(bands)
    //.unmask(999)
    .addBands(ee.Image.pixelLonLat())
    .reduceRegion({
      reducer: ee.Reducer.toList(), 
      geometry: roi, 
      scale: 30,
      maxPixels: 1e13
    });
    
  return ee.FeatureCollection(
    ee.Array(pixels.values())
      .transpose()
      .toList()
      .map(function (values) {
        var properties = ee.Dictionary.fromLists(pixels.keys(), values);
        var longitude = ee.Number(properties.get('longitude'));
        var latitude = ee.Number(properties.get('latitude'));
        var geometry = ee.Geometry.Point(longitude, latitude);
        
        return ee.Feature(geometry, properties)
          .set('date', ee.Number(image.select('dates')))
          //.set('constant', ee.Number(image.select('constant')))
          //.set('srb4', ee.Number(image.select('SR_B4')))
          //.set('srb3', ee.Number(image.select('SR_B3')))
          .set('ndvi', ee.Number(image.select('NDVI')))
    
      })
  );
}

I tried to fix it by putting an unmask, assuming that the size of the bands is different, but it doesn't work for me.

  • Please edit the question to limit it to a specific problem with enough detail to identify an adequate answer. – Community Jul 17 '23 at 18:00

0 Answers0