Map Algebra for Site Selection in R

Introduction

The Department of Planning of the (imaginary) oasis Aïn Kju Dzjis is planning to build the National Institute for Oasis Management (NIOM) in their village. They came up with the following conditions for building the complex:

  1. No industry, mine or landfill within 300 meters of the new complex;
  2. Not on locations presently in use for buildings, water or roads;
  3. The slope should be less than or equal to 3%;
  4. The distance from an existing road should be less than 500 meters;
  5. The area should be contiguous;
  6. The area should be greater than, or equal to 2 hectares.

They hired you as a GIS consultant to find the most appropriate locations. You will use map algebra to perform the required multicriteria analysis.(Van der Kwast, 2018).

Install and load packages as listed below.

Now we load the libraries. For more information on packages use help() (eg., help("raster")).

Loading of Data

  • Functions to be used in this section:
    • raster {raster}
    • tmap {tmap}

To begin, we laod in all tif files(.tif) using the function raster().

Lets check the properties of the RasterLayer Object using print().

cat("buildings\n"); print(buildings) ; cat("isroad\n"); print(isroad); cat("iswater\n"); print(iswater) ;
buildings
class      : RasterLayer 
dimensions : 60, 60, 3600  (nrow, ncol, ncell)
resolution : 50, 50  (x, y)
extent     : 288674.7, 291674.7, 3349810, 3352810  (xmin, xmax, ymin, ymax)
crs        : +proj=utm +zone=30 +datum=WGS84 +units=m +no_defs 
source     : C:/MapAlgebra/building.tif 
names      : building 
values     : 0, 65535  (min, max)
isroad
class      : RasterLayer 
dimensions : 60, 60, 3600  (nrow, ncol, ncell)
resolution : 50, 50  (x, y)
extent     : 288674.7, 291674.7, 3349810, 3352810  (xmin, xmax, ymin, ymax)
crs        : +proj=utm +zone=30 +datum=WGS84 +units=m +no_defs 
source     : C:/MapAlgebra/isroad.tif 
names      : isroad 
values     : 0, 65535  (min, max)
iswater
class      : RasterLayer 
dimensions : 60, 60, 3600  (nrow, ncol, ncell)
resolution : 50, 50  (x, y)
extent     : 288674.7, 291674.7, 3349810, 3352810  (xmin, xmax, ymin, ymax)
crs        : +proj=utm +zone=30 +datum=WGS84 +units=m +no_defs 
source     : C:/MapAlgebra/iswater.tif 
names      : iswater 
values     : 0, 65535  (min, max)
cat("roads\n"); print(roads) ; cat("topo\n"); print(topo)
roads
class      : RasterLayer 
dimensions : 60, 60, 3600  (nrow, ncol, ncell)
resolution : 50, 50  (x, y)
extent     : 288674.7, 291674.7, 3349810, 3352810  (xmin, xmax, ymin, ymax)
crs        : +proj=utm +zone=30 +datum=WGS84 +units=m +no_defs 
source     : C:/MapAlgebra/roads.tif 
names      : roads 
values     : 0, 65535  (min, max)
topo
class      : RasterLayer 
dimensions : 60, 60, 3600  (nrow, ncol, ncell)
resolution : 50, 50  (x, y)
extent     : 288674.7, 291674.7, 3349810, 3352810  (xmin, xmax, ymin, ymax)
crs        : +proj=utm +zone=30 +datum=WGS84 +units=m +no_defs 
source     : C:/MapAlgebra/topo.tif 
names      : topo 

It is very clear all raster layer have the same spatial resolution and same UTM projection.

However, to be sure we can check this in R using the function CompareRaster().

Condition 1

No industry, mine or Landfill within 300 metres of the complex. The raster layer building, is discreete with values;

  • 0 - None
  • 1 - House
  • 2 - Public building
  • 3 - landfill
  • 4 - Industry
  • 5 - Mine

We need to re-classify the raster layer with;

  • 0 - No industry
  • 1 - Industry In R we can do this using the functions calc() or reclassify(). However at this stage we would learn to use the clac() function.

In R, the distance function distance() computes distance from NA cells to non-NA cells. Hence we need to assing NA to all pixels with values of (0) in industry_class.

The IndustryDist layer is UTM projected with (+units = m), hence calculated distance would be in metres.

Now lets plot the industry_dist layer in tmap().Areas close to the industry are shown in red.

Now we enforce the condition of Industry,Mine or Landfill should be 300 metres away from complex.

Condition 3

The slope should be less than or equal to 3 %. In R we can compute the Slope using the terrain() function however this would be done in degrees.

Now lets enforce the criteria of 3(%) percent slope. Note, slope was calculated in degrees.

Percent of slope is determined by dividing the amount of elevation change by the amount of horizontal distance covered, and then multiplied by (100). Knowing the percent slope we can find the slope in degrees using inverse tangent. \(tan^{-1}\) of 3% slope would be approximately 1.72 degrees.

Condition 4

The distance from an existing road should be less than 500 metres. The road raster layer is discrete and has 3 classes with values;

  • 0 - No road
  • 1 - Dirt road
  • 2 - Tarmac road

The reclassify() function would be use to reclassify values into 0(No roads) and 1(Dirt and Tarmac roads).

Lets now compute the distances for the reclassified road Map using the distance() function.

Lets enforce condition 4.The distance from an existing road should be less than 500 metres

Lets combine all the criteria. In R we would multiply all the boolean condition.

Condition 5

The area should be contiguous(share common border). Contiguity forms the concepts of neighbors and how the pixels relate(interact) with other pixels.

At this point, we would recategorize the rasta values base on contiguity.We would only consider Vertical and Horizontal contiguity(Rook case).After clumping using clump() we then convert the raster cells to polygons using the rasterToPolygons() function.

At this stage we would be using the dplyr pipe %>% quite alot.

Selected Locations

Lets now plot a map of final selected areas.

Lets also plot the selected site in mapView() to have a visual statisfaction of real-time location.


Acknowledgement

Sincere gratitude to Dr.Hans van der Kwast the author of the book Qgis and Open Data for Hydrological Applications and His in-depth tutorial on Qgis on his youtube page HansvanderKwast. This resource seeks to simulate what was done in the eBook QGIS and Open Data for Hydrological Applications-Exercise Manual.(Exercise 4: Map Algebra), however using the R programming language. As a student myself, I believe this workflow would endow students with some requisite raster data analysis skills using the R programing language.



References


Lovelace,R.,Nowosad,J.,and Muenchow,J.(2019) GeoComputation with R*.1st edn.

Bocca Raton:Chapman and Hall/CRC.


Van der Kwast, J. (2018) Qgis and Open Data for Hydrlogical Applications-ExerciseManual.

version3.4.1b.ocw.un-ihe.org.


Van der Kwast,J.(2018) 'Data Exercise 4:Spatial planning Using map algebra'.

Available at: https://ocw.un-ihe.org/course/view.php?id=11§ion=2 (Accessed April 2021).