In this lesson, you will be guided through a complete GIS analysis in QGIS.
Note
Lesson developed by Linfiniti and S Motala (Cape Peninsula University of Technology)
You are tasked with finding areas in and around the Cape Peninsula that are a suitable habitat for a rare fynbos plant species. The extent of your area of investigation in the Cape Peninsula is: south of Melkbosstrand, west of Strand. Botanists have provided you with the following preferences exhibited by the species in question:
As a volunteer for Cape Nature, you have agreed to search for the plant on the closest suitable piece of land to your house. Use your GIS skills to determine where you should go to look.
In order to solve this problem, you will have to use the available data
(available in exercise_data/more_analysis
) to find the candidate area
that is closest to your house. If you don’t live in Cape Town (where this
problem is based) you can choose any house in the Cape Town region. The
solution will involve:
32733
).UTM33S
coordinate
reference system.Rasterprac
that you should create
somewhere on your computer. You will save whatever layers you create in this
directory as well.In order to process the data, you will need to load the necessary layers (street names, zones, rainfall, DEM) into the map canvas.
Sélectionnez le fichier Street_Names_UTM33S.shp.
Cliquer sur Ouvrir.
The dialog closes and shows the original dialog, with the file path specified in the text field next to the Browse button. This allows you to ensure that the correct file is selected. It is also possible to enter the file path in this field manually, should you wish to do so.
Cliquez sur Ouvrir. La couche vecteur est chargée dans votre carte. Une couleur lui est attribuée automatiquement; elle sera modifiée plus tard.
Renommer la couche en Streets
.
Zoning
.Rainfall
(with an initial capital).
Initially when you load them, the images will be gray rectangles. Don’t
worry, this will be changed later.In order to properly see what’s going on, the symbology for the layers needs to be changed.
Raster layer symbology is somewhat different.
2.00
(it should be set to
0.00
by default).4.00
.Now that all the data is loaded and properly visible, the analysis can begin. It is best if the clipping operation is done first. This is so that no processing power is wasted on computing values in areas that aren’t going to be used anyway.
admin_boundaries/Western_Cape_UTM33S.shp
into
your map.Districts
.You will now build a query to select only the following list of districts:
Bellville
,Cape
,Goodwood
,Kuils River
,Mitchells Plain
,Simons Town
, andWynberg
.=
sign is added to the SQL query.In order to select more than one district, you’ll need to use the OR
boolean operator.
Click the OR button and it will be added to the SQL query.
Using a process similar to the above, add the following to the existing SQL query:
"NAME_2" = 'Cape'
Add another OR
operator, then work your way through the list of
districts above in a similar fashion.
The final query should be
"NAME_2" = 'Bellville' OR "NAME_2" = 'Cape' OR "NAME_2" = 'Goodwood' OR
"NAME_2" = 'Kuils River' OR "NAME_2" = 'Mitchells Plain' OR "NAME_2" =
'Simons Town' OR "NAME_2" = 'Wynberg'
Click OK. The districts shown in your map are now limited to those in the list above.
Now that you have an area of interest, you can clip the rasters to this area.
Rasterprac
directory.In order to create the hillshade, you will need to use a plugin that was written for this purpose.
Cette extension est incluse par défaut dans QGIS 1.8. Toutefois, elle pourrait ne pas être immédiatement visible. Pour vérifier si c’est accessible sur votre système:
You will now have access to this plugin via the Raster ‣ Terrain analysis menu item.
Remember that plugins may sometimes depend on certain Python modules being installed on your system. Should a plugin refuse to work while complaining of missing dependencies, please ask your tutor or lecturer for assistance.
The new hillshade layer has appeared in your Layers list.
80%
.The slope image has been calculated and added to the map. However, as usual it is just a gray rectangle. To properly see what’s going on, change the symbology as follows.
Remember to save the map periodically.
Rasterprac
directory as the location for the output
layer.In the Raster bands list on the left, you will see all the raster layers in your Layers list. If your Slope layer is called slope, it will be listed as slope@1.
The slope needs to be between 15
and 60
degrees. Everything less
than 15
or greater than 60
must therefore be excluded.
Using the list items and buttons in the interface, build the following expression:
((slope@1 < 15) OR (slope@1 > 60)) = 0
Set the Output layer field to an appropriate location and file name.
Click OK.
Now find the correct aspect (east-facing: between 45
and 135
degrees) using the same approach.
Build the following expression:
((aspect@1 < 45) OR (aspect@1 > 135)) = 0
Find the correct rainfall (greater than 1200mm
) the same way. Build
the following expression:
(rainfall@1 < 1200) = 0
Having reclassified all the rasters, you will now see them displayed as gray
rectangles in your map (assuming that they have been added to the map
correctly). To properly display raster data with only two classes (1
and
0
, meaning true or false), you will need to change their symbology.
The Custom min / max values fields should now populate with
0
and 1
, respectively. (If they do not, then there was a mistake
with your reclassification of the data, and you will need to go over that part
again.)
The only criterion that remains is that the area must be 250m
away from
urban areas. We will satisfy this requirement by ensuring that the areas we
compute are 250m
or more from the edge of a rural area. Hence, we need
to find all rural areas first.
Hide all layers in the Layers list.
Unhide the Zoning vector layer.
Right-click on it and bring up the Query dialog.
Build the following query:
"Gen_Zoning" = 'Rural'
See the earlier instructions for building the Streets query if you get stuck.
When you’re done, close the Query dialog.
You should see a collection of polygons from the Zoning layer. You will need to save these to a new layer file.
rural.shp
.Sélectionnez la couche rural en couche d’entrée et laissez décochée la case Utiliser seulement les entités sélectionnées
Now you need to exclude the areas that are within 250m
from the edge of
the rural areas. Do this by creating a negative buffer, as explained below.
-250
into the associated field; the negative value means that the buffer must be
an internal buffer.rural_buffer.shp
.In order to incorporate the rural zones into the same analysis with the three existing rasters, it will need to be rasterized as well. But in order for the rasters to be compatible for analysis, they will need to be the same size. Therefore, before you can rasterize, you’ll need to clip the vector to the same area as the three rasters. A vector can only be clipped by another vector, so you will first need to create a bounding box polygon the same size as the rasters.
WGS 84 / UTM zone 33S : EPSG:32733
.bbox.shp
.Now that you have a bounding box, you can use it to clip the rural buffer layer.
rural_clipped
.Now it’s ready to be rasterized.
You’ll need to specify a pixel size for a new raster that you create, so first you’ll need to know the size of one of your existing rasters.
X
and Y
values under the heading
Dimensions in the Metadata table.rural_raster.tif
.X
and Y
values
you made a note of earlier.-burn 1
. This tells the Rasterize function to “burn” the existing
vector into the new raster and give the areas covered by the vector the new
value of 1
(as opposed to the rest of the image, which will
automatically be 0
).Now that you have all four criteria each in a separate raster, you need to
combine them to see which areas satisfy all the criteria. To do so, the rasters
will be multiplied with each other. When this happens, all overlapping pixels
with a value of 1
will retain the value of 1
, but if a pixel has
the value of 0
in any of the four rasters, then it will be 0
in
the result. In this way, the result will contain only the overlapping areas.
Click the Raster ‣ Raster calculator menu item.
Build the following expression (with the appropriate names for your layers, depending on what you called them):
[Rural raster] * [Reclassified aspect] * [Reclassified slope] *
[Reclassified rainfall]
Set the output location to the Rasterprac
directory.
Name the output raster cross_product.tif
.
Ensure that the Add result to project box is checked.
Click OK.
Change the symbology of the new raster in the same way as you set the style for the other reclassified rasters. The new raster now properly displays the areas where all the criteria are satisfied.
To get the final result, you need to select the areas that are greater than
6000m^2
. However, computing these areas accurately is only possible for
a vector layer, so you will need to vectorize the raster.
Rasterprac
.candidate_areas.shp
.All areas of the raster have been vectorized, so you need to select only the
areas that have a value of 1
.
Open the Query dialog for the new vector.
Build this query:
"DN" = 1
Click OK.
Create a new vector file from the results by saving the
candidate_areas vector after the query is complete (and only the
areas with a value of 1
are visible). Use the Save as...
function in the layer’s right-click menu for this.
Save the file in the Rasterprac
directory.
Name the file candidate_areas_only.shp.
Save your map.
Open the new vector layer’s right-click menu.
Select Open attribute table.
Click the Toggle editing mode button along the bottom of the
table, or press Ctrl+E
.
Click the Open field calculator button along the bottom of the
table, or press Ctrl+I
.
Under the New field heading in the dialog that appears, enter the
field name area
. The output field type should be an integer, and the
field width should be 10
.
In Field calculator expresion, type:
$area
This means that the field calculator will calculate the area of each polygon in the vector layer and will then populate a new integer column (called area) with the computed value.
Click OK.
Do the same thing for another new field called id. In Field calculator expresion, type:
$id
This ensures that each polygon has a unique ID for identification purposes.
Click Toggle editing mode again, and save your edits if prompted to do so.
Now that the areas are known:
Build a query (as usual) to select only the polygons larger than
6000m^2
. The query is:
"area" > 6000
Save the selection as a new vector layer called solution.shp.
You now have your solution areas, from which you will pick the one nearest to your house.
house.shp
.You will need to find the centroids (“centers of mass”) for the solution area polygons in order to decide which is closest to your house.
Cliquez sur l’élément du menu Vecteur ‣ Outils de géométrie ‣ Centroïdes de polygones
Rasterprac
.solution_centroids.shp
.id
field
as their unique ID field.id
field).This is the final answer to the research question.
For your submission, include the semi-transparent hillshade layer over an appealing raster of your choice (such as the DEM or the slope raster, for example). Also include the polygon of the closest solution area(s), as well as your house. Follow all the best practices for cartography in creating your output map.