Book Image

Hands-On Geospatial Analysis with R and QGIS

By : Shammunul Islam, Brad Hamson
Book Image

Hands-On Geospatial Analysis with R and QGIS

By: Shammunul Islam, Brad Hamson

Overview of this book

Managing spatial data has always been challenging and it's getting more complex as the size of data increases. Spatial data is actually big data and you need different tools and techniques to work your way around to model and create different workflows. R and QGIS have powerful features that can make this job easier. This book is your companion for applying machine learning algorithms on GIS and remote sensing data. You’ll start by gaining an understanding of the nature of spatial data and installing R and QGIS. Then, you’ll learn how to use different R packages to import, export, and visualize data, before doing the same in QGIS. Screenshots are included to ease your understanding. Moving on, you’ll learn about different aspects of managing and analyzing spatial data, before diving into advanced topics. You’ll create powerful data visualizations using ggplot2, ggmap, raster, and other packages of R. You’ll learn how to use QGIS 3.2.2 to visualize and manage (create, edit, and format) spatial data. Different types of spatial analysis are also covered using R. Finally, you’ll work with landslide data from Bangladesh to create a landslide susceptibility map using different machine learning algorithms. By reading this book, you’ll transition from being a beginner to an intermediate user of GIS and remote sensing data in no time.
Table of Contents (12 chapters)
GRASS, Graphical Modelers, and Web Mapping

Getting to know the QGIS environment

The QGIS desktop is used to display, analyze, and to do different design formatting with data. The QGIS desktop has four main components: a Menu bar, Tool Bars, Panels, and Map Display. The Menu bar is the top section and appears as follows:

Just under this, we have Tool Bars, which look like this:

We then have the Panels section on the left side, which is composed of these parts: Browser and Layers. The Browser gives us different options for data connection and working with layers. Layers shows all the vector and raster files that we can load to QGIS:

We also have Map Display, which shows us the map outputs:

In the Map Display section, as shown in the preceding screenshot, we see some of the projects the author has been working on; in your case, if you are starting afresh, this section will be blank at first.

Using QGIS, we can complete many geospatial data management and spatial data analysis tasks. The following is a screenshot of some of the useful sections of QGIS:

We can add different spatial data such as vector layers, raster layers, and also database layers using the different functionalities provided in QGIS: Layer | Add Layer | ...:

We will now add a vector file (shapefile) in QGIS to illustrate how it is being done in this GIS software. Suppose we want to add the file BGD_adm3.shp to our QGIS environment; we can do this by following these steps:

  1. Click on Add Vector Layer… under Add Layer, which is under Layer:

  1. We click on the indicated rectangular shape to browse to the folder where the shapefile we want to add is located (in the Data folder under Chapter 1):
  1. Now we browse to BGD_adm3.shp under the Data folder of Chapter 1, select it, and then press Close:

  1. Now click Add and then click Close. Now, we will see a map of the districts of Bangladesh in the Map Display as follows:

Now we will look at one more important aspect of vector data: its attribute table. An attribute table contains information about the shape of points, lines, and polygon features, or mainly the geometry of features, in addition to any other information associated with those features. This information is recorded in a tabular form, where each row represents a record and each column corresponds to field or a feature. We can access this table by right-clicking on the BGD_adm3 layer in the Layers panel of QGIS and then by left-clicking on Open Attribute Table:

Now we will see the attribute table associated with this shapefile:

Similar to adding a vector layer, we can add a raster layer (or layers) and other database layer(s) to the QGIS environment, which we will look at more in-depth as we proceed further in this book.

QGIS has a number of plugins that are add-ons that increase the functionality of QGIS. We can click on Plugin in the Menu Bar and then click on Manage and Install Plugins to install new plugins, as shown in this screenshot:

Now we will see a list of available plugins. Select the plugin you want to install, and then click on Install plugin. When the installation is finished, click Close:

In the next chapter, we will look at the basics of GIS and remote sensing (RS) and we will explore further how R and QGIS handle them and how we can use these two software for basic geospatial data loading and visualization.