fundamentals of raster analysis in raster datasets in qgis. this is an updated version of the raster

Download Fundamentals of Raster Analysis in raster datasets in QGIS. This is an updated version of the raster

Post on 09-Jul-2020

1 views

Category:

Documents

0 download

Embed Size (px)

TRANSCRIPT

  • Fundamentals of Raster Analysis in QGIS

    Ryan Lennon

    May 2020

    Abstract

    This is an introductory raster tutorial which provides instructions on how to perform basic raster functions in QGIS 3.10 (A Coruna), which is the most recent stable long-term release to date of QGIS. This tutorial is written as an extension of the introductory workshop and manual "Introduction to GIS Using Open Source Software (with QGIS)".

    Contents

    1 Introduction 2

    2 Loading in the Data 2

    3 Retrieving Basic Information about your Raster Datasets 5 3.1 Managing Raster Projections . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6 3.2 Filling NoData Values . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8 3.3 Produce Raster Unique Values Report . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8

    4 Using the Raster Calculator 10 4.1 Converting Temperature from Celsius to Fahrenheit . . . . . . . . . . . . . . . . . . . . . 10 4.2 Subsetting Raster Pixels . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12

    5 Clipping Rasters 13 5.1 Clip Operations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13

    6 Extracting Raster Statistics 15 6.1 View Raster Layer Histogram . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17 6.2 Sampling Raster Values . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17

    7 Converting Raster Layers into Vector Layers 18 7.1 Performing an Attribute Query . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 20 7.2 Perform an Intersect Between Raster Cells and Vector Polygons . . . . . . . . . . . . . . 21 7.3 Raster to Point . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 23 7.4 Calculate Distance to Water from Each Raster Cell . . . . . . . . . . . . . . . . . . . . . . 24

    8 Overlaying Raster Datasets with NYC Orthoimagery 24

    9 Raster Styles 27 9.1 Loading a Print Composition . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 28

    R. Lennon, Baruch CUNY, 2020 1 CC BY-NC-ND 4.0

  • 10 Conclusion 29 10.1 More Information on Raster Data Sources . . . . . . . . . . . . . . . . . . . . . . . . . . . . 29

    1 Introduction

    This document provides introductory overview of how to carry out basic analytical operations on raster datasets in QGIS. This is an updated version of the raster tutorial written for QGIS 3.4 (Madeira) that explores different raster functions. This tutorial should expand the user’s ability to extract information from general raster datasets, which could include a wide variety of information.

    Anyone is welcome to use this document under a Creative Commons Attribution Noncommercial No Derivative Works 4.0 License (CC BY-NC-ND 4.0): http://creativecommons.org/licenses/ by-nc-nd/4.0/ for personal or classroom use.

    In this tutorial we will analyze temperature as it relates to discrete features in the landscape. Temperature is one example of a measurement that is best represented in raster format, because it is a continuous feature in the landscape. Other features that might influence or be influenced by temperature, such as parking lots, buildings, or trees are better represented as discrete objects which is why we typically store them as vector shapefiles.

    You will see that QGIS includes a number of tools to extract information from raster datasets by using the discrete geometries of vector objects as a spatial reference. These tools can help us to answer research questions, to learn about our local environment or just to create useful map products.

    For the purposes of this tutorial we will be using temperature datasets derived from the Landsat 8 OLI tile which includes New York City. The Landsat satellite collects infrared thermal radiation which is used to create a raster image representing land surface temperature. This temperature data can be used to study variations of land surface temperature throughout New York City, and anywhere in the world.

    2 Loading in the Data

    The first step is to download the working data from http://www.baruch.cuny.edu/geoportal/ practicum/raster/. Unzip the file and you will see that it contains several raster temperature datasets (.tif file extension) and several shapefiles (.shp file extension) for features that we will be referencing the raster data to.

    First, we will load in the surface temperature raster which is derived from the Landsat 8 satellite.

    1. Launch QGIS Desktop 3.10 (A Coruna).

    2. In the upper-left hand corner, click New Project.

    3. Click Open Data Source Manager in top menu bar and click on the Add Raster tab.

    4. In the Source section, next to the Raster dataset(s) box, click the ellipsis . Navigate to the working folder C:\Downloads\Raster Tutorial Data in the browse dialog and select the NYC_LST_20170831.tif image.

    R. Lennon, Baruch CUNY, 2020 2 CC BY-NC-ND 4.0

    http://creativecommons.org/licenses/by-nc-nd/4.0/ http://creativecommons.org/licenses/by-nc-nd/4.0/ http://www.baruch.cuny.edu/geoportal/practicum/raster/ http://www.baruch.cuny.edu/geoportal/practicum/raster/

  • 5. Click Add.

    QGIS should render the image onto the map canvas. If you would like to center the map can- vas on the image, you can right-click on the image in the layers list in the bottom-left and click Zoom to Layer.

    Load in the New York Borough Boundaries shapefile. This is a vector shapefile that represents the boundaries of each of New York’s five boroughs and is clipped to the shoreline.

    1. Click Open Data Source Manager in top menu bar and click on the Add Vector tab.

    2. In the Source section, next to the Vector dataset(s) box. click the ellipsis . In the browse dialog and select the nybb.shp shapefile.

    3. Click Add.

    4. Once it is added, click on the nybb.shp in the layers list in the lower-left hand side of the map canvas and drag it to the top of the drawing order.

    R. Lennon, Baruch CUNY, 2020 3 CC BY-NC-ND 4.0

  • In the layers list on the left, right-click on the nybb.shp layer and click Properties. Click on the

    Symbology tab . Set the opacity slider to 50 percent

    and click OK . This will allow you to see the temperature layer along with the NYC borough boundaries, so you have some spatial reference to what you are looking at. Note that QGIS uses applies a color to the shapefile at random, so the color may show up as different from the image above.

    R. Lennon, Baruch CUNY, 2020 4 CC BY-NC-ND 4.0

  • Notice that now you can see the other layers underneath the New York borough boundaries outline. Also note that the order in which the layers are listed in the layers list on the left (from top to bottom) is the order in which they appear on the map canvas, so right now we see the temperature raster as being partially obfuscated by the New York borough boundaries. We will talk more about setting raster symbology later on in the tutorial, but for now you can play with these to arrange your map so that you can see what you are doing.

    3 Retrieving Basic Information about your Raster Datasets

    Before we can use many tools in QGIS we have to enable the processing toolbox. In order to do this we have to go through the plugins menu. Click on the plugins dropdown in the toolbar and click Manage and Install Plugins.

    In the search bar type Processing, and the plugin for Processing should come up in the results . Click the box next to Processing and click Install plugin . You

    R. Lennon, Baruch CUNY, 2020 5 CC BY-NC-ND 4.0

  • should now see the Processing button in the toolbar. Click this button to open the Processing Toolbox.

    3.1 Managing Raster Projections

    It is important that when we add raster files to a project we know which projection they are in so that we can accurately compare them to other datasets spatially. When you add your first spatial dataset to a QGIS project, the map canvas assumes the projection of that dataset. The map canvas will remain in this projection unless you change it. This is important to know for when we overlay datasets that have different projections.

    1. In the toolbar at the top of the screen, click on the Raster dropdown.

    2. Select Miscellaneous, then select the Raster Information tool.

    3. The Raster Information tool dialogue should appear.

    4. Click on the Input layer dropdown and select the NYCLandsatST20170831.tif raster that was just added to the project.

    5. Because we want to save the output statistics to a file, click the ellipsis next to the Layer [save to temporary file] box and select Save to File. Then select the working directory C:\Downloads\Raster Tutorial Data, and let’s name the new output file LandsatST0831.html to stay consistent with the naming convention for the original file.

    6. Click Run.

    Once the process is complete, a link to the output should appear in the lower left-hand corner of your screen. When you click on the link it should open in your computer’s default handler for HTML files, which may be a web browser like Firefox. The results should look like this:

    R. Lennon, Baruch CUNY, 2020 6 CC BY-NC-ND 4.0

  • Notice that the projection and datum for the raster is listed as USER:100000 - * Generated CRS... We can also access this information by right-clicking on the raster dataset in the layers list, clicking

    on Properties, and clicking on the Information tab . We can also see that the NoData value is -3.3999999521443642

Recommended

View more >