0% found this document useful (0 votes)
57 views

21.1 Results For An Overview of The Interface: Twentyone

This document provides answer sheets for exercises from Chapter 21 of the QGIS Training Manual. It includes expected results and screenshots for tasks involving adding layers, adjusting symbology, labeling points of interest, classifying raster data, and creating new vector datasets through digitizing and topology tools. The summaries provide high-level overviews of the key steps and expected outcomes for each section to aid in self-checking work.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
57 views

21.1 Results For An Overview of The Interface: Twentyone

This document provides answer sheets for exercises from Chapter 21 of the QGIS Training Manual. It includes expected results and screenshots for tasks involving adding layers, adjusting symbology, labeling points of interest, classifying raster data, and creating new vector datasets through digitizing and topology tools. The summaries provide high-level overviews of the key steps and expected outcomes for each section to aid in self-checking work.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 46

CHAPTER

TWENTYONE

ANSWER SHEET

21.1 Results For An Overview of the Interface

21.1.1 Overview (Part 1)

Refer back to the image showing the interface layout and check that you remember the names and functions of the
screen elements.
Back to text

21.1.2 Overview (Part 2)

1. Save as
2. Zoom to layer
3. Invert selection
4. Rendering on/off
5. Measure line
Back to text

21.2 Results For Adding Your First Layer

21.2.1 Preparation

In the main area of the dialog you should see many shapes with different colors. Each shape belongs to a layer you
can identify by its color in the left panel (your colors may be different from the ones below):

647
QGIS Training Manual

Back to text

21.2.2 Data loading

Your map should have seven layers:


• protected_areas
• places
• rivers
• roads
• landuse
• buildings (taken from training_data.gpkg) and
• water (taken from exercise_data/shapefile).
Back to text

21.3 Results For Symbology

21.3.1 Colors

• Verify that the colors are changing as you expect them to change.

Open the Layer Styling panel


• It is enough to select the water layer in the legend and then click on the button.
Change the color to one that fits the water layer.

648 Chapter 21. Answer Sheet


QGIS Training Manual

Note: If you want to work on only one layer at a time and don’t want the other layers to distract you, you can hide a
layer by clicking in the checkbox next to its name in the layers list. If the box is blank, then the layer is hidden.

Back to text

21.3.2 Symbol Structure

Your map should now look like this:

If you are a Beginner-level user, you may stop here.


• Use the method above to change the colors and styles for all the remaining layers.
• Try using natural colors for the objects. For example, a road should not be red or blue, but can be gray or black.
• Also feel free to experiment with different Fill style and Stroke style settings for the polygons.

21.3. Results For Symbology 649


QGIS Training Manual

Back to text

21.3.3 Symbol Layers

Customize your buildings layer as you like, but remember that it has to be easy to tell different layers apart on the
map.
Here’s an example:

Back to text

650 Chapter 21. Answer Sheet


QGIS Training Manual

21.3.4 Symbol Levels

To make the required symbol, you need three symbol layers:

The lowest symbol layer is a broad, solid gray line. On top of it there is a slightly thinner solid yellow line and finally
another thinner solid black line.
If your symbol layers resemble the above but you’re not getting the result you want:
1. Check that your symbol levels look something like this:

2. Now your map should look like this:

21.3. Results For Symbology 651


QGIS Training Manual

Back to text

21.3.5 Symbol Levels

1. Adjust your symbol levels to these values:

2. Experiment with different values to get different results.


3. Open your original map again before continuing with the next exercise.
Back to text

652 Chapter 21. Answer Sheet


QGIS Training Manual

21.4 Outline Markers

Here are examples of the symbol structure:

21.4. Outline Markers 653


QGIS Training Manual

Back to text

21.4.1 Geometry generator symbology

• Click on the button to add another Symbol level.

