(Simple) GEE tutorial

Page 1

GOOGLE EARTH ENGINEÂ

prima

rizky

m


Google Earth Engine (GEE) is cloud based computing platform to perform analysis of satellite imageries and geospatial visualization. the user can write and run script according to their algorithm under GEE environment


1. GEE Sign Up and Registration

https://earthengine.google.com/



after signed up, there will be a welcome email from GEEÂ


Display screen of code editor of GEE

https://code.earthengine.google.com


2. Exploring GEE Code Editor

https://earthengine.google.com/platform/


2. Exploring Code Editor of GEE Make new repository and folder

Repository: several folders in one repository Folder : several files in one folder File : the script for running algorithm


The file made inside the Repository and then drag to the Folder


3. Learning basic function in GEE code editor

// -> double slashes are for making notes in script and will not be executed

print('hello');

print(...) is used to show text or variable in console

'run' to execute the script or 'Ctrl + Enter' from the click

keyboard


var example = ('this is an apple'); print('text:',example); print(example,'text:');

var is variable to assign text, number, image or dataset.

the component inside variable can

print(...)

be shown by using

and there is no rule to put it; whether after text or before text.


var number = ('1,2,3'); var numbers_in_array = [1,2,3]; print('1. these are numbers',number); print('2. these are numbers',numbers_in_array );

the underscore is functioned as space for variable name consists of two words or more


var image_example = ee.Image(1); var added = image_example.add(2); var subtracted= image_example.subtract(2); var divided= image_example.divide(2); var multiplied = image_example.multiply(2);

ee.Image is Earth Engine image constructor, to process image in Earth Engine data catalog.

In this example, we use constant image (dummy)

(= 1). We

with pixel value

print('added:',added, 'subtracted:', subtracted, 'divided:',divided,'multiplied',multiplied);

can make calculation such addition, subtraction, division and multiplication.


added : 1 + 2 = 3 subtracted : 1 - 2 = -1 divided : 1 : 2 = 0.5 multiplied : 1 * 2 = 2 In the console, we can see the

image

properties and information, such as band and the minimum and maximum value of the image's band


4. Geometry, Image, and Map Visualization

Based on Map

Based on Satellite


Geometry tools

To move around the map

To add a marker

To draw a shape

Zoom in

Zoom out To draw a line


drop a marker


Importing Landsat-8 image to the script

we will choose the Landsat-8 collection 1 tier 1 and realtime data TOA reflectance.

Click

ImportÂ


There will be new entry; variable with imageCollection as its name.

Constructing filter criteria for image collectionÂ

Filter image collection based on area (geometry)

Filter image collection based on acquisition date

Filter image collection based on cloud cover


var data_selection = imageCollection.filterBounds(geometry) .filterDate('2017-01-01','2017-12-31') .filter(ee.Filter.lt('CLOUD_COVER',30)); print('Property of data selection by point',data_selection)

The

geometry is our previous point or

variable with name geometry. The filter date format is: YYYY-MM-DD

lt in the third filter means less

The .

than, in this case the image collection is limited to images that has cloud cover percentage less than 30.


Properties of Landsat 8 image

In console, we can see the number of bands, number of pixels, type of pixel value (float), the projection, and other properties.Â


Displaying Landsat image in map

Selecting the least cloud cover image:

1. Sort the data collection by using 'CLOUD_COVER' 2. Get the first image from the sorted image collection 3. Display the image

1- var sorted = data_selection.sort('CLOUD_COVER'); 2- var scene = ee.Image(sorted.first()); 3- Map.addLayer(scene, {bands: ['B5,B4,B3'], min:0, max:0.5}, 'The least cloud cover image'); Map.centerObject(scene,8); //To zoom in or zoom out the map


Map.addLayer (scene, {bands: ['B5,B4,B3'], min:0, max:0.5}, 'The least cloud cover image') The RGB setting with false color configuration. The min and max value for each bands.


Map.addLayer (scene, { }, 'The least cloud cover image')

If there is no parameter inside the it will be

{ }Â ,

set automatically by GEE to

RGB setting (B1, B2, B3) with range between 0 -1 (because the image in float number).

'The least cloud cover image' is the layer name.


Setting visual parameter as variable

var vis_rgb= {bands:['B4,B3,B2'], min:0, max:0.5}; or/and var vis_fc  = {bands:['B5,B4,B3'], min:0, max:0.5}; between the image and layer name. Put back the variable name

Map.addLayer (scene, vis_rgb, 'The least cloud cover image') or/and Map.addLayer (scene, vis_fc, 'The least cloud cover image')


Displaying another Landsat images in the map 1. Make the data collection into list 2. Get the desired image from the list and assign to image

var data_sel_list= data_selection.toList(data_selection.size()); var display_image = ee.Image(data_sel_list.get(0)); Map.addLayer (display_image , vis_rgb, 'Landsat image'); Change the 0 to other numbers (depend on how many images in one image collection. If there are 7 images; the maximum number is 6).


5. Exporting Landsat images

a. Export to Google Drive b. Export to Google Cloud Storage c. Export to Assets


Select image and band to be exported to Google Drive

var img_export = scene.select('B2','B3','B4','B5','B6','B7'); Landsat-8 bands: B1 -> coastal aerosol

B8 -> Panchromatic

B2 -> Blue

B9 -> Cirrus

B3 -> Green

B10 -> Thermal infrared 1

B4 -> Red

B11 -> Thermal infrared 2

B5 -> Near infrared

BQA -> Bitmask

