Baixe QGIS User Guide: Installing and Using Vector and Raster Datasets e outras Manuais, Projetos, Pesquisas em PDF para Sistemas de Informação, somente na Docsity!
An Introduction to GIS
Using QGIS (v. 3.0)
Author: Michael L. Treglia
[email protected] 13 May 201 8 License: This work is licensed under a Creative Commons Attribution- NonCommercial-ShareAlike 4.0 International License. Please see the following website for complete license details or contact Michael Treglia at [email protected] with concerns. http://creativecommons.org/licenses/by-nc-sa/4.0/legalcode
Opening Notes Open-source tools for various types of work, are constantly expanding. Herein, I provide a tutorial of QGIS (www.qgis.org), which is capable of almost any GIS operation I’ve ever needed, either on its own, or using the various plugins and associated tools. QGIS installs and directly links with other programs including SAGA GIS and GRASS GIS, allowing users to take advantage of cooperation among the free and open source software developers. Furthermore, data can be exported to a variety of formats, for use in other programs. My goal here is to provide a basic skill-set to the new GIS/QGIS user, so they may navigate the software for their own work, and further explore its capabilities. This tutorial is by no-means comprehensive. I suggest users browse and search the QGIS documentation (https://qgis.org/en/docs/index.html) when they are stuck, or make use of relevant support channels (https://qgis.org/en/site/forusers/support.html). Furthermore, a lot of examples are given here without going into intricacies of analysis. Thus, I suggest before quantitative analytics, users read further on the tools/analyses that can be employed.
- Opening Notes
- Table of Contents.................................................................................................................
- Installing QGIS
- Installing Plugins
- Data Sources Used in this Tutorial
- Get to Know QGIS
- Opening Files (General)
- Open Shapefiles,
- Open Delimited Text Layer (e.g., points based on a table with Coordinates)
- Add a Background Layer
- Open and Manipulate a Raster Layer
- Projections
- Projection of Layers and Project
- Changing Projections (CRS)
- Changing Project CRS.......................................................................................
- Changing Vector CRS (for a Shapefile or Text-Delimited Layer)
- Changing Raster CRS
- Geo-Processing of Data Layers and Associated Tables
- Some Basic Vector Operations
- Layer) Clipping (Remove unwanted sections of a layer, based on bounds of another
- Difference Clip (Clip out the inner area of a polygon)
- View and Edit the Attribute Table
- Spatial Join
- Some Basic Raster Operations
- Calculate Slope from a DEM
- Reclassify Raster
- Raster Calculator
- Using Vector and Raster Datasets Together
- Clipping a Raster
- Compute Zonal Statistics for Polygons
- Making a Quality Map
- Setting up for a Map
- Putting Everything Together
- Adding the Map of interest to the Layout
- Adding Gridlines and Coordinates
- Adding Scale Bar, North Arrow, and Legend
- Adding an Inset
- Final Formatting and Exporting the Map..............................................................
- Closing Remarks................................................................................................................
Installing QGIS I generally recommend working with the most recent version of QGIS available, with the most recent features, or the most recent Long Term Release, which is designed to be maintained with bug-fixes and such for the next three release cycles. Long term releases might not have the most newest features found in the most recent version, but focus is broader stability across time. At the time of writing, the most recent version is 3.0.2; the long-term release is 2.18.9. Everything presented herein was tested using QGIS 3.0.2, 64 bit, on Windows 10. Though there have been some changes since 2.18.x, the general workflows will be consistent. (Releases are denoted as x.y.z, where changes in ‘x’ denotes some potentially larger changes in the software, changes in ‘y’ denote additions of features and bug fixes, and changes in ‘z’ generally reflect bug-fixes.) For Windows users: Download and run the standalone installer, available here: https://qgis.org/en/site/forusers/download.html (QGIS Standalone Installer Version 3.0.2 will be sufficient; the OSGeo4W installer gives more advanced options, but is not needed).
- When it gives you the option, you do not need to download the sample datasets, although feel free to and use them for other tutorials or examples. For Mac OS users: Download files should be available on the main QGIS download page. (At time of writing, when clicking to expand the box for “MacOS” from a non-Mac computer, the
Data Sources Used in this Tutorial The data sources used in this tutorial are available for download in a single .zip folder, at the URL where you accessed this document. Individual data layers and original sources are listed below. Please see the URLs for the original sources or the included metadata for individual layers for more detail. Throughout the document, I primarily refer to layers with the italicized names given below. Text Delimited Table
- Copperhead Data – “Brazos County A contortrix_TxCentral.csv” – Specimen locations for copperheads, Agkistrodon contortrix , in Brazos County, Texas, provided by the Biodiversity Research and Teaching Collections at Texas A&M University (https://brtc.tamu.edu/). Most localities were definitely collected in the WGS84 datum; the others are assumed to be for this tutorial. Vector Data (Shapefiles) The following layers for Brazos County and the city of College Station, TX were accessed from the City of College Station GIS Department in 2014 (newer files may be available at: http://www.cstx.gov/index.aspx?page=3683).
- County Boundary – Brazos_County_Boundary_8- 20 - 02.shp (in /CountyBoundary)
- City Limits – City_Limits.shp (in /CityBoundary)
- Rivers and Streams – Rivers_and_Streams.shp (in: /RiversStreams”)
Raster Data The raster dataset used in this tutorial is the 1 Arc-second (~30m) Digital Elevation Model from the U.S. Geological Survey
- DEM – imgn31w097_1.img (in /DEM 1ArcSec) Get to Know QGIS Open QGIS on your computer using the QGIS Desktop icon in your Start Menu or Desktop.
- By default, only one pane is likely open – the “Layers/Browser” pane on the left side. You can adjust what is open by going to the “View” menu from the toolbar, and mouse-over “Panels”, and see different options.
- Explore icons by hovering over them with the mouse; click on menu-bar items to explore the drop-down menus.
- To save the project click the “Save” icon and designate a file location. When you re-open a project, any layers that you were using should be in the same locations on your computer; if they are not, you will need to re-designate the appropriate file paths. If you transfer data and a project file to another computer, keep the files in the same locations relative to one another and the project should open without a problem. Make sure to periodically save the project as you work. In the latest versions, QGIS automatically shows the most recent projects. You can simply click a desired project to return to it, or otherwise navigate through QGIS to proceed with a new project.
o Select County Boundary , City Limits , and Rivers and Stream layers respectively, and click the “Add” button. **Note – To access data from ESRI Geodatabase (.gdb files; not used in this exercise), set “Source Type” to “Directory”, and navigate to .gdb files.
- Adjust the layer order by clicking and dragging layers up and down in the “Layers” pane. o Put Rivers and Streams on top, then City Limits , and County Boundary
- To adjust layer symbology (how the data appear): o Right click on individual layers and select “Properties” (or Double Click on the layer) o Select “Style” on the left; click on a symbol in the “Symbol Layers” box, and customize to your liking. ▪ You can also open a “Layer Styling” panel via “View” on the toolbar - > “Panels” - > “Layer Styling”
- To view the tabular data associated with a layer, right click on the layer and select “Open Attribute Table”.
- To view information about a layer at a specific point in space, click on the “Identify Features” icon on the tool bar, and click on the point of interest. The default setting show information about the layer highlighted in the “Layers” pane. Open Delimited Text Layer (e.g., points based on a table with Coordinates)
- In the Data Source Manager “Add Delimited Text Layer” icon. (See example dialogue box on next page.)
o Navigate to the appropriate file ( Copperhead Data ; “Brazos County_A contortrix.csv”) o Expand the “File Format” section and select the appropriate text delimiter (comma for this file). o Expand the “Records and Fields” section – if the first line contains field names (column names) as in this case, make sure the “First record has field names” box is checked. o Expand the “Geometry Definition” section (typically “Point Coordinates”), and identify fields for X and Y coordinates (e.g., Longitude and Latitude, respectively). o If the data are based on a geographic projection Decimal Degrees are expected as with the Copperhead data ; if data are as Degrees Minutes Seconds, check the “DMS Coordinates” box. ▪ By default, the CRS (Coordinate Reference System) for the new layer is set to the CRS of the project, Lat/Long, WGS84 (EPSG 4326). You can change the CRS of the layer by clicking on the globe icon, though that is not needed in this case. o Click “Add” o The layer should now appear in “Layers” pane. You can adjust the symbology by editing the properties as described above.
Add a Background Layer When we import spatial data, we often like to visualize them over some sort of background layer, such as aerial imagery, or a simple map. This allows us to identify if layers are being displayed in approximately the right location, and it can help with some preliminary interpretation of data. For this exercise, we will utilize the QuickMapServices Plugin.
- Click on “Web” from the menu bar at top, navigate to “QuickMapServices Plugin”
“Search QMS”; the search panel for this plugin will appear.
- By default, some Google layers will be available to load. If you click “Add” while selecting any specific layer, the newly added background layers will appear as the bottom-most layer. o You can also use the Search bar to find map services that are made available in this plug-in (e.g., search for Google, Bing, or Open Street Map). Open and Manipulate a Raster Layer
- In the Data Source Manager click the “Raster” icon o Navigate to the desired file; can either specify desired file type or browse any of the available types. Browse to the “DEM 1ArcSec” folder and select “imgn31w097_1.img”.
- Change Color Palette to enhance visualization. o Right-click on the layer (“imgn31w097_1”) and select “Properties” o Click “Style” – There are lots of options to adjust. The below steps just serve as an example. (See next page for sample dialogue box).
▪ Change “Render Type” to “Singleband pseudocolor” (Avoid multi- band options unless you are using multi-band imagery (e.g., Landsat imagery)) ▪ Adjust the Min/Max settings as desired.
- Using the true “Min/Max” (third option) will have the color gradient span the entire range of values in the raster dataset. ▪ Select a color ramp that you like (e.g., the default is ‘viridis’) and click “Classify” button to set bins automatically, and click “Apply”.
Projections Projection of Layers and Project QGIS automatically reads projection information (i.e., the Coordinate Reference System [CRS]), if available, from respective layer files. For shapefiles, it relies on the “.prj” file; for raster data, it is often embedded in the file. If you load data without built-in projection information (e.g., a Delimited Text File), it generally assumes a geographic coordinate system (Lat/Long), and uses the World Geodetic Survey 1984 (WGS84) datum, or may use the Project CRS the user to specify. It is always a good idea to check that the projection information is interpreted correctly by QGIS.
- To check the CRS, (and set it if it was not automatically detected) right-click on layer and select “Set Layer CRS”. o If you do this for the Copperhead Data you will see the CRS that selected is WGS84 (using Lat/Long coordinates). This is correct – the datum of the original data was exactly that, so nothing needs to be changed, although if it was incorrect, you could fix that here. By default, QGIS uses “Projection on the Fly” – for visualization (but not necessarily analysis) of multiple layers in different CRSs, they are automatically transformed to be in the same coordinate space. Previous versions of QGIS had a box to check within the ‘CRS’ tab of Project Properties (Accessed via “File” - > “Project Properties” or by clicking on the ‘EPSG: [Current CRS]’ in the bottom left of the screen - ). In newer versions of QGIS (3.x.x), you an turn off Projection on the Fly by checking the box for “No Projection (or unknown/non-Earth Projection)”, which will project everything on cartesian coordinates. If you do this and – click the “Zoom Full” button on the toolbar at top, and the map area will zoom out to include all layers. (In this situation, will want to
turn off the QuickMapServices layer, and you will a large blank space between very small datasets.) Changing Projections (CRS) For many operations it is necessary to have all layers in the same CRS; even if it is not necessary, it can help speed-up processing considerably. The DEM has elevation in meters, according the layer’s metadata, and it is in a geographic projection (Lat/Long, NAD83). However, for computing some derivatives of elevation such as Slope, it is helpful to have the horizontal units the same as the units for elevation. Thus, we will work in a projection that is also defined in meters, the Albers Equal Area Projection. This projection may cause some distortion in shape, but maintains accurate area measurements. This is just a demonstration, and in doing your own work, it is important to consider how spatial distortions may manifest in different projections. The steps for converting the CRS of raster and vector layers are somewhat different. Furthermore, when converting the CRS of raster layers, it is important to think about how resampling may cause distortion. This will not be covered in depth here, but Mike Bostock provides a useful visualization of this: https://bost.ocks.org/mike/example/. Changing Project CRS As aforementioned, we will use the Albers Equal Area Projection, useful for dealing with the DEM. Other projections, such as Universal Transverse Mercator could also be used.
- Navigate to the Project Properties dialogue box.
- Check the box for “Add Saved File to Map”
- Click “OK” (the original layer can then be removed from the map by right clicking on it and selecting “remove).
- Now do this for the remaining shapefiles. Changing Raster CRS As with vector datasets, when reprojecting a raster, a new file is created and added to the project
- Click on the “Raster” toolbar menu - > “Projections” - > “Warp (Reproject)”. In the Dialogue box (illustrated on the next page):
- Designate the input file from the current project
- The Source CRS can be left blank if it’s correctly assigned already
- Set the Target SRS to the desired CRS (EPSG 102008).
- Check the box for “Load into canvas when finished” to bring the final product into the current project.
- Boxes for NoData and Output resolution boxes can be left untouched for default settings (e.g., the NoData value will be assigned to a default for the data type; the Output resolution will be approximately the same size as the original, but with units converted).
- Select the desired resampling method. o For continuous variables, typically want to use something like bilinear or cubic spline that interpolates. If it is a categorical variable, nearest neighbor (“Near”) is generally appropriate.
- Advanced parameters can be untouched for this exercise, though here you will find options for changing the data time, and a few other parameters.
- For this case, users should set a file path for the Reprojected file. **Note – This uses a tool called ‘GDAL’ to do the processing, with code that could be used in a command line tool (and edited) presented at the bottom of this window. Details for this specific operation are given at http://www.gdal.org/gdalwarp.html. After these reprojections, you can remove the original layers.