HOW-TO QGIS For Students 2020

You might also like

Download as pdf or txt
Download as pdf or txt
You are on page 1of 11

QGIS 3.4: HOW TO? and WHY?

Version 2020, Erwan Pathier.


QGIS 3.4: HOW TO? and WHY? ............................................................................................ 1
How to switch from French to English ? ................................................................................ 2
How to install a new plugin? .................................................................................................. 2
How to use SAGA tools? ....................................................................................................... 2
How to create and edit a new shapefile? ................................................................................ 2
How to know the pixel size and units of my Raster? ............................................................. 3
Why I can’t see my data in the map view anymore? I lost them! .......................................... 3
How to know the Coordinate reference system of the map (QGIS canevas) ......................... 3
How to display coordinates in a different system from the map view? ................................. 3
How to get a nice topographic colormap for my DEM? ........................................................ 3
How to do hill-shading on my DEM? .................................................................................... 3
Why my hill-shading is ugly and looks too contrasted? ........................................................ 4
How to visualize my DEM in 3D? ......................................................................................... 4
How to do a topographic profile across my DEM? ................................................................ 4
Why when I want to open my project (.qgs file) I have an Error? ......................................... 5
How to change the projection of a Raster? ............................................................................ 6
How to see and compare the pixel values of Raster layers? .................................................. 6
How to compute the difference of two Raster layers? ........................................................... 6
How to replace a value by another in a Raster? ..................................................................... 6
How to merge several Raster? ................................................................................................ 7
Why my raster is so slow to display and how to accelerate the display? ............................... 7
How to crop a raster image according to the extent to another one ....................................... 7
How to clip a vector layer? .................................................................................................... 7
How to georeference a raster knowing one of its corner coordinates and its projection? ...... 7
How to georeference a raster which is not in a known coordinate Reference System? ......... 8
How to create a gridded DEM from a list of point XYZ? ...................................................... 9
How to add a coordinate grid in QGIS? ................................................................................. 9
How to recover the layer panel: I lost it! ................................................................................ 9
How to get pixel values of a Raster layer from a list of points coordinates? ....................... 10
How to join points to make a polyline? ................................................................................ 10
How to use subscript and superscript in map title:............................................................... 10
How to use special character in legend ................................................................................ 10
How to switch from French to English ?

Main menu > Préférences > Options > Général :

restart QGIS.

How to install a new plugin?


Main menu > Plugin > Manage and install plugins
Select the plugin in the list (you can filter the list by name)
Click on install plugin.

Note, if you don’t have access to internet only a short list of pre-installed (but not always
activated) appears: tick the box for activation.

How to use SAGA tools?


Main Menu > Processing> Toolbox: in the processing panel (on the right) > SAGA > choose
a tool.

If the Processing tab is not in the main menu, check for main menu > plugins > install and
Manage extension > processing

If SAGA tools do not appear in the Toolbox Panel:


Main menu > Processing > Options and configuration > Provider > Saga : activate.
At the bottom of the Processing Panel, choose advanced interface.

In case of problem running SAGA tools, you may try to uncheck “Use SAGA 2.0.8 syntax”

How to create and edit a new shapefile?


Add layer> new > New Shapefile Layer :
Choose which kind of feature you want to edit (point, line or polygone) : only one type
per shapefile is accepted.

If you want to add attribute when you create a new object


New attribute : give a name, and specify type and click on “Add to attribute list”

Click OK : a new layer is added to QGIS, put it on the top

To add a new feature: right click on the layer and choose toggle Editing
Tools of the edit toolbar are now active.
If you do not see the edit toolbar : main menu > view > toolbars > check Digitizing.

Select the appropriate tools and create object by clicking on the map. Right click to stop and
store the object: a new window appears asking you to fill the attributes.

When you have finished digitizing: click on the “save” icon of the digitizing toolbars.
How to know the pixel size and units of my Raster?
Select your raster layer, right-click > properties > Metadata > properties > Pixel size

Why I can’t see my data in the map view anymore? I lost them!
There are several possible reasons for that:
- The layer of these data is masked by another layer: in the layer panel unselect the
layers on top of the desired layer.
- Data are outside the map view frame: in the layer panel select the layer
- Transparency of the layer is set to 100%
- Map view Coordinate Reference system (CRS) is not compatible your data CRS.

If these actions can’t solve the problem: open a new blank project, open only this layer, it
may help to understand the problem.

How to know the Coordinate reference system of the map (QGIS canevas)
Click on the icon “CRS Status” located at the bottom right of the QGIS windows.

How to display coordinates in a different system from the map view?