B6 -> Shortwave infrared 1 B7 -> Shortwave infrared 2

We will select the several bands from

scene: image with the

Landsat-8 (

least cloud cover)


var exportName = 'Landsat8_img'; Export.image.toDrive({ image: img_export.float(), region : img_export.get('system:footprint'), description: exportName, maxPixels: 1e13, scale : 30 //meter per pixel });


var exportName_asset = 'Landsat8_img'; Export.image.toAsset({ image: img_export.float(), region : img_export.get('system:footprint'), description: exportName_asset, maxPixels: 1e13, scale : 30 //meter per pixel });


GOOGLE EARTH ENGINEÂ


Registration GEE Exploring GEE code editor Learning basic function in GEE Editor Geometry, image and map visualization Exporting Landsat image 6- NDVI Calculation (Vegetation Index Calculation) 7- Cloud scoring and removing 8- Classification


6. Normalized Difference Vegetation Index Calculation

NDVI

NIR - RED =

NIR + RED

you can try other indices such as NDWI, NDSI or EVI etc.

var NDVI = ((scene.select('B5')).subtract(scene.select('B4'))) .divide((scene.select('B5')).add(scene.select('B4'))); var ndviParams= {palette: ['blue','white','green'], min:-1, max:1}; Map.addLayer (NDVI, ndviParams, 'NDVI image');


7. Cloud scoring and removing

1- Add cloud band by using simple cloud score from GEE 2- Create a mask from cloud score 3- Apply the mask to the image


1- Add cloud band by using simple cloud score from GEE var scored = ee.Algorithms.Landsat.simpleCloudScore(display_image); print('L8 cloud score', scored);

Cloud band contains cloud score from 0 (not cloudy) to 100 (most cloudy).


2-Â Â Create a mask from cloud score var mask = scored.select('cloud').lte(20); print(mask);

The mask value is 0 and 1, where

1 is pixels match with

the statement :

Map.addLayer(mask,{},'mask',false);

[.lte(20) = less than equal 20]

false is used for not automatically displaying the image on map


3-Â Â Apply the mask to the image var masked= display_image.updateMask(mask); Map.addLayer(masked,vis_fc,'masked',false);

We can examine the result of cloud removal and change the value to get the best of cloud scoring; that give minimum impact to other non-cloud pixels


9. Classification

1- Supervised Classification users need to categorize the land use and land cover of the study area into classes, and select the points which represent those classes based on their local knowledge or field survey. 2- Unsupervised classification depends on algorithm to categorize pixels into several classes according to their similarity (or in GEE called as clustering process).


Supervised classification in GEE

1-

Decide how many classes will be classified in one area.

2-

Collect several training points for each class.

3-

Merge class points and select bands to be classified

4-

Classify the image.

5- Add some legend


1- Decide how many classes will be classified in one area. Class Number

Class Name

Class Color

1. settlement red 2. paddy fields/ agricultural fields orange 3. water body blue 4. forest / dense vegetation dark green


2- Collect several training points for each class a- features from google fusion tables The training points can

(shapefile -> KML -> google fusion

be collected to GEE by :

tables)

b- construct feature collection by using geometry tools for all classes

Further information about fusion tables can be read in https://developers.google.com/earthengine/feature_collections


2-Â Â Select several points for each class, as training points. b- construct feature collection by using geometry tools for all classes

Click new layer, there will be layer named geometry2.


2-Â Â Select several points for each class, as training points. b- construct feature collection by using geometry tools for all classes

Click the gear button/customize button and this window will appear Rename the variable name from geometry2 to class name, e.g: settlement.


2-Â Â Select several points for each class, as training points. b- construct feature collection by using geometry tools for all classes

set the import as to Feature Click + add properties to add class properties


2-Â Â Select several points for each class, as training points. b- construct feature collection by using geometry tools for all classes

Type class as properties name, and put number, for e.g 1 (the first class of land cover type)


Zoom in the satellite image and add the marker in area that is settlement. The number of points (beside the layer name) will be increased. Select 20-30 points. Do the same process for other classes


Assign multi-points geometry (features) as feature collection

var c1_settlement= ee.FeatureCollection(settlement); do the same process to other classes, you can use any other name for the variable. In this case there are four classes: var var var var

c1_settlement = ee.FeatureCollection(settlement); c2_agriculture = ee.FeatureCollection(agriculture); c3_water = ee.FeatureCollection(water); c4_forest = ee.FeatureCollection(forest);


3- Merge class points and select bands to be classified var class_points = c1_settlement .merge(c2_agriculture). merge(c3_water).merge(c4_forest );

var img_toclassify = display_image.select('B2','B3','B4','B5','B6','B7');


4- Classify the image var training =img_toclassify.sampleRegions({ collection: class_points, properties: ['class'], scale: 30}); // //Train a CART classifier with default parameters. var classifier= ee.Classifier.cart().train(training, 'class'); // // Classify the image var classified = img_toclassify.classify(classifier);


// // Set a parameter to visualize the classification image // //put the color pallete same as the geometry color

var vispar_cls ={palette: ['#af371c','#ffc82d','#00ffff','#19c254'],min: 1, max: 4}; Map.addLayer(classified, vispar_cls, Â 'classification');


Add some classification legend: // //add some legend print('Classification legend:', 'red  : Settlement', 'orange: Agriculture fields', 'cyan  : Water body', 'green : Forest')


Turn static files into dynamic content formats.

Create a flipbook
Issuu converts static files into: digital portfolios, online yearbooks, online catalogs, digital photo albums and more. Sign up and create your flipbook.