Transcript
Page 1: An Introduction to QGIS 1. What is QGIS?ebrelsford.github.io/talks/2016/doitt/course.pdf4 2. Working with vector data Like any good GIS, QGIS is capable of opening vector data of numerous

1

AnIntroductiontoQGIS

1.WhatisQGIS?

QGIS(http://qgis.org)isanopensourceGIS(GeographicInformationSystem).Inthissectionwewillcover:

abriefhistoryofQGIS,installingQGIS,andQGISandtheworldofFreeandOpenSourceSoftware(FOSS)

InstallingQGISWhileQGISshouldalreadybeinstalledonthemachinesweareworkingon,it'sworthnotingthatyoucaninstallitonalmostanymachineforfree.SowhetheryouuseaMacorWindows(orevenLinux),youcaninstallQGISonyourhomecomputertodoGISwork.

InstallingonWindows

InstallingQGISonaWindowscomputerislikeinstallinganyotherpieceofsoftware.Youdownloadtheinstallerandrunit.Downloadthestandaloneinstalleratdownload.qgis.org(http://download.qgis.org/).

Page 2: An Introduction to QGIS 1. What is QGIS?ebrelsford.github.io/talks/2016/doitt/course.pdf4 2. Working with vector data Like any good GIS, QGIS is capable of opening vector data of numerous

2

TheWindowsQGISInstallerdownloadpage

InstallingonMacOSX

Unfortunately,installingQGISonMacOSXisslightlymorecomplicatedthaninstallingitonaWindowscomputer.YouwillneedtodownloadandinstallseveralpackagesintheorderspecifiedonKyngChaos(http://www.kyngchaos.com/software/qgis),apopularsitethatpackagesopensourceGISsoftwareforMacOSX.Thepackagesyouneedtoinstallare:

GDAL(http://www.kyngchaos.com/software/frameworks#gdal_complete)(usetheGDALCompletepackageatthetopofthispage),NumPy(http://www.kyngchaos.com/software/python)(usethemostrecentversionyoucan),and,finally,QGIS(http://www.kyngchaos.com/software/qgis)(usethemostrecentversionunderCurrent,rightnowthatis2.12.1-1).

TheMacOSXQGISInstallerdownloadpage

Page 3: An Introduction to QGIS 1. What is QGIS?ebrelsford.github.io/talks/2016/doitt/course.pdf4 2. Working with vector data Like any good GIS, QGIS is capable of opening vector data of numerous

3

Restassuredthatwhiletheabovemaysoundcomplicated,youwillbesuccessfulaslongasyoudownloadeachoftheaboveinorderandinstalltheminorder.Youcanalwaysstartoverifyouneedto.

ResourcesTheQGISDownloadpage(http://qgis.org/en/site/forusers/download.html)KyngChaosQGISOSXinstaller(http://www.kyngchaos.com/software/qgis)27DifferencesBetweenArcGISandQGIS(http://gisgeography.com/qgis-arcgis-differences/)QGIS2.0(https://www.youtube.com/watch?v=sQ8ytFJE_Wk)(Thisvideoisn'tveryhighquality,butitcontainsaversionofthehistoryoftheprojectifyou'reinterested.)TheUnknowns:AManager'sGuidetoOpenSource(https://www.youtube.com/watch?v=jUgiG6eaYtI)(PaulRamsey'sexcellenttalkaboutthebenefitsofopensourcesoftware.)

Page 4: An Introduction to QGIS 1. What is QGIS?ebrelsford.github.io/talks/2016/doitt/course.pdf4 2. Working with vector data Like any good GIS, QGIS is capable of opening vector data of numerous

4

2.WorkingwithvectordataLikeanygoodGIS,QGISiscapableofopeningvectordataofnumerousfiletypes,manipulatingthatdata,andexportingthedata.InthissectionwewillgetfamiliarwithhowQGISdealswithvectordata.Wewillcover:

OpeningvectordataIncludingdatafromdatabases

SelectingdataLayersTheattributetableExpressionsCoordinateReferenceSystemsManagingprojects

OpeningvectordataHereweopencommontypesofvectordatasourcesusinganumberofmethodsyouwillruninto.

Exercise2-1:Openashapefile

QGISwillopenmostvectordatafilesinfourways:

theAddLayermenutheBrowserPaneldouble-clickingthefiledragging-and-droppingthefile

TheAddLayermenu

Page 5: An Introduction to QGIS 1. What is QGIS?ebrelsford.github.io/talks/2016/doitt/course.pdf4 2. Working with vector data Like any good GIS, QGIS is capable of opening vector data of numerous

5

Ingeneral,QGISisgoingtobeabletoopenfilesthataresupportedbyOGR(http://gdal.org/1.11/ogr/ogr_formats.html),thoughthismayvaryslightlydependingonhowQGISwasinstalled.

WerecommendaddingfoldersthatyoucommonlyusetoyourfavoritesinthebrowserpanelwhichshouldappearontheleftsideofyourQGISwindow.

TheBrowserPanel

Let'sopenashapefilefromNYCOpenData:

1. EnsurethatyouhavetheRoadbed(https://data.cityofnewyork.us/City-Government/Roadbed/xgwd-7vhd)fileonyourharddrive.

2. OpenitbygoingtoLayer>AddLayer>AddVectorLayerandbrowsingforit.

RemovethelayerfromtheLayersPanelandtryopeningthefileusingtheotherthreemethodsmentionedabove(BrowserPanel,double-clicking,anddrag-and-drop).

Exercise2-2:OpenaCSV

HereweopenaCSVwithgeographicdatainit.Whenyou'reopeningaCSVwithgeographicdatainitscolumns,youneedtousetheAddDelimitedTextLayermenu.Allothermethodswillignorethegeographicdatainthefile.

1. InQGISgotoLayer>AddLayer>AddDelimitedTextLayer.2. BrowsefortheMotorVehicleCollisions2015(https://data.cityofnewyork.us/Public-

Safety/NYPD-Motor-Vehicle-Collisions-2015/kref-x3ki)fileandensurethatavalidpreviewofthefileshowsupinthebottomofyourwindow,thenpressOK.

Page 6: An Introduction to QGIS 1. What is QGIS?ebrelsford.github.io/talks/2016/doitt/course.pdf4 2. Working with vector data Like any good GIS, QGIS is capable of opening vector data of numerous

6

TheAddDelimitedTextLayerdialogbox

Exercise2-3:OpenaWFSlayer

Finally,let'sloadaWFSlayerusingoneoftheUSGS'spublicWFSserver.TheUSGShasasetofgeologicdatasetsavailableonline(https://mrdata.usgs.gov/geology/state/state.php?state=NY),includingaWFSversion.

1. OpentheUSGSNewYorkgeologicmapdata(https://mrdata.usgs.gov/geology/state/state.php?state=NY)page.

2. CopythelinktotheWFSservice,under"OGCWMS".3. InQGIS,gotoLayer>AddLayer>AddWFSLayer.4. CreateanewconnectionandpastetheWFSlinkintotheURLfield.5. SelectyournewconnectionandpressConnect.6. SelectoneoftheavailablelayersandpressAdd.

Page 7: An Introduction to QGIS 1. What is QGIS?ebrelsford.github.io/talks/2016/doitt/course.pdf4 2. Working with vector data Like any good GIS, QGIS is capable of opening vector data of numerous

7

AddinganewWFSconnection

AddingaWFSlayer

Page 8: An Introduction to QGIS 1. What is QGIS?ebrelsford.github.io/talks/2016/doitt/course.pdf4 2. Working with vector data Like any good GIS, QGIS is capable of opening vector data of numerous

8

Exercise2-4:Loadingdatabaselayers

WewillconnecttoapubliclyaccessiblePostGISdatabasethatwassetupforthisworkshop:

1. GotoLayers>AddLayer>AddPostGISLayers.2. Createanewconnection:

host:qgisworkshop.cwxs47o7ilc1.us-west-2.rds.amazonaws.comdatabase:workshopusernameandpasswordwillbeprovidedtoyouForthepurposesofthisworkshopIrecommendsavingtheusernameandpasswordforyourconvenience.

3. Connecttoyournewconnectionandfindtheavailabletablesbyexpandingthepublicschema.

4. AddoneofthetablesasalayerbyselectingitandclickingAdd.

Page 9: An Introduction to QGIS 1. What is QGIS?ebrelsford.github.io/talks/2016/doitt/course.pdf4 2. Working with vector data Like any good GIS, QGIS is capable of opening vector data of numerous

9

TheCreateaNewPostGISConnectiondialog

Page 10: An Introduction to QGIS 1. What is QGIS?ebrelsford.github.io/talks/2016/doitt/course.pdf4 2. Working with vector data Like any good GIS, QGIS is capable of opening vector data of numerous

10

TheAddPostGISTabledialog

Exportingvectordata

Exercise2-5:Exportingvectordata

Similarlytoopeningvectordata,youcanexportvectordatainmanyofthesupportedOGRvectorformats(http://gdal.org/1.11/ogr/ogr_formats.html).Inordertoexportvectordataitmustfirstbeopenasalayerinyourlayerspanel.Right-clickonthelayerandselectSaveAs,andyouwillhaveaccesstotheSavevectorlayeras...dialog.

OnceavectorlayerisopeninQGIS,itdoesn'tmatterwhattheoriginalfiletypeofthelayerwas.Soconvertingfromanysupportedfiletype(ordatabasetable)toanyothersupportedfiletypeworksexactlythesameway.

Page 11: An Introduction to QGIS 1. What is QGIS?ebrelsford.github.io/talks/2016/doitt/course.pdf4 2. Working with vector data Like any good GIS, QGIS is capable of opening vector data of numerous

11

The"Savevectorlayeras..."dialog

1. Addalayertoyourlayerspanelifyoudon'talreadyhaveoneopen.Useoneofthelayersfromthepreviousexercise.

2. Right-clickonlayerinthelayerspanel.3. SelectSaveAs....4. Pickaformatotherthantheonethelayerwasoriginallyin.5. BrowsetosavethefileinanappropriateplaceandpressOK.

TheAttributeTable

Page 12: An Introduction to QGIS 1. What is QGIS?ebrelsford.github.io/talks/2016/doitt/course.pdf4 2. Working with vector data Like any good GIS, QGIS is capable of opening vector data of numerous

12

Herewecovercommonattribute-relatedtasks:

FilteringSelectingInvertselectionMoveselectiontotopQuerytoolFieldcalculator,addingandconvertingvalues

Exercise2-6:Filteringandselectingdata

1. Re-opentheMotorVehicleCollisions2015(https://data.cityofnewyork.us/Public-Safety/NYPD-Motor-Vehicle-Collisions-2015/kref-x3ki)fileinQGISifitisnotopen.

2. Withthecollisionslayerselectedinthelayerspanel,findtheattributetableicontoopentheattributetable.Therearetwootherwaysyoucandothis:right-clickthelayerandselectOpenAttributeTableorselectthelayerandgotoLayers>OpenAttributeTable.

3. Withtheattributetableopen,filterthedata:a. ClickthebuttonatthebottomleftthatreadsShowAllFeatures.b. GotoColumnFilter>BOROUGH.c. Enteraboroughnameinallcaps(egBRONX).d. Press[Enter]ortheApplybutton.

4. Thefilteronlyreducesthenumberoffeaturesthatappearintheattributetable,notonthemapcanvas.Let'sselectfeatureswehavefilteredto:a. Right-clickononeofthefeaturesintheattributetable.b. SelectSelectAll.c. Allofthefeaturesintheboroughyoupickedshouldbehighlighted.

5. Removeyourfilter:a. ClickthearrownexttoAdvancedFilter(expression)inthebottomleftofthe

attributetable(whereitusedtosayShowAllFeatures).b. SelectShowAllFeatures.

6. Yourselectedfeaturesarenowinterspersedwithunselectedfeaturesintheattributetable.Ifyouwantalloftheselectedfeaturestoappeartogether,findtheMoveSelectiontoTopbuttonandclickit.

7. TotherightoftheMoveSelectiontoTopbuttonistheInvertSelectionbutton.ClickthistoseeallthefeaturesthatdidnothavetheboroughyouchoseintheBOROUGHfield.

8. Let'ssaveonlythefeatureswithourchosenborough:a. PressInvertSelectionagaintoselectonlyfeatureswithyourchosenboroughin

theBOROUGHfield.b. Exittheattributetablebyclosingit.c. Rightclickonthelayerinthelayerspanel.d. SelectSaveAs....e. Browseforavalidlocationtosavethefileto.f. EnsureSaveonlyselectedfeaturesischecked.g. PressOK.h. Anewlayerwithjustyourselectedfeaturesshouldbeaddedtoyourlayerspanel.

9. Nowthatwearedonefilteringandselecting,unselectthefeatures:a. Selecttheoriginallayerinthelayerspanel.b. Opentheattributetable.

Page 13: An Introduction to QGIS 1. What is QGIS?ebrelsford.github.io/talks/2016/doitt/course.pdf4 2. Working with vector data Like any good GIS, QGIS is capable of opening vector data of numerous

13

c. FindtheUnselectAllbuttontotheleftoftheMoveSelectiontoTopbutton,andclickit.

ExpressionsInthissectionwewilluseexpressionsintwoways:

SelectbyexpressionFieldcalculator

Exercise2-7:Selectingbyexpression

1. Re-opentheMotorVehicleCollisions2015(https://data.cityofnewyork.us/Public-Safety/NYPD-Motor-Vehicle-Collisions-2015/kref-x3ki)fileinQGISifitisnotopen.

2. Withthecollisionslayerselectedinthelayerspanel,findandclicktheSelectbyexpressionbutton.

3. Let'srecreatetheselectionfromthepreviousexercise:a. Inthemiddlepanel,expandFieldsandValues.b. Double-clickBOROUGH.Thisshouldadd"BOROUGH"tothetextareaintheleft

panel.c. Abovetheleftpanel,click=.d. WithBOROUGHstillselectedinthemiddlepanel,gototherightpanelandpress

Allunique.e. Double-clickoneoftheresultingboroughnames.Yourleftpanelshouldnowlook

somethinglike"BOROUGH"='BRONX'.f. PressSelect.

4. Let'sselectanotherboroughinstead:a. Intheleftpanel,deletetheboroughnameandthequotationmarksaroundit(eg

'BRONX').Leavethecursorafter=.b. Intherightpanel,double-clickadifferentboroughname.c. PressSelect.

5. Let'saddanotherboroughtoourselection:a. Intheleftpanel,deletetheboroughnameandthequotationmarksarounditagain

(eg'BRONX').Leavethecursorafter=.b. Intherightpanel,double-clickadifferentboroughname.c. InsteadofpressingSelect,clickthearrownexttoSelectandchooseAddto

selection.Youshouldnowhavecrashesintwoboroughsselected.6. NowselectallofthecollisionsthathappenedinJuly:

a. Deletethepreviousexpressionfromtheleftpanel.b. ExpandFieldsandValuesanddouble-clickDATE.c. ExpandOperatorsanddouble-click>=.d. Afterthe>=intheleftpanel,type'07/01/2015'.e. UnderOperatorsdouble-clickAND.f. UnderFieldsandValuesdouble-clickDATE.g. UnderOperatorsdouble-click<=.h. Afterthe<=intheleftpanel,type'07/31/2015'.i. Yourexpressionshouldlooklike"DATE">='07/01/2015'AND"DATE"<='07/31/2015'.

j. PressSelect.7. Sinceweknowtheformatofthedates,wecandothesameasabovebyjustlookingat

Page 14: An Introduction to QGIS 1. What is QGIS?ebrelsford.github.io/talks/2016/doitt/course.pdf4 2. Working with vector data Like any good GIS, QGIS is capable of opening vector data of numerous

14

thefirsttwocharactersinDATE:a. Deletethepreviousexpressionfromtheleftpanel.b. UnderStringinthemiddlepanel,double-clickleft,whichgetsthefirstncharacters

fromthefield.c. UnderFieldsandValuesdouble-clickDATE.d. Intheleftpanelafter"DATE",type,2tospecifythatwewantthefirsttwo

characters.e. Type)toclosetheleftfunction.f. Type='07'tocomparetheoutputofleftto07.g. Yourexpressionshouldlooklikeleft("DATE",2)='07'.h. PressSelect.i. UseSaveAs...andsaveonlytheselectedfeatures.Wewillbeusingthisinfuture

exercises.

Exercise2-8:Usingthefieldcalculator

Wewilladdsimplecolumnstoafile.

1. Re-opentheMotorVehicleCollisions2015(https://data.cityofnewyork.us/Public-Safety/NYPD-Motor-Vehicle-Collisions-2015/kref-x3ki)fileinQGISifitisnotopenandselectthelayerinthelayerspanel.

2. FindtheOpenFieldCalculatorbuttonandclickit.3. Createanewfield:

a. SetOutputfieldnametoinjuries.b. LeaveOutputfieldtypesettointegerandOutputfieldwidthsetto10.c. CreateanexpressionthataddsNUMBEROFPEDESTRIANSINJURED,NUMBER

OFCYCLISTINJURED,andNUMBEROFMOTORISTINJURED.d. PressOK.

4. Opentheattributetableandconfirmthatanewfieldwascreatednamedinjuries.5. ConfirmthatyourmathwascorrectbyusingSelectbyexpressiontoselectall

featureswhereournewfield(injuries)isequaltotheoriginalfield(NUMBEROFPERSONSINJURED).

CoordinateReferenceSystemsWewilllookatthreewaysofdealingwithcoordinatereferencesystems:

Project-wide,Settingthelayer'sprojection,andChangingthelayer'sprojection

Exercise2-9:Changingalayer'scoordinatereferencesystem

1. Re-opentheRoadbed(https://data.cityofnewyork.us/City-Government/Roadbed/xgwd-7vhd)fileinQGISifitisnotopen.ThelayeriscurrentlyinEPSG:4326.WewantthelayertobeinStatePlaneLongIsland(EPSG:2263)todosomegeoprocessingwithanotherlayer.

2. Right-clickonthelayerinthelayerspanel.3. ChooseSaveAs....4. SelectESRIShapefilefortheformat.

Page 15: An Introduction to QGIS 1. What is QGIS?ebrelsford.github.io/talks/2016/doitt/course.pdf4 2. Working with vector data Like any good GIS, QGIS is capable of opening vector data of numerous

15

5. ClickBrowseandchooseavalidlocationfortheshapefile.Werecommendendingthefilenamewith_2263.

6. NexttotheCRSdropdown,clicktheSelectCRSbutton.7. IntheCoordinateReferenceSystemSelectordialog,type2263intheFilterfield

tofindNAD83/NewYorkLongIsland(ftUS).Clickittoselectit,thenpressOK.8. PressOKbackintheSavevectorlayeras...dialog.9. AnewlayerwiththeselectedCRSshouldbeaddedtoyourlayerspanelinadditionto

theoldlayer.

Exercise2-10:Correctingalayer'scoordinatereferencesystem

Hereweintentionallyloadalayerinthewrongcoordinatereferencesystemandfixit:

1. Open7MajorFelonyIncidents(https://data.cityofnewyork.us/Public-Safety/NYPD-7-Major-Felony-Incidents/hyij-8hr7).

2. UsingtheAddaDelimitedTextLayerdialog,browseforthefeloniesfile.3. Confirmthat:

a. GeometrydefinitionissettoPointcoordinates.b. XfieldissettoXcoordinate.c. YfieldissettoYcoordinate.

4. PressOK.5. IfpromptedtoselectaCRSchooseEPSG:4326.QGISshoulddefaulttothis.6. ThefileisactuallyinStatePlaneLongIsland(EPSG:2263).Youcanconfirmthisby

openinganotherlayerinNYCandzoomingtothelayer'sextents--theywillnotoverlapcorrectly.

7. Let'sfixthefelonieslayer'sCRS:a. Double-clickonthelayerinthelayerspanel.b. GototheGeneraltab.c. UnderCoordinatereferencesystem,findandclicktheSelectCRSbutton(tothe

rightoftheCRSdropdown).d. FiltertheCRSsbytyping2263intheFilterfield.SelectthecorrectCRSandpress

OK.e. PressOKtoapplyyourchangestothelayer'sproperties.

8. Oncethepointsredraw,theyshouldnowoverlapcorrectlywithotherNYCdata.

Managingprojects

Exercise2-11:Handlinglostdata

1. OpenalayerinQGISifyoudonothaveanyopencurrently.2. SavetheprojectbygoingtoProject>Save.3. CloseQGIS.4. Opentheprojectbydouble-clickingit.Ensurethattheprojectloadsasexpected.5. CloseQGISagain.6. Moveoneoftheproject'sdatafilesonyourcomputertoanotherfolderonyour

computer.Forexample,ifoneoftheproject'slayersisashapefile,moveallofthefilesinthatshapefile(orthefoldertheyarein)somewhereelse.

7. Opentheprojectagainbydouble-clickingit.8. UsetheHandlebadlayersdialogtofixthedatafile'slocation:

a. Selectthelayer.

Page 16: An Introduction to QGIS 1. What is QGIS?ebrelsford.github.io/talks/2016/doitt/course.pdf4 2. Working with vector data Like any good GIS, QGIS is capable of opening vector data of numerous

16

b. ClickBrowse.c. Findthelayeronyourcomputer.d. ClickOK.

9. Ifthiswassuccessful,theprojectshouldnowopenexactlyasitwasbefore.

TheSaveProjectdialogbox

TheHandleBadLayersdialogbox

Page 17: An Introduction to QGIS 1. What is QGIS?ebrelsford.github.io/talks/2016/doitt/course.pdf4 2. Working with vector data Like any good GIS, QGIS is capable of opening vector data of numerous

17

TheHandleBadLayersdialogboxwiththelayer'snewlocationset

ResourcesQGIS:AttributeTablesandSelectingFeatures(https://www.youtube.com/watch?v=Fm6bjyijamk)(video)QGIS:WorkingwithProjections(https://www.youtube.com/watch?v=iOhhFIIOb08)(video)

Page 18: An Introduction to QGIS 1. What is QGIS?ebrelsford.github.io/talks/2016/doitt/course.pdf4 2. Working with vector data Like any good GIS, QGIS is capable of opening vector data of numerous

18

3.StylingvectordataQGIShasaveryflexiblesystemforstylingvectordata,bothforusewhileviewingdataonyourscreenandwhenpublishingthedataforthepublictoseeinprintorontheweb.ThissectiongetsyoustartedstylingdatainQGIS.

Basicstyles

Exercise3-1:Basicandcategorizedstyles

LayerandstyleamapofsomepartoftheNYCcoastlineusingthefollowingdatasets:

StreetCenterlines(https://data.cityofnewyork.us/City-Government/NYC-Street-Centerline-CSCL-/exjm-f27b)Hydrography(https://data.cityofnewyork.us/Environment/Hydrography/drh3-e2fd)MotorVehicleCollisions2015(https://data.cityofnewyork.us/Public-Safety/NYPD-Motor-Vehicle-Collisions-2015/kref-x3ki)

1. Addeachoftheabovetoyourlayerspanel.Youmayreplaceanyofthesewithotherdatalayersasyouchoosealongasyouhaveapointlayer,alinelayer,andapolygonlayer.

2. Styleeachlayerinturn:a. Double-clickthelayerinthelayerspanel.b. SelecttheStyletabontheleft.c. Changethesettingsforthelayer'sstyles.Asyoudo,experimentwithoverlaying

multiplesymbollayersandlookattheblendingmodes.Exploreabit.3. Addlabelstothestreetcenterlines:

a. Double-clickthelayerinthelayerspanel.b. SelecttheLabelstabontheleft.c. ChangethedropdownatthetopofthedialogtoShowlabelsforthislayerand

selectacolumnnexttoLabelwith.d. Stylethelabelsasyoulike.

4. Let'scategorizethecollisiondatabythetypeofvehicleinvolved:a. Double-clickthecollisiondatalayerandopenitsStyletab.b. ChangeSingleSymbolinthetoplefttoCategorized.c. UsetheColumndropdowntoselectVEHICLETYPECODE1.d. ClickClassify.e. ClickApply.ThisshouldapplythecategorizedstylewhileleavingtheStyletab

open.f. Changethestyleforoneofthecategoriesbydouble-clickingonitssymbolanduse

Applytoviewthechanges.5. Saveyourprojectasexercise3-1.

Exercise3-2:Graduatedstyles

Let'sundothecategorizationandstylethecollisiondatabasedonthenumberofinjuries:

1. LoadtheMotorVehicleCollisions2015(https://data.cityofnewyork.us/Public-

Page 19: An Introduction to QGIS 1. What is QGIS?ebrelsford.github.io/talks/2016/doitt/course.pdf4 2. Working with vector data Like any good GIS, QGIS is capable of opening vector data of numerous

19

Safety/NYPD-Motor-Vehicle-Collisions-2015/kref-x3ki)ifit'snotalreadyopen.2. Double-clickthecollisiondatalayerandopenitsStyletab.3. ChangeSingleSymbolinthetoplefttoGraduated.4. UsetheColumndropdowntoselectNUMBEROFPERSONSINJURED.5. ClickClassifyandApplytoseetheresults.6. LookattheHistogramtabintheStyledialog:

a. ClickLoadvalues.b. Thisgivesyouanideaofhowmanyfeaturesfallintoeachbin.

7. YoucanedittheclassboundariesintheHistogramtabortheClassestab.Let'schangethemintheClassestab:a. Double-clickontherowunderValuesforthefirstclass.b. ChangeLowervalueto0ifit'snotalreadyandUppervalueto0.99tocreatea

classforcollisionswith0injuriesreported.c. Double-clickontherowunderLegendforthefirstclassandenter0--thisisthe

labeltheclasswillreceiveinthemap'slegend.d. Edittheotherclassesasyoufindappropriateandstylethem.

8. Saveyourprojectasexercise3-2.

Advancedstylesusingexpressions

Exercise3-3

ManystyleattributesinQGIScanbestyledusingexpressions.Let'susethisfunctiontomakethecollisionmarkerslargerwheremoreinjurieswereinflicted:

1. LoadtheMotorVehicleCollisions2015(https://data.cityofnewyork.us/Public-Safety/NYPD-Motor-Vehicle-Collisions-2015/kref-x3ki)ifit'snotalreadyopen.

2. Double-clickthecollisiondatalayerandopenitsStyletab.3. UseSingleSymbolratherthanCategorizedorGraduatedstyles.4. Stylethemarkersasyoulike.5. NexttoSize,totherightoftheinputfield,clicktheDatadefinedoverridebutton

andselectFieldtype>NUMBEROFPERSONSINJURED.6. ClickApplytoseetheresult:thepointdiametersshouldvarybythenumberof

injuries.7. Youmightwanttoadjustthediameterbysomefactorofthenumberofinjuries.Let's

dothis:a. IntheStyletab,clicktheDatadefinedoverridebuttonandunderthe

ExpressionsectionselectEdit.b. Youcannowenteranyexpressionyouwish.Forexample,enter"NUMBEROF

PERSONSINJURED"*5,pressOK,andApplythestyle.c. YoucaneditthislayerbyclickingtheDatadefinedoverridebuttonandunderthe

ExpressionsectionselectEditagain.8. Saveyourprojectasexercise3-3.

HeatmapsThereareafewwaystomakeheatmapsinQGIS.Herewecoverboth:

theheatmapstyleandtheheatmapplugin

Page 20: An Introduction to QGIS 1. What is QGIS?ebrelsford.github.io/talks/2016/doitt/course.pdf4 2. Working with vector data Like any good GIS, QGIS is capable of opening vector data of numerous

20

Exercise3-4:Theheatmapstyle

Thisisthesimplewaytomakeheatmaps:

1. LoadtheMotorVehicleCollisions2015(https://data.cityofnewyork.us/Public-Safety/NYPD-Motor-Vehicle-Collisions-2015/kref-x3ki)ifit'snotalreadyopen.

2. Double-clickthecollisiondatalayerandopenitsStyletab.3. UseHeatmapratherthanCategorizedorGraduated.4. SelectacolorrampandpressApply.5. Saveyourprojectasexercise3-4.

Exercise3-5:Theheatmapplugin

Herewecreateaheatmapbycreatingarasteroftheheatmapandstylingthat.

1. LoadtheMotorVehicleCollisions2015(https://data.cityofnewyork.us/Public-Safety/NYPD-Motor-Vehicle-Collisions-2015/kref-x3ki)ifit'snotalreadyopen.

2. Preparethedata.WewillworkwithasmallerdatasethereandchangetheCRS:a. Selectsomesubsetofthedatausinganexpression(eg"BOROUGH"='BRONX').

Makeitsmallenoughthatit'sstillverydensebuthasfewerpointstoworkwith.Shootfor20kto50kpoints.

b. Right-clickonthelayer,selectSaveAs....IntheSaveAsdialog,select2263fortheCRS.EnsurethatSaveonlyselectedfeaturesischecked.

3. NowweensurethattheHeatmappluginisinstalledandenabled:a. GotoPlugins>ManageandInstallPlugins....b. Searchforheatmap.c. IfthecheckboxnexttoHeatmapisnotchecked,checkit.ThisenablesitinQGIS.d. ExitthePluginsdialog.

4. GotoRaster>Heatmap>Heatmapandchangethefollowingsettings:a. Inputpointlayer:thecollisionslayerthatwejustcreated.b. Outputraster:avalidlocationtosaveto.c. Outputformat:GeoTIFF.d. Radius:2000layerunits.AsthelayerisinCRS2263weknowthatthisisfeet.

5. PressOK.6. Whentherasterlayerloads,let'sstyleit:

a. Double-clicktherasterlayerinthelayerspanel.b. ChangeRendertypetoSinglebandpseudocolor.c. SelectacolorrampunderGeneratenewcolormap.d. PressClassify.e. Applythestyle.

7. Repeatsteps4-6andexperimentwithchangingtheradiusandsomeoftheadvancedsettings.

8. Saveyourprojectasexercise3-5.

PrintComposer

Exercise3-6

HerewecreateaPDFofamapusingQGIS'sbuilt-inPrintComposer:

Page 21: An Introduction to QGIS 1. What is QGIS?ebrelsford.github.io/talks/2016/doitt/course.pdf4 2. Working with vector data Like any good GIS, QGIS is capable of opening vector data of numerous

21

1. Loadoneofthemulti-layeredprojectsfromthepreviousexercises(egExercise3-1).2. Makeyourfirstprintcomposer:

a. GotoProject>NewPrintComposer.b. UsetheAddnewmaptoolanddrawarectanglefortheviewportofthemap.c. AddatitleusingtheAddnewlabeltool.d. AddalegendusingtheAddnewlegendtool.Gobacktoyourprojectandrename

layersasrequiredtomakethelegenduseful.Ifitdoesn'tmakesensetochangenamesorpropertiesontheprojectitself,findtheItempropertiestabandeditthelegendthere.

e. Addascalebarandcustomizeit.f. Addotheraccessoriesasyoufindnecessary.g. Whenyouaredone,presstheExportasPDFbuttonandsavethePDFsomewhere

accessible.3. Makeaprintcomposerwithaninsetmap:

a. Inyourmapcanvas,zoomouttothelayer'sextent(eg,allofNYC).b. GotoProject>NewPrintComposer.c. UsetheAddnewmaptoolanddrawarectanglefortheviewportofthemap.This

willbetheoverviewmap.d. Leavingtheprintcomposeropen,switchtoyourmapcanvasandzoomintoanarea

youwishtouseasaninset.e. GobacktotheprintcomposerandusetheAddnewmaptooltoaddanothermap

alongsideorontopoftheoverviewmap.Thiswillbetheinsetmap.f. AddaframearoundtheinsetmapunderItemproperties.g. Addanoverviewtotheoverviewmap:selecttheoverviewmap,gotoItem

properties,scrolldowntoOverviews,addnewone(+),andselectMap1nexttoMapframe.

h. Styletheoverviewasyoulike.4. Withtheprintcomposeryouusedinthepreviousstep,experimentwithlockinglayers

andstyles:a. SelecttheinsetmapandcheckLocklayersformapitemunderItem

properties.b. Withtheprintcomposeropen,gobacktoyourmapcanvasandhidethemore

detailedlayerssuchasstreets.c. GobacktoyourprintcomposerandpresstheRefreshviewbuttoninthetoolbar.

Theoverviewmapshouldberefreshedwithyourmapasitlooksinyourmapcanvas.

ResourcesMoreaboutlayerandfeatureblending(https://docs.qgis.org/2.2/en/docs/user_manual/working_with_vector/vector_properties.html#layer-rendering).

Page 22: An Introduction to QGIS 1. What is QGIS?ebrelsford.github.io/talks/2016/doitt/course.pdf4 2. Working with vector data Like any good GIS, QGIS is capable of opening vector data of numerous

22

4.GeoprocessingInthissectionwewillcover:

Basicgeoprocessingsuchas:ClipBufferIntersect

AshortintroductiontobuildingmodelsandPythonscripts

Basicgeoprocessing

Exercise4-1

Hereweusebuffertogetshapesrepresentingtheareawithin50feetofaroad:

1. OpentheRoadbed(https://data.cityofnewyork.us/City-Government/Roadbed/xgwd-7vhd)andBoroughBoundaries(https://data.cityofnewyork.us/City-Government/Borough-Boundaries/tqmj-j8zm)datainQGIS.

2. EnsurethatbothfilesareinthesameCRSbyopeningtheLayerPropertiesandlookingintheGeneraltabforboth.Iftheydonotmatch,useSaveAs...tore-projectoneofthelayers.

3. UsingthelayersthatareinthesameCRS,selectoneboroughintheboroughboundarieslayer.

4. Let'smakeourfileabitsmallerandmoremanageablebyclippingtheroadbedlayertotheselectedborough:a. GotoVector>GeoprocessingTools>Clip.b. SetInputvectorlayertotheroadbedlayer(thelayeryouwanttoclip).c. SetCliplayertotheboroughboundarieslayer(thelayeryouwanttoclipto).d. CheckUseonlyselectedfeaturestocliponlyusingtheboroughyouselected.e. BrowseforanappropriateplacetosavetheoutputfileandpressOK.

5. Nowlet'sbuffertheroadbedlayerfortheboroughyouselected:a. FirstconverttheclippedroadbedlayertoCRS2263.Thisisnecessarytoensurethat

theunitswebufferbyarefeet.(UseSaveAs...,selecttheCRS,anddothefollowingoperationsontheconvertedfile).

b. GotoVector>GeoprocessingTools>Buffer.c. SetInputvectorlayertothelayeryouwanttobuffer(theoneconvertedtoCRS

2263).d. SetBufferdistanceto50.e. LeaveDissolvebufferresultsunchecked.f. PressOK.

Exercise4-2:Overlayandgeometryoperations

1. Opentwopolygonfilesofyourchoosing.2. ExperimentwithafewofthefunctionsprovidedunderVector>Geoprocessing

ToolsandVector>GeometryTools.

Page 23: An Introduction to QGIS 1. What is QGIS?ebrelsford.github.io/talks/2016/doitt/course.pdf4 2. Working with vector data Like any good GIS, QGIS is capable of opening vector data of numerous

23

Buildingmodels

Exercise4-3:Asimplemodel

Hereweautomatesomeoftheworkcoveredinthepreviousexercise--takinganinputvectorlayer,reprojectingittoCRS2263,andbufferingitby50feet:

1. GotoProcessing>GraphicalModeler.2. Createthemodel:

a. Dragavectorlayerinputfromtheleftpaneltotheright.SetParameternametoInput.

b. SwitchtotheAlgorithmstabintheleftpanel.c. UnderGeoalgorithms>Vector>GeneraltoolsfindReprojectlayeranddrag

itovertotheright.ChangeTargetCRSto2263andsetthedescriptiontoReprojectlayerto2263.

d. UnderGeoalgorithms>Vector>GeometryoperationsfindFixeddistancebufferanddragitovertotheright.ChangeInputlayertotheoutputfromtheprevious('Reprojected'fromalgorithm'Reprojectlayerto2263'step)andsettheDistanceto50.ThensettheDescriptiontoBufferby50feetandBuffer<OutputVector>toOutput.Thelastisthenamewegivetheoutputlayer.

e. Abovetherightpane,settheNametoBufferby50feetandGrouptoCommongeoprocessing.

f. PresstheSavebuttonandsavethemodelinanappropriatelocation.3. Nowlet'srunthemodel:

a. ClosethemodelforthemomentandopentheBoroughBoundaries(https://data.cityofnewyork.us/City-Government/Borough-Boundaries/tqmj-j8zm)datainQGIS.

b. OpenthemodelagainbygoingtoProcessing>GraphicalModelerandopeningthefileyoujustsaved.

c. ClicktheRunmodelbutton.d. Selecttheappropriateinputlayerandanappropriateoutputfilelocationandpress

Run.e. Confirmthattheoutputfileisabufferedversionoftheoriginal.

4. Ifyou'replanningonusingandsharingthemodel,youshoulddocumentit:a. OpenthemodelinGraphicalModelerifitisclosed.b. PresstheEditmodelhelpbutton.c. Ontheleftselectitemstoedit(suchasthedescriptionofthemodel)andenteryour

textontheright.

Exercise4-4:Buildingyourownmodel

Withapartner,createaworkflowthatusesmultiplegeoprocessingalgorithmsandcreateamodelforit:

1. ExploretheavailablegeoprocessingalgorithmsinQGISavailablethroughtheGUI.Forthemostpart,thesewillbeunderVector>GeoprocessingToolsandVector>GeometryTools.

2. Usingdataofyourchoosing,createamulti-stepgeoprocessingworkflowgiventhefunctionsavailablethroughtheGUIandconfirmthattheoutputdataisasyouexpected.

Page 24: An Introduction to QGIS 1. What is QGIS?ebrelsford.github.io/talks/2016/doitt/course.pdf4 2. Working with vector data Like any good GIS, QGIS is capable of opening vector data of numerous

24

3. CreateamodelwithProcessing>GraphicalModelerthatperformsthesameworkflowasyoucreatedinthepreviousstep,saveit,andrunitonanotherfile.Confirmthatitfunctionsasexpected.

Exercise4-5:Usingthepythonconsole

1. GotoPlugins>PythonConsole.2. ThePythonConsoleshouldappearatthebottomofthescreen.3. Typeiface.getActiveLayer().name()andpressEnter.Thenameoftheactivelayer

shouldprintintheconsole.4. IfyouwouldliketoknowmoreaboutthepythoninterfacetoQGIS,youcantype

help(iface)intheconsoleandpressEnter.5. Let'sdosomesimplegeoprocessinginpython:

a. EnterimportprocessingintheterminalandpressEnter.b. Enterprocessing.alglist()intheterminalandpressEnter.Alloftheprocessing

algorithmwillbeprinted.c. Let'sfocusonanalgorithmwewouldliketouse:enterprocessing.alglist('hull')

toseeonlythealgorithmswithhullintheirnames.d. We'llusetheconvexhullalgorithm.Tolearnhowtouseit,enter

processing.alghelp('qgis:convexhull').Wearetoldthattherearefourparameters:INPUT,FIELD(ifweweremakingmultipleconvexhullsbasedonafield),METHOD,andOUTPUT.

e. Enterprocessing.runalg('qgis:convexhull',<LAYERNAME>,None,0,<FULLPATHTOOUTPUTFILE>),butreplace<LAYERNAME>withalayeryouwouldliketocalculatetheconvexhullof,and<FULLPATHTOOUTPUTFILE>withthepathyouwouldliketosaveto.

f. Openthefolderyousavedtoandyoushouldhaveanewshapefile--addthattoyourlayerspanel.

6. Let'ssaveourcommandtoascript:a. ClicktheShoweditorbuttononthepythonconsole'stoolbar.Totherightyou

shouldnowhaveaneditorpane.b. Enterimportprocessingonthefirstlineandyourfinalcommandfromstep5on

thesecondline.c. ClicktheRunscriptbuttontorunyourscriptagain.d. Savethescriptsomewhereaccessible.

ResourcesADesktopAnalyst'sGuidetoQGIS,Part2(http://boundlessgeo.com/2015/07/desktop-analysts-guide-qgis-part-2-beyond-basics/)hassomegoodexamplesofmodel/scriptbuildingTheGraphicalModeler(http://docs.qgis.org/2.0/en/docs/user_manual/processing/modeler.html)intheQGISdocumentation.AutomatingComplexWorkflowsusingProcessingModeler(http://www.qgistutorials.com/en/docs/processing_graphical_modeler.html)intheQGISdocumentation.QGISGraphicalModelerExample(https://www.youtube.com/watch?v=6QmA-eZtnog)video

Page 25: An Introduction to QGIS 1. What is QGIS?ebrelsford.github.io/talks/2016/doitt/course.pdf4 2. Working with vector data Like any good GIS, QGIS is capable of opening vector data of numerous

25

PyQGISDeveloperCookbook(http://docs.qgis.org/testing/en/docs/pyqgis_developer_cookbook/index.html)GettingStartedwithPyQGIS(http://www.qgistutorials.com/en/docs/getting_started_with_pyqgis.html)

Page 26: An Introduction to QGIS 1. What is QGIS?ebrelsford.github.io/talks/2016/doitt/course.pdf4 2. Working with vector data Like any good GIS, QGIS is capable of opening vector data of numerous

26

5.CombiningVectorDataThissectioncoversmethodsforcombiningdatathatisstoredacrossmultiplevectorlayers,including:

AttributejoinsSpatialjoins

SelectingbylocationCountingbylocation

AttributejoinsHerewecombinedataacrosslayersbasedonafieldthatoverlaps.

Exercise5-1

1. OpenBuildingFootprints(https://data.cityofnewyork.us/Housing-Development/Building-Footprints/tb92-6tj8)inQGISandreducethenumberofbuildingswe'reworkingwith:a. SelectonlythebuildingfootprintsinManhattan.Youshouldbeabletodosowith

Selectbyexpressionandanexpressionlikeleft("BBL",1)='1'.b. SaveAs...andsaveonlytheselectedfeatures.c. Thenclosetheoriginalbuildingfootprintsfile.

2. OpenBuildingsSubjecttoHPDJurisdiction(https://data.cityofnewyork.us/Housing-Development/Buildings-Subject-to-HPD-Jurisdiction/kj4p-ruqc)inQGISwithoutusingtheAddDelimitedTextLayerfunctionality.Youcansimplydrag-and-dropthefileintothelayerspanelsinceitdoesnothaveanygeographicdatawithinit.

3. Addajoin:a. OpentheLayerPropertiesfortheManhattanbuildingfootprintslayer.b. SelecttheJoinstabontheleft.c. Clickthe+toaddanewjoin.d. SetJoinlayertotheHPDbuildingslayer.e. SetJoinfieldandTargetfieldtoBIN.

4. Selectonlythefeaturesthatjoined:a. UseSelectbyexpression.b. Writeanexpressionthatselectsfeatureswhereoneofthejoinedcolumns(fromthe

HPDBuildingsfile)isnotnull,eg"Buildings_Subject_to_HPD_Jurisdiction_BuildingID"isnotnull.

c. Confirmthatsomebuildingsareselected.d. OpentheattributetableandexaminethecolumnsthatwerejoinedfromtheHPD

Buildingfile(thesewillbeallthewaytotheright).5. Editthejointoselectonlythecolumnsyouwant:

a. GobacktoJoinsinthelayerpropertiesfortheManhattanbuildingfootprintslayer.

b. Selectthejoinyoucreated.c. ClicktheEditbutton.d. CheckChoosewhichfieldsarejoinedandcheckonlythefieldsyouwouldliketo

bringoverfromtheHPDBuildingsfile.Thisishelpfulsincemanyofthefieldsareredundant.

Page 27: An Introduction to QGIS 1. What is QGIS?ebrelsford.github.io/talks/2016/doitt/course.pdf4 2. Working with vector data Like any good GIS, QGIS is capable of opening vector data of numerous

27

e. CheckCustomfieldnameprefixandreplacethecurrenttextinthefieldwithHPD.Thiswillmakethefieldnamesmoremanageable.

6. UseSaveAs...tosaveonlythefeaturesthatjoined.7. ConfirmthatthenewfilehasthecolumnsfromtheHPDBuildingsfilethatyou

selected.

Exercise5-2

Performanotherattributejoinbetweentwootherlayers:

1. OpenMapPLUTOforQueens(http://www1.nyc.gov/site/planning/data-maps/open-data/dwn-pluto-mappluto.page#mappluto)andOilBoilers(https://data.cityofnewyork.us/Housing-Development/Oil-Boilers-Detailed-Fuel-Consumption-and-Building/jfzu-yy6n).

2. JointhetwolayersbyBBL.3. SelectonlythematchingparcelsinMapPLUTOandsavethemtoanewfile.

Spatialjoins

Exercise5-3:Selectingbylocation

1. OpenCityCouncilDistricts(https://data.cityofnewyork.us/City-Government/City-Council-Districts/yusd-j4xi)andtheHPDbuildingsinManhattanascreatedinExercise5-1.

2. ConfirmthatthelayersareinthesameCRSoruseSaveAs...ononeofthelayerstomakethemmatch.

3. SelectonecitycouncildistrictinManhattan.4. GotoVector>ResearchTools>SelectbyLocation:

a. SelecttheappropriatelayersforSelectfeaturesin(thebuildingslayer)andthatintersectfeaturesin(thecitycouncildistrictslayer).

b. CheckOnlyselectedfeaturestoonlyselectbuildingsintheselectedcitycouncildistrict.

c. PressOK.d. Onlythebuildingsinthecitycouncildistrictyouselectedshouldbeselected.

Exercise5-4:PointsinPolygon

1. OpenCityCouncilDistricts(https://data.cityofnewyork.us/City-Government/City-Council-Districts/yusd-j4xi)andvehiclecollisionsinJuly2015ascreatedinExercise2-6.

2. ConfirmthatthelayersareinthesameCRSoruseSaveAs...ononeofthelayerstomakethemmatch.

3. GotoVector>AnalysisTools>PointsinPolygon:a. SelecttheappropriatelayersforInputpolygonvectorlayer(citycouncildistricts)

andInputpointvectorlayer(collisionsinJuly2015).b. Chooseanappropriatelocationtosavetheoutputshapefile.

4. Createachoroplethwiththeresultinglayer(usingtheGraduatedstylewithColumnsettoPNTCNT).

5. Choroplethsbycountaregenerallyabadidea,solet'smakeachoroplethbydensityinstead:a. OpentheStyletabforthelayer.

Page 28: An Introduction to QGIS 1. What is QGIS?ebrelsford.github.io/talks/2016/doitt/course.pdf4 2. Working with vector data Like any good GIS, QGIS is capable of opening vector data of numerous

28

b. NexttotheColumndropdownpresstheExpressionbutton.c. Theexpressionshouldcurrentlybethefieldname(PNTCNT).Let'sdivideitbythe

areabyadding/$areaafter.TheresultshouldbePNTCNT/$area.d. PressOKtoexittheExpressiondialog.e. PressClassifytore-classifythelayerafterchangingthecolumnorexpression.f. Applythestyle.g. Ifcouncildistrictsaremissing,youmayneedtochangetheboundariesofthe

classes(makethefirst'sLowervaluesmaller,thelast'sUppervaluehigher).Thishappenssometimeswhenusingexpressions.Irecommendusingthismethodtoexperimentwithexpressionsandstyles,thenusetheFieldCalculatortoaddacolumnwiththeexpressionyouchooseandstylebasedonthatcolumn(asyouwillinthenextstep).

6. AddacolumnwiththedensityexpressiontothelayerusingtheFieldCalculatorandstylethelayerusingyournewcolumn.

Exercise5-5:PointsinPolygon

1. OpenCityCouncilDistricts(https://data.cityofnewyork.us/City-Government/City-Council-Districts/yusd-j4xi)andAirbnbListings.

2. ConfirmthatthelayersareinthesameCRSoruseSaveAs...ononeofthelayerstomakethemmatch.

3. PerformaPointsinPolygonanalysisandfindthemeanpriceineachcouncildistrictasyoudo.

4. Visualizethedatahoweveryoulike.

Exercise5-6:Joinattributesbylocation

1. OpenBuildingsSubjecttoHPDJurisdictioninManhattan(fromExercise5-1)andCityCouncilDistricts(https://data.cityofnewyork.us/City-Government/City-Council-Districts/yusd-j4xi).

2. ConfirmthatthelayersareinthesameCRSoruseSaveAs...ononeofthelayerstomakethemmatch.

3. GotoVector>DataManagementTools>JoinAttributesbyLocation:a. SelecttheappropriatelayersforTargetvectorlayer(citycouncildistricts)and

Joinvectorlayer(HPDbuildingsinManhattan).b. SelectTakesummaryofintersectingfeatures.c. SelectMeanandselectSum.d. Chooseanappropriatelocationtosavetheoutputshapefile.e. PressOK.f. Thismaytakeaminuteortwo.WhenQGISisdoneitwillaskyouifyouwanttoadd

thenewlayertoyourTOC(layerspanel).Doso.g. Confirmthattheresultinglayerincludesthemeanandsumofeachnumericfieldin

thebuildingsfile.4. Createachoroplethusingoneofthefieldsinthenewlayer.

Exercise5-7:Joinattributesbylocation

1. OpenBuildingsSubjecttoHPDJurisdictioninManhattan(fromExercise5-1)andCityCouncilDistricts(https://data.cityofnewyork.us/City-Government/City-Council-Districts/yusd-j4xi)againifyouclosedthem.

Page 29: An Introduction to QGIS 1. What is QGIS?ebrelsford.github.io/talks/2016/doitt/course.pdf4 2. Working with vector data Like any good GIS, QGIS is capable of opening vector data of numerous

29

2. JoinAttributesbylocationagain,butthistimeintheotherdirection:toeachbuildingadditscitycouncildistrict'sdata.

Page 30: An Introduction to QGIS 1. What is QGIS?ebrelsford.github.io/talks/2016/doitt/course.pdf4 2. Working with vector data Like any good GIS, QGIS is capable of opening vector data of numerous

30

6.EditingVectorDataEditingandcreatingdataInthissectionwewillcover:

EditingdataCreatingdataAdvancedDigitizing

Exercise6-1:Editingdata

1. OpentheBuildingFootprints(https://data.cityofnewyork.us/Housing-Development/Building-Footprints/tb92-6tj8)inQGIS.

2. Pickabuildingtoedit.Zoomandpanyourmaptoit.3. Entereditmode:

a. Ensurethelayeryouwanttoeditisselectedinthelayerspanel.b. Findandpresstheeditbuttonintheedittoolbar.

4. UsingtheMoveFeature(s)tool,movethebuildingyouwanttoedit.5. UsingtheNodeTool:

a. Moveoneormorenodes,andb. Addanewnodebydouble-clickingsomewhereononeoftheedgesofthebuilding.

6. Let'saddaringtoabuilding:a. SelectabuildingwiththeSelectFeaturestoolb. GotoEdit>AddRingc. Drawtheholeyouwanttoremovefromtheinsideofthebuilding,right-clicking

whenyou'redone.7. Experimentwithothereditingtools.8. Presstheeditbuttonagaintoexiteditmodeandsaveyourfile.Untilyousaveyouare

indangeroflosingyouredits.

Exercise6-2:Creatingdata

1. Removealllayersfromyourlayerspanel.2. AddanOpenLayersaerialimagerylayer:

a. GotoWeb>OpenLayersplugin>BingMaps>BingAerialwithlabels.b. IfOpenLayersisnotavailable,openPlugins>ManageandInstallPlugins...,

searchforOpenLayers,andenabletheplugin.3. Createanewpolygonshapefile:

a. GotoLayer>CreateLayer>NewShapefileLayer.b. SetTypetoPolygon.c. Selectthelocationinwhichyouwouldliketosavetheshapefile.

4. Tracesomebuildings:a. Withyournewshapefileselectedinthelayerspanel,entereditmode.b. Zoomandpantotheareayouwouldliketotracebuildingsin.Astheimageryis

beingloadedfromtheinternetthiscanberelativelyslow,andwhenyouzoomintoofarthelayerwilldisappear.Youshouldbeabletozoomto(ormanuallyset)Scale1:2,500.

Page 31: An Introduction to QGIS 1. What is QGIS?ebrelsford.github.io/talks/2016/doitt/course.pdf4 2. Working with vector data Like any good GIS, QGIS is capable of opening vector data of numerous

31

c. SelecttheAddFeaturetool.d. Clicktocreatethefirstnodeofyourbuilding.e. Eachclickcreatesanewnode.Addnodesateachcornerofthebuilding.f. Onceyouarehappywithyourshape,right-clickanywhere(anewnodeisnot

createdwhenyoudothis).g. Repeatthisprocesstocreateafewmorebuildings.

5. Leaveyournewlayeropenandineditmodeforthenextexercise.

Exercise6-3:AdvancedDigitizing

1. Openyournewshapefileifitisnotopen.2. Enableeditmode.3. EnableAdvancedDigitizing:

a. GotoView>Panels>AdvancedDigitizingPanel.b. TheAdvancedDigitizingPanelshouldappearontheleft.PresstheEnable

advanceddigitizingtoolsbutton.4. Nowtraceafewmorebuildings:

a. SelecttheAddFeaturetool.b. Placeyourfirsttwopoints.c. Asyouplaceyourthirdpoint,AdvancedDigitizingshowsyoutheangleyouare

creating(inthepanelnexttoa)andsnapsto90degrees.d. Youcanalsosettheanglemanuallybytypingaandenteringtheangleyouwant

(eg45)andpressingEnter.e. AdvancedDigitizingalsoshowsyouthedistanceofthelineyouarecreating,and

youcansetitmanuallybytypingd,enteringthedistanceyouwant,andpressingEnter.

f. ExperimentwithAdvancedDigitizingandcreateafewmorebuildings.

ResourcesAdvancedDigitizingpanelvideoonYoutube(https://www.youtube.com/watch?v=QsjmLa16obs)

Page 32: An Introduction to QGIS 1. What is QGIS?ebrelsford.github.io/talks/2016/doitt/course.pdf4 2. Working with vector data Like any good GIS, QGIS is capable of opening vector data of numerous

32

7.RasterDataExercise7-1:Openingrasterdata

1. OpenLandCover(https://data.cityofnewyork.us/Environment/Landcover-Raster-Data-2010-/9auy-76zt)inQGIS.Youshouldbeabletodosoasyouhavewithvectordata(double-clickanddrag-and-drop),andifyouwanttodoitthroughamenugotoLayer>AddLayer>AddRasterLayer.

2. Let'smakethefileabitmoremanageable:a. Zoomandpanyourmaptoasectionofthecityyou'dliketoworkwith.b. GotoRaster>Extraction>Clipper.c. WiththeClipperdialogopen,clickanddragonthemaptodrawarectangleofthe

areayouwouldliketoclipto.d. BrowsetoselectaproperlocationtosavetheresultingfiletoandpressOK.

Exercise7-2:Therastercalculator1. OpentheclippedfilefromExercise7-1ifyouclosedit.2. Selectavalueyouwouldliketoextract.Ifyou'renotsurewhichyou'dliketouse,

expandthelayerinyourLayersPanelandfindthenumberassociatedwithacoloryouwouldliketoisolate.

3. GotoRaster>Rastercalculator.4. Browsetoselectaplacetosaveyouroutputfile.5. Double-clickontheclippedlayerintheRasterbandsarea.6. Intheexpressionfield,addanequalssign(=)andthenumberyoupicked.Youshould

haveanexpressionlike"clipped@1"=5.7. PressOKandyoushouldhaveanewlayerthatisblackandwhite.

Exercise7-3:VectorizingrasterdataNowwewillturnthefeaturesweselectedfromtherasterintovectors.

1. OpentheclippedandreducedfilefromExercise7-2ifyouclosedit.2. GotoRaster>Conversion>Polygonize.3. SelecttheclippedlayerfortheInputfile.4. BrowsetoselectaproperlocationforyourshapefileandpressOK.

Exercise7-4:GeoreferencingimagesLet'sturnanimagewithnogeodataintoaGeoTIFF:

1. Downloadanimagetogeoreference:a. FindaplateattheNYPL'spublicdomaindigitalcollection

(http://digitalcollections.nypl.org/collections/de1dcfb0-c5f6-012f-1dfc-58d385a7bc34#/?tab=navigation)ofanareaofthecityyouwillbeabletogeoreference.

b. Clickontheplate.

Page 33: An Introduction to QGIS 1. What is QGIS?ebrelsford.github.io/talks/2016/doitt/course.pdf4 2. Working with vector data Like any good GIS, QGIS is capable of opening vector data of numerous

33

c. OnthenewpageunderDownloadoptionsclickononeofthelargersizes(eg2560px)andsavethefilesomewhereaccessible.

2. AddtheimagetoQGIStogeoreference:a. InQGIS,ensurethattheGeoreferencerGDALpluginisinstalledandenabled.b. GotoRaster>Georeferencer>Georeferencer.c. ClicktheOpenRasterbutton,findtheimageyoujustdownloadedit,andopenit.

3. LeavetheGeoreferenceropenbutgobacktoyourmapcanvas.Addareferencelayer(Web>OpenLayersPlugin>...).WewilluseOpenStreetMap,butanythingwithlabelsshouldsuffice.

4. BackintheGeoreferencer,addgroundcontrolpoints:a. Panandzoomboththerasterandthemapcanvastoarecognizablelandmarksuch

asastreetcorner.b. IntheGeoreferencer,selecttheAddPointtool.c. Clickonthelandmarkyouchose.d. TheEntermapcoordinatesdialogopens.e. ClickFrommapcanvas.f. TheGeoreferencerdisappears.Clickthelandmarkinyourmapcanvas.Keepinmind

thattheimageyoudownloadedshowspropertyoutlines.g. SwitchbacktotheGeoreferencerandrepeatuntilyouhavethreeorfourground

controlpoints.5. Setyourgeoreferencingsettings:

a. IntheGeoreferencer,clicktheTransformationSettingsbuttononthetoolbar.b. SetTransformationtypetoThinPlateSpline.Thisshouldsufficeunlessyour

imageisverydistorted.c. SetOutputrastertosomewhereaccessible.d. SetTargetCRStoEPSG:3857asthisistheCRSofthereferencelayerweare

using.Youcanreprojecttheresultlaterifyouneedto.e. CheckLoadinQGISwhendone.

6. ClickRunintheGeoreferencertoolbar.YoushouldseeaprogressindicatorandyourGeoTIFFshouldappearonyourmapcanvas.

7. Ifyouareunhappywiththeresults,deletegroundcontrolpointsandrepeattheabove(steps4-6).

Page 34: An Introduction to QGIS 1. What is QGIS?ebrelsford.github.io/talks/2016/doitt/course.pdf4 2. Working with vector data Like any good GIS, QGIS is capable of opening vector data of numerous

34

8.PluginsQGIS'spluginecosystemisopenandrelativelylarge.Inthissectionwewillcoversomeofthefollowingplugins:

GeoServerExplorerOpenLayersOSMDownloaderCartoDBqgis2threejsqgis2leafTimeManager

Exercise8-1:qgis2threejsqgis2threejscreatesa3Dvisualizationofyourdatathatisaccessiblefromawebbrowser.ThiscanbeusefulbecauseyoucanthenhostthevisualizationonlineandpeoplecanviewandinteractwiththevisualizationwithouthavingQGISinstalled.

1. Clearanyexistinglayersfromyourlayerspanel.2. OpenBuildingFootprints(https://data.cityofnewyork.us/Housing-Development/Building-

Footprints/tb92-6tj8).3. Zoomintosomesmallerportionofthelayer(eg10x10blocks).4. Makea3Dmapwithallbuildingsthesameheight:

a. GotoWeb>Qgis2threejs>Qgis2threejs.b. UnderPolygon,checkthecheckboxnexttoyourbuildingslayer.c. Don'tchangeanythingelse,thedefaultswilldofornow.d. PressRun.e. Abrowserwindowshouldopenwithyour3Dvisualizationrunning.f. Youcanrotatethemapbyclickinganddragging,zoombyscrolling.

5. Makethebuildingshaveheightsbasedonthenumberoffloorsineach:a. GotoWeb>Qgis2threejs>Qgis2threejs.b. UnderPolygon,checkthecheckboxnexttoyourbuildingslayer.c. SetHeighttoNUM_FLOORSandMulitplierto6.d. PressRun.

6. Addapointlayertoyourlayerspanelandexperimentwithitinqgis2threejs.7. AddaDEMtoyourvisualization:

a. OpenNYCDEMUptown(anexcerptofNYCDEM(https://data.cityofnewyork.us/City-Government/1-foot-Digital-Elevation-Model-DEM-/dpc8-z3jc))inQGISalongwithyourotherlayers.

b. AddanaeriallayerusingWeb>OpenLayerspluginandmovetheaeriallayersothatitisabovetheDEMbutbelowyourvectorlayers.

c. GotoWeb>Qgis2threejs>Qgis2threejs.d. EnsuretheDEMyouaddedisselectedastheDEMLayer.e. Intheoptionsforyourbuildingslayer,ensurethatModeissettoRelativetoDEM.f. PressRun.

8. Saveyourqgis2threejsvisualizationtoanHTMLfile--thisisafilethatcouldbesharedonline.

Page 35: An Introduction to QGIS 1. What is QGIS?ebrelsford.github.io/talks/2016/doitt/course.pdf4 2. Working with vector data Like any good GIS, QGIS is capable of opening vector data of numerous

35

Exercise8-2:qgis2leafSimilarlytoqgis2threejs,qgis2leafcreatesavisualizationofyourdatathatisaccessiblefromawebbrowser.qgis2leafwillonlyworkwith2Dvisualizations,however.

1. Clearanyexistinglayersfromyourlayerspanel.2. Openoneborough'sbuildings(fromExercise5-1).3. Zoomintosomesmallerportionofthelayer(eg10x10blocks)andselectsomeof

thebuildingswiththerectangletool.4. Makethewebmap:

a. GotoWeb>qgis2leaf>ExportsaQGISproject....b. ClickGetLayersandselectyourbuildingslayer.c. CheckExportselectedonlyasmakingawebmapwithallofthebuildingsina

boroughisgoingtobeslow--wearemakingthemapwithjusttheselectedones.d. ForBasemapsselectStamenToner.e. Givethemapaname,title,andsubtitle.f. PressOK.g. Themapshouldappearinyourbrowser.Interactwiththemapinyourbrowser.Click

onsomeofthebuildings.5. Savethewebmap:

a. GotoWeb>qgis2leaf>ExportsaQGISproject....b. Leaveallthesettingsastheywereinthepreviousstep.c. ChangeOutputprojectfoldertoafolderyouhaveaccessto.d. PressOK.e. Findthefolder--thisisthefilethatyouwouldshareonline.

Exercise8-3:GeoServerExplorerBoundlessreleasedtheGeoServerExplorerpluginafewmonthsago(http://boundlessgeo.com/2015/12/announcing-the-new-geoserver-qgis-plugin/)toreplacetheOpenGeoSuiteplugin.Herewe'llconnecttoanexamplecatalogandloadsomedatafromit.

1. EnsurethattheGeoServerExplorerpluginisinstalled.2. GotoWeb>GeoServer>GeoServerExplorer.3. AddanexampleGeoServercatalog:

a. Right-clickonCatalogsintheGeoServerExplorerpanel.b. Givethecataloganame(egEric'sGeoServer).c. SetURLtotheurlprovidedtoyou.d. SetUsernametoadminandPasswordtogeoserver.e. PressOK.f. Inamomentthenewcatalogshouldappear.Pleasenotethatthisisanexample

catalogthatwillnotbeaccessibleafterthisworkshop.4. AddalayerfromtheGeoServercatalog:

a. ExpandthecatalogyouaddedandlookunderLayers.b. Pickalayer,right-clickonit,andselectAddtocurrentQGISproject.

Exercise8-4:CartoDB

Page 36: An Introduction to QGIS 1. What is QGIS?ebrelsford.github.io/talks/2016/doitt/course.pdf4 2. Working with vector data Like any good GIS, QGIS is capable of opening vector data of numerous

36

CartoDBisanotherhandywaytosharemapsandmapdataonline.ThispluginallowsyoutouploadanddownloaddatalayerstoaCartoDBaccount.

1. EnsuretheCartoDBpluginisinstalled.2. CreateafreeCartoDBaccount(https://cartodb.com/signup)ifyoudonothaveone.3. AddtheCartoDBaccounttoQGIS:

a. FindtheAddConnectionbuttoninyourtoolbarsandclickit.b. ClickNew.c. EnteryourusernameandAPIKey.InCartoDB,clickonyouraccountandgoto

YourAPIKeystofindyourkey.d. ClickConnect.

4. AdddatatoCartoDB:a. Openarelativelysmalllayerinyourlayerspanel.Buildingsforoneboroughshould

beokay.b. GotoWeb>CartoDBplugin>UploadlayerstoCartoDB.c. SelectyourlayerandclickUpload.d. GobacktoyourCartoDBaccountandconfirmthatyourdataisinCartoDBunder

Datasets.5. AddamaptoCartoDB:

a. IfthedatayouuploadedtoCartoDBwasnotaddedtoyourlayerspanel,dothatnow(Web>CartoDBplugin>AddCartoDBLayer).

b. Stylethelayerhoweveryoulike.c. GotoWeb>CartoDBplugin>CreateNewMap.d. GivethemapaNameandDescriptionasyouseefit.e. PressCreate.f. ConfirmthatthemapwascreatedinCartoDB,stylesandall,inyouraccountunder

Maps.

Exercise8-5:TimeManagerTimeManager(https://github.com/anitagraser/TimeManager)cananimateyourmapdatabydateandtime,providingthatyougiveitaproperdatefield.Let'strythiswiththebuildingdata.

1. EnsuretheTimeManagerpluginisinstalled.2. AddtheBuildingFootprintsfileforoneboroughtoyourlayerspanel.3. Let'screateaproperdatefieldfortheyeareachbuildingwasbuilt:

a. Entereditmodeonthebuildingslayer.b. UsingtheFieldcalculatoraddanewdatefield.c. Theexpressionyouuseshouldbesomethinglikeconcat("CNSTRCT_YR",'-01-

01'),whichshouldgiveyoudatessuchas1760-01-01.d. Addthecolumnandexiteditmode,savingyourchanges.

4. EnabletheTimeManagerpanelbygoingtoPlugins>TimeManager>Togglevisibility.

5. IntheTimeManagerpanel,entertheseSettings:a. AddLayerwithyourbuildinglayer.b. Selectyourlayer.c. SelectthefieldyoujustcreatedforStartTime.d. PressOK,thenscrolltotherightandcheckAccumulateFeaturesforthelayer.e. PressOKtoexitthesettingsdialog.

Page 37: An Introduction to QGIS 1. What is QGIS?ebrelsford.github.io/talks/2016/doitt/course.pdf4 2. Working with vector data Like any good GIS, QGIS is capable of opening vector data of numerous

37

6. ChangeTimeframesizeto5years.7. PressthePlaybutton,andthebuildingsshouldfillinastheyarebuilt.

Resourcesqgis2threejsvideo(https://www.youtube.com/watch?v=edPiNvZJScM)qgis2threejsdocumentation(http://qgis2threejs.readthedocs.org/en/docs-release/)GeoServerplugindocumentation(http://boundlessgeo.github.io/qgis-geoserver-plugin/)

Page 38: An Introduction to QGIS 1. What is QGIS?ebrelsford.github.io/talks/2016/doitt/course.pdf4 2. Working with vector data Like any good GIS, QGIS is capable of opening vector data of numerous

38

9.MovingforwardwithQGISThishasbeenaveryquickintroductiontoQGISandhopefullyyou'refeelingrelativelycomfortablewithitnow.Aswithlearninganythingnew,therewillsurelybetimesthatyouneedhelpwithQGIS.Luckilythereareresourcesonlineandofflinethatshouldkeepyouontrack.

AskingquestionsonlineByfarthemostpopularwaytoaskquestionsaboutQGISonlineisGISStackExchange(http://gis.stackexchange.com/).Thesiteletsyoupostaquestion,andotherswillattempttoansweryourquestion.Everyonegetstovoteonhowhelpfuleachresponseis,sogoodanswerstendtobubbleuptothetop.Youshouldsearchthesitefirstbeforepostinganewquestion.

AskingquestionsinpersonThereisachapterofthepopularMaptimemeetup(http://maptime.io/)inNewYork,MaptimeNYC(http://www.meetup.com/maptime-nyc/).It'safriendlyplacetomeetotherpeoplewhoworkonmap-relatedthings,andmanyparticipantsknowtheirwayaroundQGIS.

OnlineresourcesTheQGISUserGuide(http://docs.qgis.org/2.8/en/docs/user_manual/)isonlineandfree.

IhavepostedmanyQGISvideosonYoutube(https://www.youtube.com/channel/UCsmBq4ziqRgBZSJK8sGF0Fg)thatmighthelpyououtifyou'relookingforvisual,step-by-stepdirections.

BooksHereareafewbooksaboutQGISIwouldrecommend:

LearningQGIS(https://www.packtpub.com/application-development/learning-qgis-second-edition)isabasicintroductiontoQGISforthoselookingtoreinforcethetopicscoveredinthisworkshop.

MasteringQGIS(https://www.packtpub.com/application-development/mastering-qgis)isanexcellentbookforthosewhoarecomfortablewithQGISbutlookingforaguidetodeepertopicssuchastheprocessingtoolboxandwritingscripts(includingplugins).

It'snotoutyet,butI'mlookingforwardtoQGISMapDesign(http://locatepress.com/qmd).

BlogsIfyouwanttostayontopofQGISdevelopmentasithappens,therearesomepeoplewhoblogregularlyaboutQGIS.QGISPlanet(http://plugins.qgis.org/planet/)aggregatestheseblogs,buthereareafewofmyfavorites:

AnitaGraser(http://anitagraser.com/)

Page 39: An Introduction to QGIS 1. What is QGIS?ebrelsford.github.io/talks/2016/doitt/course.pdf4 2. Working with vector data Like any good GIS, QGIS is capable of opening vector data of numerous

39

NyallDawson(http://nyalldawson.net/)NathanWoodrow(http://nathanw.net/)

WrittenbyEricBrelsford(http://ebrelsford.github.io).

ThisworkislicensedunderaCreativeCommonsAttribution-ShareAlike4.0InternationalLicense(http://creativecommons.org/licenses/by-sa/4.0/).


Top Related