0% found this document useful (0 votes)
21 views59 pages

Gee Api1

GEEE
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
21 views59 pages

Gee Api1

GEEE
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 59

ADVANCED GIS AND REMOTE SENSING

(IRGN 490)

Ran Goldblatt

Lecture 9:
Google Earth Engine API-1
Images and Image Collections

https://code.earthengine.google.com/

Advanced GIS and Remote Sensing | Winter 2017 |


Ran Goldblatt
Google Earth Engine Coder (API)

• Used to run algorithms on georeferenced imagery and vectors.

• Includes a library of functions that can be applied to imagery for display and
analysis.

• Vector datasets (feature collections) are used via Google Fusion Tables.

• MUCH more control on the analysis process

Advanced GIS and Remote Sensing | Winter 2017 |


Ran Goldblatt
The Application Programming Interface (API) of Google Earth Engine (EE) https://code.earthengine.google.com/

3
2 1

5
4

https://code.earthengine.google.com/

1- Code editor | 2- Archive panel, documentation, examples | 3- Report panel, debugging and output
4- Display screen | 5- Draw feature geometries
Advanced GIS and Remote Sensing | Winter 2017 |
Ran Goldblatt
Advanced GIS and Remote Sensing | Winter 2017 |
Ran Goldblatt
Advanced GIS and Remote Sensing | Winter 2017 |
Ran Goldblatt
Advanced GIS and Remote Sensing | Winter 2017 |
Ran Goldblatt
Let`s begin…

Advanced GIS and Remote Sensing | Winter 2017 |


Ran Goldblatt
print('hello class!'); hello class!

JavaScript statements
• JavaScript statements have a pair of parentheses ()
• They end with a semicolon ;
• Anything between single quotes is called a 'string'.
• Strings:
• Used to print out readable information.
• Define sets of characters that name datasets or parts of datasets
print('hello class'); Advanced GIS and Remote Sensing | Winter 2017 |
Ran Goldblatt
Image and Image collection = Rasters
Images
• Pixels with associated values.
• An image can have multiple bands
• Each band in an image contains:
• A name
• Pixel value
• Resolution
• Projection

Advanced GIS and Remote Sensing | Winter 2017 |


Ran Goldblatt
Image collection

• Collections/
Mosaics of EE images

• Example:
• A collection of all L8 images
in a given time period
• Each image collection has
an ID.

Advanced GIS and Remote Sensing | Winter 2017 |


Ran Goldblatt
“Calling” Image Collections
Option 1

Searching and importing images


One method to access images and image collections:
“search” and import the dataset. No need to know the ID.
Advanced GIS and Remote Sensing | Winter 2017 |
Ran Goldblatt
“Import” will add the image to the workspace

This image collection has a name:


LANDSAT/LE7_TOA_1YEAR

Advanced GIS and Remote Sensing | Winter 2017 |


Ran Goldblatt
Variables
• Variables store values that make the code more readable.
• Must begin with a letter (or a $ or _)
• They are CASE-sensitive
• The first time you use a given variable, start with the word var.

You can choose the name of the variable!


Advanced GIS and Remote Sensing | Winter 2017 |
Ran Goldblatt
The print() statement can be used to get information about
the added image collection:

print(landsat8TOA);

This image collection has a name: LANDSAT/LC8_L1T_8DAY_TOA


Advanced GIS and Remote Sensing | Winter 2017 |
Ran Goldblatt
Another method to add images and image collections:
ee.ImageCollection()
This function “tells” EE that a given ID is a name of an image collection:
LANDSAT/LC8_L1T_8DAY_TOA is an Image collection- Access it as a parameter.

ee.ImageCollection('LANDSAT/LC8_L1T_8DAY_TOA')

var something = ee.ImageCollection()

var landsat8TOA = ee.ImageCollection('LANDSAT/LC8_L1T_8DAY_TOA');


print(landsat8TOA); Advanced GIS and Remote Sensing | Winter 2017 |
Ran Goldblatt
Let`s search for another image collection:

var landsat7TOA = ee.ImageCollection('LANDSAT/LE7_TOA_1YEAR');


print(landsat7TOA);
Advanced GIS and Remote Sensing | Winter 2017 |
Ran Goldblatt
var landsat7TOA =
ee.ImageCollection('LANDSAT/LE7_TOA_1YEAR');
print(landsat7TOA);

The Image collection includes features  Images


