Download - GIS TUTORIAL 4: Introduction to Google Earth Engine

Transcript
Page 1: GIS TUTORIAL 4: Introduction to Google Earth Engine

1

GISTUTORIAL4:IntroductiontoGoogleEarthEngineInthistutorialyouwillreceiveabriefintroductiontoGoogleEarthEngineandlearnhowtoeditandrunsimplescriptstoproduceSentinel-2andLandsat-5satelliteimagery.

1 GettingStarted

1.1 GoogleEarthEngineintroduction

GoogleEarthEngine(GEE)shouldrunfromanymodernbrowser–youdonotneedtoinstallextrasoftware.ChromeisagoodchoiceasitisalsocreatedbyGoogle.

TouseGEE,youneedtosigninwithyourGoogleaccounthere:

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

Ifyouhavenotalreadysignedupyouwillneedtodosohere:https://earthengine.google.com/signup/.

• ItwilltakeafewdaysforGoogletoapproveyouraccesstoGEE,sopleasedothispromptlyifyouhavenotalreadydoneso.Onceyouhavesignedinyouwillseethefollowingscreenwhenyouvisitthemainwebsite.

Page 2: GIS TUTORIAL 4: Introduction to Google Earth Engine

2

1.2 GoogleEarthEngineinterface

Unlike QGIS which is controlled through a graphical user interface, GEE relies on scripts –programming code that gives the platform its instructions. The interface is made up of thefollowingwindowsandcontrolswhichwillbereferredtorepeatedlythroughoutthesetutorials.

TheConsolewindowhastwoothertabs,theInspectorandTaskstabswhichneedtobeclickedontobeaccessed.ThesameistruefortheScripts/Docs/Assetswindow,butwewon’tbeusingtheseasmuch.

Page 3: GIS TUTORIAL 4: Introduction to Google Earth Engine

3

2 EditingandRunningASimpleSentinel-2Script(videotutorialplaylist)

WearegoingtobeusingasimplescripttoviewanddownloadsomeSentinel-2imagery.• Sentinel-2isasatelliteownedandoperatedbytheEuropeanSpaceAgencythathasbeen

collectingdatasinceJune2015.• Unlikealotofsatelliteimagery,Sentinel-2isfreetodownloadanduse.• Ithasaten-metreresolutionandthirteendifferentbands.ItisverysimilartoLandsat

whichwehaveusedbefore,buttheESAversioninsteadofNASA.Youcanfindoutaboutthesatellitehere.

Thescripthasalreadybeenwrittenforus.Whatwearegoingtodointhenextstepsisaccessit,editittoourownspecifications,andthenrunit.

• Click here to open the simplest version of the script in your web browserhttps://code.earthengine.google.com/e02fefa580c9e7d1a0af6e96f5baccf5

First,havealookatthetextintheCodeEditor.

Itmaylookcomplicated,butbasicallyeachlineisaninstructiontotellthescripttodosomething:

• Thegreentextisnotestoexplainwhateachpartofthescriptdoes:o Line3:importstheSentinel-2collectiono Line6:definestheSentinel-2bandsweareinterestedino Line 9: creates a single image by taking themiddle value of all the available

Sentinel-2imageryforeachpixelo Line12:tellsGEEhowtodisplayourimageo Line15:tellsGEEtodisplayito Line18:automaticallymovestheMapViewtothecentreoftheredrectangle.

Page 4: GIS TUTORIAL 4: Introduction to Google Earth Engine

4

Aswework throughthe tutorial,wewillencounter longerversionsof thescriptswhichhavemoreinstructionstorefineourresultsfurther.

2.1 Geometrytoolsanddefiningyourareaofinterest(videotutorial)

Whenwefirstopeneachversionofthescript,themapwillautomaticallyzoomtoanareaofOmanandsomeSentinel-2imageryforthatareawillstarttoload.

• So,thefirstthingwewilldoischangethistoourownareaofinterest.• Click“Geometryimports”intheGeometryToolsandturnonthe“geometry”polygon.

• ClickonthepolygonandclickDelete.

• NavigateinthemaptoyourownareaofinterestandusetheRectangletooltodefineanewarea.

• OnceyouhavedrawnyourrectanglepresstheStopDrawing(Hand)button.

Page 5: GIS TUTORIAL 4: Introduction to Google Earth Engine

