This worksheet shows you how to do the following, using an example dataset:
Firstly you will need to set up a new QGIS ‘project’ folder with a suitable name on your machine. Put it somewhere that is easily accessible. All GIS data you download, acquire and create will be stored in this folder.
Note that GIS data can be very large - sometimes so large that, for example, you cannot easily email them or submit them to Moodle. Thus, you may wish to locate your GIS prject folder on some cloud location such as OneDrive.
Project > Save As – give the project a suitable name
and save it in your GIS folder.“QGIS allows users to define a global and project-wide CRS (coordinate reference system) for layers without a pre-defined CRS. It also allows the user to define custom coordinate reference systems and supports on-the-fly (OTF) projection of vector and raster layers. All of these features allow the user to display layers with different CRSs and have them overlay properly”
Project >
Properties – click on
CRS on the left hand side of the
window.__
We now need to set the correct co-ordinate system for the project. The following example is in the UK and therefore will use Ordnance Survey maps as a base map. In this case the CRS will be OSGB 1936/British National Grid.
To locate this use the ESPG code: 27700 – in Filter: type 27700 and the CRS will be displayed – highlight. OK.
Save your work.
NB: if you are creating a project that uses the WGS84 coordinate system the ESPG code is 4326.
Each of the coordinate systems in the world has an EPSG code and it is a quick and accurate way of finding them. Go to http://spatialreference.org/ref/epsg/ for details.
The project properties box also allows you to customise the project in other ways – click on each of the icons on the left hand margin of the window for details.
There are several ways to add data layers.
Then, click on the layer type you want to add as appropriate (for example Add Vector Layer or Add Raster Layer) and navigate to the layer – via Source: * Datasets – click on the three dots in the grey box to navigate to folder (for your chosen layer, add the file **.shp if a vector file)
Navigate to your GIS folder in the Browser Window, highlight the layers required and drag them into the map area (or press the + Add button at the top of the Browser window)
Repeat as required.
On your toolbar you will see a magnifying glass with a cross in it: - click on this and then draw a box around the study location. Keep repeating this until you reach a view that you are happy with. If you wish to zoom back out to the full extent of the map data use the zoom full tool If you want to re-centre the image use the pan map tool to drag it into the required position.
You may find it useful to create what is known as a
Bookmark.
A bookmark identifies a particular geographic location that you want to
save and reference later. For example, you might create a bookmark that
identifies a study area. As you pan and zoom around your map, you can
easily return to the study area by accessing the bookmark.
View > New Spatial BookmarksView > Show Spatial Bookmarks
In the Browser window on the left hand side of the screen Spatial Bookmarks will appear:
Spatial Bookmarks > User Bookmarks -
click on the one required
This is a very simple but useful tool, especially if you are moving around the screen to different survey sites for example.
Right-click on the layer to be symbolised, >
Properties
Click on Symbology on the left hand side of window and
alter colour and size as required. OK
Suppose we had a layer that contained a categorical variable, such as a name or a species. We might want the objects corresponding to each different category to be coloured differently.
PropertiesSymbology on left hand side of windowSingle Symbol to CategorizedAll other valuesYou may want to make one or more of the map layers semi-transparent so that you can see the layer below it. This can be done as follows:
For each layer as required:
Right click on layer > Properties >
Symbology – alter the Opacity using the slider
bar as required. OK.
(This is available for the Single Symbol symbology).
Datasets often cover a much great area than is required. The coverage of the layer can be reduced using a function known as Clipping.
In this exercise we will clip the OSM world map to the bounding box of the UK marine Conservation Zones layer
Vector drop down menu >
Geoprocessing tools > Clip
Select as follows:
Input Layer: What you are going to use as your ‘cookie
cutter’ i.e. what you will be using to clip the other dataset?Overlay Layer: What you want to clip o
Clipped: This will be the new layer created with the
clipped data. Click on the grey box with the 3 dots –Save to File >
navigate to the folder you want to save the layer in. File name: The
name of your new clipped layer Save As Type: SHP files (*.shp)RunCloseA new layer will be created and added to the project. Yay!
You cannot edit the attribute table of a Delimited Text Layer. This is annoying but true. If you need to edit it, a workaround is to export it as a Shapefile (ie a vector layer). To do this, right-click on the layer name in the Layers pane, then export the layer as a Shapefile using Export/Save Features as, as shown below. Finally, load that Shapefile back into your project (as a vector layer), and remove the original layer.
Don’t forget to chose the right CRS
To do this you open the attribute table, toggle the Edit pencil (top left) to On, then click on the New Field Icon. ‘Field’ is GIS (actually, database) speak for column. In the window that pops up, choose a name, inh Type box decide what type of data your new field will contain (Integers, Decimals, Text or date) and if you have chosen Text, make sure the ‘Length’ box permits as many characters as you are likely to need. I usually put a number that is plenty big enough, like 50 or 100.
Add a new field to an attribute table
This requires the use of a very short script. Scripting is a very powerful feature of QGIS. So much so that if you become very proficient at QGIS you may well end up doing virtually everything by writing a script full of instructions to do what you want, rather than pointing and clicking at menus.
There are two kinds of language that can be used for scripting in QGIS. One is Python, and the other is SQL, which is the standard language for doing manipulations wih databases. This should not be surprising, since your QGIS is a database, of spatial data. We will use a tiny bit of SQL.
Now, fear not, we don’t to know much at all about programming to do what we need. Hold tight, and off we go:
Suppose we wanted to colour the anemone points at each location according to the size of the cluster found there. For each cluster we have its size recorded in the column “Number” of the attribute table. We would like to create a new column called ‘Size’where in each row we indicate ’Small’ if the cluster size in that row was less than 10, ‘Medium’ if it was between 10 and 50, and ‘Large’ if it was over 50. The cluster size, remember, is recorded in the column called ‘Number’. This will give us three different size categories, and hence three colours for the points in the map.
This is what we could do:
For the anemone layer, open the attribute table.
Make sure that editing is toggled on (Ctrl-E or Cmd-E if on a Mac)
Click on the Field Calculator icon. This is the one that looks like an abacus (Ctrl-I or Cmd-I if on a Mac) This will open something like this window:
Make sure you click the ‘Create a new field’ button. What do you think this does?
Give the field a name. Here, let’s call it ‘Size’.
Set the output field type to Text and the Outputput field length to, say 50.
in the expression window, copy the exact expression as shown, being careful to use double quotes for the name of the Number column, and single quotes for the value ‘Smal’, ‘Medium’ and ‘Large’ that we are going to put in the new Size column we are creating.
Use of an expression in the field calculator
We are using the CASE WHEN THEN ELSE function. This is
one of many functions available in QGIS. If you click on the function
name in the list of functions, you get help on how to use it, including
examples.
Find the pathway to a project sub-folder
The path (pathway, url) to the folder is shown at the top of the window that opens. Copy this and append the name of the information file file you want to use so that you get (in my case):
Users/michaelhunt/Library/CloudStorage/OneDrive-CornwallCollege/QGIS/fistral/helpsheets/Anemone.docx
It may look slightly different on Windows machines and on Macs. Copy and paste this url somewhere as you will soon need to use it.
Setting a whole field to have the same expression
Press OK.
Now, for the attribute layer, go to Properties / Actions / Create Default Actions
Find the ‘Open URL’ line
In the Action and Capture columns for this line, make sure that you have:
Setting an Open File action
Click OK
And finally, in the map canvas, click on the Actions icon in the top ribbon (towards the far right) and click on the Open File line:
Action: Open file
Once you have a map as you want it in the map canvas, go to Project/New Print Layout and eneter a name for the map layout you are about to create.
This will bring up the layout window:
Canvas for creating a new map layout
Using the Add Item menu, you can now add a map (this be whatever is currently in your map canvas), a scale bar and a North arrow, and many other things.
Finally, print the map to a pdf file.