I am using the GEE APIClient in NodeJS to perform clustering and classification tasks which work fine. After performing any of them, I can return the imageURL to the frontend with the getMap()
function. Besides that, I am trying to store the resulting ee.Image()
as an asset or as a GeoTIFF to a Google Cloud bucket.The clustered image always exports successfully, however, the classified image fails if the training points are too many (~30), when attempting to send the request I get ENAMETOOLONG.
This is my export asset function:
async function exportGEEImage(id, image, geometry, scale, crs) {
try {
await authenticateIfNecessary();
//Initialize Earth Engine
ee.initialize(baseurl=EARTH_ENGINE_URL, project='my-project', async () => {
const assetId = `projects/my-project/assets/${id}`;
//console.log('Exporting to asset ID:', assetId);
// Define the export task
const task = ee.batch.Export.image.toAsset({
image: image,
description: id,
assetId: assetId,
region: geometry,
scale: scale,
crs: crs,
maxPixels: 1e13
});
// Start the task
await task.start();
const checkStatus = async () => {
const tasks = await ee.data.listOperations();
tasks.forEach(task => {
const values = task['Serializable$values'];
if (values.metadata.description == id) {
console.log('pending')
if (values.metadata.state == 'SUCCEEDED') {
//console.log('Export completed successfully!');
classificationAPI.saveClassificationResults({id: id, asset: {asset: assetId}});
return;
} else if (values.metadata.state == 'FAILED') {
//console.error('Export failed:', id);
return;
} else {
setTimeout(checkStatus, 30000);
}
}
});
};
checkStatus();
});
} catch (error) {
console.error('Error exporting image:', error);
}
}
If I print the image object to be exported I get the following for a clustered image. However, if it is a classified image I get an object containing all the processing steps which size/length increases based on the number of training points, etc. It can be a JSON with more than 4000 lines.
{
func: {
signature_: {
args: [Array],
description: 'Applies a clusterer to an image. Returns a new image with a single band containing values from 0 to N, indicating the cluster each pixel is assigned to.',
returns: 'Image',
name: 'Image.cluster'
}
},
args: {
image: {
func: [Object],
args: [Object],
varName: null,
sourceFrame: null
},
clusterer: target {
func: [Object],
args: [Object],
varName: null,
sourceFrame: null
}
},
varName: null,
sourceFrame: null
}
This is the error I get when trying to export the classified image:
Error: spawn ENAMETOOLONG
at ChildProcess.spawn (node:internal/child_process:420:11)
at spawn (node:child_process:733:9)
at exports.XMLHttpRequest.send (my-path\node_modules\xmlhttprequest\lib\XMLHttpRequest.js:503:22)
at Object.module$contents$ee$apiclient_apiclient.send (my-path\node_modules\@google\earthengine\build\main.js:19304:13)
at module$contents$ee$apiclient_EERequestService.send (my-path\node_modules\@google\earthengine\build\main.js:19085:54)
at module$exports$eeapiclient$promise_api_client.PromiseApiClient.$request (my-path\node_modules\@google\earthengine\build\main.js:9329:69)
at module$exports$eeapiclient$ee_api_client.ProjectsImageApiClientImpl.export (my-path\node_modules\@google\earthengine\build\main.js:14537:26)
at Object.ee.data.startProcessing (my-path\node_modules\@google\earthengine\build\main.js:21323:40)
at module$contents$ee$batch_ExportTask.start (my-path\node_modules\@google\earthengine\build\main.js:23436:56)
at module$contents$ee$apiclient_Call.callback (my-path\server\routes\earthengine-api.js:1260:21) {
errno: -4064,
code: 'ENAMETOOLONG',
syscall: 'spawn'
}
I have tried 'casting' the result and saving each processing step into a const instead of doing all in a single line but I got the same result.
const finalTrainingImage = training_image.select(bands);
const clippedImage = finalTrainingImage.clip(geometryClassification);
const classified = clippedImage.classify(trained);
const image = ee.Image(classified)
Serializing or JSON.stringify()
or evaluate()
the ee.Image doesn't work either. The issue seems to come from the GEE library directly when sending the XML export request.
Is there a way that the object can be evaluated or resolved before exporting it so the ee.Image object does not include the training points and therefore consist of a smaller JSON?
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1742335009a4424474.html
评论列表(0条)