5

• NowclickRunintheCodeEditor.

• TurnofftheredrectangleintheGeometryImportsmenuandwaitfortheimagerytoload

Page 6: GIS TUTORIAL 4: Introduction to Google Earth Engine

6

• YoucannowzoominandexploretheSentinel-2imageryofyourarea.

2.2 EditingtheSentinel-2bandsintheCodeEditor(videotutorial)

Bydefault,thescriptisprogrammedtocreatea“truecolourcomposite”–animagewithcoloursthatwewouldrecognisewiththenakedeye.

Wearenowgoing tochange theSentinel-2bands tomakedifferent colourcompositeswhichhighlightcertainfeaturesinthesatelliteimagery,suchasgeology,urbanareasorvegetation.Thisisveryusefulwhenweareassessingchangetolandscapeovertimeandexaminingdisturbancesandthreatstoarchaeologicalsites.

• Clickheretoopenthenextversionofthescripthttps://code.earthengine.google.com/42eee8ffa6ee2e80e400cdd2c9b58028

o ThiswillreturnustoourdefaultexampleinOman.• Findthe“BANDS”sectionofthescriptintheCodeEditor.• Changethered“B”numbersin“S2_bands”tomatchoneofthebandcombinationslisted

inthenotesandclickRun.

• Tryadifferentbandcombinationtocompare.• TurnonanddeletetheredrectangleinGeometryTools.• RepeatthestepsinSection3.1andredrawarectangleinyourownareaofinterestand

tryrunningthescriptforsomedifferentbandcombinations.

Page 7: GIS TUTORIAL 4: Introduction to Google Earth Engine

7

2.3 FilteringtheSentinel-2collectionbydate(videotutorial)

Inourearlierscripts,wehavecreatedamosaicusingtheentireSentinel-2collection,whichcontainshundredsofimagesfrom2015onwards.GEEallowsustodefineadaterangethatweareinterestedinandfiltertheimagerytoonlythosedates.Thisisincrediblyusefulifweareanalysingchangetolandscapesorarchaeologicalsitesovertimeandwanttocomparedifferenttimeperiods.

• Clickheretoopenthenextversionofthescripthttps://code.earthengine.google.com/d750f44cc671e657b2812c42b59c55e1

• Findthe“DATE”sectionofthescriptintheCodeEditor

Thetwodatesinredtextdefinethestartandendofthefilterrange.

• Thesedatescanbechanged,butitisimportanttonotethatSentinel-2imagerywasonlyproducedfromJune2015,sothisistheearliestdatethatcanbeselected.

• Changetheyearto2016onbothdatesandclickRun.• Expand“ImageCollection”intheConsoleWindow.

Page 8: GIS TUTORIAL 4: Introduction to Google Earth Engine

8

Ifyouexpandthe‘features’section,itwilltellyouthedetailsofeachimageinthecollectionbasedonthedatesthatyouhavegiven.

• RepeatthestepsinSection3.1todefineyourownareaofinterestandtrychangingthedateranges.

• Seeifyoucanspotanychangesinyourareaovertime.

2.4 ExportingSentinel-2imagerytoQGIS(videotutorial)

HavingnowusedallthedifferentpartsofthissimpleSentinel-2script,wearenowgoingtolearnhowtoexporttheimageryintoQGIS.

• Clickheretoopenthefinalversionofthescripthttps://code.earthengine.google.com/d1e21be1c93d44d27376027173b14075

• SetyourareaofinterestfollowingthestepsinSection3.1.• ChooseabandcombinationthatyouarehappywithasoutlinedinSection3.2.• SetthedatefiltertoausefulrangeasdescribedinSection3.3.• Runthescriptandmakesureyouarehappywiththefinalimage.• ScrolldowntothelastsectionofthescriptintheCodeEditor.

Thissectioncontrolstheexportsettings:

• image:tellsthescriptwhichimagetoexport(S2_mosaic),• description:specifiesthenameoftheexportjob(Sentinel_2),• scale:specifiestheresolutionoftheimage(10m),• maxPixels:definesthemaximumnumberofpixelsperimage(1e13=

10000000000000),• region:specifiestheareatobeexported(geometryindicatesthatitshouldexportthe

areadefinedbytheredrectangle).

