WOCAT FAO Tutorial QGIS
WOCAT FAO Tutorial QGIS
Introduction to QGIS
1
Title: Tutorial for an Introduction to QGIS
Editors: César Luis García, Ingrid Teich, Hanspeter Liniger, Rima Mekdaschi Studer and
Nicole Harari.
FAO
FAO, Food and Agriculture Organization of the United Nations, Viale delle Terme di Caracalla Viale
delle Terme di Caracalla, 00100 Rome, Italy,
Tel +39 06 57054888, Fax +39 06 57056275,
E-mail: Ingrid.Teich@fao.org; Cesar.Garcia@fao.org
http://www.fao.org/
2
Acknowledgements
This tutorial has been developed in a joint effort between WOCAT and CACILM II FAO-GEF project
for the training of more than 70 experts from 5 Central Asian countries (Kazakhstan, Kyrgyzstan,
Tajikistan, Turkmenistan and Uzbekistan), to support countries in mapping land degradation and
achieving Land Degradation Neutrality. The editors would like to acknowledge the persons that
have contributed to the development of this tutorial. Special thanks goes to the donor agencies:
FAO and GEF.
3
TABLE OF CONTENTS
4
1. BRIEF INTRODUCTION
This guide was developed for a basic training in Geographic Information Systems (GIS),
to serve as a quick introduction to QGIS, which is the base software on which other
applications and plugins, relevant to Sustainable Land management and Land
Degradation Mapping, run, i.e: Trends.Earth (Conservation International) and
Watershed Tool (WOCAT). The document aims to convey basic applications offered by
this computer tool to produce practical knowledge, solve problems of georeferenced
information management and creation of maps. This manual has step-by-step
explanations of the practices carried out in the training to serve as a reference material.
However, it can also be used by those who want to venture into GIS (self-taught). Please
see the QGIS page for further practical and theoretical guidance with sample data and
examples:
https://www.qgis.org
2. INSTALLING QGIS
QGIS is an open source and free software that can be downloaded for every operating
system. It is distributed in both a Latest Release version, which has the most recent
developments and features and a Long-Term Release that is updated once a year, so it
remains stable for longer periods. Also, for windows users it is provided in the 32bit and
64bit versions according to your operating system.
To download the program, visit the web page and select your preferred option. To
choose 64-bit or 32-bit version you can check your operating systems first by pressing
the Windows key + Pause or going to Control panel System.
Once the installer is downloaded, run it and follow the instructions to complete the
installation. When completed, a folder will appear on your desktop with all the
shortcuts, to start QGIS just double click on QGIS DESKTOP x.x.x with GRASS x.x.x .
5
3. INTERFACE
QGIS can be run from a User Interface (GUI) or command line and integrates tools from
other free and open systems like GRASS, GDAL, SAGA and programming languages like
Phyton and R. The GUI is has different components that can be re-arranged and
personalized. Basically the main QGIS GUI types of components are:
1. Menu Bar
2. Toolbars
3. Panels
4. Map View
5. Status Bar
There are many Panels and Toolbars in QGIS that can be made visible and/or located in
different parts of the GUI Windows. Just try a right click on the menu bar (2) to see the
available ones.
Also in the Browser or Layer Panels (3) you can make a Right click on a file to access the
contextual menu that contains many options.
6
4. OPENING AND MANAGING VECTOR DATA - EXERCISE 1
4.1.2 Please extract the data in a folder and explore to see few Shape files (*.shp) that
will be used in this demonstration.
Layers are a free open dataset for the whole world produced by OpenStreetMap (OSM)
https://www.openstreetmap.org. There are many ways to access and download data
from this repository, like external services (https://overpass-turbo.eu/ or
https://download.geofabrik.de/) or QGIS plugins like: OSMDownloader or QuickOSM.
The layers provided contain OSM data for:
Tajikistan Border: Country limits
Tajikistan Admin 4: Second administrative level boundaries (province)
Tajikistan Admin 6: Third administrative level boundaries (district)
Tajikistan Roads: Main roads
Tajikistan River: Main Rivers
Tajikistan Place: Populated places
1.- Using the Data Source Manager (Ctrl + L) to choose the type of File and specify
details.
2.- Using QGIS Browser and double clicking on the layer you want to open.
3.- My Favorite 😊: Just Drag and Drop from your normal file explorer.
4.1.3 Please, open all the files provided to see their content in the Map View. By using
the QGIS Browser you can select all of them and open them all at once:
7
Here you have to consider a few things:
The color of the layer is assigned randomly
The order of appearance is from top to botton in the list, so if you have a
polygon with solid fill on top it will cover what is below.
You can just drag and drop items in the list and toggle the visibility in order to
organize your view.
4.1.4 Play with the order and visibility to see the layers:
8
4.1.5 After exploring the structure of the open layers to know what type of vector file
we have in each case (point, line, polygon), we should proceed to explore what data we
have in the databases and what their representation system is. A lot of information and
functions can be obtained trough the Context Menu, by Right Clicking the name of the
layer:
A.- Context Menu: has many basic functions for the specific layer.
B.- Open Attribute Table, will give us access to the database associated with the
Layer
C.- Properties: Opens the layer Properties Menu: One of the most used functions
for Layer management. Here you can (and we will use it a lot):
- Check the layer information and Sources
- Change the Symbology
- Manage Labels
- Etc. etc.
4.1.6 Please explore the Attribute table of some of the Layers to we what’s in there.
And try some of this bottons, Specially the last one:
9
4.2 Changing Polygon Style
STEPS:
Toggle the visibility off for all Layers except for the Tajikistan_Border.
Go to Layer Properties -> Symbology -> Click on Simple Fill (1), then click the arrow in
the Fill color bar (2) and when the Color windows opens, check the Box with Transparent
Fill (2). Then choose the color of outline in the Stroke Color bar (3) and set a width for
the line 0.86 (4) click Ok to see if it works (I Hope so).
10
4.3 Styling Polygon by Categories in the data
Now let’s paint all the Tajikistan_Admin_L4 units with a different color:
STEPS
Go to Layer Properties -> Symbology -> Choose Categorized (1), Then choose the Field
from the Attribute Table that you want to categorize (2 - “Name”) and press Classify (3)
to get all the possible values for that Field. You can apply different palettes like color
ramps for numerical values or Random color for cases like this with nominal categorical
values. You can also personalize the colors by clicking on each Symbol (4). Press Ok when
done to see the result.
11
4.4 Styling Lines considering their type and hierarchy
Now it gets a bit trickier, for the Tajikistan_Roads, we would like to classify them and
assign different type of lines and colors according to hierarchy:
Go to Layer Properties -> Symbology -> Choose Categorized (A), Then choose the
Field from the Attribute Table that you want to categorize (B - “highway”) and press
Classify (C) to get all the possible values for that Field. Now it is time to choose the
Symbol for each class (D): Double click on the symbol near “trunk” and choose the
type of line. You can choose “topo main road” from the Favorites sections and set
Width to 1:
12
For primary you can choose “topo road” also Width 1. And for Secondary just change
the color of the Simple Line to Brown and use a Width of 0.5.
You can now press OK and see the result. But be aware that some issues arise. For
example, “secondary” roads might be on top of “trunk” road. We would like to make
sure that a priority order is followed and more important roads appear on top of other
with less hierarchy:
Also, if you use the Identify feature tool you will see that the Roads are made of
segments. Normally the joins are not visible if you use a Simple Line, like in
“secondary” road, but under composed lines (trunk and primary) it produces an effect
that we also want to correct:
13
For this please go back to Layer Properties -> Symbology -> Advance (E) -> and choose
Symbol levels… when the windows Pops-up (F) click on Enable symbol level. Please
complete the table as shown (F), the logic is to assign a higher number to higher
hierarchies. Once you are done press OK. If you want to save a style for later use, you
can click on Style (G) and choose Save Style.
Use the Identify feature tool and Open the Attribute table to explore the data.
14
According to the Attribute Table the total number of points in the layer is:
The field “place” in the database contains lots of different values, indicating the type of
settlement. If you want to get a report on all the possibilities, you can run this tool to make a
list: Vector -> Analysis Tools -> List Unique Values… and in the Target Field(s) Option choose:
“place”:
For our map we want to filter this layer in order to have only City and Towns:
For this please Right click on the Layer name (1) to get the Context Menu and choose
Filter… (2). This should Open the Query Builder: Choose the target field (3) “place” and
press All (4) to get the list of all values for this field. You can either write the Filter
15
expression below (6) or you can just Double click on Fields, Values and Operators (3 , 4
, 5) and they will automatically be written below (6). Press OK when you are done.
If you check now the Attribute Table the total number of points in the layer should
have changed:
Let’s have some styling for these points. You can use the “topo pop capital” (5) size 3.2
for the Cities and for Towns just make the dot Black and size 1:
16
Time to add some Labels for the points:
In Layer Properties -> choose Labels (1) -> Choose Single Labels (2) and the field that
contains the text “Name” (3). There are many options for Labels to control how and
where text is added, for now we only add a Buffer (4) by checking the option Draw
text Buffer.
17
It seems there are too many names in the map ☹. But we can solve that:
18
We can choose to Label only certain type of points or use different styles for different
hierarchies. In Layer Properties -> choose Labels (1) -> Choose Rule-based Labeling (3)
and Double click on the first Rule (3) to enter Edit Rule. Enter a name in Description
(4) and define the Filter (5). You can either write or press the Ɛ button to open the
Expression Builder, this works similarly to the Query Builder we used before (try it!).
Then click the OK in all windows to get Labels only on the cities. In Rule-based Labeling
you can use the + button to set new rules for other types of points.
I hope you map looks cleaner and clearer now…. Lets prepare it for printing!!!
In this section we aim at putting the map into a Page designer and export it from QGIS
in one of the many formats or send it to printing. So far, we have been working in the
Map Canvas and now we have to lay out items and release our creativity:
First step is to open the Layout Manager (1), every page for printing that we create will
be here to view/edit. Being our first for this project, just create a Empty Layout (2).
When the windows pop-ups, just name the name of the print you are creating (3).
This will Open the Layout Editor in a separate window… it has so many options that is
scary!!! …No worries, you will not suffer alone. 😊
19
If you place your Mouse on any on the icons you see and wait 1 second a small label
will tell you what is the name of that tool.
The first tool we use is Add Map (1), and it will allow us to create an Item (2) where the
map (whatever is on your canvas) will appear. I made a rectangle almost the size of the
page (2), but you can choose your how section of the page to put the map.
Next is to move your map and adjust the zoom (scale), use the Move item content (3)
tool for moving things inside your square, or set a Scale manually (4). If you want to
move or resize the Item or select another item (after we add new ones) you need the
tool called Select/Move Item (5). The other Items we will create and use to make our
map are usually the ones in the red circle (6): Add Label, Add Legend, Add Scale Bar and
Add North Arrow. Every Item that we create will have an Item Properties Tab (7).
Let’s see the example of adding the Legend:
20
First click on Add Legend (6) and choose a place to put the Item in the Page. It will
appear something like (A), where all the legends from all the layers appears. So, this
needs editing: for that you need to unclick Auto update (B) and using the tools in (C)
you can change any thing you like and delete all the ones that are not shown in the
map. Until you get something like the one in (D).
Please experiment by adding: 1.- North arrow, 2.- A title for the map (Add Label), 3.-
scale bar.
Once your map is ready, you can lock the Layers and styles of your Layout by clicking:
Lock layers and Lock Styles for layers as indicated in (8). Finally, you can export it to:
PDF, PNG, JPG, TIFF, SVG, etc. using one of the buttons in the top tool bar (9).
21
4.7 Time to practice
Please now make your own map. You can also make a different zoom, use the river
layer or District boundaries. Save your result as .png.
Here are some nice results from participants who took the training.
22
5. QGIS BASICS 2: WORKING WITH DIGITAL ELEVATION MODELS
5.1 Introduction: Rater data & Digital Elevation Models
There are many sources and resolutions of Digital Elevation Models (DEM), and you
will have to choose depending on the use you want to make with these datasets.
Among the free options are:
SRTM mission (NASA's Shuttle Radar Topography Mission), which covered the
whole world and many DEMs have been produced with resolutions ranging
from 30m to 1km.
ALOS PALSAR produced global DEM at 30m and 12.5m resolution and
contains images of different years.
ASTER Global also produced many different versions of a classic 30m DEM.
Most of these products are made by or with support of NASA and JAXA and can be
found in this repositories:
ASF Vertex:
https://search.asf.alaska.edu/#/
NASA
https://search.earthdata.nasa.gov/search
USGS
https://earthexplorer.usgs.gov/
One of the more classic interpretations of SRTM is the SRTM 90m Digital Elevation
Database v4.1 produced by CGIAR-CSI. More information about this product can be
found in their webpage (http://srtm.csi.cgiar.org/) and we will use this one for our
exercise. Downloads can be made from the page at either 5° or 30° Tiles.
We already provide in the course´s shared folder two of these tiles downloaded for our
Study area: srtm_50_05.tif and srtm_51_05.tif
23
5.2 Opening and viewing the data set
First of all, please download and unzip the Exercise_QGIS_2.zip file in your working
folder.
Raster or Satellite images come in different resolutions in different tile or scene sizes
and in different reference systems. So, it is very important to learn how to use a tool to
stich neighboring images, change their projections and clip them to the study area.
Now we have our DEM from CGIAR and we will do exactly that.
Please Open in a new QGIS project the file Tajikistan_Admin_L4. Then Open the 2
SRTM files. We are going to work in the Khatlon Province in Tajikistan:
As you can see these are separate images so we will need to find a tool to merge them
in order to cover the province with one image.
24
5.3 Mosaic raster layers
To find the necessary tools, you first need to find the toolbox. You can Right Click in
any place on the toolbar (1) and when the panel option appears choose Processing
Toolbox Panel (2). This will open your Toolbox in a new Panel where you can simply
Browse or use the search bar to search for tools (3).
The first tool we will use is one to stich the images together into a single mosaic. There
are few tools that do this in QGIS, we will try the one that comes from SAGA GIS.
Please search in the search bar (3) the word “mosaic” and find the “Mosaic raster
layers” tool indicated in (4) and Double Click to open it.
25
The tool (1) is very simple to use, just choose the Input grids by clicking in … (2), then
in the new windows check the 2 SRTM tiles and click OK. We will need to specify the
pixel size of the output image (3) you can check in Properties -> Information the value
of the original tiles and paste it here (0.000833 for this case). Set Fit to “cells” (4). And
press Run to get a new file with both tiles merged. A new image called “Grid” should
have appeared. Sometimes an error message appears but do not worry, if the grid was
created, the process most probably worked well.
Every time you run a tool you will be producing a new raster file. So be aware that
large areas and file sizes duplicate every time you Run a process. In this last case we
didn’t select name and location of a file, so a temporary file was produced and if not
saved it will later be automatically erased when you close QGIS. Before saving it, we
will project the new grid in a plane and choose a coordinate system for that. The
downloaded images are in a geographic projection, where the units are degrees (EPSG:
4326) and we need to have both the vector layer (Tajikistan_Admin_L4) and the STRM
images with the same coordinate system to make operations among them.
26
5.4 Reproject
Now that we have a single image for the whole area (called “grid” by default), we are
going to transform it into the coordinate system we have been using for the study
area: WGS 84/ UTM42N (EPSG: 32642).
For this we are going to use another tool “Warp (Reproject)” which comes from GDAL.
You can find it in the Toolbox as the previous time or in the top menu: Raster ->
Projections (1). Select the last image, “Grid” as the Input layer (2). The source
reference system (CRS) is optional but easy to fill (3), the target CRS is important so
please select or search (4) for EPSG:32642 or WGS84/UTM zone 42N. There are many
Resampling methods to use for this process, fell free to explore them, I selected
Bilinear (5) and I am quite happy with the result.
Points (6) and (7) in Advanced parameters are also optional. But if you would like to
save some Mb of storage you can choose High Compression (6) and Int16 (7) in the
case of this DEM. Please this time choose to “Save to File…” in the … dots of step (8)
and save the result in your working folder with the file name of: “SRTM_UTM42N”.
Great!! So far DEM tiles where downloaded, stitched and reprojected, it is time to cut
our region of interest. In this case the Khatlon Province.
27
5.5 Cutting out the region of interest (Khatlon Province)
This requires we do 2 things:
First Select Tajikistan_Admin_L4 in the Layer Panel and then use the Select Features
tool from the Toolbar (1). Then you can click (2) on the Khatlon polygon (South East of
Tajikistan) to select it.
Once the province is selected, to extract the area of interest to a new image we will use
the “Clip Raster by Mask Layer…” tool (3). The input layer is our “SRTM_UTM42N” layer
we just created (4). We will cut that image using as mask the Tajikistan_Admin_L4 layer
(5). This will cut using all the Tajikistan provinces except we check the option “Selected
features only” (6), please do not forget to mark that! Please also check the “Match the
extent …” box (7) in order to reduce the extent of the output layer. Steps (8) and (9) are
optional but will help with the file size (feel free to try). Please choose to “Save to File…”
in the … dots of step (8) and save the result in your working folder with the file name of:
“DEM_Khatlon”.
28
Your result should look something like:
The result is not very appealing, but it will look better if we adjust the style. You can
also use the Identify feature tool to explore what data is stored in those pixels.
To change the style of a raster layer you have to also visit the Properties -> Symbology
menu that is found in the layer’s Context menu.
In Symbology (1) choose “Singleband Pseudocolor” in Render type (2). Then we will adjust the
minimum and maximum value we want to visualize in the palette in this case from 0 to 3600+
(3). Now is time to choose a nice color ramp, click on the arrow (4) to see more options, then
click on “Create New Color Ramp…” (5). A new window will open (6) please choose the “cpt-
city” palettes and press OK… yet other windows will open (7) and choose from the
“Topography” group the one called Wiki-scharzwald and press OK. Then please update the
values by pressing “Classify” (8) button.
For now, do not worry about the X and leave Blending mode in “Normal”, but
remember where the option is for later. Just click OK and let’s see the result.
29
You should now see something like this:
30
Let´s do a solid version too:
The solid version is called “Hillshade” and it is actually a rendering based in a light
source. The steps to build it are very simple:
31
Choose Hillshade Tool from the menu (1), use the DEM_Khatlon as Input Layer (2). One of the
parameters is the Z-Factor (3), this regulates the vertical exaggeration to make more evident
changes in the terrain, lets use 2 for this exercise. Other parameters are Azimuth and Altitude
(4) that simulate the location of the Sun in the sky, for example: Azimuth of 0 will be North and
Altitude of 90 is the Sun straight Up. Please choose to “Save to File…” in the … dots of step (5)
and save the result in your working folder with the file name of: “DEM_Khatlon_Hillshade”.
Click Run and the new Layer should automatically appear.
Wouldn’t it be fun to make a combination of this to maps? Merging the solid appearance of
the Hillshade with the colorful altitude of the DEM? Remember the X?
If you set the Blending Mode to Multiply in the DEM and put it on top of the Hillshade it
produces the combination. See:
32
This is nice, but let’s do something more useful:
This is a very useful and easy to make map. Just open the Slope tool (1), set the DEM_Khatlon
as Input Layer and save it as: “DEM_Khatlon_slope”. This will get you a black and white map
with the Slope calculated in Degrees:
33
We can also use a categorical classification with the following criteria:
34
In Symbology (1) choose “Singleband Pseudocolor” in Render type (2). Choose Discrete in
Interpolation (3), choose Equal Interval as Mode (4) and set Classes to 7 (5). Then use the
Double Click to start changing the values (6) using the criteria previously described in the table.
Remember that you can save the Style for latter use (7) before saving.
35
5.8 Aspect calculation
Aspect is a very important factor describing the slope orientation. This is of great
importance in many regions since light patterns or wind/humidity could be
correlated to a certain direction.
In Raster -> Analysis -> Aspect… you can run the process by adding the
“DEM_Khatlon” as Input layer (1). Save the result as “DEM_Khatlon_Aspect” (2). The
result should look like the map below.
36
You can improve the visualization by adding ranges to the orientation:
Many times, it is useful to transfer these categories to the pixel values, this is called
Reclassification.
37
You can select any available Raster from the list (1) define the output layer (2) and use
different operators to build your expressions (3) that can be mathematical or logical. In this
case we use a combination of both.
(RasterLayer > 1) * 2
Here what we mean is that if what is inside the brackets () is true, then it is replaced by 1.
In this case this means that if pixel values in RasterLayer are greater than 1 (and therefore the
statement is true) then the logic operator is (1) * 2 = 2
on the contrary, if the statement inside brackets is false, it is replaced by 0. In this case it
means that if the value in the pixel is equal or smaller than 1 then (0) * 2 = 0
So, we can use the same classification criteria for Aspect layer in order to create a categorical
Aspect using the following criteria:
For this, you can copy and paste the following expressions in the Raster Calculation Expression:
Please, save the result as “DEM_Khatlon_Aspect_Category”. Your new Layer should now have
only 5 values. You can use the following Unique values (1) styling criteria:
38
5.10 Watershed delineation
Watershed delineation is a process that yields a lot of different Layers and requires many
different tools. The tools also require several parameters that have to be finetuned with
observation, trial and error and criteria. So basically, you have to play around with it since
every place is different and there is no one solution that fits all cases.
If you are not interested in water bodies (accumulation) and want to get a drainage network
that goes all the way out of your DEM, then you run a Fill tool to get rid of imperfections (pits
39
and holes). You can run the r.fill.dir or any other that could generate depressionless Raster.
Please name it “DEM_Khatlon_Depless”.
The next tool will be r.watershed. Use as Elevation the DEM_Khatlon_Depless (1), set the
Minimum size of exterior watershed basin to 1000 (2). If you have memory available put some
to work 😊 (3) to speed up the process. Click the Enable Single Flow direction (4) to get
smoother results.
This tool will produce a lot of results, so explore and play with the colors to understand it:
40
If you decide you like the Basin delineation you see in the Raster “Unique label for each
watershed basin”, or that it has potential to be adapted you can convert it to Vector to
manage it better. We are interested in a basin that goes to the town of Buston, located south
of Muminabad, in the west of the Khatlon province.
Use the r.to.vect tool to transform that raster into a Polygon layer:
Then is easier to look in the resulting polygons and select the basins of interest (1), you can
then Export (2) and Save a new layer ( clicking the Option (3) Save only selected features) that
only contains polygons of the desired watersheds (4). Please Name it as “Buston_basin”
41
Now if you want to merge all these polygons into one you can simply use the Dissolve Tool:
Once you have performed the r.watershed tool you can also use the r.water.outlet tool. This
requires that on of the output raster layer called Drainage direction (1) and that you specify
the coordinates that you want to use for closing the Basin (2). It is recommended to choose
one point that falls on a river, you can use Stream segments or Number of cells that drain
through each cell to help you choose.
42
6.10 Do it yourself!
Now it is time to make a nice printed map with the DEM and/or the Slope. Here are
some of the results from the participants:
43
6. XYZ TILES
Wouldn’t it be cool to have in our projects background maps and images? Like Google Satellite
or Google Maps:
Then XYZ Tiles is your best option. Go to the Browser and Right Click for New Connection (1):
Then you simply need to give it a Name and the URL of the background map (2).
44
Here is a list of URL to load many different ones that you can use, once you press ok it will be
available for you every time you open QGIS.
45
7. DOWNLOADING OPEN STREET MAP DATA
You can only download small section but there are many sites that will provide an access to
the OSM data.
GEOFABRIK
This site stores data at Continental level and Country level. Data can be downloaded in pbf
and shp formats, both can be opened in QGIS.
Link: https://download.geofabrik.de/
https://download.geofabrik.de/asia.html
OSMaxx
You can select whole countries or personal regions. You can also choose different output
formats, like:
OVERPASS
This site let’s you use an API to place queries and make personalized filter. You can either use
the Wizard or write your own Query.
The Link is: https://overpass-turbo.eu/
46
Paste the example scripts in the window and change the name of the country and admin_level
is required, then click on RUN (1) and when the windows appear (2) choose Continue anyway.
Once you see the result on the map, clik Export (3) and choose the type of file (4) KML is
usually the smallest file size and GeoJSON is the other option that open directly in QGIS with
Drag and Drop.
1) Administrative limits by country. Change ‘name:en’ with you country name. Change
admin_level: 4-provinces, 6-Districs
/*
Get boundary of admin levels by country
*/
[out:json][timeout:25];
// gather results
(
area['name:en'='Kyrgyzstan'][admin_level=2][boundary=administrative]->.myarea;
47
rel(area.myarea)[admin_level=4][boundary=administrative];
);
// print results
out body;
>;
out skel qt;
2) Get all the roads in a country. Change ‘name:en’ with you country name.
[out:json][timeout:25];
// gather results
(
area['name:en'='Tajikistan'][admin_level=2][boundary=administrative]->.myarea;
way(area.myarea) ["highway"];
);
// print results
out body;
>;
out skel qt;
3) Get only some types of roads in a country. Change ‘name:en’ with you country name. Add or
remove types in RED.
[out:json][timeout:25];
// gather results
(
area['name:en'='Tajikistan'][admin_level=2][boundary=administrative]->.myarea;
way(area.myarea) ["highway"~"^(motorway|trunk|primary|secondary)$"];
);
out body;
>;
out skel qt;
3) Get Places for a country. Change ‘name:en’ with you country name.
[out:json][timeout:25];
(
area['name:en'='Tajikistan'][admin_level=2][boundary=administrative]->.myarea;
node(area.myarea) ["place"];
);
out body;
>;
out skel qt;
48
8. ADDITIONAL TRAINING MATERIAL BASED ON QUESTIONS
This material was prepared based on the questions from participants:
Also would be better to get list of latitude and longitudes of these borders
And to calculate the coordinates of each point you can use the tool
49
This will produce another Point Shapefile with additional columns for X and Y at the
end. You can also choose the coordinate system for these columns, I normally use
WGS84 for this one.
If you want you can add this information back into your polygon by making Joins:
Here you just go back to the polygon layer and in Properties -> Joins (1) you can click
the + (2) to add new information. Simply choose the Layer and the Fields for matching
(3) then select what Fields you want to add to your polygon attributes (4) and the
Prefix if you like.
Note: this Join is not changing your original Shp database, it only happens for this
project. If you want to make it permanent you need to Export to a new Shp Layer.
Alternative: Also, you can add directly a new field to your original Layer by going to the
attribute table and using the Field Calculator… see next page:
50
In the Context Menu, Open the attribute table and choose the Field Calculator (1),
then you can decide Name and type of Data (2) and write the formula (3) in this case:
x(centroid($geometry)) Meaning for every geometry take the centroid and get the
x
51