provided by: UNU-EHS
First, Part C is a guide to download the required data for this next part of the Recommended Practice. Second, this part prepares the data (e.g. resizing to Eastern Cape boundaries) to be compatible for the analysis.
NOTE
Please create a folder called Data in whose subfolders you can store all the data needed for this practice.
Map Value | Hazard class |
---|---|
0 | Not affected (H0) |
1 | Damaged (H1) |
2 | Destroyed (H2) |
Download the R script for this part at the beginning of this page under Part C.
NOTE
- To write lines in R as comments use “#” before starting the sentence.
- Do not use backslashes (’') to enter data paths but “/”.
- Folder names should not have empty spaces because R cannot read them.
library(raster)
## Loading required package: sp
library(rgdal)
## rgdal: version: 1.2-18, (SVN revision 718)
## Geospatial Data Abstraction Library extensions to R successfully loaded
## Loaded GDAL runtime: GDAL 2.2.3, released 2017/11/20
## Path to GDAL shared files: C:/Users/Karen/Documents/R/win-library/3.3/rgdal/gdal
## GDAL binary built with GEOS: TRUE
## Loaded PROJ.4 runtime: Rel. 4.9.3, 15 August 2016, [PJ_VERSION: 493]
## Path to PROJ.4 shared files: C:/Users/Karen/Documents/R/win-library/3.3/rgdal/proj
## Linking to sp version: 1.2-7
setwd("X:/YOUR/PATH/Data")
dir.create("outputs")
memory.limit(50000)
Administrative boundaries and the LC map are only available on national level. Thus, the LC map and the local municipality boundaries are clipped to the size of Eastern Cape (EC).
SA_lm<-readOGR("./adm/lm/Local_Municipalities_2016.shp")
## OGR data source with driver: ESRI Shapefile
## Source: "D:\UN-SPIDER\WP2\UNU-EHS\Data\adm\lm\Local_Municipalities_2016.shp", layer: "Local_Municipalities_2016"
## with 213 features
## It has 13 fields
## Integer64 fields read as strings: OBJECTID
lm<-subset(SA_lm, PROVINCE=="EC")
writeOGR(lm,"./outputs/lm2016.shp", "lm", driver = "ESRI Shapefile")
head(SA_lm)
EC<-readOGR("./adm/pl/EC.shp")
SA_LC2014<-raster("./LC2014/sa_lcov_2013-14_gti_geo_wgs84_vs22b.tif") # add LC map of the whole SA
LC2014c<-crop(SA_LC2014,EC) # crop the raster with the EC shapefile
LC2014<-mask(LC2014c, EC)
writeRaster(LC2014,"./outputs/LC2014_EC.tif")
As the hazard map (250m) and the landcover map (30m) have different resolutions, the hazard map needs to be resampled to the pixel size of the landcover map. Before doing that, make sure they have the same projection (in this example lat/lon).
H2015_250m<-raster("./H2015_250m/2015_2016_ThreeCl.tif") # add the hazard map which is to be resampled
H2015<-resample(H2015_250m, LC2014,method="ngb") # resample with nearest neighbour method to not loose category values
writeRaster(H2015,"./outputs/2015H_30m.tif")
The land cover map contains several LC classes including artificial, water and forest, which are not relevant for this assessment. In this example, we specifically focus on grassland for livestock and cropland for crop production. Thus, only grass- and cropland areas need to be extracted. The class value for grassland is 7, while class values for cropland are 10-31 (see also legend 72 x class land-cover legend.pdf in Report_Metadata).
a<-c(1:72) # add a vector with all the values of the LC map
#grassland
# grassland =7
b<-c(rep(NA,6),1,rep(NA, 65)) # add a vector in which the 7th positio is 1, th rest NA
recl_grassland<-cbind(a,b)
LC_grassland<-reclassify(LC2014,rcl = recl_grassland)
writeRaster(LC_grassland, "./outputs/LCGrass2014.tif")
#cropland
# all cultivated agricultural land=1, non-agricultural=NA (10-31=1)
c<-c(rep(NA,9), rep(1,22), rep(NA,41))
recl_crop<-cbind(a,c)
LC_crop<-reclassify(LC2014, rcl = recl_crop)
writeRaster(LC_crop, "./outputs/LCCrop2014.tif")
head(recl_grassland, n=10)
## a b
## [1,] 1 NA
## [2,] 2 NA
## [3,] 3 NA
## [4,] 4 NA
## [5,] 5 NA
## [6,] 6 NA
## [7,] 7 1
## [8,] 8 NA
## [9,] 9 NA
## [10,] 10 NA
Part D contains the final computation of outputs. The hazard information is combined with census data in order to estimate the number of affected people by drought. For Step 1 and Step 3 to Step 5 we show the process for grassland. However, in the original script cropland is also included.
In order to analyse the affected grassland (or cropland) in the respective hazard class, the hazard map is overlaid with grassland (or cropland) and the number of hectares of each hazard class per local municipality are estimated.
HgrassC<- crop(H2015,LC_grassland) # crop the hazard map with the grassland layer
Hgrass<-mask(HgrassC,LC_grassland)
writeRaster(Hgrass, "./outputs/H_grass2015.tif", overwrite=TRUE)
v<-extract(Hgrass, lm) #Extract raster values to polygons
v.counts <- lapply(v,table) # Get class counts for each polygon
class.df <- as.data.frame(t(sapply(v.counts,'[',1:length(unique(Hgrass))))) # Create a data.frame where missing classes are NA
lm@data <- data.frame(lm@data, class.df)# Add back to polygon data
write.csv(lm@data, file = "./outputs/H_grass2015.csv")
Hgrass2015<-lm@data
Hgrass2015<-subset(Hgrass2015, select = c(OBJECTID,MUNICNAME,X0, X1, X2))
Hgrass2015$GrassH0area<-Hgrass2015$X0*0.09 # multiply to get ha
Hgrass2015$GrassH1area<-Hgrass2015$X1*0.09
Hgrass2015$GrassH2area<-Hgrass2015$X2*0.09
Hgrass2015$GrassTotalArea<-Hgrass2015$GrassH0area+ Hgrass2015$GrassH1area+Hgrass2015$GrassH2area
Hgrass2015
In order to estimate the number of affected people information on the livestock and crop dependent population per municipality is needed. Thus, census data needs to be reorganized to yield in the relevant information. See table below and save file in StatSA folder as AgrDepPop.csv. Alternatively, the file can also be downloaded here ##LINK###.
Column | Content description | Data source |
---|---|---|
MUNICNAME | Name of the municipality identical to the name of the shapefile (lm.shp). Sort alphabetically. | |
ID | ID EC1 to EC33. Please first sort the MUNICNAME aphabetically and then give IDs | |
agriHH2011 | Number of agricultural households by local municipality | StatSA (2011) |
[X]Prod | Number households in production activity X (Livestock, Poultry, Vegetables, Other crop production, Fodder grazing). | StatSA (2011) |
SumProdHH | Sum of [X] Prod | |
RatioProd&agriHH | Because there are doublecounts in SumProdHH a ratio between SumProdHH and agriHH2011 is calculated [agriHH2011/SumProdHH]. | |
CropDepHH, LSDepHH | Number of households associated with crop and livestock production, respectively summed as follows from [X]Prod: [(VegProd+OtherProd)multiplied with RatioProd&agriHH, and (LivestockProd+FodderGraz) multiplied with RatioProd&agriHH] Poultry and Other is neglected | |
HHSize2016 | Average household size for that municipality in 2016 (HH based distribution). | StatSA (2016) |
CropDepPop, LSDepPop | Crop- and livestock-dependent population per municipality. = CropDepHH, LSDepHH * HHSize2016 |
The information of the livestock (or crop) dependent population needs to be merged with the information of the affected land. Next densities of dependent people are calculated (e.g. livestock dependent population per hectare).
AgrDepPop<-read.csv("./StatSA/AgrDepPop.csv") # add the census data (which has been created in Excel before!)
AgrDepPop
AgrDepPop<-subset(AgrDepPop, select=c(ID, MUNICNAME, LSDepPop, CropDepPop))
GrassDepPop = merge(Hgrass2015,AgrDepPop, by ="MUNICNAME") # merge the two sets by MUNICNAME
GrassDepPop<-subset(GrassDepPop, select= c(MUNICNAME, GrassH0area, GrassH1area,GrassH2area, ID, GrassTotalArea, LSDepPop ))
GrassDepPop$LSPopDens<-GrassDepPop$LSDepPop/GrassDepPop$GrassTotalArea # LS dependent population density
Then the density of livestock or crop dependent population is multiplied with the affected area, which yields in the affected population per hazard class.
GrassDepPop$LSPopH0<-GrassDepPop$LSPopDens*GrassDepPop$GrassH0area # LS Dependent population in H0
GrassDepPop$LSPopH1<-GrassDepPop$LSPopDens*GrassDepPop$GrassH1area # LS Dependent population in H1
GrassDepPop$LSPopH2<-GrassDepPop$LSPopDens*GrassDepPop$GrassH2area # LS Dependent population in H2
GrassDepPop$ShareLSPopH0<-GrassDepPop$LSPopH0/GrassDepPop$LSDepPop # calculate the shares of pop in hazard class/ total population
GrassDepPop$ShareLSPopH1<-GrassDepPop$LSPopH1/GrassDepPop$LSDepPop
GrassDepPop$ShareLSPopH2<-GrassDepPop$LSPopH2/GrassDepPop$LSDepPop
The number of people per hazard class (H0-H2) are then added up to yield in the total affected population dependent on livestock/crops.
GrassDepPop$LSPopAff<-GrassDepPop$LSPopH1+GrassDepPop$LSPopH2 # affected population (H1+H2)
GrassDepPop$ShareLSPopAff<-GrassDepPop$LSPopAff/GrassDepPop$LSDepPop # calculate share of total affected pop (h1+h2)
write.csv(GrassDepPop,"./outputs/affLSPop2015.csv")
GrassDepPop
In the last step the separated information on affected livestock and crop dependent population are merged into a single .csv and also linked back to the local municipality shapefile, so that the information is also spatially available.
affPop2015<-merge(CropDepPop,GrassDepPop, by="MUNICNAME")
affPop2015$affPop<-affPop2015$CropPopAff+affPop2015$LSPopAff
affPop2015$ShareaffPop<-affPop2015$affPop/(affPop2015$CropDepPop+affPop2015$LSDepPop)
write.csv(affPop2015,"./outputs/affPop2015.csv")
affPop2015
lm<-shapefile("./outputs/lm2016.shp")
m<-merge(lm, affPop2015, by="MUNICNAME")
writeOGR(m,"./outputs/affPop2015.shp", "affPop2015", driver = "ESRI Shapefile" )