Use the tool “coordinate capture”
Activate it in View > Panel > select coordinate capture
In the first field you can select the coordinate system of your choice
Click on the “start capture” to be able to get the coordinates

How to get a nice topographic colormap for my DEM?


Select the DEM layer, right-click > properties > Symbology:
In “render type”: select “singleband pseudocolor”
In “Color ramp”, using the scroll menu select your colormap.
Note that there are additional colormaps available, if you select “Create new color
ramp” at the bottom of the scroll menu. Then a “Color Ramp Style” windows pop up, then
select “cpt-city”: you will have a large choice of color bar. For instance for topography select
topography > Wiki-Schwarzwald-cont
Once we have selected the colormap, click on “Classify” (if the min and max value looks
strange, in load min/max values click on load (with accuracy > Actual (slower) checked)

How to do hill-shading on my DEM?


Raster > Terrain Analysis > Hillshade:
Elevation Layer : Select input layer
Output Layer : Indicate outputfile (use Select… buton on the right)
Illumination :
Azimuth (horizontal angle) in degree : 00 illumination from North
45 illumination from North-East
90 illumination from East

Vertical Angle in degree : 05 nearly horizontal (sunset)
90 vertical

Alternative: interactive hillshade:


View > Layer styling : select the DEM layer
Select hillshade mode (scroll bar) :

Then by moving the dot inside the circle you can interactively see
the effect of a change of illumination angle (if not check that live update at the bottom
is checked)

Why my hill-shading is ugly and looks too contrasted?


By default, the hillshading suppose that the length unit of the pixel size of your DEM is the
same than the elevation values of your DEM. If the pixel size of you DEM is defined in
decimal degrees (cf. How to know the pixel size and unit of my Raster? ) for instance
0.0008333° instead of 90m, which can be the case if your DEM’s CRS is a Geographic
Coordinate System and the elevation in meter, QGIS interpreted that as if the pixel size was
0.0008333 m (which is a shame!)

One should expect to fix this problem by changing the z-elevation factor. However, I did not
get good results with that (you will may be luckier than me…)

Use rather Raster > Analysis > DEM


You can here specify a Scale (ratio of vert. units to horiz): you can use the approximation
that 1° of latitude ~= 100km, and then put scale to 100000.

An alternative is to change the DEM’s CRS into a projected coordinate system with
coordinate in meter like UTM. (Cf. How to change the projection of a Raster?)

How to visualize my DEM in 3D?


You can use the plugin Qgisthreejs
Install plugin Qgisthreejs (Cf. How to install a new plugin?)
Menu principal > Web > Qgisthreejs > Qgisthreejs :
In DEM: select the DEM layer
Display type : keep Map canvas image
You can increase the resolution of the output 3D block using the slider.
You can also specify a vertical exaggeration in the “World” panel .
In firefox a new tab is open.
In case of problem check whether your web browser supports WebGL: go to
http://get.webgl.org/

How to do a topographic profile across my DEM?

Select your DEM layer


Main menu > Plugins > Profile Tools > terrain profile: a new panel opens and the mouse
pointer is now a cross.
With the cross cursor you can digitize the profile line (double click to finish).
Note that you can do a profile simultaneously across several rasters (click on “add layers”)

To export the result as text that can be imported in Excel : click on “Table” tab and “copy to
clipboard”.

If you want to keep the profile location and to be able to modify it:
- first create a new vector layer of line type (cf. How to create and edit a new
shapefile?). Then Layer > Toogle > Editing and you can use the digitizing tools to
trace your polyline.
- select the DEM layer and Plugins > Profil Tools > Terrain Profile: choose the option
«selected polyline» instead of « temporary polyline »
- Select the vector layer and then with the mouse cursor select the polyline

Note that if you change the active tools, it is sometimes not possible to recover the profile
tools. In this case, do again Plugins > Profil Tools > Terrain Profile

Why when I want to open my project (.qgs file) I have an Error?

Le problème vient certainement de l'emplacement de votre fichier .qgs. Pour résoudre le


problème il faut bien comprendre la 3eme colonne du tableau: Elle donne l'emplacement du
fichier de données que QGIS cherche à ouvrir mais n'y arrive pas.
Cet emplacement est indiqué en relatif par rapport à la position de votre fichier .qgs.

Par exemple, si votre fichier .qgs est situé dans le répertoire C:/temp/ et que le projet fait
appel à un fichier toto.shp situé dans le répertoire C:/temp/vecteur/ son chemin relatif
est ./vecteur/toto.shp
Le point '.' signifie le répertoire où se situe votre fichier .qgs
Deux points '..' signifie qu'il faut remonter d'un repertoire dans l'arborescence. Exemple : si
votre fichier .qgs est situé dans le répertoire C:/temp/rep1/rep2/rep3/ et si le chemin indique
dans la 3eme colonne est ../../vecteur/tata.shp, cela veut dire que le projet fait appel à un
fichier situé dans le répertoire C:/temp/rep1/vecteur/ (../.. signifie remonter de deux
repertoires dans l'arborescence)
Pour résoudre votre problème : regardez sur votre ordinateur où sont situé les fichiers qu'il
cherche à ouvrir sans succès. En cliquant sur la case de la 3eme colonne, vous pouvez lui dire
où il se situe.

How to change the projection of a Raster?


If you want to modify the projection of a raster (i.e. create a new raster with a different
geometry):
Raster > projection > warp (reprojection): indicate the raster layer and the target projection

Note that In version 2.0 there is a bug if you need to have an output format different of
geotiff.
Edit the gdal_warp command line
By defaut -of Gtiff = output format Gtiff can be modified

More generally the reprojection windows of QGIS offer only a few options of the gdalwarp
function. You can edit the command line to satisfy your needs
Look also at gdalwarp help.

How to see and compare the pixel values of Raster layers?


Use the plugin Value Tool:
Install the plugin (see How to install a new plugin? )
Main Menu > View > Panel > Value Tool.

You can also use Profile tools for doing value profile across several Rasters (see How to do a
topographic profile across my DEM?)

How to compute the difference of two Raster layers?


Use Raster Calculator:
Main Menu > Raster > Raster calculator
Formula: Raster1@1 – Raster2@1 (select the Raster band in the list)

Ouput layer: click on “current layer extent” the result will have the same extent and
resolution than the currently selected layer in the Raster bands list. Do it systematically
because the extent and resolution are not automatically updated which can lead to error in the
output file.

It is recommended to use Rasters having the same coordinate reference system (see How to
change the projection of a Raster?)

How to replace a value by another in a Raster?


One way is to use the Raster calculator
Main Menu > Raster > Raster calculator;

(Raster1 = val1) * val2 + (Raster1 > val1) * Raster1 + (Raster1 < val1) *
Raster1
Replace Val1 by Val2

Another example:
(Raster1 < 100) * -9999 + (Raster1 >= 100) * Raster1
Replace all pixel of Raster1 smaller than 100 by -9999

(See also How to compute the difference of two Raster layers?)


How to merge several Raster?
Main menu > Raster > Miscellaneous > Merge

Select input files


select output file name (a .tif file is recommended)

Note this fonctionnality is a call to the gdal_merge function that contain more options than the
one offered in the QGIS dialog box (see http://www.gdal.org/gdal_merge.html for details).
However, you can always edit the command line to add other options: Clic on the pen icon, on
the bottom right.

If the image overlap or have different resolution some rules applied by default, that can lead
to unexpected result: see http://www.gdal.org/gdal_merge.html for details.

Why my raster is so slow to display and how to accelerate the display?


It may be due to the large size of your image and also to its compression type and level.
A way to accelerate the display is to build “pyramid”

Right click on the raster layer > properties > pyramids:


- You can select all the selected levels (faster results if you do large range of zoom
in/out, however the drawback is the size of the auxiliary .ovr file created).
- build pyramid

How to crop a raster image according to the extent to another one

1 - Vector->Research Tool->Polygon from layer extent (use the raster layer that define the
area you want to crop)
2 - Raster > extraction > clipper > in clipping mode select mask layer and use the previously
created shapefile.

How to clip a vector layer?


One way is to use the select tools:

(main menu > view > toolbar > attributes)

Select the vector layer


Tools select by rectangle for instance
Right click on the layer > save as:
- Give a filename .shp
- Check “save only selected features”
Open the new file.

How to georeference a raster knowing one of its corner coordinates and its
projection?
A way to do it is to create a “world file”.
Here is an exemple of a world file, which is a simple text file:
10.0000000000
0.0000000000
0.0000000000
-10.0000000000
313230.5315482824
4924747.8622969911
That gives the following information:

10.0000000000 increment of pixel size in X in unit of the


projection system.
0.0000000000 rotation parameter
0.0000000000 rotation parameter
-10.0000000000 increment of pixel size in Y in unit of the
projection system.
313230.5315482824 Translation en X (equivalent to coordinate X of
the centre of the upper left pixel corner).
4924747.8622969911 Translation en Y (equivalent to coordinate Y of
the centre of the upper left pixel corner).

See http://fr.wikipedia.org/wiki/World_file for more details

Note that the coordinate reference system is not specified in the file. You will have to specify
it when opening the raster in QGIS.

Rename the world file according to the corresponding raster file:


Exemple:
My_raster_to_be_georefenced.jpg should be accompanied by a worldfile
My_raster_to_be_georefenced.jpw

How to georeference a raster which is not in a known coordinate Reference


System?
Toolbar Raster > georeferencer

A new window opens:


Add the raster layer to be georeferenced
Specify the CRS that will be used to enter the coordinate of some points on the Raster
(if you will use the QGIS map to pick up the coordinate, then specify the CRS of the current
QGIS map)
Then read the detailed explanation (in French) here:
http://docs.qgis.org/1.8/fr/docs/user_manual/plugins/plugins_georeferencer.html

Note that you can use the current QGIS map to specify the selection of your point, for
that once you have selected a point on the raster to be georeferenced click on “From map
Canvas”
How to create a gridded DEM from a list of point XYZ?
First you need to convert the point list into a shapefile: You need a text file with delimiter
separating the X, Y and Z coordinates:
Main menu > layer > add delimited text layer:
- Select appropriate delimiter (check in the preview box if the text file is correctly read)
- Specify the X (East-West), Y (North-South) column
- OK
Then specify the Coordinate reference system.
At that stage the points are displayed in QGIS in a temporary layer. If there are a large
number of points, you may uncheck the render tick box located at the bottom right of the
QGIS window, to avoid them to be displayed.

For the next step it is better if the map windows have the same CRS than the data you want to
grid.

Main menu > Raster > Interpolation:


Select the temporary layer
Select the field that contain the value to interpolate (field 3, in case of a X Y Z file)
Select TIN model
Select the cell size according to the average point density.

Note that for Lidar data it exist some plugins like LAStool that are far more efficient to
generate grid. However the plugin is not supported for all Operating System.

How to add a coordinate grid in QGIS?


1- On the canvas (map on the screen): View > decoration > Grid
2- To make a nice figure from my project
Project > New Print Composer :
Add new map (draw rectangle on layout): this add a new item called by
default Map0 (see on the right panel)
In “Item properties” tap, expand Grid:
Add a new grid (Grid 1 by default)
Set an appropriate coordinate interval (if set to zero: no grid
is displayed!)
There are several other parameters you can tune.

How to recover the layer panel: I lost it!


Main menu > View > Panels > Layers
How to get pixel values of a Raster layer from a list of points coordinates?
See plugins Point sampling tool
(be careful, the point shapefile and raster layers should be in the same coordinate system)
http://www.qgistutorials.com/en/docs/sampling_raster_data.html

You can also use plugin Raster interpolation, which interpolate the pixel value depending of
the points position within the pixel.

How to join points to make a polyline?


Consider these plugins:
Point2one
ReconstructLine

How to use subscript and superscript in map title:


Select the label item of your map (if it does not exist use icon “Add new label”)

Items Panels > Items properties > Main properties box: write the text in HTML format, and
check the option “render as HTML”.

For example, if you copy paste the following line

Test: f<SUB>(x)</SUB>=x<SUP>2</SUP>

You should get

Test: f(x)=x2

How to use special character in legend


Pour la légende c'est plus compliqué que pour un item label (voir How to use subscript and
superscript in map title), car l'option "render as HTML" n'existe pas:
Une solution, utiliser une police qui supporte les exposants et indices, voir aussi :
http://gis.stackexchange.com/questions/192842/subscript-labels-in-qgis-legends

La police Arial Unicode MS supporte les chiffres en exposant ou indice,


pour les lettres voir plutôt la police Dejavu (mais toutes les lettres ne sont pas supportées).

Pour trouver rapidement un caractère dans la table en connaissant son code :

1. Cliquez sur la liste Police, puis sur la police que vous souhaitez parcourir.
2. Activez la case à cocher Affichage avancé.
3. Cliquez sur la liste Jeu de caractères, puis sur Unicode.
4. Cliquez sur la liste Grouper par, puis sur Tous.
5. Dans la zone Page Unicode, tapez les quatre caractères composant la valeur Unicode
du caractère que vous recherchez.

Ce caractère apparaît en surbrillance dans la grille de caractères.


Pour connaitre le code voir sur

https://en.wikipedia.org/wiki/Unicode_subscripts_and_superscripts

exemples :

 pour le 4 en indice, il faut taper le code 2084 dans "Page Unicode"


 pour le m en indice, il faut taper le code 2096 dans "Page Unicode" (pas disponible
pour Arial Unicode MS, mais Ok pour Dejavu)

Remarque: Avec cette méthode, en plus des indices et exposant, on peut aussi utiliser des
lettre grecques, etc...

You might also like