Using aWhere Data with QGIS

You are here:
< All Topics
image_pdfDownload as PDF

aWhere Training Tutorial

Introduction

This tutorial aims to get you started with aWhere data visualization and basic analysis in QGIS, free and open-source geographic information system software that enables viewing, editing, and analysis of geospatial data. It first provides you with a background on the data structure and variables. Next, it shows you how to load data into QGIS and visualize different variables using preset styles. Lastly, it shows you how to clip this weather data for a more specific area of interest for future analysis.

Using QGIS

Install

Download the desktop version of QGIS:

Explore the Interface

Here’s what the main interface looks like (your panels and their configuration may look slightly different):

The QGIS user interface features a series of useful panels:

In the Layers panel, you can see a list, at any time, of all the layers available to you. The checkbox next to each layer is used to show or hide it. The order of layers in this window corresponds to the order in which they are mapped – layers listed first will be mapped on top. Expanding collapsed items (by clicking the arrow or plus symbol beside them) will provide you with more information on the layer’s current appearance. Right-clicking on a layer will give you a menu with lots of extra options. If you do not see the Layers panel, you can enable it by going to View > Panels > Layers.

The Browser panel allows you to navigate folders on your local computer and access GIS datasets such as Google Maps tiles for geospatial context. If you do not see the Browser panel, you can enable it by going to View > Panels > Browser.

The Map Canvas is where the map layers will be displayed.

The Toolbars contain many of the commonly used GIS tools. Hover your cursor over any icon, and its name will appear. See if you can find the following tool icons: starting a New Project, Open an existing project, Save your project, Pan, Zoom In, Zoom Out, Measure Line.

Import aWhere data

aWhere data is available for download on our adaptER Platform. Please click the Geospatial Downloads app to download the data files for a country of interest. Select countries are publicly available, please contact us to learn more about getting the files for different geographies.

The aWhere weather data that we want to load is in a comma-separated value (.csv) format.
On the menu at the top of the screen, go to Layer > Add Layer > Add Delimited Text layer.

The Data Source Manager will appear. Next to the File Name field, click on the three dots ( … ) and navigate to your weather data file with a .csv extension. Click “Open”. 

Make sure CSV is selected as the File format.

Under Geometry definition, make sure the “Well known text (WKT)” is selected .
Geometry type should be “Detect”. The Geometry field will be automatically populated with the name of the column that contains the geometry data, “shapewkt”. Choose “WGS 84” as the Coordinate Reference System.

Click “Add” at the bottom of this window to load the weather data. Click “Close” to close the Data Source Manager window. The layer we just loaded will appear in your Layers panel as well in the Map Canvas with an arbitrary color for all of the grid cells. 

Apply QGIS styles

How to display variables in a relevant and visually appealing way?

Let’s use a QGIS style to visualize weather variables across the mapped region. The style is simply a gradient of colors that map to specific ranges or quantities of each weather variable such as current accumulated precipitation, the difference between current and long-term accumulated precipitation, and average maximum temperature.

Current Accumulated Precipitation

First, we will apply a QGIS style to visualize current accumulated precipitation (mm). 

1. Right-click on the weather file in the Layers panel, then select Properties. (You can also double-click on the imported file to open its properties)

2. In the Layer Properties window, navigate to the “Symbology” tab.

3. Click on the “Style” dropdown menu in the bottom of the window and select “Load Style”.

4. Navigate to the folder where you have QGIS style files (they have the “.qml” extension). One of these is the “Accumulated_Precipitation_20_classes.qml”, which contains 20 accumulated precipitation ranges that each map to a unique color.

This style automatically selects the “CSUMPRE” column and sets each grid cell to its respective color based on which accumulated precipitation range it falls in.

For instance, a grid cell with a low accumulated precipitation value of 15 mm will be colored with orange (10 – 20 mm). A grid cell with a moderate accumulated precipitation value of 75 mm will be colored with green (70 – 80 mm). A grid cell with a high accumulated precipitation value of 350 mm will be colored with bright pink (300 – 400 mm). 

You can extensively personalize the visualization within this Symbology tab, or just click “Apply” to map this preset style onto the CSUMPRE weather data. 

Click “OK” to close the Layer Properties window and take a look at the mapped data. Current accumulated precipitation is now visualized on the map! 

