How the Congressional Budget Office Assists Lawmakers
Application of Google Earth Engine in Open NAPs
1. 1
Google Earth Engine
Google Earth Engine (GEE) is a tool that performs large scaled, data driven environmental
analysis. It combines remotely sensed geospatial datasets from USGS, NOAA, NASA, Google
and more! GEE is unique and innovative because one can perform highly interactive algorithm
development at the global scale and across large amounts of data quickly and efficiently.
Explore available datasets: https://explorer.earthengine.google.com/#index.
Detailed information, tutorials and guides at the Google Earth Engine API website:
https://developers.google.com/earth-engine/.
Google Earth education: https://www.google.com/earth/education/
Useful tips for getting started in Earth Engine!
● Use // at the beginning of a line to write comments in your script. These lines are not
run with the rest of your code
● /* Multi line comments start with a forward slash and a star, and end with a star and a
forward slash. */
2. 2
● Click the ‘run’ button, at the top right corner of the editor window to run your script
● Variables are used to store objects, and are defined using the keyword var.
var number = 42;
● ; is used at the end of each line, function or statement to let GEE know that it ends
var image = ee.Image('LANDSAT/LC8_L1T_TOA/LC80440342014077LGN00');
● Parentheses are used to pass parameters to functions.
print('This string will print in the Console tab.');
● Anything within ‘single quotes’ is a string, that stores a series of characters. When run,
will print out the characters.
var example = ‘This is a string’;
Exercise 1: Hello world!
Printing out information to the console is a basic task for getting information about an object,
displaying the numeric result of a computation, displaying object metadata or helping with
debugging. You will be performing the iconic ‘Hello World!’ example!
In the code editor, type the following and then run your code:
print('Hello World!');
Another way to do this, is to store the message ‘Hello World!’ in a variable and then print the
results of the variable.
var message = ‘Hello World!’;
print(message);
Exercise 2: Image Collections
An image collection refers to a dataset of Earth Engine images. Images are taken at a global
temporal scale, and you can filter through image collections to display specific time periods or
locations around the world! In this exercise you will call in a collection of images, filter the
images by date and sort by cloud cover.
Search for ‘Landsat 8 toa’ and click on USGS Landsat 8 TOA Reflectance (Orthorectified).
Then copy and paste the image collection ID: LANDSAT/LC8_L1T_TOA.
In the code editor, type the following (in blue):
3. 3
var collection = ee.ImageCollection('LANDSAT/LC8_L1T_TOA');
var start = ee.Date('2015-01-01');
var finish = ee.Date('2016-01-01');
var point = ee.Geometry.Point(-83.0511, 42.3382);
Sorting by ‘cloud cover’ (least to most) and then selecting the first image, will display the least
cloudy image in the filtered collection.
var filtered = collection.sort('CLOUD_COVER').filterDate(start, finish).filterBounds(point);
print('Landsat 8 toa', filtered.first());
Assign the least cloudy image to a variable named ‘scene’ to add to the map.
var scene = ee.Image(filtered.first());
var color = {bands: ['B4', 'B3', 'B2'], max: 0.3};
Map.addLayer(scene, color, 'true-color composite');
You can search for other datasets such as Landsat, MODIS, srtm and radiance.
Exercise 3: Functions
Functions can be defined as a way to reuse code and make it easier to read. Once you have
written a function, use .map() to apply the function across an image collection.
In the code editor, type the following. Try out different statements for this function to print:
var my_hello_function = function(string) {
return 'Hello ' + ' ' + string + '!';
};
print(my_hello_function('world'));
OR
var my_hello_function = function(string) {
return 'My name is' + ' ' + string + '!';
};
print(my_hello_function('Beyonce'));
Exercise 4: Explore GEE
GEE provides a bunch of scripts for you to look through and learn from. In the Scripts tab to the
left of the editor, expand the Examples folder and look through the Image and Image Collection
4. 4
scripts. Run some of them to see the kinds of image analysis that can be done using Earth
Engine.
Some scripts to try running:
Image > Normalized Difference
Image > Hillshade
Image > From Name Landsat8
Image Collection > Clipped Composite
Image Collection > Linear Fit
Exercise: Clipping!
Under the ‘Clipped Composite’ example script, change the filters to visualize difference states.
Ex. var fc = ee.FeatureCollection('ft:1fRY18cjsHzDgGiJiS2nnpUU3v9JPDc2HNaR7Xk8')
.filter(ee.Filter.or(
ee.Filter.eq('Name', 'Kentucky'),
ee.Filter.eq('Name', 'Virginia')));
Change one of the filters to Arizona and find the Grand Canyon!
Then use the print() statement to print some of the results of the variables used in this script.
Exercise: All of the lights!
Explore the night time lights around the world using the ‘Linear Fit’ example script. Run the
script and look through the layers that are added to the map. The ‘stable lights first asset’ layer
5. 5
visualizes the lights at night. The ‘stable lights trend’ layer visualizes the trend of lights from
1991 to present day. Which countries produce the most light and why do you think that is?
Exercise 5: Applications
After doing the above exercises in GEE, can you think of any real world applications for this
tool? Brainstorm 3 different ways that you think GEE can be used in the forestry field or another
environmental field.
To learn more!
1. Read through the Earth Engine API docs. Read through the Introduction and Get Started
sections, work your way through the API tutorials, and then dive deeper into any
concepts that you are interested in. From the Javascript Playground, the docs can be
accessed via the menu Help -> User guide.
2. Join and participate in the Google Earth Engine Developers forum, where Earth Engine
users post and answer questions about the platform.