Professional Documents
Culture Documents
GEE Intro 2018
GEE Intro 2018
GEE Intro 2018
Introduction
1
Outline
• What is GEE?
• Practical to get you started
– introduce some functionality to GEE API
• Advanced practical on queries
– Use satellite data and shapefiles to query something
• Extra bonus
– At end is a run through of how to get shapefiles into GEE
2
What is GEE?
• Cloud-based platform for geospatial analysis
• Access over 40 years of satellite imagery
• Upload own data sets to integrate with publicly available data
• Apply range of common algorithms to data
• Export images, tables, charts, map outputs
Sentinel-2
Sentinel-1
3
4
Example: Time Series in Kenya
• Is it possible to estimate NDVI time series of
agricultural fields in Kenya?
• Method:
– VHR Land use classification (QuickBird).
– Create mask of agricultural fields
– Mask landsat 5 time series from 2002-2012 to the
field level.
5
6
Results
• DOH!
– Landsat 5 has no data for a time series
7
Results
• MODIS data exists but, resolution too coarse
8
Home page
• https://earthengine.google.com/
• https://explorer.earthengine.google.com/#workspace
9
Quick Quiz
10
EarthEngine API introduction
11
API Introduction
• API requried to analyse data more fully
• Mainly uses a version of JavaScript but some Python
• Do not have to be a coding genius to use GEE
• Many helpful tutorials:
– https://developers.google.com/earth-engine/getstarted
– https://developers.google.com/earth-engine/tutorials
12
https://code.earthengine.google.com/
The API
Code examples,
saved scripts, Code editor Code management,
debugging etc
13
Available Algorithms
• Docs tab > ee.Image
– Shows the algorithms that can be run on an image
– Eg: Add
– Click to see an explanation of the algorithm.
– var image3 = image1.add(image2)
• Sums the pixels in the first raster to the second raster
creating a new variable (var) called image3.
14
EarthEngine API Practical 1
“Differences in NDVI"
15
Before you start
• Have two Script windows open
• Use one to paste in each new set of instructions
• Once you are happy with what they are doing add them to the
second script window and add a comment. Save the script for
future use.
16
Tutorial 1 – can copy all into EE
17
Tutorial 1 –
18
Tutorial 1 – Image collections
20
Tutorial 1 – Filter by Date
Map.addLayer(ee.ImageCollection('LANDSAT/
LC8_L1T').filterDate('2013-06-01','2013-12-31'),
{'bands': ['B5', 'B4', 'B3'], 'min':6000, 'max':18000});
Map.setCenter(-122.44, 37.77, 7);
21
Tutorial 1 – Reducers -
23
Tutorial 1 – Variables
var landsat8 =
ee.ImageCollection('LANDSAT/LC8_L1T');
var secondHalf2013 = landsat8.filterDate('2013-
06-01', '2013-12-31');
var median = secondHalf2013.median()
Map.addLayer(median, {'bands':['B5', 'B4', 'B3'],
'min':5000, 'max':18000});
Map.setCenter(-119.84, 37.83, 8);
24
Tutorial 1 – Image Band Math
26
Tutorial 1 – Image Band Math 3
27
Tutorial 1 – Image Band Math 4
28
Tutorial 1 – Image Band Math 5
//band math. subtract the 2000 ndvi values from the 2010
ndvi values
var difference = ndvi2010.subtract(ndvi2000);
Map.setCenter(-122.44, 37.74, 13);
Map.addLayer(difference,
{palette: 'FF0000, 000000, 00FF00', min: -0.3, max: 0.3});
29
Tutorial 1 – Masking
30
Tutorial 1 – Masking – add to bottom of script
var classifiedImage =
ee.Image('MODIS/051/MCD12Q1/2001_01_01');
print(classifiedImage)
31
Tutorial 1 – Masking – add to bottom of script
33
Tutorial 1 – Masking
34
Tutorial 1 – Masking
// use this mask instead to mask out water in ndvi difference.
var collection = ee.ImageCollection('LANDSAT/LT5_L1T_32DAY_NDVI');
var filtered2000 = collection.filterDate('2000-01-01', '2000-12-31');
var filtered2010 = collection.filterDate('2010-01-01', '2010-12-31');
35
Sharing Scripts
• https://
code.earthengine.google.com/232f900373b96
d22696f796c7b06348a
36
Review
• Display images
• Difference between Image and
ImageCollection
• Simple mathemetical operators applied to
images
– Band math in ENVI
• Filtered on date
• masking
37
Tutorial 2
38
What is a Fusion Table?
• ”Experimental data visualisation web application”
– Worrying?
• Those familiar with GIS - Fusion tables are the way that
shapefiles or polygons can be imported into EE.
• Known as Feature (single) or Feature Class (multiple).
39
What is a Fusion Table
• Can create them by importing:
– Spreadsheet or delimited text file (.csv; .tsv; .txt)
– KML file (google earth)
– Shapeescape tool (.shp to fusion table)
40
Denmark Fusion Table
Table ID: 1l8U580LAtM9d-fYUUfd5kRaK1BlNVZKAP8SmhEOi
41
Display Denmark FT
//Display Denmark GADM 1 Levels
var ft = ee.FeatureCollection('ft:1l8U580LAtM9d-
fYUUfd5kRaK1BlNVZKAP8SmhEOi');
Map.addLayer(ft);
Map.centerObject(ft);
42
Use the Denmark FT
43
Which Danish Area is most green?
• Use the fusion table in EE to find out
– Average NDVI in 2015 for each Danish polygon.
44
find out the median NDVI of Midtjylland in 2011
• //clip to Midtjylland
• //this shows us the median pixel value in 2011 for all pixels in
Midtjylland.
46
• //what about average value of Midtjylland as a whole
compared to the other areas?
• //use reduceRegion()
var average =
midtNDVI.reduceRegion(ee.Reducer.mean(),midt, 500);
print(average);
49
Mapping functions
• This is not mapping in the normal sense. Instead we define a
function for a feature in a collection and then we apply it to the
entire feature collection
var averageNDVI = ft.map(function(feature) {
var Districtaverage = median2.reduceRegion(ee.Reducer.mean(),
feature.geometry(), 500);
return feature.set({'ndvi':Districtaverage});
});
print(averageNDVI);
• //we have added a new property to each of the features within the
fusion table giving the average NDVI in 2015.
50
Review
• Created fusion table from csv and shp file.
• Uploaded and displayed in EE API
• Performed basic queries on NDVI data using FT.
• Wrote a Function and mapped it to a collection.
51
Comments
• The fusion tables are experimental – what does that mean?
• There are limits to the file sizes for upload
• Difficult to get polygons uploaded without using shapeescape
• Difficult to create your own data in GoogleEarth and then
converting it to fusion table as the geometry and name
variables require specific types.
52
Good to know
• Fusion table creation is temperamental – general advice if get
errors is to try again and vary a few things:
– Eg - Chrome browser doesnt always seem to work for
creating fusion tables
• FT’s are public. You can protect them with invite only status
but you still have to upload your data onto a public google
cloud
– Check the data use policies before doing this!
• Uploading to shapeescape could also be against data
providers policies.
53
Benefits of GEE?
• ”GEE does the same things as the software i am used to”
– Uses the Google Cloud Server capabilities so the analysis is
run on the fly.
– You do not need to download and process gb’s of data.
– Example:
• NDVI time series for 12 months at 8-day repeat?
• In ENVI ~ 46 images per tile
• GEE – run the analysis on the 46 images without having
to download.
54
55
Create a Fusion Table
From csv
56
Create Fusion Table
• First we need a spatial data file.
• Open the Kenya_points.csv file
57
Create Fusion Table
• First we need a spatial data file.
• Open the Kenya_points.csv file
58
Create a Fusion Table
• Open Google Drive
• Select new and Fusion table option
59
Create Fusion Table
• If not an option select connect more apps and search for
fusion table
60
Create a Fusion Table
• In drive Select new and the Fusion table option
• Navigate to the kenya_points.csv file you just created using
the browse button and select next
61
Create a Fusion Table
• Import new table? Check the formatting looks ok
62
Create a Fusion Table
• This is the Fusion Table – ready for use in EE.
63
Create a Fusion Table
• Check Map of Latitude to check if the points look in a
reasonable location
64
Create a Fusion Table
• How do we get the Fusion Table into EE?
• Need the ID.
• File > About this table > ID
65
Fusion Table ID
• This is a unique code for your table. Anyone who has this code
can access your file.
• Notice that the ID also appears in the address bar
66
Fusion Table ID
• If you forget the ID? Or copy it wrong?
• It is in Drive so you can always check again
67
Display Kenya FT
// Load in the Kenya Samples Fusion Table and display
var kenya = ee.FeatureCollection('ft:1-1p5mlDeaqxcPENYI0-
iaurkOfkZR-nQAptma_Dw
');
Map.addLayer(kenya, {'color': 'FF0000'});
Map.centerObject(kenya);
print(kenya);
68
Shapefile to Fusion Table
• ShapeEscape (http://www.shpescape.com/)
• Can convert ArcMap .shp file to FusionTable.
• Put all of the files associated with an ArcMap .shp file into a
folder and zip
• Upload the .zip to ShapeEscape and wait.
• Automatically uploads the files and provides the Fusion Table
ID.
• Click the link to explore the fusion table.
69