Google Earth Engine video export error (a.element.map is not a function) - google-earth-engine

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); }),
...

Related

How do I merge a collection of imagines into a single image then export it

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([])))

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
});

recursive function on each pixel in google earth engine

I want to filter time series in the google earth engine which requires two for loops over time-series of a single pixel. I searched around and not found any example related to this. I know about .map function and I am using it for the generation of RVI on the earth engine. I found about .toArray function but not found any example related to my problem.
I will appreciate any help in this regard. Also, I am new to the earth engine so this may be a trivial question for others.
This is the code that I have. I took it from a blog and modified it according to my need. I am stuck after this.
var sentinel1 = ee.ImageCollection('COPERNICUS/S1_GRD_FLOAT');
// Filter VH, IW
var vh = sentinel1
// Filter to get images with VV and VH dual polarization.
//.filter(ee.Filter.listContains('transmitterReceiverPolarisation', 'VH'))
// Filter to get images collected in interferometric wide swath mode.
.filter(ee.Filter.eq('instrumentMode', 'IW'))
// reduce to VH polarization
//.select('VH')
// filter 10m resolution
.filter(ee.Filter.eq('resolution_meters', 10));
// Filter to orbitdirection Descending
var vhDescending = vh.filter(ee.Filter.eq('orbitProperties_pass', 'DESCENDING'));
// Filter time 2015
var vhDesc2015 = vhDescending.filterDate(ee.Date('2021-01-01'), ee.Date('2021-04-30'));
// Filter to MKD roi
var s1_mkd = vhDesc2015.filterBounds(roi);
print('All metadata:', s1_mkd);
var count = s1_mkd.size();
print('Count: ', count);
//var dates = s1_mkd.aggregate_array("system:time_start")
//print('dates: ', dates);
var dates = s1_mkd
.map(function(image) {
return ee.Feature(null, {'date': image.date().format('YYYY-MM-dd')})
})
.distinct('date')
.aggregate_array('date')
print('dates: ', dates);
var featureCollection = ee.FeatureCollection(dates
.map(function(element){
return ee.Feature(null,{prop:element})}))
//Export a .csv table of date, mean NDVI for watershed
Export.table.toDrive({
collection: featureCollection,
description: 'Timeseries',
folder: 'WC_raw',
fileFormat: 'CSV',
});
var rvi4s1 = function(img){
var vh = img.select('VH');
var vv = img.select('VV');
var col = vv.divide(vv.add(vh)).sqrt().rename('dop');
var dop = col.select('dop')
var value = dop.multiply(vh.multiply(4).divide(vv.add(vh))).rename('rvi4s1');
return value;
};
var rvi = s1_mkd.map(rvi4s1);
print(rvi);

"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'],
});

OpenLayers: parsed GeoJSON points always display at coords(0 , 0)

this is the first time i use OpenLayers and i don't understand what i'm doing wrong.
I try to display a simple point parsed from GeoJSON. The data seems to be parsed correctly (i checked with the console) but whatever point i give, it always displays at a position i guess to be LonLat(0,0) on my vector layer.
What am i doing wrong ?
var map, baseLayer, placesLayer, geojsonParser ;
// data below have been simplified and reformated to enhance readability
var geojsonData =
{
"type":"Feature",
"geometry":
{
"type":"Point",
"coordinates":[-4.0280599594116,5.3411102294922]
},
"properties":
{
"id":273,
"name":"ABIDJAN"
}
};
$(document).ready(function(){
map = new OpenLayers.Map('map');
baseLayer = new OpenLayers.Layer.OSM();
placesLayer = new OpenLayers.Layer.Vector();
geojsonParser = new OpenLayers.Format.GeoJSON();
placesLayer.addFeatures(geojsonParser.read(geojsonData));
map.addLayers([baseLayer,placesLayer]);
map.setCenter(
new OpenLayers.LonLat(-4, 5.3).transform(
new OpenLayers.Projection("EPSG:4326"),
map.getProjectionObject()
), 5
);
}); // document ready
This is the right solution:
var geojson_format = new OpenLayers.Format.GeoJSON({
'internalProjection': new OpenLayers.Projection("EPSG:900913"),
'externalProjection': new OpenLayers.Projection("EPSG:4326")
});
source: https://gist.github.com/1118357
Hi it sounds like you need to transform the long/lat coordinaites into the correct display coordinates:
You can either declare the projections and then transform your geometry feature:
var projWGS84 = new OpenLayers.Projection("EPSG:4326");
var proj900913 = new OpenLayers.Projection("EPSG:900913");
feature.geometry.transform(projWGS84, proj900913);
Or get the map projection "on the fly" more like this:
var projWGS84 = new OpenLayers.Projection("EPSG:4326");
feature.geometry.transform(projWGS84, map.getProjectionObject());
Obviously if you are using a different input projection from me change "ESPG:4326" to whatever you require.
HTH
C
EDIT:
In your case you would need to write something like:
geojsonData.geometry.transform(projWGS84, map.getProjectionObject());

Resources