I try to download some data using getDownloadUrl (see below). Unfortunately, i always get the following message:
Failed to execute 'send' on 'XMLHttpRequest': Failed to load
Does anyone have an idea why this fails? I tried Export.image.toDrive as an alternative but this one fails too.
////// Get Sweden as ROI
var country = ee.FeatureCollection('USDOS/LSIB_SIMPLE/2017');
var sweden = country.filter(ee.Filter.eq('country_na', 'France'))
var roi = sweden;
Map.addLayer(roi, {}, 'ROI')
Map.centerObject(roi)
/////// START SCRIPT
// // Load satellite images
var hansenImage = ee.Image('UMD/hansen/global_forest_change_2015'); // latest version of Hansen forest layer
var mcd = ee.ImageCollection('MODIS/006/MCD64A1'); // MODIS Burned Area layer version 6
//print(mcd)
// // create forest mask for 2000 -- very low tau
var tau = 30; // Calibration parameter: Forest threshold (defaults = 20)
var forestRoi = hansenImage.select('treecover2000').clip(roi) // Crop satellite image to region of interest
var forestMask = forestRoi.gt(tau); // this is forest area in 2000
// // update forest mask to 2015
var lossImage = hansenImage.select(['loss']);
var gainImage = hansenImage.select(['gain']);
var forestMask2015 = forestMask.subtract(lossImage).add(gainImage);
//Map.addLayer(lossImage.mask(lossImage), {palette:'blue'},'loss'); Map.addLayer(gainImage.mask(gainImage), {palette:'red'},'gain')
var NewForestMask = ee.Image(forestMask2015.mask(forestMask2015))
Map.addLayer(NewForestMask, {palette:'green'}, 'Forest Mask 2015')
// // Calculate the total forest area
var forestarea=NewForestMask.multiply(ee.Image.pixelArea());
var forest_region=forestarea.reduceRegion({reducer: ee.Reducer.sum(),geometry: roi,scale: 500, maxPixels: 5e9});
print('Total forest area in 2015 (m2): ',forest_region)
// // Constrain MCD image to required time, space and band
var burndate_layer = mcd.select('BurnDate'); //
//Map.addLayer(burndate_layer, {}, 'burndate_layer')
//var qa_layer = mcd.select('QA');
var yearBegin=2017;
var yearEnd=2018;
var date1=ee.Date.fromYMD(yearBegin,1,1).format('YYYY-MM-dd');
var date2=ee.Date.fromYMD(yearEnd,12,31).format('YYYY-MM-dd');
print(date1,date2)
var collection = mcd.filterDate(date1,date2).filterBounds(roi);
print(collection)
// // identify burned pixels & calculate total burned area
// Function: Identify burnt pixel across image collection
var areaFunction = function(image) {
var test=ee.Image(image);
var correctValue = test.select('BurnDate').gt(0).and(test.select('BurnDate').lt(366));
return correctValue.mask(correctValue);
};
// Function: Convert MCD burnt pixels into forest burnt area
var burnFunction = function(image) {
var test=ee.Image(image).mask(NewForestMask);
var area=test.multiply(ee.Image.pixelArea());
return area
};
// apply both functions
var burned = collection.map(areaFunction);
var areaburned = burned.map(burnFunction);
// // Aggregate monthly burnt area
var results = ee.FeatureCollection(
areaburned.map(function(img) {
var reduced_image_data=img.reduceRegion({reducer: ee.Reducer.sum(),geometry: roi,scale: 500, maxPixels: 5e9});
return ee.Feature(null, {'result': reduced_image_data.get('BurnDate')});
}));
// // export map of all burned pixels (works only for single polygon)
var burned_i = burned.mosaic().multiply(NewForestMask)
var burned_i_all = burned.mosaic()
// var burned_i = burned.mosaic().clip(roi)
// // Visualize outputs
Map.addLayer(burned_i, {palette:'red'}, 'Forest burned areas')
Map.addLayer(burned_i_all, {palette:'darkred'}, 'all burned areas')
// // calculate burned area (2000-2017)
var burned_i_area=burned_i.multiply(ee.Image.pixelArea())
var burned_m2 = burned_i_area.reduceRegion({reducer: ee.Reducer.sum(),geometry: roi,scale: 500, maxPixels: 5e9});
print('Total forest burned area in 2000-2017 (m2): ',burned_m2)
// // Export results to .xls (date & area)
print(results.getDownloadURL('csv',['system:index', 'result', '.geo']));
// // export map using a single polygon
Export.image.toDrive({
image: burned_i,
description: "burned_area_mask",
region: roi,
scale: 30,
})
// //---------------- end of script -------------------// //
```go