• Move the new symbol at the bottom of the list clicking the button.
• Choose a good color to fill the water polygons.
• Click on Marker of the Geometry generator symbology and change the circle with another shape as your wish.
• Try experimenting other options to get more useful results.
Back to text

654 Chapter 21. Answer Sheet


QGIS Training Manual

21.5 Results For Vector Attribute Data

21.5.1 Exploring Vector Data Attributes

• There should be 9 fields in the rivers layer:


1. Select the layer in the Layers panel.

2. Right-click and choose Open Attribute Table, or press the button on the Attributes Toolbar.
3. Count the number of columns.

Tip: A quicker approach could be to double-click the rivers layer, open the Layer properties ► Fields tab,
where you will find a numbered list of the table’s fields.

• Information about towns is available in the places layer. Open its attribute table as you did with the rivers layer:
there are two features whose place attribute is set to town: Swellendam and Buffeljagsrivier. You can add
comment on other fields from these two records, if you like.
• The name field is the most useful to show as labels. This is because all its values are unique for every object
and are very unlikely to contain NULL values. If your data contains some NULL values, do not worry as long
as most of your places have names.
Back to text

21.6 Results For Labels

21.6.1 Label Customization (Part 1)

Your map should now show the marker points and the labels should be offset by 2mm. The style of the markers and
labels should allow both to be clearly visible on the map:

21.5. Results For Vector Attribute Data 655


QGIS Training Manual

Back to text

21.6.2 Label Customization (Part 2)

One possible solution has this final product:

656 Chapter 21. Answer Sheet


QGIS Training Manual

To arrive at this result:


• Use a font size of 10
• Use an around point placement distance of 1.5 mm
• Use a marker size of 3.0 mm
• In addition, this example uses the Wrap on character option:

21.6. Results For Labels 657


QGIS Training Manual

• Enter a space in this field and click Apply to achieve the same effect. In our case, some of the place names
are very long, resulting in names with multiple lines which is not very user friendly. You might find this setting
to be more appropriate for your map.
Back to text

658 Chapter 21. Answer Sheet


QGIS Training Manual

21.6.3 Using Data Defined Settings

1. Still in edit mode, set the FONT_SIZE values to whatever you prefer. The example uses 16 for towns, 14 for
suburbs, 12 for localities, and 10 for hamlets.
2. Remember to save changes and exit edit mode
3. Return to the Text formatting options for the places layer and select FONT_SIZE in the Attribute field of
the font size data defined override dropdown:

Your results, if using the above values, should be this:

21.6. Results For Labels 659


QGIS Training Manual

Back to text

21.7 Results For Classification

21.7.1 Refine the Classification

The settings you used might not be the same, but with the values Classes = 6 and Mode = Natural Breaks (Jenks) (and
using the same colors, of course), the map will look like this:

660 Chapter 21. Answer Sheet


QGIS Training Manual

Back to text

21.8 Results For Creating a New Vector Dataset

21.8.1 Digitizing

The symbology doesn’t matter, but the results should look more or less like this:

21.8. Results For Creating a New Vector Dataset 661


QGIS Training Manual

Back to text

21.8.2 Topology: Add Ring Tool

The exact shape doesn’t matter, but you should be getting a hole in the middle of your feature, like this one:

• Undo your edit before continuing with the exercise for the next tool.

662 Chapter 21. Answer Sheet


QGIS Training Manual

Back to text

21.8.3 Topology: Add Part Tool

• First select the Bontebok National Park:

• Now add your new part:

21.8. Results For Creating a New Vector Dataset 663


QGIS Training Manual

• Undo your edit before continuing with the exercise for the next tool.
Back to text

21.8.4 Merge Features

• Use the Merge Selected Features tool, making sure to first select both of the polygons you wish to merge.
• Use the feature with the OGC_FID of 1 as the source of your attributes (click on its entry in the dialog, then
click the Take attributes from selected feature button):

Note: If you’re using a different dataset, it is highly likely that your original polygon’s OGC_FID will not be 1. Just
choose the feature which has an OGC_FID.

