1

I have exported GeoTIFF files from GEE and attempted to keep the pixel value in that raster layer. Once the file was imported into ArcGIS Pro the stats (min, max, mean and sd) were stretched between 0-255 instead of keeping the original pixel value from NDVI. Below is my code:

//get mean and std of NDVI
var mean = ee.Number(stats.get('NDVI_mean'));
var std = ee.Number(stats.get('NDVI_stdDev'));
//find regions in ndvi has value higher than mean +1SD 
var maskImage = ndvi.updateMask(ndvi.gt(mean.add(std)));
//use the visualize function to set visualize parameters min and max equals to min and max in the raster 
var visualizeMinMaxNDVI = function(maskImage) {
  var minMax = maskImage.reduceRegion({
  reducer: ee.Reducer.minMax(),
  bestEffort: true,
});
  var visParams = {
          min: minMax.getNumber('NDVI_min'),
          max: minMax.getNumber('NDVI_max')
          };
  return maskImage.visualize(visParams)
            .set({min: minMax.getNumber('NDVI_min'), max: minMax.getNumber('NDVI_max')});
};

// set visualization parameters based on min and max value
var maskImage = visualizeMinMaxNDVI(maskImage);

// Export a cloud-optimized GeoTIFF.
Export.image.toDrive({
  image: maskImage,
  description: '21072016UNDVItest',
  scale: 10,
  region: table,
  fileFormat: 'GeoTIFF',
  formatOptions: {
    cloudOptimized: true
  }
});

I'm very new to GEE, I think when I export my GeoTIFF layer the data was 8 bit (shown in ArcGIS Pro) which caused the color stretch?

  • Please provide a link to a running script, with all used assets shared. – Daniel Wiell Feb 10 at 10:41
  • Hi @Daniel here is the link for the script [link] (code.earthengine.google.com/…) and here is the shared assets (the mask) link. I used sentinel 2 dataset you can add these code at the start:var imageCollection = ee.ImageCollection("COPERNICUS/S2"), table = ee.FeatureCollection("users/Xuhong/Blueskin_Bay_Mask_UTM_Erased");Thanks – Rose Chai Feb 10 at 21:49
1

When you execute this line:

var maskImage = visualizeMinMaxNDVI(maskImage);

...you are transforming the NDVI image, which I assume is floating point, to an 8-bit RGB image because it is applying .visualize() (docs).

To maintain the original NDVI values, export the original maskImage instead of the visualized version. Here, I have set the result of visualizeMinMaxNDVI(maskImage) as maskImageVis and exported the original maskImage image.

// set visualization parameters based on min and max value
var maskImageVis = visualizeMinMaxNDVI(maskImage);

// Export a cloud-optimized GeoTIFF.
Export.image.toDrive({
  image: maskImage,
  description: '21072016UNDVItest',
  scale: 10,
  region: table,
  fileFormat: 'GeoTIFF',
  formatOptions: {
    cloudOptimized: true
  }
});

Use .visualize() to style images for display, but not for analysis.

| improve this answer | |
  • Hi @Justin thanks for your answer it worked. But once I import the GeoTIFF layer into ArcGIS the area isn't in maskImage showed black and if I click on it it shows "stretch.pixel.value: nan". I used to tick "display background value" in "mask" under "symbology" in ArcGIS to get rid of the black area but it's not working this time. I can't put "nan" under "mask" I guess it only accepts number. I also tried .unmask(-9999) when exporting the image to give the unmask area a number but then in ArcGIS it changes "min" in "symbology" as -9999.... – Rose Chai Feb 11 at 0:16
  • I think you are on the right track with .unmask(-9999) and then in ArcMap add -9999 as a mask value (somewhere in the properties) and manually set the min and max to -1 and 1 respectively when you display it with stretched symbology. – Justin Braaten Feb 11 at 17:12
  • Thanks so much @Justin it worked I ended up using reclassify to generate binary layer in ArcGIS so -9999 turns out to be fine. – Rose Chai Feb 18 at 1:31

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.