Page 9: GIS TUTORIAL 4: Introduction to Google Earth Engine

9

Unlessyouareexportingaverylargeimageandwantalowerresolution(e.g.100or1000m),youcanleavethesesettingsastheyare.

• IntheConsolewindowclicktheorangeTaskstab.• Clicktheblue‘Run’buttonnextto“Sentinel_2”.• Type“GEE”in“Drivefolder”.• GiveyourSentinel-2imageaname(includingthegeneralareaandbandcombinationis

agoodidea)andclickRun.

• WaituntiltheexportcompletesintheTaskwindowo Whileitisworkingitwillshowacogandhowlongagothetaskstarted,o Whenitiscompleteitwillturnblueandshowatickmarko Thismaytakeafewminutesdependingonthesizeoftheimage

• IfitistakingalongtimeclicktheRefreshbutton,orthe[?]thatappearsnexttothesmallcog.

• OpenanewtabandgotoGoogleDrivehttps://drive.google.com/drive/u/0/my-drive• FindandopenyournewGEEfolder.

Page 10: GIS TUTORIAL 4: Introduction to Google Earth Engine

10

• FindyourSentinel-2image,rightclickitandselectDownload.• Whenthedownloadhascompleted,movetheimageintoyourGISfolderandcreatea

newfolderforit(e.g.GEE).

• OpenQGISandaddyourSentinel-2imageusingthe‘OpenDataSourceManager’buttonontheToolbarandchoosing‘Raster’.

o NavigatetoyoursavedSentinel-2imagefileandclickAdd.

Page 11: GIS TUTORIAL 4: Introduction to Google Earth Engine

11

• ReturntotheGEEwindowtosaveyourcopyofthescriptsoyoucanrevisititlater.• ClicktheblackarownexttotheSavebuttonandselect“SaveAs”.• GiveyourscriptanameandclickSave.

YoucannowaccessthisscriptinyourScriptswindow.

PRACTICE:createanddownloadaSentinel-2compositeforyourareaofinterestandincorporateitintoamapinQGIS.

3 WorkingwithSentinel-2andLandsat-5Data(videotutorialplaylist)

Sentinel-2imageryisexcellentforexaminingthemostrecentalterationstothelandscape,buttheimageryonlygoesbacktoJune2015.Ifwewanttocompareimageryoveralongertimeperiod,weneedtoincludeotherimagery.

TheLandsat-5satellitecollectedverysimilardatatoSentinel-2between1984and2012.Thisistheperfectdatasetforexaminingchangestothelandscapeoveralongperiodoftime.OurnextscriptcombinesbothSentinel-2andLandsat-5datatoprovideacomparisonbetweenmodernandhistoricalimagery.

3.1 TheLayersPanelanddefiningyourareaofinterest(videotutorial)

First,wearegoingtoopenthescript,explorethetwodifferentlayersanddefineanewareaofinterest.

• Clickheretoopenthenewscript:https://code.earthengine.google.com/1132354830d01200e6e064cafd4c4f95

Page 12: GIS TUTORIAL 4: Introduction to Google Earth Engine

12

• HoveryourmouseovertheLayersPanel(ontheupperrightsideoftheMapView).

NoticethattwolayersarenowbeingdisplayedintheMapViewWindow–theSentinel-2imageaboveandtheLandsat-5below.

• TurnofftheSentinel-2imagebyclickingonthecheckbesideitandzoomintotheimagerytocomparethetwodatasets.

• DeletetheoldredrectangleanddefineanewareaofinterestwiththeGeometryToolsfollowingtheinstructionsinSection3.1.

o Comparethetwodifferenttypesofimageryforyourarea.

Page 13: GIS TUTORIAL 4: Introduction to Google Earth Engine

13

Page 14: GIS TUTORIAL 4: Introduction to Google Earth Engine

14

3.2 FilteringtheSentinel-2andLandsat-5collectionsbydate(videotutorial)

Togetthemostoutofthisscriptwewanttobeabletosetthedatesoftheimagerytofollowourownparameters.

Youshouldnoticethatthisnewscriptisverysimilartothepreviousone,exceptthatitnowcontainstwoparts–onefortheLandsat-5imageryandonefortheSentinel-2imagery.Thebasiccommandsarealmostidenticalforbothdatasets,andtothepreviousscriptthatwelookedat.