Use the “Map Navigation Toolbar” to explore the data: 

5. Finally, let’s rename our data layer using a descriptive name so we know which weather variable was mapped.
Right-click on the layer name, select Rename, and add “current_precip” onto its name.
Press Enter to save this new name. Now your Layers panel will have the following entry:

Current vs. Long-Term Normal (LTN) Accumulated Precipitation

Let’s apply another preset QGIS style to a second weather variable: DFLTSUM, the Difference between Current Precipitation and the Long-term Normal (mm). 

If we modify the style of our current precipitation data layer, then we will replace the style that we just applied. Since it will be informative to compare both current and LTN precipitation variables, let’s make a copy of the current_precip data layer and apply a new style to the copy. This will allow us to visualize both current precipitation and the difference between current and long-term normal precipitation across the region. 

1. Right click on the original data layer, select “Duplicate”

2. A new layer will appear in the Layer manager. It will have the same name as our current_precip layer with “ copy” appended on the end.

3. This layer copy is currently hidden (its name is gray). Click on the checkbox next to its name to make it visible (now its name will be black).

4. Let’s rename our layer copy with a descriptive name to specify which variable we will be mapping.

Right-click on the layer copy > Rename > replace “current_precip copy” with “dif_current-ltn_precip”. Press Enter to save this new layer name.

Your layers should now be named with “current_precip” and “dif_current-ltn_precip”:

5. Uncheck the current_precip layer, since we want to focus on the “dif_current-ltn_precip” layer right now.

Remember that the first layer listed within the Layers panel will always be mapped on top of the layers listed below it, when the checkmark is present next to its name. If we hide the top layer by un-checking it, the layer(s) below will be visible in the map instead

6. Let’s apply a preset QGIS style to visualize the DFLTSUM variable. 

Right click on the “dif_current-ltn_precip” layer > select Properties.
Navigate to the Symbology tab. Style > Load Style.
Open the “Current-LTN_Precip_15_classes.qml” QGIS style.

This style maps 15 ranges of current-LTN precip differences to unique colors, and automatically selects the “DFLTSUM” Column that contains these values within our weather data. 

Red grid cells have large negative differences between current and LTN precipitation, which means these areas are much drier than usual. Blue grid cells have large positive differences between current and LTN precipitation, which means that these areas are much wetter than usual. White grid cells have small differences (-10 to 10 mm) between current and LTN precipitation, which means that precipitation levels are similar compared to the long-term record.

Click “Apply” and then “OK” to close the Layer Properties. Now our map visualizes DFLTSUM values! 

Average Maximum Temperature

Let’s visualize one more weather variable, Current Average Maximum Temperature (in Celsius). Here is a condensed list of the same steps used to map the previous variable:

1. Right-click on the “dif_current-ltn_precip” layer > Duplicate. A new layer will appear with “copy” on the end of its name.

2. Right clisk on the layer copy > Rename > replace “dif_current-ltn_percip copy” with “maxtemperature” instead. Press Enter to save this layer name.

3. You now have 3 layers named respectively with “current_precip”, “dif_current-ltn_precip”, and “maxtemperature”.

4. Uncheck the name of the “dif_current-ltn_precip” layer to hide it.

5. Click the checkmark next to the name “maxtemperature” layer to make it visible.

6. Right-slick on the “maxtemperature” layer > Properties > Symbology tab > Style > Load name of this QGIS style, it contains 22 different ranges for average maximum temperature that each map to a unique color.
Blue corresponds to low average temperatures (-30 to -5 degrees Celsius).
Red corresponds to high average maximum temperatures (28 to 30 degrees Celsius).

7. Click “Apply” and “OK” to visualize this variable across the region.

Base Map Layers

How to add a Google, Open Street Map, or other base layer for geospatial context?

Add base map layers to QGIS 3

To add a series of map layers to your QGIS 3 installation, open the Python Console and run the code in the “qgis_basemaps.py” script by Klas Karlsson, available here (as well as in the tutorial materials):

To add a single map layer to your QGIS 3 installation: In the Browser panel, right-click on XYZ Tiles > Add Connection.

Provide a name for the map layer that you would like to load and supply the URL that informs QGIS about where to retrieve the imagery. 