Note: Using the Merge Attributes of Selected Features tool will keep the geometries distinct, but give them the same
attributes.

Back to text

21.8.5 Forms

For the TYPE, there is obviously a limited amount of types that a road can be, and if you check the attribute table for
this layer, you’ll see that they are predefined.
• Set the widget to Value Map and click Load Data from Layer.
• Select roads in the Label dropdown and highway for both the Value and Description options:

664 Chapter 21. Answer Sheet


QGIS Training Manual

• Click OK three times.


• If you use the Identify tool on a street now while edit mode is active, the dialog you get should look like this:

Back to text

21.8. Results For Creating a New Vector Dataset 665


QGIS Training Manual

21.9 Results For Vector Analysis

21.9.1 Distance from High Schools

• Your buffer dialog should look like this:

The Buffer distance is 1 kilometer.


• The Segments to approximate value is set to 20. This is optional, but it’s recommended, because it makes the
output buffers look smoother. Compare this:

666 Chapter 21. Answer Sheet


QGIS Training Manual

To this:

21.9. Results For Vector Analysis 667


QGIS Training Manual

The first image shows the buffer with the Segments to approximate value set to 5 and the second shows the value set
to 20. In our example, the difference is subtle, but you can see that the buffer’s edges are smoother with the higher
value.
Back to text

21.9.2 Distance from Restaurants

To create the new houses_restaurants_500m layer, we go through a two step process:


• First, create a buffer of 500m around the restaurants and add the layer to the map:

668 Chapter 21. Answer Sheet


QGIS Training Manual

• Next, extract buildings within that buffer area:

21.9. Results For Vector Analysis 669


QGIS Training Manual

Your map should now show only those buildings which are within 50m of a road, 1km of a school and 500m of a
restaurant:

670 Chapter 21. Answer Sheet


QGIS Training Manual

Back to text

21.10 Results For Network Analysis

21.11 Fastest path

Open Network Analysis ► Shortest Path (Point to Point) and fill the dialog as:

Make sure that the Path type to calculate is Fastest.


Click on Run and close the dialog.
Open now the attribute table of the output layer. The cost field contains the travel time between the two points (as
fraction of hours):

21.10. Results For Network Analysis 671


QGIS Training Manual

Back to text

21.12 Results For Raster Analysis

21.12.1 Calculate Aspect

• Set your Aspect dialog up like this:

Your result:

672 Chapter 21. Answer Sheet


QGIS Training Manual

Back to text

21.12.2 Calculate Slope (less than 2 and 5 degrees)

• Set your Raster calculator dialog up with:


– the following expression: slope@1 <= 2
– the slope layer as the Reference layer(s)

21.12. Results For Raster Analysis 673


QGIS Training Manual

• For the 5 degree version, replace the 2 in the expression and file name with 5.
Your results:
• 2 degrees:

674 Chapter 21. Answer Sheet


QGIS Training Manual

• 5 degrees:

21.12. Results For Raster Analysis 675


QGIS Training Manual

Back to text

21.13 Results For Completing the Analysis

21.13.1 Raster to Vector

1. Open the Query Builder by right-clicking on the all_terrain layer in the Layers panel, and selecting the Properties
► Source tab.
2. Then build the query "suitable" = 1.
3. Click OK to filter out all the polygons where this condition isn’t met.
When viewed over the original raster, the areas should overlap perfectly:

676 Chapter 21. Answer Sheet


QGIS Training Manual

4. You can save this layer by right-clicking on the all_terrain layer in the Layers panel and choosing Save As…,
then continue as per the instructions.
Back to text

21.13.2 Inspecting the Results

You may notice that some of the buildings in your new_solution layer have been “sliced” by the Intersection tool.
This shows that only part of the building - and therefore only part of the property - lies on suitable terrain. We can
therefore sensibly eliminate those buildings from our dataset.
Back to text

