You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I am a student and very new to coding on Google Earth Engine. I am attempting to export the rasters I created so that I can work with them in RStudio. The error message I get is "Error: GeometryConstructors.MultiGeometry: Geometry coordinate projection requires non-zero maxError. (Error code: 3)". I researched the error and looked at similar discussions but haven't been able to solve the issue. Any help is greatly appreciated! Here is the code:
// Define function to mask clouds, scale, and add variables
// (NDVI, time and a constant) to Landsat 8 imagery.
function maskScaleAndAddVariable(image) {
// Bit 0 - Fill
// Bit 1 - Dilated Cloud
// Bit 2 - Cirrus
// Bit 3 - Cloud
// Bit 4 - Cloud Shadow
var qaMask = image.select('QA_PIXEL').bitwiseAnd(parseInt('11111',
2)).eq(0);
var saturationMask = image.select('QA_RADSAT').eq(0);
// Apply the scaling factors to the appropriate bands.
var opticalBands = image.select('SR_B.').multiply(0.0000275).add(-
0.2);
var thermalBands = image.select('ST_B.*').multiply(0.00341802)
.add(149.0);
// Replace the original bands with the scaled ones and apply the masks.
var img = image.addBands(opticalBands, null, true)
.addBands(thermalBands, null, true)
.updateMask(qaMask)
.updateMask(saturationMask);
var imgScaled = image.addBands(img, null, true);
// Now we start to add variables of interest.
// Compute time in fractional years since the epoch.
var date = ee.Date(image.get('system:time_start'));
var years = date.difference(ee.Date('1970-01-01'), 'year');
// Return the image with the added bands.
return imgScaled
// Add an NDVI band.
.addBands(imgScaled.normalizedDifference(['SR_B5', 'SR_B4'])
.rename('NDVI'))
// Add a time band.
.addBands(ee.Image(years).rename('t'))
.float()
// Add a constant band.
.addBands(ee.Image.constant(1));
}
// //Merced point:
var centerPoint = ee.Geometry.Point([ -120.37559812236756, 37.27069238838713]);
var crop1 = ee.Geometry.Point([ -120.33645932842225, 37.28298585843524]);
var crop2 = ee.Geometry.Point([ -120.41336362529725, 37.260582920157454]);
var landsat9sr = ee.ImageCollection('LANDSAT/LC09/C02/T1_L2')
.filterBounds(roi)
.filterDate('2022-01-01', '2024-01-01')
.map(maskScaleAndAddVariable);
var landsatCombined = landsat8sr.merge(landsat9sr);
// Set map center over the ROI.
Map.centerObject(roi, 10);
// // Plot a time series of NDVI at a single location.
var landsatChart = ui.Chart.image.series(landsatCombined.select('NDVI'), centerPoint)
.setChartType('ScatterChart')
.setOptions({
title: 'Landsat 8 and 9 NDVI time series at centerPoint',
lineWidth: 1,
pointSize: 3,
});
print(landsatChart);
// // Plot a time series of NDVI with a linear trend line at a single location.
var landsatChartTL = ui.Chart.image.series(landsatCombined.select('NDVI'), centerPoint)
.setChartType('ScatterChart')
.setOptions({
title: 'Landsat 8 and 9 NDVI time series at centerPoint',
trendlines: {
0: {
color: 'CC0000'
}
},
lineWidth: 1,
pointSize: 3,
});
print(landsatChartTL);
// // List of the independent variable names
var independents = ee.List(['constant', 't']);
// // Name of the dependent variable.
var dependent = ee.String('NDVI');
// // Compute a linear trend. This will have two bands: 'residuals' and
// // a 2x1 (Array Image) band called 'coefficients'.
// // (Columns are for dependent variables)
// // Flatten the coefficients into a 2-band image.
var coefficients = trend.select('coefficients')
// Get rid of extra dimensions and convert back to a regular image
.arrayProject([0])
.arrayFlatten([independents])
.clip(roi);
//Map.addLayer(coefficients, {}, 'coefficients image');
//print(coefficients, 'coefficients');
// Compute a detrended series.
var detrended = landsatCombined.map(function(image) {
return image.select(dependent).subtract(
image.select(independents).multiply(coefficients)
.reduce('sum'))
.rename(dependent)
.copyProperties(image, ['system:time_start']);
});
// Plot the detrended results.
var detrendedChart = ui.Chart.image.series(detrended, centerPoint, null, 30)
.setOptions({
title: 'Detrended Landsat time series at ROI',
lineWidth: 1,
pointSize: 3,
trendlines: {
0: {
color: 'CC0000'
}
},
});
print(detrendedChart);
// Use these independent variables in the harmonic regression.
var harmonicIndependents = ee.List(['constant', 't', 'cos', 'sin']);
//print(harmonicIndependents, 'harmonicIndependents');
// Add harmonic terms as new image bands.
var harmonicLandsat = landsatCombined.map(function(image) {
var timeRadians = image.select('t').multiply(2 * Math.PI);
return image
.addBands(timeRadians.cos().rename('cos'))
.addBands(timeRadians.sin().rename('sin'))
.clip(roi);
});
print(harmonicLandsat, 'harmonicLandsat');
// // Fit the model.
var harmonicTrend = harmonicLandsat
.select(harmonicIndependents.add(dependent))
// The output of this reducer is a 4x1 array image.
.reduce(ee.Reducer.linearRegression(harmonicIndependents.length(),
1));
print(harmonicTrend, 'harmonicTrend');
// // Turn the array image into a multi-band image of coefficients.
var harmonicTrendCoefficients = harmonicTrend.select('coefficients')
.arrayProject([0])
.arrayFlatten([harmonicIndependents]);
// Plot the fitted model and the original data at the centerPoint.
print(ui.Chart.image.series(
fittedHarmonic.select(['fitted', 'NDVI']), centerPoint, ee.Reducer
.mean(), 30)
.setSeriesNames(['NDVI', 'fitted'])
.setOptions({
title: 'Harmonic model: original and fitted values: centerPoint',
lineWidth: 1,
pointSize: 3,
}));
// Plot the fitted model and the original data at the pecans.
// Compute phase and amplitude.
var phase = harmonicTrendCoefficients.select('sin')
.atan2(harmonicTrendCoefficients.select('cos'))
// Scale to [0, 1] from radians.
.unitScale(-Math.PI, Math.PI);
print(phase, 'phase');
var amplitude = harmonicTrendCoefficients.select('sin')
.hypot(harmonicTrendCoefficients.select('cos'))
// Add a scale factor for visualization.
.multiply(5);
print(amplitude, 'amplitude');
// Compute the mean NDVI.
var meanNdvi = landsatCombined.select('NDVI').mean();
print(meanNdvi, 'meanNdvi');
// Use the HSV to RGB transformation to display phase and amplitude.
var rgb = ee.Image.cat([
phase, // hue
amplitude, // saturation (difference from white)
meanNdvi // value (difference from black)
]).hsvToRgb();
var cdl = ee.Image('USDA/NASS/CDL/2023').select(['cropland']);
Map.addLayer(cdl.clip(roi), {}, 'CDL 2023');
// save phase, amplitude, meanNDVI, and cdl as rasters to be used in R for classification
// exports the rasters to GeoTIFFs, which will be saved in the specified folder in your Google Drive
Export.image.toDrive({
image: phase,
description: 'phase',
folder: 'RS_Lab12', // Folder you create in your Google Drive where file will write
fileNamePrefix: 'phase',
scale: 30, // Adjust the scale as needed. Resolution in meters
region: roi, // Define the region of export, here we use the image's geometry
crs: 'EPSG:4326', // Define the coordinate reference system
maxPixels: 1e13 // Adjust max pixels if needed. In this lab, your area should be small, so this won't be an issue most likely
});
Export.image.toDrive({
image: amplitude,
description: 'amplitude',
folder: 'RS_Lab12', // Folder you create in your Google Drive where file will write
fileNamePrefix: 'amplitude',
scale: 30, // Adjust the scale as needed. Resolution in meters
region: roi, // Define the region of export, here we use the image's geometry
crs: 'EPSG:4326', // Define the coordinate reference system
maxPixels: 1e13 // Adjust max pixels if needed. In this lab, your area should be small, so this won't be an issue most likely
});
Export.image.toDrive({
image: meanNdvi,
description: 'meanNdvi',
folder: 'RS_Lab12', // Folder you create in your Google Drive where file will write
fileNamePrefix: 'meanNdvi',
scale: 30, // Adjust the scale as needed. Resolution in meters
region: roi, // Define the region of export, here we use the image's geometry
crs: 'EPSG:4326', // Define the coordinate reference system
maxPixels: 1e13 // Adjust max pixels if needed. In this lab, your area should be small, so this won't be an issue most likely
});
Export.image.toDrive({
image: cdl,
description: 'cdl',
folder: 'RS_Lab12', // Folder you create in your Google Drive where file will write
fileNamePrefix: 'cdl',
scale: 30, // Adjust the scale as needed. Resolution in meters
region: roi, // Define the region of export, here we use the image's geometry
crs: 'EPSG:4326', // Define the coordinate reference system
maxPixels: 1e13 // Adjust max pixels if needed. In this lab, your area should be small, so this won't be an issue most likely
});
// After running the export.image functions above, 4 Tasks will appear in the upper right corner
// You then need to click Run on each (and then Run again on the popup) to make them upload to your Google Drive
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
Hello all!
I am a student and very new to coding on Google Earth Engine. I am attempting to export the rasters I created so that I can work with them in RStudio. The error message I get is "Error: GeometryConstructors.MultiGeometry: Geometry coordinate projection requires non-zero maxError. (Error code: 3)". I researched the error and looked at similar discussions but haven't been able to solve the issue. Any help is greatly appreciated! Here is the code:
// Define function to mask clouds, scale, and add variables
// (NDVI, time and a constant) to Landsat 8 imagery.
function maskScaleAndAddVariable(image) {
// Bit 0 - Fill
// Bit 1 - Dilated Cloud
// Bit 2 - Cirrus
// Bit 3 - Cloud
// Bit 4 - Cloud Shadow
var qaMask = image.select('QA_PIXEL').bitwiseAnd(parseInt('11111',
2)).eq(0);
var saturationMask = image.select('QA_RADSAT').eq(0);
}
// //Merced point:
var centerPoint = ee.Geometry.Point([ -120.37559812236756, 37.27069238838713]);
var crop1 = ee.Geometry.Point([ -120.33645932842225, 37.28298585843524]);
var crop2 = ee.Geometry.Point([ -120.41336362529725, 37.260582920157454]);
// // Import the USGS Landsat 8 Level 2, Collection 2, Tier 1 image collection),
// // filter, mask clouds, scale, and add variables.
var landsat8sr = ee.ImageCollection('LANDSAT/LC08/C02/T1_L2')
.filterBounds(roi)
.filterDate('2022-01-01', '2024-01-01')
.map(maskScaleAndAddVariable);
var landsat9sr = ee.ImageCollection('LANDSAT/LC09/C02/T1_L2')
.filterBounds(roi)
.filterDate('2022-01-01', '2024-01-01')
.map(maskScaleAndAddVariable);
var landsatCombined = landsat8sr.merge(landsat9sr);
// Set map center over the ROI.
Map.centerObject(roi, 10);
// // Plot a time series of NDVI at a single location.
var landsatChart = ui.Chart.image.series(landsatCombined.select('NDVI'), centerPoint)
.setChartType('ScatterChart')
.setOptions({
title: 'Landsat 8 and 9 NDVI time series at centerPoint',
lineWidth: 1,
pointSize: 3,
});
print(landsatChart);
// // Plot a time series of NDVI with a linear trend line at a single location.
var landsatChartTL = ui.Chart.image.series(landsatCombined.select('NDVI'), centerPoint)
.setChartType('ScatterChart')
.setOptions({
title: 'Landsat 8 and 9 NDVI time series at centerPoint',
trendlines: {
0: {
color: 'CC0000'
}
},
lineWidth: 1,
pointSize: 3,
});
print(landsatChartTL);
// // List of the independent variable names
var independents = ee.List(['constant', 't']);
// // Name of the dependent variable.
var dependent = ee.String('NDVI');
// // Compute a linear trend. This will have two bands: 'residuals' and
// // a 2x1 (Array Image) band called 'coefficients'.
// // (Columns are for dependent variables)
var trend = landsatCombined.select(independents.add(dependent))
.reduce(ee.Reducer.linearRegression(independents.length(), 1))
.clip(roi);
Map.addLayer(trend, {}, 'trend array image');
// // Flatten the coefficients into a 2-band image.
var coefficients = trend.select('coefficients')
// Get rid of extra dimensions and convert back to a regular image
.arrayProject([0])
.arrayFlatten([independents])
.clip(roi);
//Map.addLayer(coefficients, {}, 'coefficients image');
//print(coefficients, 'coefficients');
// Compute a detrended series.
var detrended = landsatCombined.map(function(image) {
return image.select(dependent).subtract(
image.select(independents).multiply(coefficients)
.reduce('sum'))
.rename(dependent)
.copyProperties(image, ['system:time_start']);
});
// Plot the detrended results.
var detrendedChart = ui.Chart.image.series(detrended, centerPoint, null, 30)
.setOptions({
title: 'Detrended Landsat time series at ROI',
lineWidth: 1,
pointSize: 3,
trendlines: {
0: {
color: 'CC0000'
}
},
});
print(detrendedChart);
// Use these independent variables in the harmonic regression.
var harmonicIndependents = ee.List(['constant', 't', 'cos', 'sin']);
//print(harmonicIndependents, 'harmonicIndependents');
// Add harmonic terms as new image bands.
var harmonicLandsat = landsatCombined.map(function(image) {
var timeRadians = image.select('t').multiply(2 * Math.PI);
return image
.addBands(timeRadians.cos().rename('cos'))
.addBands(timeRadians.sin().rename('sin'))
.clip(roi);
});
print(harmonicLandsat, 'harmonicLandsat');
// // Fit the model.
var harmonicTrend = harmonicLandsat
.select(harmonicIndependents.add(dependent))
// The output of this reducer is a 4x1 array image.
.reduce(ee.Reducer.linearRegression(harmonicIndependents.length(),
1));
print(harmonicTrend, 'harmonicTrend');
// // Turn the array image into a multi-band image of coefficients.
var harmonicTrendCoefficients = harmonicTrend.select('coefficients')
.arrayProject([0])
.arrayFlatten([harmonicIndependents]);
// Compute fitted values.
var fittedHarmonic = harmonicLandsat.map(function(image) {
return image.addBands(
image.select(harmonicIndependents)
.multiply(harmonicTrendCoefficients)
.reduce('sum')
.rename('fitted'));
});
print(fittedHarmonic, 'fittedHarmonic');
// Plot the fitted model and the original data at the centerPoint.
print(ui.Chart.image.series(
fittedHarmonic.select(['fitted', 'NDVI']), centerPoint, ee.Reducer
.mean(), 30)
.setSeriesNames(['NDVI', 'fitted'])
.setOptions({
title: 'Harmonic model: original and fitted values: centerPoint',
lineWidth: 1,
pointSize: 3,
}));
print(ui.Chart.image.series(
fittedHarmonic.select(['fitted', 'NDVI']), crop1, ee.Reducer
.mean(), 30)
.setSeriesNames(['NDVI', 'fitted'])
.setOptions({
title: 'Harmonic model: original and fitted values: Crop1',
lineWidth: 1,
pointSize: 3,
}));
print(ui.Chart.image.series(
fittedHarmonic.select(['fitted', 'NDVI']), crop2, ee.Reducer
.mean(), 30)
.setSeriesNames(['NDVI', 'fitted'])
.setOptions({
title: 'Harmonic model: original and fitted values: Crop2',
lineWidth: 1,
pointSize: 3,
}));
// Compute phase and amplitude.
var phase = harmonicTrendCoefficients.select('sin')
.atan2(harmonicTrendCoefficients.select('cos'))
// Scale to [0, 1] from radians.
.unitScale(-Math.PI, Math.PI);
print(phase, 'phase');
var amplitude = harmonicTrendCoefficients.select('sin')
.hypot(harmonicTrendCoefficients.select('cos'))
// Add a scale factor for visualization.
.multiply(5);
print(amplitude, 'amplitude');
// Compute the mean NDVI.
var meanNdvi = landsatCombined.select('NDVI').mean();
print(meanNdvi, 'meanNdvi');
// Use the HSV to RGB transformation to display phase and amplitude.
var rgb = ee.Image.cat([
phase, // hue
amplitude, // saturation (difference from white)
meanNdvi // value (difference from black)
]).hsvToRgb();
Map.addLayer(rgb, {}, 'phase (hue), amplitude (sat), ndvi (val)');
var cdl = ee.Image('USDA/NASS/CDL/2023').select(['cropland']);
Map.addLayer(cdl.clip(roi), {}, 'CDL 2023');
// save phase, amplitude, meanNDVI, and cdl as rasters to be used in R for classification
// exports the rasters to GeoTIFFs, which will be saved in the specified folder in your Google Drive
Export.image.toDrive({
image: phase,
description: 'phase',
folder: 'RS_Lab12', // Folder you create in your Google Drive where file will write
fileNamePrefix: 'phase',
scale: 30, // Adjust the scale as needed. Resolution in meters
region: roi, // Define the region of export, here we use the image's geometry
crs: 'EPSG:4326', // Define the coordinate reference system
maxPixels: 1e13 // Adjust max pixels if needed. In this lab, your area should be small, so this won't be an issue most likely
});
Export.image.toDrive({
image: amplitude,
description: 'amplitude',
folder: 'RS_Lab12', // Folder you create in your Google Drive where file will write
fileNamePrefix: 'amplitude',
scale: 30, // Adjust the scale as needed. Resolution in meters
region: roi, // Define the region of export, here we use the image's geometry
crs: 'EPSG:4326', // Define the coordinate reference system
maxPixels: 1e13 // Adjust max pixels if needed. In this lab, your area should be small, so this won't be an issue most likely
});
Export.image.toDrive({
image: meanNdvi,
description: 'meanNdvi',
folder: 'RS_Lab12', // Folder you create in your Google Drive where file will write
fileNamePrefix: 'meanNdvi',
scale: 30, // Adjust the scale as needed. Resolution in meters
region: roi, // Define the region of export, here we use the image's geometry
crs: 'EPSG:4326', // Define the coordinate reference system
maxPixels: 1e13 // Adjust max pixels if needed. In this lab, your area should be small, so this won't be an issue most likely
});
Export.image.toDrive({
image: cdl,
description: 'cdl',
folder: 'RS_Lab12', // Folder you create in your Google Drive where file will write
fileNamePrefix: 'cdl',
scale: 30, // Adjust the scale as needed. Resolution in meters
region: roi, // Define the region of export, here we use the image's geometry
crs: 'EPSG:4326', // Define the coordinate reference system
maxPixels: 1e13 // Adjust max pixels if needed. In this lab, your area should be small, so this won't be an issue most likely
});
// After running the export.image functions above, 4 Tasks will appear in the upper right corner
// You then need to click Run on each (and then Run again on the popup) to make them upload to your Google Drive
Beta Was this translation helpful? Give feedback.
All reactions