For example, to load the “Carto Positron” map layer, enter the following within the XYZ Connection window: 

Name = Carto Positron 
URL = https://cartodb-basemaps-a.global.ssl.fastly.net/light_all/{z}/{x}/{y}.

The “Carto Positron” layer will appear within the XYZ Tiles dropdown menu

Display base map layer

Drag the name of any base map layer within the XYZ Tiles to the Layers Panel. You can also double-click on the base map layer within XYZ Tiles to add it to the Layers panel.
Rearrange your layers so that the base map layer is listed below your other layers in the Layers panel. This ensures that the other layers are mapped on top of the base map layer.

For instance: double click on the “Carto Positron” base map layer to add it to your Layers panel. Make sure the “current_precip” layer is visible and higher than the Carto Positron layer within the Layers list. Your displayed map should show the mapped weather variable with Carto Positron imagery in the background.

Intersect dataset boundaries

How to combine aWhere data with other datasets (e.g.administrative boundaries)?

for the purpose of this exercise, the open-source Global administrative Areas (GADM) dataset is used. The GADM provided administrative boundaries for different levels of subdivision. The full dataset can be accessed through http://gadm.org/ and it was developed from a collaboration between University of California, Berkeley Museum of Vertebrate Zoology (Julian Kapoor and John Wieczorek), the International Rice research Institute (Nel Garcia, Aileen Maunahan, Arnel Rala) and the University of California, Davis (Alex Mandel) and contributions of many others.

For Ethiopia, the GADM data includes four levels of administrative boundaries:

  • Level 0 – National
  • Level 1 – State
  • Level 2 – Zone
  • Level 3 – Woreda

In the “Browser Panel” navigate to the “shapefiles” folder for this tutorial on your computer.

The “gadm36_ETH_shp” subfolder contains the GADM version 3.6 administrative boundary shapefiles for Ethiopia. Drag the “gadm36_ETH_3.shp” file to the Map Canvas window to import the Woreda boundaries into this project.

Perhaps we are interested in the current precipitation within a single woreda, such as Degehabur. From the browser panel, drag the “Woreda_Degehabur.shp” file to the Map Canvas as well.

There are myriad ways you can combine different datasets. One is by selecting the aWhere data that intersects with the woreda area of interest and exporting this subset of data, which can be subsequently analyzed in RStudio.

A useful tool for this operation is the “Select by location” tool, which you can access by navigating to Vector (on the top menu bar) > Research Tools > Select by location

In the “Select by location” wizard: 
“Select features from “ the aWhere dataset (the current_precip layer)
“Where the features” intersect
“By comparing to the features from” the Woreda_Degehabur layer

Click “Run” to select all grid cells, data points or “Virtual Weather Stations” that intersect with the area of the Degehabur woreda. When processing is done, and it will take long for larger regions, a summary wizard will open. Close the wizard.

In Layers Panel, uncheck both shapefile layers and show the current_precip layer. The grid cells that intersect with the woreda of interest will be highlighted. In the image below, they appear bright yellow within the boundary of the Degehabur woreda, which is precisely the intersection that we would expect to see.

In the “Layers Panel”, right-click on the aWhere current_precip layer and click “Save As…”

In the “Save vector layer as…” wizard, specify and output filename of “woreda_degehabur_current_precip”, chose the CSV format, tick the “Save only selected features”, and most importantly, in “Layer Options” > Geometry, chose “AS_WKT”. As mentioned in the data structure session, the Well-known text format allows the .csv file to the geospatially ready-to-use.

In the next wizard hit “Cancel” and right-click on the layer just added and click “Remove”.

Use the “Add Delimited Text Layer” tool you have used when importing an aWhere file into QGIS and use the same procedure as detailed in the start of this tutorial. Load the Accumulated Precipitation style. 

Now you have only the ag-metereological data for the Ethiopian woreda of Degehabur in a .csv format, which can be imported in RStudio and analyzed.

What’s next?

Review the next tutorial in the series to zoom in to locations of interest with the Tutorial: Generating Locations Files in QGIS.

If you have any questions, please contact customersupport@awhere.com 

Was this article helpful?
0 out Of 5 Stars
5 Stars 0%
4 Stars 0%
3 Stars 0%
2 Stars 0%
1 Stars 0%
How can we improve this article?
Table of Contents