21.13. Results For Completing the Analysis 677


QGIS Training Manual

21.13.3 Refining the Analysis

At the moment, your analysis should look something like this:

Consider a circular area, continuous for 100 meters in all directions.

If it is greater than 100 meters in radius, then subtracting 100 meters from its size (from all directions) will result in
a part of it being left in the middle.

678 Chapter 21. Answer Sheet


QGIS Training Manual

Therefore, you can run an interior buffer of 100 meters on your existing suitable_terrain vector layer. In the output
of the buffer function, whatever remains of the original layer will represent areas where there is suitable terrain for
100 meters beyond.
To demonstrate:
1. Go to Vector ► Geoprocessing Tools ► Buffer(s) to open the Buffer(s) dialog.
2. Set it up like this:

21.13. Results For Completing the Analysis 679


QGIS Training Manual

3. Use the suitable_terrain layer with 10 segments and a buffer distance of -100. (The distance is automatically
in meters because your map is using a projected CRS.)
4. Save the output in exercise_data/residential_development/ as
suitable_terrain_continuous100m.shp.
5. If necessary, move the new layer above your original suitable_terrain layer.
Your results will look like something like this:

680 Chapter 21. Answer Sheet


QGIS Training Manual

6. Now use the Select by Location tool (Vector ► Research Tools ► Select by location).
7. Set up like this:

8. Select features in new_solution that intersect features in suitable_terrain_continuous100m.shp.


This is the result:

21.13. Results For Completing the Analysis 681


QGIS Training Manual

The yellow buildings are selected. Although some of the buildings fall partly outside the new suit-
able_terrain_continuous100m layer, they lie well within the original suitable_terrain layer and therefore meet
all of our requirements.
9. Save the selection under exercise_data/residential_development/ as final_answer.
shp.
Back to text

21.14 Results For WMS

21.14.1 Adding Another WMS Layer

Your map should look like this (you may need to re-order the layers):

682 Chapter 21. Answer Sheet


QGIS Training Manual

Back to text

21.14.2 Adding a New WMS Server

• Use the same approach as before to add the new server and the appropriate layer as hosted on that server:

21.14. Results For WMS 683


QGIS Training Manual

• If you zoom into the Swellendam area, you’ll notice that this dataset has a low resolution:

Therefore, it’s better not to use this data for the current map. The Blue Marble data is more suitable at global or
national scales.
Back to text

684 Chapter 21. Answer Sheet


QGIS Training Manual

21.14.3 Finding a WMS Server

You may notice that many WMS servers are not always available. Sometimes this is temporary, sometimes it is
permanent. An example of a WMS server that worked at the time of writing is the World Mineral Deposits WMS at
http://apps1.gdr.nrcan.gc.ca/cgi-bin/worldmin_en-ca_ows. It does not require fees or have access constraints, and it
is global. Therefore, it does satisfy the requirements. Keep in mind, however, that this is merely an example. There
are many other WMS servers to choose from.
Back to text

21.15 Results For GRASS Integration

21.15.1 Add Layers to Mapset

You can add layers (both vector and raster) into a GRASS Mapset by drag and drop them in the Browser (see Follow
Along: Load data using the QGIS Browser) or by using the v.in.gdal.qgis for vector and r.in.gdal.qgis
for raster layers.
Back to text

21.15.2 Reclassify raster layer

To discover the maximum value of the raster run the r.info tool: in the console you will see that the maximum
value is 1699.
You are now ready to write the rules. Open a text editor and add the following rules:

0 thru 1000 = 1
1000 thru 1400 = 2
1400 thru 1699 = 3

save the file as a my_rules.txt file and close the text editor.
Run the r.reclass tool, choose the g_dem layer and load the file containing the rules you just have saved.
Click on Run and then on View Output. You can change the colors and the final result should look like the following
picture:

21.15. Results For GRASS Integration 685


QGIS Training Manual

Back to text

