Skip to content

lopezvoliver/eetasks-examples

Repository files navigation

Sample GEE test scripts for the vscode EE Tasks extension

This repository contains sample GEE scripts that have been tested to work with the vscode EE Tasks extension.

Read more about how to use the EE Tasks: run GEE script command here.

In addition, it contains some small related node scripts, including one that demonstrates the authentication and initialization of the earthengine JavaScript API.

Sample GEE scripts

To run these scripts in vscode, first install the EE Tasks vscode extension and follow the sign in instructions.

Finally, open the script to run, press F1 and type EE Tasks: run GEE script.

  1. helloGEE: demonstrates the use of print either directly or as a callback function in .getInfo()
  2. ExportTableToDrive: demonstrates a simple Export.table.toDrive with a call to Map.addLayer ignored.
  3. ExportImageToDrive: demonstrates a simple Export.Image.toDrive.

Node scripts

Hello world

The helloNodeGEE.js is a minimal node script demonstrating the authentication and initialization of the EE library with one asynchronous and one synchronous request. It requires a valid access_token.

If you have stored credentials generated by the python Earth Engine client (~/.config/earthengine/credentials), then you can generate a token (valid for one hour) using the printToken.js node script.

The following instructions are not required to run the sample GEE scripts within the vscode EE Tasks extension.

You will need to use npm to install the google/earthengine JavaScript API.

npm install @google/earthengine

Next, generate the token:

node printToken.js

If a valid token is generated, the output should look like this:

{
  access_token: 'ya29...<VERY LONG STRING HERE>...',
  expires_in: 3599,
  scope: 'https://www.googleapis.com/auth/earthengine https://www.googleapis.com/auth/devstorage.full_control',
  token_type: 'Bearer'
}

Copy the access_token string and export the EETOKEN environment variable:

export EETOKEN="ya29...<VERY LONG STRING HERE>..."

Finally, run the example:

node helloNodeGEE.js

The output should look like this:

$ node helloNodeGEE.js 
Hello from synchronous request
Hello from callback

Testing xmlHttpRequest

This small test uses XmlHttpRequest to create a synchronous request, which is what the earthengine Javascript api uses for .getInfo() without a callback function.

This small test should simply return "undefined".

However, the same code in a vscode extension (e.g., eetasks) behaves wildly different depending on the OS:

- Linux: works as expected
- MacOS: An error is raised (but can be caught)
- Windows: crashes the Extension Host. 

See: microsoft/vscode#199492

About

Sample GEE scripts for the vscode EE tasks extension

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published