How do I merge a collection of imagines into a single image then export it - google-earth-engine

I would like to merge a collection of images (unknown amount) of a polygon into a single image and then export it to google drive for analysis in qgis. This is the code I have tried to us
// Define the AOI
var aoi = XXX;
Map.centerObject(aoi);
Map.setOptions('SATELLITE');
var dataset = ee.ImageCollection('UQ/murray/Intertidal/v1_1/global_intertidal');
var visualization = {
bands: ['classification'],
min: 0.0,
max: 1.0,
palette: ['0000FF']
};
Map.addLayer(dataset, visualization, 'Intertidal areas');
I have tried the following code to export the image, but obviously because I am viewing a collection of images, I cannot export a single image of the mosaic
// Export to base Google Drive
Export.image.toDrive({ image: FraserRiver , description: 'exportToDrive', fileNamePrefix: ' FraserRiver', scale: 30, region: aoi, maxPixels: 800000000000 });

This code simply extracts all bands within an image collection and put them in one single image (got the idea from https://www.nature.com/articles/s41597-021-00827-9):
// Function to merge bands
var mergeBands = function(image, previous) {
return ee.Image(previous).addBands(image);
};
// Merge bands
var image = ee.Image(mycollection.iterate(mergeBands, ee.Image([])))

Related

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

I'm new to use Google Earth Engine and trying to export satellite image dataset to my google drive folder. But I'm getting the error below.
Error: Exported bands must have compatible data types; found inconsistent types: Float32 and Byte.
This is my code.
var dataset = ee.ImageCollection('FIRMS')
.filterDate('2021-04-01', '2021-11-10')
.filterBounds(roi)
.sort('CLOUD_COVER')
.first()
var fires = dataset.select('T21');
var firesVis = {
min: 325.0,
max: 400.0
};
Map.addLayer(fires.clip(roi), firesVis, 'California Fires 2021');
Map.centerObject(roi,15);
// Export data to google drive
Export.image.toDrive({
image : fires,
description : 'California_wildfires_2021',
scale : 30,
region : roi,
maxPixels : 1e13
})
Any help is appreciated.
Also please let me know how to convert the tiff files to images(png/jpeg/jpg).
Now, add any shapefile or roi and try it.
In the middle of the code their I had used max(),there you can use mean(), median() and min() etc.,
here is the code:
var dataset = ee.ImageCollection('FIRMS').filter(
ee.Filter.date('2021-04-01', '2021-11-10'));
var fires = dataset.select('T21').max().clip(shp);
var firesVis = {
min: 325.0,
max: 400.0,
palette: ['red', 'orange', 'yellow'],
};
Map.centerObject(shp, 6);
Map.addLayer(fires, firesVis, 'Fires');
// Export data to google drive
Export.image.toDrive({
image : fires,
description : 'California_wildfires_2021',
scale : 1000,
region : shp,
maxPixels : 1e13
});

How do you import sentinel - 2 data in Earth engine

This is the code i have so far.
var roi = ee.FeatureCollection(polygon);
Map.addLayer(roi, {}, 'Turkey');
//Load Sentinel data
var image = ee.ImageCollection("COPERNICUS/S2_SR")
filterDate('2019-04-01', '2019-04-10')
//Remove cloud contamination
.filter(ee.Filter.lt('CLOUDY_PIXEL_PERCENTAGE', 20))
.filterBounds(roi)
//Visualise data
var visParamsTrue = {bands: ['B4', 'B3', 'B2'], min:0, max:2500 ,gamma:1.1};
Map.addLayer(image.clip(roi), visParamsTrue, 'Sentinel 2019');
Map.centerObject(roi, 20);
I want to import sentinel - 2 data within the study region using Google Earth Engine.
This is just an example of the expected result -
Sentinel data is imported within the vector points
This is what i get -
Sentinel data is not imported
How do i fix this?
The code above is taken from the youtube video : https://www.youtube.com/watch?v=N_yJDMgRfik

"The service is currently unavailable" Google earth engine

I am trying to produce some Landsat images which are intersecting large rivers. The output of the code is ImageID. However, when I run the code, it takes about 5 mins and shows "The service is currently unavailable" or "User memory limit exceeded". I guess too many images are selected and sorted. Please help. Any suggestions would be truly appreciated.
https://code.earthengine.google.com/1167e0c6656b0e99a345d15643a671b7
var table2 = ee.FeatureCollection("users/bo_wang1/Yukon_River");
//1. Display the shapefile into the interactive map
//Display the view to the center of the screen and scale the view
Map.centerObject(table2,10);
//Define styling and determine the color of the shapefile
var styling = {color: 'red', fillColor: '00000000'};
Map.addLayer(table.style(styling));
//2. Loading L8 image collection (TOA reflectance)
var l8_collection= ee.ImageCollection('LANDSAT/LC08/C01/T1_SR');
//3. Filter by time window
var x1= l8_collection.filterBounds(table2)
.filterDate('2019-05-01', '2019-09-30')
.sort('CLOUD_COVER');
print ('L8 2019 image collection:',x1);
print('# images', x1.size());
// extract the different rows and paths
var distinctRows = x1.distinct(['WRS_ROW']).aggregate_array('WRS_ROW');
var distinctPaths = x1.distinct(['WRS_PATH']).aggregate_array('WRS_PATH');
print(distinctRows, distinctPaths)
//Extract least cloudy L8 scene in each tile
var imagePerPath = distinctPaths.map(function(path){
var imagePerRow = distinctRows.map(function(row){
var images = x1.filter(ee.Filter.and(ee.Filter.eq('WRS_ROW', row), ee.Filter.eq('WRS_PATH', path)));
return images.sort('CLOUD_COVER').first();
});
return imagePerRow;
});
var leastCloud = ee.ImageCollection.fromImages(imagePerPath.flatten());
// print and add the geometries of the images to the map
Map.addLayer(ee.FeatureCollection(leastCloud.map(function(image){return image.geometry()})))
print('leastCloud',leastCloud);
//Get the number of images
var count = leastCloud.size();
print('Count:', count);
//Get and print property and ImageID
print(leastCloud.first().propertyNames());
var imageID = leastCloud.aggregate_array('LANDSAT_ID');
print(imageID);
//Export Landsat_ID to CSV
Export.table.toDrive({
collection: leastCloud,
description: 'Get_ImageID',
folder: 'Shapefile from GEE',
fileFormat: 'CSV',
selectors: ['LANDSAT_ID'],
});

Google Earth Engine video export error (a.element.map is not a function)

I'm trying to export a time-lapse here but got a weird error:
Error Creating or Submitting Task
a.element.map is not a function
I want to keep the visParams on my exported video by visualize() which I'm not sure is the right way to do so or not. do you have any suggestions for it?
var l8 = ee.ImageCollection("LANDSAT/LC08/C01/T1_TOA"),
region = ee.Geometry.Polygon(
[[[44.76385083079123, 38.28074335406828],
[44.76385083079123, 37.1334667575582],
[46.08221020579123, 37.1334667575582],
[46.08221020579123, 38.28074335406828]]], null, false),
params = {"opacity":1,"bands":["B4","B3","B2"],"min":0.07630298537191671,"max":0.3954072752450793,"gamma":1.356};
var collection = l8.filterBounds(region)
.filterMetadata('CLOUD_COVER', 'LESS_THAN', 30);
.filterDate('1999-01-01', '2020-01-01');
var l8med = collection.median();
Map.addLayer(collection, params, 'Layer');
print(collection.size());
var newimg = l8med.visualize(params);
Export.video.toDrive({
collection: newimg,
description: 'a1',
dimensions: 720,
framesPerSecond: 12,
folder: "GEE",
maxFrames: 100000,
region: region
});
You made a single image out of the collection using .median() and then tried to export that, so it can't work — there's no time series to make a video out of, after that.
You do need .visualize() but you need to do it for each image:
Export.video.toDrive({
collection: collection.map(function (image) { return image.visualize(params); }),
...

How to increase resolution of exported image in Google Earth Engine?

I have some code to export an LS8 image to Drive using GEE. Somehow, the resolution of the image seems to be lower (larger pixels) than what I am able to see on the browser. How can I increase the resolution? This is the code I´ve been using, with two different options.
I attempted to use .resample() as a solution but it produced a single band image that did not look good.
geometry2 = /* color: #57d64b */ee.Geometry.Polygon(
[[[-78.2812086867645, 2.3386717366200585],
[-77.56984394067075, 2.3729749945579948],
[-77.72227924340513, 2.776314152654142],
[-78.20842426293638, 2.725560942159387]]]);
function maskL8sr(image)
{
// Bits 3 and 5 are cloud shadow and cloud, respectively.
var cloudShadowBitMask = ee.Number(2).pow(3).int();
var cloudsBitMask = ee.Number(2).pow(5).int();
// Get the pixel QA band.
var qa = image.select('pixel_qa');
// Both flags should be set to zero, indicating clear conditions.
var mask = qa.bitwiseAnd(cloudShadowBitMask).eq(0)
.and(qa.bitwiseAnd(cloudsBitMask).eq(0));
// Return the masked image, scaled to TOA reflectance, without the QA bands.
return image.updateMask(mask).divide(10000)
.select("B[0-9]*")
.copyProperties(image, ["system:time_start"]);
}
// Map the function over one year of data.
var collection = ee.ImageCollection('LANDSAT/LC08/C01/T1_SR')
.filterDate('2016-04-01', '2018-7-31')
.map(maskL8sr)
var composite = collection.median();
var VIS = {bands: ['B5', 'B6', 'B4'], min: 0, max: 0.47};
// Display the results.
Map.addLayer(composite,VIS ,"compt2");
var params ={
crs: 'EPSG:4326',
maxPixels: 1e12,
region:geometry2
}
Export.image(composite,'Guapi',params);
Export.image.toDrive({
image: composite,
description: 'Guapi',
scale: 30,
region: geometry2,
maxPixels: 1000000000
});

Resources