Generating a Locations File in QGIS

You are here:
< All Topics
image_pdfDownload as PDF

aWhere Training Tutorial

Introduction

One of the greatest benefits to aWhere’s 9km contiguous grid is that ability to look at weather trends at the farm level through to a continent level. This tutorial will show you how to collect a set of coordinates locations (latitude/longitude) to dig deeper into weather anomalies in your area of interest. With aWhere’s weather data files you can investigate trends such as drier or wetter than normal conditions, hotter or colder temperatures, and current conditions that might impact crop production and food security.

Identifying Anomalies in Your Area of Interest

If your location set will be focused on weather anomalies, you need to understand the context of the country to ensure you understand how the weather might impact current activities on hte ground. To get you going, we have a set of questions that you should ask yourself wen investigating areas that are drier or wetter than normal.

  1. Is it the dry or rainy season in this country/region? Very dry conditions would be alright during the dry season!
  2. How long has it been dry?
  3. Which crops might be impacted in these areas? (refer to crop production maps)
  4. Which other activities could be impacted by out of normal weather?
    i.e. wildlife, watershed management/water availability
  5. Hydrologic drought (impacting water table) vs. agricultural drought (drought stress in the current crop). Agricultural drought can start to occur within two weeks without precipitation. A hydrological drought occurs over several months of low rainfall that is not sufficient to recharge aquifers. 
  6. Interpreting Precipitation /Potential Evapotranspiration
Interpreting P/PETPrecipitation divided by Potential Evapotranspiration (P/PET), is an excellent indicator of water availability to support crop production. 
Precipitation / Potential Evapotranspiration (P/PET) ThresholdsImpact on Crops
<0.45Forage begins to fail – rainfed agriculture is not viable and forest ecosystems are stressed and collapse at this low level of precipitation.
0.6-0.8Pearl millet is one of the most drought tolerant cereal crops and is common in dryland agriculture of West Africa and South Asia
0.8Maize shows symptoms of drought stress and it this low P/PET persists for several weeks the crop will fail. Sorghum is more tolerant and better suited for P/PET values around 0.8. 

Before starting this tutorial please make sure you have gone through the steps in the Tutorial: Using aWhere Data with QGIS.

Tip: If you already have a set of locations/farms/etc (and their corresponding latitude and longitudes), you can skip to step 7 below to ensure your file is correctly formatted for use in R.

Using QGIS to Create a Locations File

Import aWhere data and load style

The aWhere weather data that we want to load is in a comma-separated value (.csv) format and should be saved in your BaseData folder if you are following the suggested folder structure seen here.

On the menu at the top of the screen, go to Layer > Add Layer > Add Delimited Text layer.

The Data Source Manager screen will appear. Next to the File Name field, click on the three dots ( ) and navigate to your weather data file with a .csv extension in your BaseData folder. 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. 

Now that your data is loaded, please follow the steps in Tutorial: Using aWhere Data with QGIS to load an appropriate style to your map. For this example, we will look at the precipitation/potential evapotranspiration (P/PET) trends in Zambia. Follow the steps below to generate a locations file.

Generating a Locations File in QGIS

For this map, we will use a map of Precipitation / potential evapotranspiration difference from the long-term normal to identify areas that are drier than normal. 

Tip: Don’t forget to verify if your area of interest is currently in the rainy season or not! If your area of interest is not currently in the rainy season, you could look at temperature anomalies

1. Once your map is loaded and you have a layer that shows the P/PET difference from the long-term normal, you are ready to start selecting individual grid cells to export into a csv file which can be looked at more closely at the historical trends using R.

The map below of P/PET difference from the long-term normal for Zambia (Jan 18-Feb 19, 2020), shows that parts of the western, central, and eastern provinces are experiencing drier than normal conditions during what is normally the rainy season. From the legend below the layer title (red box), anything that has a negative value and is colored from yellow-red shows the grid cells where it is drier than normal. These are the areas we will start selecting to create our locations file.

2. Before using the Select Features tool, let’s zoom into our area of interest using the magnifying glass button across the top toolbar. The “plus sign” will zoom in, the “minus sign” will zoom out. Once you are zoomed into the area you would like to investigate you can start selecting grid cells.

Use the Pan tool (hand) to pan across the map.

Tip: If you ever lose the view of your map (sometimes we zoom in or out too far, you can right click on your layer and select Zoom to Layer. This will bring your layer back into view in the map console

3. Using the Select Features tool located across the top toolbar, we will export a sample of 5 locations as a csv file to be used in R.

4. Once this tool is selected you will be able to start selecting grid cells. Remember that aWhere’s grid is a 9km x 9km resolution. In order to start selecting grids simply zoom in and click on the grid cell – if properly selected it will turn yellow. To select multiple grid cells at once be sure to push the Control or Command key (depending on your device’s settings) on your keyboard while you pan and select multiple cells.

The five cells that were selected in this example range from dark red to light green. You could select only features in a specific region if that is your focus or they can be from anywhere within your area of interest.

The screenshot below shows a “zoomed out” view of the map with the 5 grid cells selected, shown in yellow.

5. Now that you have identified the grid cells you would like to use as your locations when we move to R, you need to save them as a CSV file.

Select your layer, right click on the layer, select Export, then Save Selected Features As
Another window will popup that looks like the screenshot below.

First, click the grey button at the end of the File Name line and save your file in your RunSet folder.

Next, make sure the box Save only selected features is checked.

Geometry type should be Automatic – if not, use the dropdown menu to set this.

Under the Layer Options, the GEOMETRY can be AS_WKT if you would like to be able to map the original grid cells. If not, you can select Default in the dropdown menu. Add the saved file to map option will add these features back into the map as a layer.

You can see here that the selected grid cells were successfully added back into the map as a new layer called “TestLocationsZambia” (also seen in dark red) Now, we need to cleanup the CSV file to get it ready to leverage using R.

6. Open the CSV file that is saved in your RunSet folder (if you are using the suggested folder structure). This file was called TestLocationsZambia.csv and was saved directly to the RunSet folder when we exported it from QGIS

When you open the csv file it should look something like this – this file has 5 row, each corresponding to a specific location:

You will notice that all of the weather information is saved in this file, BUT we will actually erase most of these columns to format this file to be used in R.

7. The next step is to clean this data file so that it can be leveraged in the next set of tutorials. Every aWhere training R script requires the “locations file” to be saved as either a Text file (.txt) or a CSV file (.csv) and only requires three columns (all lowercase):

place_namelatitudelongitude

This means that in the current locations file, we need to erase columns A and E through S. Column B is the locationID of the aWhere virtual weather station at the centroid of the grid cell and needs to be renamed place_name. Note: if you know the nearest city, town, village, etc. you can use that as the place_name. For these purposes, these locations were chosen somewhat randomly but if you are able to find the nearest populated area to the coordinates in your file it could improve the narrative of your data.

Here is what the cleaned dataset should look like – only 3 rows of data. Make sure you save your new file.
Important: the title for each column needs to be exactly as shown below to operate correctly in R.

Great work. You are now ready for the next tutorial!

What’s next?

Review the next tutorial in the series to start leveraging R to make interesting charts, graphs and more using your new locations file with the Tutorial: Getting Started with aWhere’s R Scripts.

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

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