21.16 Results For Database Concepts

21.16.1 Address Table Properties

For our theoretical address table, we might want to store the following properties:

House Number
Street Name
Suburb Name
City Name
Postcode
Country

When creating the table to represent an address object, we would create columns to represent each of these properties
and we would name them with SQL-compliant and possibly shortened names:

house_number
street_name
suburb
city
postcode
country

Back to text

686 Chapter 21. Answer Sheet


QGIS Training Manual

21.16.2 Normalising the People Table

The major problem with the people table is that there is a single address field which contains a person’s entire address.
Thinking about our theoretical address table earlier in this lesson, we know that an address is made up of many
different properties. By storing all these properties in one field, we make it much harder to update and query our
data. We therefore need to split the address field into the various properties. This would give us a table which has the
following structure:

id | name | house_no | street_name | city | phone_no


--+---------------+----------+----------------+------------+-----------------
1 | Tim Sutton | 3 | Buirski Plein | Swellendam | 071 123 123
2 | Horst Duester | 4 | Avenue du Roix | Geneva | 072 121 122

Note: In the next section, you will learn about Foreign Key relationships which could be used in this example to
further improve our database’s structure.

Back to text

21.16.3 Further Normalisation of the People Table

Our people table currently looks like this:

id | name | house_no | street_id | phone_no


---+--------------+----------+-----------+-------------
1 | Horst Duster | 4 | 1 | 072 121 122

The street_id column represents a ‘one to many’ relationship between the people object and the related street
object, which is in the streets table.
One way to further normalise the table is to split the name field into first_name and last_name:

id | first_name | last_name | house_no | street_id | phone_no


---+------------+------------+----------+-----------+------------
1 | Horst | Duster | 4 | 1 | 072 121 122

We can also create separate tables for the town or city name and country, linking them to our people table via ‘one to
many’ relationships:

id | first_name | last_name | house_no | street_id | town_id | country_id


---+------------+-----------+----------+-----------+---------+------------
1 | Horst | Duster | 4 | 1 | 2 | 1

An ER Diagram to represent this would look like this:

21.16. Results For Database Concepts 687


QGIS Training Manual

Back to text

21.16.4 Create a People Table

The SQL required to create the correct people table is:

create table people (id serial not null primary key,


name varchar(50),
house_no int not null,
street_id int not null,
phone_no varchar null );

The schema for the table (enter \d people) looks like this:

Table "public.people"

Column | Type | Modifiers


-----------+-----------------------+-------------------------------------
id | integer | not null default
| | nextval('people_id_seq'::regclass)
name | character varying(50) |
house_no | integer | not null
street_id | integer | not null
phone_no | character varying |
Indexes:
"people_pkey" PRIMARY KEY, btree (id)

Note: For illustration purposes, we have purposely omitted the fkey constraint.

Back to text

688 Chapter 21. Answer Sheet


QGIS Training Manual

21.16.5 The DROP Command

The reason the DROP command would not work in this case is because the people table has a Foreign Key constraint
to the streets table. This means that dropping (or deleting) the streets table would leave the people table with references
to non-existent streets data.

Note: It is possible to ‘force’ the streets table to be deleted by using the CASCADE command, but this would also
delete the people and any other table which had a relationship to the streets table. Use with caution!

Back to text

21.16.6 Insert a New Street

The SQL command you should use looks like this (you can replace the street name with a name of your choice):

insert into streets (name) values ('Low Road');

Back to text

21.16.7 Add a New Person With Foreign Key Relationship

Here is the correct SQL statement:

insert into streets (name) values('Main Road');


insert into people (name,house_no, street_id, phone_no)
values ('Joe Smith',55,2,'072 882 33 21');

If you look at the streets table again (using a select statement as before), you’ll see that the id for the Main Road
entry is 2.
That’s why we could merely enter the number 2 above. Even though we’re not seeing Main Road written out fully
in the entry above, the database will be able to associate that with the street_id value of 2.

