Tutorial 1 & 2
Getting access
-
Create (or verify) an email account associated with Google. e.g. abcdef\@gmail.com.
-
Register for a GEE account at https://earthengine.google.com/signup/.
The GEE Interface (Code Editor)
Figure 1. Image of Code Editor highlighting components of layout.
Programming in JavaScript
-
Every command line ends with a semi-colon (
;
) -
"
and'
can be used interchangeably -
Use comments to make your code readable
Comments start with
//
and any text in a line after the//
is a commentMulti-line comments can start with
/*
and end with*/
or use
Control
and/
- Use the keyword var to create a variable e.g.
var my_grade = 100;
- Parentheses are used to pass parameters to functions. e.g.
print("This string will print in the Console tab.");
- String objects (i.e. text) start and end with a single quote e.g.
var opinion = "GEE is awesome";
- Square brackets are used to specify items in a list.
var my_list = ["eggplant", "apple", "wheat"];
- The zero index is the first item in the list e.g.
print(my_list[0]);
- Square brackets can be used to access dictionary items by key e.g.
print(my_dict["color"]);
- Or you can use the dot notation to get the same result.
print(my_dict.color);
- Curly brackets (or braces) are used to define dictionaries (key:value pairs).
var my_dict = {"food":"bread", "color":"red", "number":42};
- For mathematical operations, you can use the built-in mathematical functions or you can use the mathematical symbols directly:
//build in function print(3.subtract(2)); //mathematical symbols print(3-2); //making it more readable print("Subtracting two from three equals",3-2);
-
Functions that combine commonly reused steps improve efficiency and make code easier to read. The my_hello_function below takes input from the user, adds some text and prints the result to the Console tab. The add_function takes an input value, adds 3, and then returns the results with an appropriate text description.
var my_hello_function = function(string) { return "Hello " + string + "!"; } print(my_hello_function("world")); //would print Hello world! in the Console tab var add_function = function(a) { return a+3; }; var a = 1; print(a + " plus 3 is " + add_function(a)); //would print 1 plus 3 is 4 in the Console tab