Spatial Analysis
QGIS offers a multitude of geoprocessing tools that allow you to manipulate vector and raster data. Elements such as Buffer
, Clip
, Dissolve
, or Intersection
allow you to create zones surrounding a border, cut the layer by a particular boundary, dissolve a specific inner geographical area, or obtain a common area between two or more layers, respectively. These tools give us a way to extract more insightful analyses from geospatial data.
Objectives
- Learn how to use the buffering tool in QGIS.
- Use the zonal statistics tool to calculate the total population within a particular region.
Buffering
The Buffering
tool is one of the most commonly used geoprocessing tools. Practically speaking, it allows you to define two areas: a region that falls within the specified distance, and a region that falls outside of the specified distance. The buffer zone is the region that falls within the defined distance. When you establish a buffer, it is important that you check what type of units your data uses. The type of units is defined by the data’s projection. You can check the projection by right-clicking on the layer and going to Properties > Information
and scroll down to the Coordinate Reference System (CRS)
section.
The buffer zone does not have to be defined by a single number – it can vary based on the values defined in a specific Attribute Table column. Furthermore, you can define multiple buffers for a single object, as well as buffers with overlapping or dissolving boundaries.
[IMAGE buffer w variation, multiple buffers, dissolved vs overlapping buffers]
Exercise 3.1. Delineate historical flood risk extent.
We will visualize flood risk zones by establishing a buffer around the major waterways in Puerto Rico based on historical flood extents.
- Open the
pr-elev-analysis
project. - Ensure that the following layers are loaded into the project:
- For analysis:
pr-rivers-corrected-reproj
- For visualization:
PRI_adm0
,pr-elev-clipped
,pr-hillshade
.
- For analysis:
- Uncheck any other layers so they are not visible to keep things organized.
- Double-check that all the layers and the map project are set to the CRS
EPSG:32630
setting (this is important so that we have a projection that usesmeters
as its distance metric). If they are not, you will need to change the CRS:- Navigate to
Processing > Toolbox
and search forReproject Layer
. Choose an input vector layer that needs to be changed, and setEPSG:32630 - WGS 84 / UTM zone 20N
as theTarget CRS
. For raster layers, you will need to useRasters > Projections > Warp (reproject)...
. - Choose to save the file as
LAYER-NAME-HERE-reproj
in theintro-gis-data/analysis
folder. - Press
Run
and then close the window. Save the project. - Repeat steps 1-3 for any other vector layers that need to be reprojected.
- To change the map canvas projection, click on the lower right corner where it says the current projection (most likely
EPSG:4326
). ChooseWGS 84 / UTM zone 20N
and chooseOK
. - Remove any layers in the wrong projection from the map and and adjust the symbology as needed.
- Navigate to
- Navigate to
Processing > Toolbox
and use the search bar to locate theTapered buffers
tool listed under theVector Geometry
category. - Rivers do not flood uniformly. Thus, instead of defining a fixed value to establish the buffer zone, we will use a buffer that gradually increases from the start of the line segment to the end of the line segment such that a greater flood extent is defined at lower elevations. The rivers in the
pr-rivers-reproj.gpkg
file have already been configured so that their start point is at a higher elevation and their end point at a lower elevation. - Define the “Tapered buffers” parameters.
- Input layer:
pr-rivers-reproj
- Start width:
0.00
- End width:
3200.00
- Segments: Select the dropdown menu button. Hover over the
Field type: int, double, string
option and selectmaxelev
. This choice will create a more gradual looking buffer.
- Input layer:
- Leave the default option to save the layer as a temporary layer as press
Run
, close the window, and save the project.
You should see a new layer called Buffered
appear on the canvas. You may notice that it looks a little messy – a number of the rivers have overlapping buffer zones. Let’s dissolve the overlapping borders to create a cleaner flood extent boundary.
Exercise 3.2. Dissolve buffer boundaries.
- Navigate to
Vector > Geoprocessing Tools > Dissolve...
- Select
Buffered
as the input layer. - Next to the
Dissolved
field, select the...
button and save the file aspr-flood-extent
in theintro-gis-data/analysis
folder. - Press
Run
and then close the window. Save the project.
Now you have a layer that indicates the possible flooding extent from rivers in Puerto Rico. Obviously this layer is a very rough flooding estimate, but it will serve our purposes for the remainder of the lesson.
Zonal Statistics
More than just visualizing data, geospatial analysis requires the ability to gain numerical insights from the data to better understand patterns and trends occurring within the study region and time period. A helpful tool for conducting this type of analysis is the Zonal Statistics tool. This process allows you to calculate the mean, median, sum, minimum, maximum, or range of a particular feature within a specified boundary. The tool is applied to raster data, but the boundary can be specified with vector or raster data.
[IMAGE zonal stats visualization]
Exercise 3.3. Calculate total population at risk of flooding.
For our next exercise, we will use the population layer to determine the number of people within the country that fall within the potential flood zone, putting them at risk of being affected by flooding events.
- Open up the
pr-elev-analysis
project in QGIS if it is not already open. - You should have the same layers loaded into the project as in Exercise 3.1 and 3.2.
- Go to
Layer > Add Layer > Add Raster Layer...
and select thepr-population-2018.tif
file in theintro-gis-data
folder. PressAdd
and close the window. - Check the projection and reproject the layer to
EPSG:32620
if necessary. - Now click on
Processing > Toolbox
to open the Toolbox panel. Search forZonal Statistics
and double-click on the name to open it. The tool should be listed under theRaster analysis
category. - Set the following parameters:
- Input layer:
pr-flood-extent
- Raster layer:
pr-population-2018-reproj
- Raster band: This field should auto populate. Leave it as is.
- Statistics to calculate: Click the
...
next to the statistics field and check only theSum
option. PressOK
to return to the parameters window.
- Input layer:
- Next to the zonal statistics field, press
...
and save the file inintro-gis-data/outputs
aspr-total-pop-flood-risk
. - Click
Run
and close the window. Save the project. - A new layer called
pr-total-pop-flood-risk
should appear. I will look the same as thepr-flood-extent
layer, but it contains more information in the attribute table. Right-click on the layer name and selectOpen Attribute Table
. - Scroll to the right to view the last column in the table
_sum
. This number is the total number of people who live in flood risk zones, or about651,000
people.
That’s quite a few people! If you wanted to know the number of people for each river feature, you could run the same operation on the non-dissolved buffer layer.
Challenge: Calculate percentage of national population at risk for flooding.
See if you can take the analysis one step further – you know the number of people who live within flood risk zones, but what percentage of the population is that? Knowing that value could aid in resource allocation or population relocation. Calculate the percentage of the national population that falls within our defined flood risk zones.
- Hint 1: Calculate the total country population and join it to the layer from Exercise 3.3
- Hint 2: The tools
Join attributes by field value
and theField calculator
will be useful in this exercise.
Congratulations! You completed the Introduction to GIS workshop. You can refer back to this material anytime you want throughout the learning series, and don’t forget to reach out with feedback or questions!