0

I want to export image to drive for my roi. For this i have specified a geometry(roi). But exported map doesn't cover the area specified and it's not showing the color palette. Is there any possible way to export a colored image (which shows in my layer) to Drive? Why it's not covering the region I have specified. Problem is in export.To.Drive section. But all the codes are given to check error that i did.

Code was:

var region = ee.FeatureCollection('users/karmakersourav/shape')
  .filter(ee.Filter.eq('NAME_1', 'Chittagong'));  
var addNDVI = function(image) {  
  var ndvi= image.normalizedDifference(['B4', 'B3']).rename('NDVI');  
  return image.addBands(ndvi);  
};  

var cloudMask = function(image) {  
  var clouds = ee.Algorithms.Landsat.simpleCloudScore(image).select(['cloud']);  
  return image.updateMask(clouds.lt(25));  
};  
// Select the land mask.  
var landMask = function(image) {  
var datamask = hansenImage.select('datamask');  
// Create a binary mask.  
var mask = datamask.eq(1);  
return image.updateMask(mask);  
};    
// Load a Landsat collection, apply the NDVI and cloud/water masking functions over it.  
var collection1 = ee.ImageCollection('LANDSAT/LE07/C01/T1_RT_TOA')  
  .filterBounds(region)  
  .filterDate('2008-01-01','2008-12-31')  
  .map(addNDVI)  
  .map(cloudMask)  
  .map(landMask)  
  .select('NDVI') ;  
print(collection1);   

//reducer  
var annualNDVI = collection1.reduce(ee.Reducer.median());  
var region_NDVI = annualNDVI.reduceRegions({  
  collection: region,  
  reducer: ee.Reducer.median(),  
  scale: 30 // the resolution of the dataset  
});   

var ndviParams = {min: -1, max: 1, palette: ['blue', 'white','green']};  
var boundParams = {palette: ['black']};  
Map.addLayer(annualNDVI.clip(region), ndviParams, 'NDVI', 1);   
Map.addLayer(region, boundParams, 'LA', 1);  

//here's the problem

Export.image.toDrive({  
 image: annualNDVI,  
 description: 'CTG_NDVi',  
 scale: 30,  
 region: roi,  
 fileFormat: 'GeoTIFF',  
 maxPixels: 1e12,  
 formatOptions: {  
    cloudOptimized: true  
  }  
});  

My imports was:

var image = ee.Image("UMD/hansen/global_forest_change_2015_v1_3"),  
    region = ee.FeatureCollection("users/karmakersourav/shape"),  
    hansenImage = ee.Image("UMD/hansen/global_forest_change_2015"),  
    roi = /* color: #98ff00 */ee.Geometry.Polygon(  
        [[[91.26571433292804, 22.382447200369512],
          [91.70516745792804, 22.24015355729955],
          [91.81503073917804, 21.50608889294255],
          [91.99081198917804, 21.158146277513005],
          [92.36434714542804, 20.74775339022756],
          [92.38631980167804, 21.362918378188724],
          [92.68868864595584, 21.285515736407884],
          [92.66671598970584, 22.12251851402064],
          [92.42501677095584, 22.964696114885136],
          [92.43600309908084, 23.237540932485988],
          [92.31515348970584, 23.620600408965007],
          [92.21627653658084, 23.781555321668222],
          [92.04049528658084, 23.691042604440895],
          [91.90865934908084, 23.731278240693108],
          [91.89767302095584, 23.47960242153599],
          [91.75485075533084, 23.28800680321665],
          [91.77682341158084, 23.08602889002461],
          [91.61202848970584, 22.99503954262493],
          [91.46920622408084, 23.277915158047364],
          [91.34835661470584, 23.308187798303887],
          [91.22750700533084, 23.600467103459394],
          [91.28243864595584, 23.872005072934794],
          [91.32638395845584, 24.082808607079368],
          [91.24947966158084, 24.263221977268092],
          [91.06271208345584, 24.223152164577193],
          [90.73312223970584, 23.88205115062075],
          [90.63424528658084, 23.660857737733508],
          [90.54635466158084, 23.328365731356676],
          [90.65621794283084, 22.83312931280329],
          [90.98580778658084, 22.437667249990497],
          [90.98580778658084, 22.071621721722586]]]);
1

You have two question. The first one is why the color pallet is not showing in the exported image.

Actually, you export an one-banded ('gray-scale') image and the visualization you provided in the web API of GEE is only for the visualization there. In a program you open the GeoTiff (e.g. ArcMap), you will have to set the visualization parameters again, as the program just reads the values of each pixels and usually by default give it a gray scale.

Your seconds question relates to the geometry. You present the image on the Map in the API clipped to 'region', while you export the image using 'roi'. This explains why it is different. I would recommed to clip the image by region (which is a feature collection, so use clipToCollection), and export the image by the bounding rectangle of that feature collection.

Export.image.toDrive({  
 image: annualNDVI.clipToCollection(region),  
 description: 'CTG_NDVi',  
 scale: 30,  
 region: ee.Feature(region.first()).bounds(),  
 fileFormat: 'GeoTIFF',  
 maxPixels: 1e12,  
 formatOptions: {  
    cloudOptimized: true  
  },
  skipEmptyTiles: true
});

Furthermore, you could scale the image pixel values to 0-255 (8-bit integers), knowing that NDVI ranges between -1 and 1, to save storage space and increase your download speed:

var toBytes = annualNDVI.add(1).multiply(122.5).toByte();

link script

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.