TP1 Intro2020 en
TP1 Intro2020 en
TP1 Intro2020 en
Objectives :
To know how to display vector and raster layers.
To know how to change the coordinate system of the map view.
To know how to change the symbology of a vector layer and to add labels
To know how to change the color scale of a 1-band raster image.
To know how to do simple geoprocessing.
Preamble :
• In the PHITEM computer room: open a Windows or Linux session (if the computer
is running Windows and if you would like to run Linux, reboot and choose Linux
when prompted at startup). Then start QGIS Desktop (QGIS desktop icon in the
applications directory).
Note that QGIS is available for free on Windows, Mac and Linux (www.qgis.org) and
that we strongly recommend that you install it at home.
• If the QGIS menus are in French, change the configuration to English (the TP
instructions will always be given compared to the English version):
• Recover the data necessary for the practical work: They are under Chamilo (course
code = PAX8STAB).
Part I: projections
Vector layer and projection
The Natural Earth site (http://www.naturalearthdata.com/) provides many vector and raster
layers well prepared for making large-scale (world) maps. We will use some of them
provided in the data made available to you.
• After starting QGIS, open a vector layer containing the coasts of the whole world:
directory "WorldLand"> file "ne_10m_land.shp"
How to open a layer: either menu Layer> Add Layer, either with the following two icons
• By moving the cursor on the image, watch the evolution of the coordinates (in the
bar at the bottom).
What is the range of coordinate variation? What is the probable unit?
• In order to visualize the meridians and parallels, open a second vector layer: file
"graticule-45-30.shp"
• By default, the display of the layer is made with the CRS of the first layer loaded in
the project. In order to display the map in a different CRS, there are two
possibilities:
2. Use the projection "on the fly", that is to say that the re-projection is constantly
recalculated (at each change of zoom or movement on the image) and stored
only in the computer memory. This does not involve any modification of the file
or the creation of a new file and is therefore temporary.
By default, on-the-fly reprojection is always active in QGIS versions higher than v.3
Each of the two solutions has its own advantages and you have to know how to do both.
We are interested here in the second, which is more practical but has limits when there is
a large volume of data and one wishes to carry out complex processing: the display on the
screen can become very slow because the re -projection requires long calculations.
To test solution 2: click on button (right bottom of map view) and try various
coordinate systems among the very many available. For example, it is possible to select a
part of it using the filter field: e.g. "World" or "Mercator" allows you to narrow down the list.
It is handy to remember the main EPSG codes that you will often use: 4326 for WGS84,
and 5699 for RGF93 / Lamber-93 for example.
• return to CRS EPSG: 4326 (geographic coordinates WGS84), then open a raster
layer: file "NE1_50M_SR_W.tif".
On the left, in the Layers panel, with the mouse, it is possible to drag this raster layer
under the vector layer, which allows visualizing the two correctly.
This file is quite large, and on-the-fly re-projection is very expensive in terms of memory
usage and computing time. Not all CRSs allow a fast and/or satisfactory result. For
example try the World_Azimuthal_Equidistant projection (EPSG code: 54032).
The objective of this part is to control the visualization of the layers to obtain a useful and /
or aesthetic map.
The DEM is a raster layer which at each point of the matrix gives the altitude. At this stage,
it is advisable to “switch off” all the other layers by unchecking the box in front of the layer
names.
• In the properties of the layer, check the coordinate system used (This is a reflex to
take because you have to make sure that the layer has the same CRS as the one
you want to work with)
The 2 following points are done by default but you can change and try different parameters
:
• In the "Symbology" tab of the properties of the raster layer, you can control the
display. For the "Contrast enhancement" field select "stretch to MinMax" which
allows you to adjust the conversion from altitude to gray levels. Change the min and
max values, then click on apply to see the impact.
What is going on ? How to find the best value?
• You can also get other automatic setting of the min and max from the options of
“min/max value settings. Choose one of the other three estimation methods,
adjust the parameters and click on "Apply" to calculate the min and max value.
When you are satisfied with the display, you can save this "style" by default (button
style at the bottom), which will allow you to keep the same parameters the next time
you use the file.
• Put some color! Usually, the topography is displayed with a color scale with blue for
negative altitudes, green, brown and white for increasing altitudes. To do this, you
must change the "Render type" field to "singleband pseudocolor". Three steps are
necessary:
1. Choose a color scale: in the "create new color map" frame, for example choose
"new color ramp" at the bottom of the drop-down list, then "cpt-city", there are
several interesting palettes in the theme " topography ").
2. Choose a min and a max, click on "classify". Look at the result in the color scale
and click on "apply" to see the result on the map. Through a series of trial and
error on the max values, find a satisfactory display which corresponds to the
natural colors expected for the Alps.
3. It is also possible to play on the "brightness", "saturation" and "contrast" which
can be controlled under the color scale to improve viewing.
• Activate the COURS_D_EAU layer and ensure that it is above the DEM layer. In the
properties, "Symbology" tab modify the graphical parameters to obtain a good
display of the hydrological network (typically, the colour blue is recommended).
The display will be further improved, but to do so, it is necessary to understand the notion
of attribute.
Attributes table
• Open the attributes table of the vector stream layer, either by going through the icon
in the tool line, or by right-clicking on the name of the layer. Browse the table
and try to understand what it contains.
• To search for a river, you can filter the displayed lines: click on the bottom left and
choose "Field filter", "TOPONYME". Enter a river name for example "drac", uncheck
"case sensitive", then press "enter". To select an entity, just click on the number at
the beginning of the line (here on the number "4" in the case of Le Drac). The entity
appears on the map with a different color indicating that it is selected (you can
change the color in Project>Properties…>General). You can use the "zoom to
selection" icon of the attribute table to zoom specifically on this entity.
Note that the default text encoding used by QGIS to read this file does not respect
special character like those with accent so Isère is not properly written in the
attribute table. (this default value may be changed when opening a new vector
layer)
Generally in QGIS, there are several places "Data defined" option is found, which
means that the field that can be adjusted manually, can also be controlled by the data in
the attribute table, which allows changing the visualization according to potentially complex
criteria.
Here, in the "Rendering" tab of “the labels” menu, you can limit the entities displayed.
Under "Data defined", click on the icon next to "Show label", then enter an expression by
clicking on "Edit". If you enter “classe <5” is entered, only rivers whose class is less than 5
will be labeled.
• Attributes can also be used to control, for example, the thickness of lines. In the
"style" tab of the COURS_D_EAU layer, select "simple line", then "Data defined
properties". In the "Stroke width" field, which controls the line thickness, click on the
“Data defined override” , then “edit” and enter "2.5/CLASS" in the "expression"
field. You will find the variable in “Fields and Values”. This means that the pen width
(=thickness of the line) for each entity is calculated by the formula 2.5/CLASS. Click
on "Apply" to see the result. Note that 2.5 is here an empirical parameter
determined by trial and error.
change values. Click on the icon “Delete selected features” , then on the icon
“Save Edits” or even more simply, switch back to “Edit” mode and agree to save
the file. Note that this operation is final since the file has been modified.
It is possible to import simple data formatted in columns or from a spreadsheet. Open the
file catalog_sismalp_1989-2011_ML2.csv with Wordpad or any other editor and observe its
content. It is also possible to open it with a table (Calc or Excel). This file is an extraction
from the Sismalp database (ISTERRE,…) which lists earthquakes in the Alps. This file has
a format called CSV for "Comma-Separated Values". In fact any text file containing column
values can be imported into QGIS, two of these columns must contain longitude and
latitude or X, Y if a projection is used.
• Click on the “Add Text delimited Layer” icon , then select the earthquake file.
From the many options, it is possible to read many text file formats. The important
point is to specify the column which contains the X field (= longitude) and the Y field
(= latitude). Import and view the layer with WGS 84 in CRS and view the layer. In
the specific case of this file, the automatic detection of the right parameters is good,
it is not always the case, it may be necessary to adjust these options.
• It may be interesting to save this layer as a file in a native vector format for easier
later import. For that, it suffices (and it is valid for any vector layer) to right click on
the name of the layer and to click "Export"> "Save feature as". The output format
"ESRI Shapefile" is the most used. Give a file name. By selecting a CSR different
from that of the layer, it is possible to re-project the data, this is solution 1) which
had been mentioned at the beginning when the layers had different projections
between themselves or different from that of the project and that "the projection on
the fly is too slow". For later needs, re-project this layer in the CSR of the project
(Lambert 93).
• Display the magnitude of the earthquakes next to the points using the same
approach as above.
Rather than having the size of the symbol proportional to the magnitude, it may
be interesting to have the size of the symbol proportional to the length of fault
that broke, times a multiplying factor (in red). Why this factor? :
Use the following empirical relation which gives the link between fault surface
and magnitude:
2. the color of the point depends on the magnitude. It is a classic solution. In the
“Style” tab, you only need to switch “Single symbol” to “graduated symbol”.
Choose a color palette and click on "classify". It is difficult to choose to specify
the range covered by the color scale, if not to type by hand the intervals for each
color, which is not practical.
• As the file contains all of France, we propose to select the entities corresponding
approximately to the footprint of the Sismalp network. Rather than deleting the
entities that do not interest us as done previously with the streams, we propose a
more elegant method: For this, select the area of interest (= area which contains the
earthquakes) with the rectangle selection tool , then save the layer with "Export"
as before. Then "save only selected feature". In addition for later needs, reproject
this layer in the CSR of the project (Lambert 93). Give a recognizable file name (for
example: commune-zoneetude.shp) and save. Close the layer which contains all
the municipalities of France and open the new one which has just been created.
• Open the shape file (.shp) containing the earthquakes in the Lambert 93 CRS (most
analysis tools cannot use the on-the-fly projection, it is essential that the layers in
input of the processing are in the same projection).
• In the "Vector", "Analysis Tools" menu, choose the "Points in Polygon" tool. Specify
the municipalities as the polygon layer (take the file in Lambert 93 project well) and
the earthquakes as the point layer. Specify an output file name and to directly see
the result activate "Open output file ...". We see a layer appear that contains exactly
the same polygons as before, the difference is seen in the attribute table. Use this
new information to show the municipalities which have the most earthquakes by
using for example “graduated symbol”. It is necessary to enter the min / max values
for each color by hand, because the automatic “classify” does not work well
because of the very large number of towns without earthquake.
• This representation is not necessarily fair since the largest municipalities have a
higher probability of experiencing these events. In order to normalize by the area of
the commune, it suffices to add an attribute in the file containing the result. To do
this, in the attributes table, switch to “Edit” mode and click on the icon on the right
representing an abacus . In the form, you can create a new column (or new
attribute). Give it a short name, without space, without accent (example:
seisme_km2), specify that it is a decimal number, then in the expression register:
10^6*NUMPOINTS/surf_m2, which means that this new column will contain the
report of the two columns indicated. This gives a density per square kilometer.
Why don't we calculate a density per square meter?
Click on "Ok", then exit the "Edit" mode. Then just modify the field used to control
the display of colors and reconstruct the color scale ("classify"). You can also set
the class limits by hand, or try other types of automatic classification in place of
Equal Interval and try to find one that would work better for this distribution.
The example here may not be very dramatic because there is "not enough" earthquake
and the range of variation of commune sizes is not wide enough to get a very different
result, but in d In other cases, the calculation of a surface density may be relevant.
• For those who have time: calculate the length of river that each municipality must
manage and make an adequate display.