Every image in Earth Engine has a name. Example: This is an image
LANDSAT/LE7_TOA_1YEAR/2014Advanced GIS and Remote Sensing | Winter 2017 |
Ran Goldblatt
The image ID that we want to call: LANDSAT/LE7_TOA_1YEAR/2014

We need to explicitly tell Earth Engine that LANDSAT/LE7_TOA_1YEAR/2014 is an


image.

We will use the function: ee.Image()


“Take the name of the image and access it as a parameter”.

var landsat7TOA2014 = ee.Image('LANDSAT/LE7_TOA_1YEAR/2014');


print(landsat7TOA2014);

Advanced GIS and Remote Sensing | Winter 2017 |


Ran Goldblatt
Adding an image to the map:
Map.addLayer(something);
This statement says that we want the Map.addLayer() function
to add something to the map.
var landsat7TOA2014 = ee.Image('LANDSAT/LE7_TOA_1YEAR/2014');
Map.addLayer(landsat7TOA2014);

What is wrong with the visualization?


Advanced GIS and Remote Sensing | Winter 2017 |
Ran Goldblatt
Many images in Earth Engine have one or more bands.
For example, images from the Landsat 7 satellite include:

Band 1 - blue
Band 2 - green
Band 3 - red
Band 4 - Near Infrared
Band 5 - Short-wave Infrared
Band 6 - Thermal Infrared
Band 7 - Short-wave Infrared

Advanced GIS and Remote Sensing | Winter 2017 |


Ran Goldblatt
How does EE map the values in the image bands to colors on the map?

One band: value 0 is rendered as black and value 255 as white, with a linear gray
gradient in between.

0 255

More than one band:


EE takes the first three bands and maps the first to red, the second to green, and the
third to blue. The value of the pixel determines the intensity of the color.
L7 EE
blue B1 red

green B2 green
red B3 blue

B4
Advanced GIS and Remote Sensing | Winter 2017 |
B5 Ran Goldblatt
The Map.addLayer() function can take a second parameter {} which describes
how the image should be visualized.

Map.addLayer(ee.Image('LANDSAT/LE7_TOA_1YEAR/2014'),
{}
);

The format of this second parameter (visualization factor) is:


{'string': value, 'string': value, ... , 'string': value}

each string describes one visualization factor:


For example: 'min', 'max', 'bands‘.
We want to add a list of bands to visualize:
Map.addLayer(ee.Image('LANDSAT/LE7_TOA_1YEAR/2014'),
{'bands': ['B3', 'B2', 'B1']}
); Advanced GIS and Remote Sensing | Winter 2017 |
Ran Goldblatt
A visualization of a single Landsat image in Earth Engine.

Map.addLayer(ee.Image('LANDSAT/LE7_TOA_1YEAR/2014'), R G B
{'bands': ['B3', 'B2', 'B1']} L7 B3 B2 B1
); Advanced GIS and Remote Sensing | Winter 2017 | L8 B4 B3 B2
Ran Goldblatt
Selecting specific band(s) in an Image
.select('band name')

Map.addLayer(ee.Image('LANDSAT/LE7_TOA_1YEAR/2014')
.select('B3'));

Which is the same as:

var L7 = ee.Image('LANDSAT/LE7_TOA_1YEAR/2014');
var B3_L7 = L7.select('B3');
Map.addLayer(B3_L7);
Advanced GIS and Remote Sensing | Winter 2017 |
Ran Goldblatt
var L7 = ee.Image('LANDSAT/LE7_TOA_1YEAR/2014');
var B3_L7 = L7.select('B3');
Map.addLayer(B3_L7);

Advanced GIS and Remote Sensing | Winter 2017 |