Note: If you have already added a new street object, you might find that the new Main Road has an ID of 3
not 2.

Back to text

21.16.8 Return Street Names

Here is the correct SQL statement you should use:

select count(people.name), streets.name


from people, streets
where people.street_id=streets.id
group by streets.name;

Result:

21.16. Results For Database Concepts 689


QGIS Training Manual

count | name
------+-------------
1 | Low Street
2 | High street
1 | Main Road
(3 rows)

Note: You will notice that we have prefixed field names with table names (e.g. people.name and streets.name). This
needs to be done whenever the field name is ambiguous (i.e. not unique across all tables in the database).

Back to text

21.17 Results For Spatial Queries

21.17.1 The Units Used in Spatial Queries

The units being used by the example query are degrees, because the CRS that the layer is using is WGS 84. This
is a Geographic CRS, which means that its units are in degrees. A Projected CRS, like the UTM projections, is in
meters.
Remember that when you write a query, you need to know which units the layer’s CRS is in. This will allow you to
write a query that will return the results that you expect.
Back to text

21.17.2 Creating a Spatial Index

CREATE INDEX cities_geo_idx


ON cities
USING gist (the_geom);

Back to text

21.18 Results For Geometry Construction

21.18.1 Creating Linestrings

alter table streets add column the_geom geometry;


alter table streets add constraint streets_geom_point_chk check
(st_geometrytype(the_geom) = 'ST_LineString'::text OR the_geom IS NULL);
insert into geometry_columns values ('','public','streets','the_geom',2,4326,
'LINESTRING');
create index streets_geo_idx
on streets
using gist
(the_geom);

Back to text

690 Chapter 21. Answer Sheet


QGIS Training Manual

21.18.2 Linking Tables

delete from people;


alter table people add column city_id int not null references cities(id);

(capture cities in QGIS)

insert into people (name,house_no, street_id, phone_no, city_id, the_geom)


values ('Faulty Towers',
34,
3,
'072 812 31 28',
1,
'SRID=4326;POINT(33 33)');

insert into people (name,house_no, street_id, phone_no, city_id, the_geom)


values ('IP Knightly',
32,
1,
'071 812 31 28',
1,F
'SRID=4326;POINT(32 -34)');

insert into people (name,house_no, street_id, phone_no, city_id, the_geom)


values ('Rusty Bedsprings',
39,
1,
'071 822 31 28',
1,
'SRID=4326;POINT(34 -34)');

If you’re getting the following error message:

ERROR: insert or update on table "people" violates foreign key constraint


"people_city_id_fkey"
DETAIL: Key (city_id)=(1) is not present in table "cities".

then it means that while experimenting with creating polygons for the cities table, you must have deleted some of
them and started over. Just check the entries in your cities table and use any id which exists.
Back to text

21.19 Results For Simple Feature Model

21.19.1 Populating Tables

create table cities (id serial not null primary key,


name varchar(50),
the_geom geometry not null);
alter table cities
add constraint cities_geom_point_chk
check (st_geometrytype(the_geom) = 'ST_Polygon'::text );

Back to text

21.19. Results For Simple Feature Model 691


QGIS Training Manual

21.19.2 Populate the Geometry_Columns Table

insert into geometry_columns values


('','public','cities','the_geom',2,4326,'POLYGON');

Back to text

21.19.3 Adding Geometry

select people.name,
streets.name as street_name,
st_astext(people.the_geom) as geometry
from streets, people
where people.street_id=streets.id;

Result:

name | street_name | geometry


--------------+-------------+---------------
Roger Jones | High street |
Sally Norman | High street |
Jane Smith | Main Road |
Joe Bloggs | Low Street |
Fault Towers | Main Road | POINT(33 -33)
(5 rows)

As you can see, our constraint allows nulls to be added into the database.
Back to text

692 Chapter 21. Answer Sheet

You might also like