Skip to content

Commit 14c2b04

Browse files
committedFeb 6, 2019
jj
1 parent 86fd894 commit 14c2b04

File tree

1 file changed

+450
-0
lines changed

1 file changed

+450
-0
lines changed
 

‎Geospatial_analysis_Yale-NUS.md

+450
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,450 @@
1+
<p align="center"> <b>Geospatial Software Analysis - An Introduction to Google Earth Engine</b> </p>
2+
3+
<br><br><br><br><br><br><br><br>
4+
5+
6+
<p align="center"> <b>TC Chakraborty</b> </p>
7+
8+
<p align="center"> <b>Yale School of Forestry & Environmental Studies</b> </p>
9+
10+
<p align="center"> <b>Yale Data Driven Solutions Group</b> </p>
11+
12+
<br><br><br><br>
13+
14+
15+
<p align="center"> <b>March 16, 2018</b> </p>
16+
<br><br>
17+
<br><br><br><br>
18+
<br><br><br><br><br><br><br><br>
19+
20+
---
21+
22+
<p align="center"> https://github.com/datadrivenyale/day-of-data-2.0 </p>
23+
24+
---
25+
<br><br><br><br><br><br><br>
26+
27+
# Agenda
28+
29+
##### Introduction to Geospatial Analysis
30+
##### Data Types
31+
##### The Google Earth Engine platform
32+
##### Basic functions
33+
##### Variable types
34+
##### Geometry declaration
35+
##### Functions and mapping
36+
##### Operations on Geometries
37+
##### Features and Feature Collections
38+
##### Operations on Features
39+
##### Filters
40+
##### Operations on Images
41+
##### Operations on Image Collections
42+
##### Importing and exporting Data
43+
##### Conclusion and resources
44+
45+
---
46+
47+
# Introduction
48+
Collection, visualization, and analysis of geographical or spatial data.
49+
50+
# Data types
51+
52+
- Vector data represent lat-long coordinates
53+
54+
- Raster data comprises of pixels with associated values
55+
56+
---
57+
58+
59+
- Points
60+
61+
![Points](https://github.com/datadrivenyale/day-of-data-2.0/blob/master/5-Geospatial%20analysis/images/points-vector.png "Points")
62+
63+
- Lines
64+
65+
![Lines](https://github.com/datadrivenyale/day-of-data-2.0/blob/master/5-Geospatial%20analysis/images/line-vector.png "Lines")
66+
67+
- Polygons
68+
69+
![Polygons](https://github.com/datadrivenyale/day-of-data-2.0/blob/master/5-Geospatial%20analysis/images/polygon-vector.png "Polygons")
70+
71+
- Raster layers/bands
72+
73+
![Raster](https://github.com/datadrivenyale/day-of-data-2.0/blob/master/5-Geospatial%20analysis/images/Map-Algebra.png "Raster")
74+
75+
76+
---
77+
78+
# Google Earth Engine platform
79+
80+
[Code Editor](https://code.earthengine.google.com/ "Earth Engine Code Editor")
81+
82+
- Cloud-based platform for planetary scale geospatial analysis
83+
- Uses Google's computational resources to reduce processing time
84+
- Massive archive of remote sensing data
85+
- 200 public datasets
86+
- greater than 4000 new images every day
87+
- greater than 5 million images
88+
- greater than 5 petabytes of data
89+
90+
Source: Google Earth Engine User summit
91+
92+
---
93+
94+
![Code Editor](https://github.com/datadrivenyale/day-of-data-2.0/blob/master/5-Geospatial%20analysis/images/EE.png "Code Editor")
95+
96+
---
97+
98+
# Basic Functions
99+
100+
### Declaring variables
101+
```javascript
102+
var varname = Containerforvariabletype(variable name);
103+
```
104+
### Centering map
105+
```javascript
106+
Map.setCenter(long, lat, zoom level);
107+
```
108+
>Zoom level varies from 0 (no zoom) to 20 (highest zoom level)
109+
110+
### Displaying metadata
111+
```javascript
112+
print(variable name)
113+
```
114+
### Adding a layer to the map
115+
```javascript
116+
Map.addLayer(VARIABLENAME);
117+
```
118+
119+
---
120+
121+
# Variable types in Earth Engine
122+
123+
### Strings
124+
125+
```javascript
126+
var var_String = ee.String("This is a string. Or is it? It is.");
127+
```
128+
### Numbers
129+
```javascript
130+
var var_Numbers = ee.Number(5);
131+
```
132+
133+
### Arrays
134+
```javascript
135+
var var_Array = ee.Array([[5, 2, 3],  [-2, 7, 10],  [6, 6, 9]]);
136+
```
137+
138+
### Lists
139+
```javascript
140+
var var_List = ee.List([5, "five" , 6, "six"]);
141+
```
142+
### Dictionaries
143+
```javascript
144+
var var_Dictionary = ee.Dictionary({five: 5 , six: 6});
145+
```
146+
147+
### And the fun stuff
148+
- Geometries
149+
- Features
150+
- Feature Collections
151+
- Images
152+
- Image Collections
153+
154+
---
155+
156+
# Geometries – declaration and types
157+
158+
### Points
159+
```javascript
160+
var var_Point = ee.Geometry.Point(0, 45);
161+
```
162+
### Multi Points
163+
```javascript
164+
var var_MultiPoint = ee.Geometry.MultiPoint(0, 45, 5,6, 70,-56);
165+
```
166+
### Line String
167+
```javascript
168+
var var_LineString = ee.Geometry.LineString([[0, 45], [5,6], [70,-56]]);
169+
```
170+
### Multi Line String
171+
```javascript
172+
var var_MultiLineString = ee.Geometry.MultiLineString([[[0, 45], [5,6], [70,-56]], [[0, -45], [-5,-6], [-70,56]]]);
173+
```
174+
### Linear Ring
175+
```javascript
176+
var var_LinearRing = ee.Geometry.LinearRing(0, 45, 5,6, 70,-56, 0,45);
177+
```
178+
### Rectangle
179+
```javascript
180+
var var_Rectangle = ee.Geometry.Rectangle(0, 0, 60,30);
181+
```
182+
### Polygon
183+
```javascript
184+
var var_Polygon = ee.Geometry.Polygon([[[0, 0], [6,3], [5, 5], [-30,2], [0,0]]]);
185+
```
186+
### Multi Polygon
187+
```javascript
188+
var var_MultiPolygon = ee.Geometry.MultiPolygon([ee.Geometry.Polygon([[0, 0], [6, 3], [5, 5], [-30, 2], [0,0]]), ee.Geometry.Polygon([[0, 0], [-6, -3], [-5, -5], [30, -2], [0, 0]])]);
189+
```
190+
191+
---
192+
193+
# Features and Feature Collections
194+
195+
- Features are geometries associated with specific properties
196+
- Feature Collections are groups of features
197+
198+
199+
![Singapore map by GRC](https://github.com/datadrivenyale/day-of-data-2.0/blob/master/5-Geospatial%20analysis/images/GRC.png "Singapore Map by GRC")
200+
201+
---
202+
203+
# Functions and mapping
204+
205+
- A set of instructions to perform a specific task
206+
```javascript
207+
function function_Name(Arguments) {statements};
208+
```
209+
### Call function
210+
```javascript
211+
var result = function_Name(Input);
212+
```
213+
214+
### Map function over Feature or Image Collection
215+
```javascript
216+
var result = Input.map(function_Name);
217+
```
218+
219+
---
220+
221+
222+
# Operations on Geometries
223+
224+
[Geometry operations](https://code.earthengine.google.com/d5d2db5aa4bea6bd94355a39e1f42a3f "EE Geometry operations")
225+
226+
### Find area of geometry
227+
```javascript
228+
var Geometry_area = var_Geometry.area();
229+
```
230+
### Find length of line
231+
```javascript
232+
var Line_length = var_LineString.length();
233+
```
234+
### Find perimeter of geometry
235+
```javascript
236+
var Geometry_perimeter = var_Geometry.perimeter();
237+
```
238+
239+
### Reduce number of vertices in geometry
240+
```javascript
241+
var SimplifiedGeometry = var_Geometry.simplify(100);
242+
```
243+
### Find centroid of geometry
244+
```javascript
245+
var Centroid = var_Geometry.centroid();
246+
```
247+
### Create buffer around geometry
248+
```javascript
249+
var Buffer = var_Geometry.buffer(100);
250+
```
251+
### Find bounded rectangle of the Geometry
252+
```javascript
253+
var BoundedGeometry = var_Geometry.bounds();
254+
```
255+
### Find the smallest envelope that can envelop the Geometry
256+
```javascript
257+
var Convexhull_Geometry = var_Geometry.convexHull();
258+
```
259+
### Find common area between two or more geometries
260+
```javascript
261+
var Inter_geometry = var_Geometry1.intersection(var_Geometry2);
262+
```
263+
### Find area that includes two or more geometries
264+
```javascript
265+
var Union_geometry = var_Geometry1.union(var_Geometry2);
266+
```
267+
---
268+
# Operations on Features
269+
270+
[Feature operations](https://code.earthengine.google.com/1cd4cb760f71a56dce1cabcf44feec27 "EE Feature operations")
271+
272+
### Set property name and value of geometry to create a feature
273+
```javascript
274+
var var_Feature = ee.Feature(var_Geometry, {Name: "Feature name", Size: 500};
275+
```
276+
### Create a new feature from existing feature while renaming a property
277+
```javascript
278+
var var_Featurenew = var_Feature.select(["Name"], ["Descriptor"]);
279+
```
280+
### Extract values of a property from a Feature
281+
```javascript
282+
var values = var_Feature.get(''Size'');
283+
```
284+
---
285+
286+
# Filters
287+
288+
### Creator a filter for values of a property
289+
290+
```javascript
291+
var BFilter = ee.Filter.eq(Property_name, Value);
292+
```
293+
>or .neq , .gt , .gte , .lt , and .lte
294+
295+
### Create a filter based on maximum difference from a threshold
296+
297+
```javascript
298+
var DiffFilter = ee.Filter.maxDifference(threshold, Property_name, Value);
299+
```
300+
301+
### Create a text filter
302+
303+
```javascript
304+
var TxtFilter = ee.Filter.stringContains( Property_name, StringValue);
305+
```
306+
307+
>or .stringStartsWith, and .stringEndsWith
308+
309+
### Create a range filter
310+
311+
```javascript
312+
var RangeFilter = ee.Filter.rangeContains( Property_name, StringValue, MinValue, MaxValue);
313+
```
314+
315+
### Create a list filter to check for certain values
316+
317+
```javascript
318+
var ListFilter = ee.Filter.listContains(Property_name, Value1, Property_name2, Value2);
319+
```
320+
>.inList to test against list of values
321+
322+
### Create a filter of dates
323+
324+
```javascript
325+
var DateFilter = ee.Filter.calendarRange(StartDate, StopDate);
326+
```
327+
328+
### Create a filter for particular days of the year
329+
330+
```javascript
331+
var DayFilter = ee.Filter.dayOfYear(startDay, StopDay);
332+
```
333+
334+
### Create a filter to subset geospatial data
335+
336+
```javascript
337+
var BoundsFilter= ee.Filter.bounds(GeometryorFeature);
338+
```
339+
### Combining and inversing filters
340+
341+
```javascript
342+
var NewFilter=ee.Filter.and(Listoffilters);
343+
var NewFilter=ee.Filter.or(Listoffilters);
344+
var inverseFilter = ee.Filter.not(filter);
345+
```
346+
---
347+
# Operations on Images
348+
349+
[Image operations](https://code.earthengine.google.com/54c72f1d74cb42e7ed1245f1511562bb "EE Image operations")
350+
351+
### Selecting the bands of an image
352+
```javascript
353+
var band = var_Image.select(band name);
354+
```
355+
### Creating masks
356+
```javascript
357+
var mask =var_Image.eq(value);
358+
```
359+
>or .neq or .gt or .gte or .lt or .lte
360+
### Applying masks
361+
```javascript
362+
var masked =var_Image.mask(mask);
363+
```
364+
365+
### Pixelwise calculation
366+
```javascript
367+
var results =var_Image.sum(value);
368+
```
369+
>or .subtract , .multiply , .divide , .max , .min , .abs , .round , .floor , .ceil , .sqrt , .exp, .log, .log10, .sin , .cos , .tan , .sinh , .cosh , .tanh , .acos, .asin
370+
371+
### Shift pixels of an image
372+
```javascript
373+
newImage = oldImage.leftShift(valueofshift);
374+
```
375+
>or .rightShift
376+
377+
### Create a single value from an image by applying a reducer based on regions of interest
378+
379+
```javascript
380+
var outputDictionary = var_Image.reduceRegion(Reducer, var_Geometry, scale);
381+
```
382+
383+
---
384+
385+
# Operations on Image Collections
386+
387+
### Select the first n numbers of images in a collection (based on property)
388+
389+
```javascript
390+
var SelectedImages =var_ImCollection.limit (n, Property_name, Order);
391+
```
392+
393+
### Select images in collection based on particular properties
394+
395+
```javascript
396+
var SelectedImages = var_ImCollection.filterMetadata (Property_name, Relation , Value);
397+
```
398+
>Relations could be "equals", "less_than", "greater_than", "starts_with", "ends_with", and "contains"
399+
400+
### Select images within date range
401+
```javascript
402+
var SelectedImages = var_ImCollection.filterDate (StartDate, StopDate);
403+
```
404+
405+
### Select images within Geometry
406+
```javascript
407+
var SelectedImages = var_ImCollection.filterBounds (var_Geometry);
408+
```
409+
410+
### Perform pixelwise calculations for all images in collection
411+
```javascript
412+
var sumofimages = var_ImCollection.sum();
413+
```
414+
>or .product, .max, .min, .mean, .mode, .median, and .count
415+
416+
### Create composite of images in collection with the last image on top
417+
418+
```javascript
419+
var mosaicofimages = var_ImCollection.mosaic();
420+
```
421+
---
422+
# Importing and exporting data
423+
424+
[Image to table example](https://code.earthengine.google.com/7ba00e4d20acfdb3973bb0263757ecd7 "Image to table example")
425+
426+
[Timelapse example](https://code.earthengine.google.com/3f9c9d57c08ac12f60d0f9f213a0d359 "Timelapse example")
427+
### Export image, video or table to Google Drive, Asset, or Google Cloud
428+
429+
```javascript
430+
Export.image.toDrive({
431+
collection: var_Image, description: 'FileName', region: var_Geometry, scale: 1000}
432+
});
433+
```
434+
>or image.toCloudStorage, image.toAsset, table.toDrive, table.toCloudStorage, video.toCloudStorage, and video.toDrive
435+
436+
---
437+
438+
# Conclusion and resource
439+
440+
[Night Lights example](https://code.earthengine.google.com/2859884e8ea9b116c2ae24c3f95ec8cb "Night Lights example")
441+
- Adapted from Prof. Dana Tomlin's notes
442+
443+
### Resources
444+
[Google Earth Engine API documentation](https://developers.google.com/earth-engine/ "Google Earth Engine API documentation")
445+
446+
[Google Earth Engine Developers forum](https://groups.google.com/forum/#!forum/google-earth-engine-developers "Google Earth Engine Developers forum")
447+
448+
[Example scripts from Prof. Dana Tomlin's handouts for his course on Geospatial Software Design](https://github.com/EEYale/example-scripts "Example scripts from Prof. Dana Tomlin's handouts for his course on Geospatial Software Design")
449+
450+
- tc.chakraborty@yale.edu

0 commit comments

Comments
 (0)
Please sign in to comment.