Togetthewidestpossiblecomparisonwearegoingtochangethedatesto1984and2020fortheLandsat-5andSentinel-2imageryrespectively.

• Online7ofthescript,intheLandsatsection,changebothyearsto1984.• Online35ofthescript,intheSentinel-2section,changebothyearsto2020.• Runthescript.• Tryenteringdifferentdatesandlookforevidenceofchangebetweenthetwoimages.

Page 15: GIS TUTORIAL 4: Introduction to Google Earth Engine

15

3.3 CreatingSentinel-2andLandsat-5colourcomposites(videotutorial)

Wealsowanttobeabletocreateourowncolourcompositeswithdifferentbandcombinations,butwemustbecarefultomakesurethattheSentinel-2andLandsat-5versionsmatch.

• HavealookattheSentinel-2andLandsat-5bandsintheCodeEditorandthetwosetsofimageryintheLayerPanel.

EventhoughbothimagesareTrueColourComposites,thebandcombinationsareslightlydifferent.ThisisbecausetheinstrumentsonboardtheSentinel-2andLandsat-5satellitesarenotidentical–differentbandsfocusondifferentpartsoftheelectromagneticspectrum.

Page 16: GIS TUTORIAL 4: Introduction to Google Earth Engine

16

Thismeansthatcaremustbetakenwhenprogrammingthebandsintothescript–ifyouusethesamenumbersforeachimage,thenyouwillendupwithverydifferentlookingcolourcomposites.

Thefollowingtableprovidesequivalentbandcombinationsforbothdatasets.Italsoprovidesguidanceonpossibleapplicationsforeachbandcombination.

Composite Sentinel-2 Landsat-5 Applications natural colour 4/3/2 3/2/1 general - recognisable to the naked eye natural-like 12/8/3 7/4/2 general - recognisable but clearer than natural colour colour infrared 8/4/3 4/3/2 agricultural areas (bright red) false colour (agriculture) 11/8/2 5/4/1 agricultural areas (bright green) false colour (urban) 12/11/4 7/5/3 urbanisation false colour (land/water) 8/11/4 4/5/3 coastal and wetland areas false colour (geology 1) 12/11/2 7/5/1 desertification, mining and industry false colour (geology 2) 11/3/2 5/2/1 desertification, mining and industry

• SettheSentinel-2andLandsat-5bandstoproduceacolourinfraredcomposite.• RunthescriptandcomparetheSentinel-2andLandsat-5images.

• Ifyouhaven’talready,changetheareaofinteresttoyourarea• Changethebandcombinationstoacombinationthatisrelevanttoyourareaandrunthe

script.

Page 17: GIS TUTORIAL 4: Introduction to Google Earth Engine

17

3.4 ExportingSentinel-2andLandsat-5imagery(videotutorial)

Once you are happywith the area, date and band combinations used in your Landsat-5 andSentinel-2imagerybothcanbeexported.

• Makesureyouarehappywiththeareaofinterest,dateandbandcombinationsthatyouhavechosenfollowingthestepsintheprevioussectionsandrunyourscript.

• ClickontheTasksWindow.• Click“Run”nextto“Landsat-5”.• Type“GEE”in“DriveFolder”.• GiveitanappropriatenameincludingtheareaandbandcombinationandclickRun.• RepeatthisforyourSentinel-2image–bothcanrunatthesametime.

Page 18: GIS TUTORIAL 4: Introduction to Google Earth Engine

18

OncecompletedyoucandownloadthemfromGoogleDrivetoopeninQGISusingthestepsexplainedearlier.

Thereisalsoashortcutforgettingtotheimageeasily.

• HoveryourmouseoveracompletedimageintheTaskswindowandclickthe[?]button

• Click“OpeninDrive”

• Right-clickyourimagesandclick“Download”todownloadthem.• Whencompleted,movethemfromyourDownloadsfoldertoyourGIS/GEEfolder.• OpenandbrowseyourimagesinQGIS.• Don’tforgettosaveyourscriptifyouwanttorevisititinthefuture(the“Save”arrow>

“SaveAs”).

ACTIVITY:createoneormoremapsinQGISusingfalsecolourcompositesfromGEEtoillustratechangesinthelandscapethathavedisturbedorthatthreatenarchaeologicalsitesinyourareaofinterest.