Ran Goldblatt
Let`s call another image collection:

Task:
Filter an image collection only for scenes in a specific date
(second half of 2014) Advanced GIS and Remote Sensing | Winter 2017 |
Ran Goldblatt
Advanced GIS and Remote Sensing | Winter 2017 |
Ran Goldblatt
.filterDate()

filterDate() method on an image collection.

Each action on an image collection is a method.


A method is applied on an image collection by
.methodName(arguments) after the image collection

ee.imageCollection.filterDate(date1, date2)
'2014-06-01', '2014-12-31'
'YYYY-MM-DD', 'YYYY-MM-DD'
Advanced GIS and Remote Sensing | Winter 2017 |
Ran Goldblatt
ee.ImageCollection('LANDSAT/LC8_L1T_32DAY_TOA')
.filterDate('2014-06-01', '2014-12-31');

Which is the same as:

var L8 = ee.ImageCollection('LANDSAT/LC8_L1T_32DAY_TOA');

var L8_SecondHalf = L8.filterDate('2014-06-01', '2014-12-31');

Advanced GIS and Remote Sensing | Winter 2017 |


Ran Goldblatt
All together:

var L8 = ee.ImageCollection('LANDSAT/LC8_L1T_32DAY_TOA');

var L8_SecondHalf14 = L8.filterDate('2014-06-01', '2014-12-31');


Map.addLayer(L8_SecondHalf14, {'bands': ['B4', 'B3', 'B2']} , 'landsat 8 at 2014' );

Advanced GIS and Remote Sensing | Winter 2017 |


Ran Goldblatt
Reducers

Advanced GIS and Remote Sensing | Winter 2017 |


Ran Goldblatt
• Landsat 8 visits the same spot on the Earth every 16 days.

• Over a 6 month period, there will be approximately 12 images.

• Each pixel on the map is derived from a stack of pixels


(a pixel from each image in the collection).

• The default behavior is to select the most recent pixel- the one from the recent
scene in the stack.

• We can alter this behavior by using a reducer

For example: pick the median value in the stack.

Advanced GIS and Remote Sensing | Winter 2017 |


Ran Goldblatt
Reducers

var imageCollection = ee.ImageCollection()

var minVal = imageCollection.min()


var maxVal = imageCollection.max()
var meanVal = imageCollection.mean ()
var medianVal = imageCollection.median ()
var firstVal = imageCollection.first ()
var sumVal = imageCollection.sum ()

Advanced GIS and Remote Sensing | Winter 2017 |


Ran Goldblatt
var L8_32Days = ee.ImageCollection('LANDSAT/LC8_L1T_32DAY_TOA');
var L8_SecondHalf14 = L8_32Days
.filterDate('2014-06-01', '2014-12-31').median();
Map.addLayer(L8_SecondHalf14, {'bands': ['B4', 'B3', 'B2']} , 'landsat 8 at 2014' );

Advanced GIS and Remote Sensing | Winter 2017 |


Ran Goldblatt
Creating a TOA calibrated composite of “raw” Landsat scenes

Advanced GIS and Remote Sensing | Winter 2017 |


Ran Goldblatt
Creating a composite of “raw” Landsat scenes:

1. Take the collection of the raw scenes


2. Apply TOA calibration
3. Assign a cloud score to each pixel
4. Select the lowest possible range of cloud scores at each point
5. Compute per-band percentile values from the accepted pixels.

Reminder:
Top of Atmosphere Reflectance (%)
Consider the angle and distance between
the sun, surface and satellite.
Advanced GIS and Remote Sensing | Winter 2017 |
Ran Goldblatt
ee.Algorithms.Landsat.simpleComposite(raw image collection)

Advanced GIS and Remote Sensing | Winter 2017 |


Ran Goldblatt
Simple composite arguments:

var image = ee.Algorithms.Landsat.simpleComposite(


{collection: //The raw Landsat ImageCollection to composite.
percentile: //The percentile value to use when compositing each band. default: 50
cloudScoreRange: // Range of cloud scores to accept per pixel. default: 10
maxDepth: //Maximum number of scenes used to compute each pixel. default: 40
asFloat: // Units of output bands (true: same as the Landsat.TOA algorithm; false:
convert to uint8: multiply the reflective bands by 255, subtract 100 from the thermal
bands, round to the nearest integer. default: false
}
)

Advanced GIS and Remote Sensing | Winter 2017 |


Ran Goldblatt
Example:
var L8_Collection = ee.ImageCollection('LANDSAT/LC8_L1T');

var L8Filtered = L8_Collection.filterDate('2014-10-01', '2014-12-31');

var L8Median = L8Filtered.median();

Map.addLayer(L8Median, {'bands': ['B4', 'B3', 'B2'], min: 6000, max:17000}, 'landsat 8


median val' );

var l8_Composite= ee.Algorithms.Landsat.simpleComposite({


collection: L8Filtered,
asFloat: true
});

Map.addLayer(l8_Composite , {'bands': ['B4', 'B3', 'B2'], min: 0, max:0.3}, 'landsat 8


simple composite' ); Advanced GIS and Remote Sensing | Winter 2017 |
Ran Goldblatt
Before….

Advanced GIS and Remote Sensing | Winter 2017 |


Ran Goldblatt
And after (simple composite)….

Advanced GIS and Remote Sensing | Winter 2017 |


Ran Goldblatt
NDVI

We will:
• Add the collection
• Filter by date
• Find the maximum ndvi value
• Visualize it. Advanced GIS and Remote Sensing | Winter 2017 |
LANDSAT/LE7_L1T_32DAY_NDVI
Ran Goldblatt
var ndvi32Day= ee.ImageCollection('LANDSAT/LE7_L1T_32DAY_NDVI');
var filtered2000 = ndvi32Day
.filterDate('2014-01-01', '2014-12-31').max();
Map.addLayer(filtered2000);

The image is displayed in gray

Advanced GIS and Remote Sensing | Winter 2017 |


Ran Goldblatt
Palettes
• Palettes define the color scheme an image.

• A palette is a comma delimited string of colors, stretched


over a band's maximum and minimum pixel values.

The string '000000' is black


'FFFFFF' is white http://www.w3schools.com/colors/colors_names.asp
'FF0000' is red
'00FF00' is green
'0000FF' is blue.

We need to add a visualization parameter (just as we did with


‘bands’) that will specify a palette
Advanced GIS and Remote Sensing | Winter 2017 |
Ran Goldblatt
var collection = ee.ImageCollection('LANDSAT/LE7_L1T_32DAY_NDVI');
var filtered2000 =
collection.filterDate('2014-01-01', '2014-12-31').max();
Map.addLayer(filtered2000, {'palette':'000000, 00FF00'});
000000 00FF00

Why is the entire image green?


-1 +1
Advanced GIS and Remote Sensing | Winter 2017 |
Ran Goldblatt
var collection = ee.ImageCollection('LANDSAT/LE7_L1T_32DAY_NDVI');
var filtered2000 = collection.filterDate('2014-01-01', '2014-12-31').max();
Map.addLayer(filtered2000,
{'palette':'000000, 00FF00', 'min': 0.5, 'max': 0.7}
);

Advanced GIS and Remote Sensing | Winter 2017 |


Ran Goldblatt
Advanced GIS and Remote Sensing | Winter 2017 |
Ran Goldblatt
DEMO

https://code.earthengine.google.com/

Advanced GIS and Remote Sensing | Winter 2017 |


Ran Goldblatt
1

print('hello class!');

Advanced GIS and Remote Sensing | Winter 2017 |


Ran Goldblatt
2

1. Navigate to: El centro, California


2. Search for: landsat 7 annual TOA Percentile composites
3. Copy the ID of the image collection: LANDSAT/LE7_TOA_1YEAR
4. Call this image collection and print it to the console:

var landsat7TOA = ee.ImageCollection('LANDSAT/LE7_TOA_1YEAR');


print(landsat7TOA);

5. Copy the image ID of the 2014 image.


Call it, print it, and add it to the map:

var landsat7TOA2014 = ee.Image('LANDSAT/LE7_TOA_1YEAR/2014');


print(landsat7TOA2014);
Map.addLayer(landsat7TOA2014);
Advanced GIS and Remote Sensing | Winter 2017 |
Ran Goldblatt
3

Define the bands for the visualization:

var landsat7TOA2014 = ee.Image('LANDSAT/LE7_TOA_1YEAR/2014');


Map.addLayer(landsat7TOA2014,
{'bands': ['B3', 'B2', 'B1']}
);

Advanced GIS and Remote Sensing | Winter 2017 |


Ran Goldblatt
4

1. Search for: Landsat 8 32-Day TOA Reflectance Composite.


2. Copy the ID of the collection (LANDSAT/LC8_L1T_32DAY_TOA)
3. Filter by date to the second half of 2014, and add this image to
the map

var landsat8_32Days =
ee.ImageCollection('LANDSAT/LC8_L1T_32DAY_TOA');

var landsat8_SecondHalf14 = landsat8_32Days


.filterDate('2014-06-01', '2014-12-31');

Map.addLayer(landsat8_SecondHalf14,
{'bands': ['B4', 'B3', 'B2']}, 'landsat 8 at 2014');

Advanced GIS and Remote Sensing | Winter 2017 |


Ran Goldblatt
5

1. Define a variable for Band 2 (Blue)


2. Add Band 2 to the map

var landsat8_32Days =
ee.ImageCollection('LANDSAT/LC8_L1T_32DAY_TOA');

var landsat8_SecondHalf14 = landsat8_32Days


.filterDate('2014-06-01', '2014-12-31');

Map.addLayer(landsat8_SecondHalf14,
{'bands': ['B4', 'B3', 'B2']}, 'landsat 8 at 2014');

var L8_Band2 = landsat8_SecondHalf14.select('B2');


Map.addLayer(L8_Band2,{}, 'band 2');
Advanced GIS and Remote Sensing | Winter 2017 |
Ran Goldblatt
6

Calculate the median value of this collection and add it to the map

var L8_32Days =
ee.ImageCollection('LANDSAT/LC8_L1T_32DAY_TOA');

var L8_SecondHalf14 = L8_32Days


.filterDate('2014-06-01', '2014-12-31')

var L8_SecondHalf14Median = L8_SecondHalf14.median();

Map.addLayer(L8_SecondHalf14, {'bands': ['B4', 'B3', 'B2']} ,


'landsat 8 ' );

Map.addLayer(L8_SecondHalf14Median, {'bands': ['B4', 'B3', 'B2']} ,


'landsat 8 median' );
Advanced GIS and Remote Sensing | Winter 2017 |
Ran Goldblatt
7
Simple composite of Landsat scenes

var L8_Collection = ee.ImageCollection('LANDSAT/LC8_L1T');

var L8Filtered = L8_Collection.filterDate('2014-10-01', '2014-12-31');

var L8Median = L8Filtered.median();

Map.addLayer(L8Median, {'bands': ['B4', 'B3', 'B2'], min: 6000, max:17000});

var image = ee.Algorithms.Landsat.simpleComposite({


collection: L8Filtered,
asFloat: true
});

Map.addLayer(image , {'bands': ['B4', 'B3', 'B2'], min: 0, max:0.3}, 'landsat 8


Median Witner 2014' );
Advanced GIS and Remote Sensing | Winter 2017 |
Ran Goldblatt
8

1. Search for the ID of Landsat 7 32-Day NDVI Composite


LANDSAT/LE7_L1T_32DAY_NDVI
2. Filter by date (2014 and 2000) and extract the max NDVI value

var ndvi32Day= ee.ImageCollection('LANDSAT/LE7_L1T_32DAY_NDVI');

var filtered2014 = ndvi32Day.filterDate('2014-01-01', '2014-12-31').max();


var filtered2000 = ndvi32Day.filterDate('2000-01-01', '2000-12-31').max();

Map.addLayer(filtered2014, {}, 'max ndvi 2014');


Map.addLayer(filtered2000, {}, 'max ndvi 2000');

Advanced GIS and Remote Sensing | Winter 2017 |


Ran Goldblatt
9

Add a visualization parameter:

var ndvi32Day= ee.ImageCollection('LANDSAT/LE7_L1T_32DAY_NDVI');

var filtered2014 = ndvi32Day.filterDate('2014-01-01', '2014-12-31').max();


var filtered2000 = ndvi32Day.filterDate('2000-01-01', '2000-12-31').max();

Map.addLayer(filtered2014, {'palette':'000000, 00FF00'}, 'max ndvi 2014');


Map.addLayer(filtered2000, {'palette':'000000, 00FF00'}, 'max ndvi 2000');

Advanced GIS and Remote Sensing | Winter 2017 |


Ran Goldblatt
10

Define the minimum and maximum value for visualization


var ndvi32Day= ee.ImageCollection('LANDSAT/LE7_L1T_32DAY_NDVI');

var filtered2014 = ndvi32Day.filterDate('2014-01-01', '2014-12-31').max();


var filtered2000 = ndvi32Day.filterDate('2000-01-01', '2000-12-31').max();

Map.addLayer(filtered2014,
{'palette':'000000, 00FF00', 'min': 0.5, 'max': 0.7}, 'max ndvi 2014');

Map.addLayer(filtered2000,
{'palette':'000000, 00FF00', 'min': 0.5, 'max': 0.7}, 'max ndvi 2000');

Advanced GIS and Remote Sensing | Winter 2017 |


Ran Goldblatt
Exercise:

Navigate to any region and present 2 Landsat images for the rainy season of
2013 and one for 2016, using the median value of the composite

Advanced GIS and Remote Sensing | Winter 2017 |


Ran Goldblatt

You might also like