SlideShare a Scribd company logo
FAO- Global Soil
Partnership
Training on
Digital Soil Organic Carbon
Mapping
20-24 January 2018
Tehran/Iran
Yusuf YIGINI, PhD - FAO, Land and Water Division (CBL)
Guillermo Federico Olmedo, PhD - FAO, Land and Water Division (CBL)
DATA PREPARATION
COVARIATES
COVARIATES
The example covariates from this chapter were
prepared by ISRIC (ISRIC, 2017).
COVARIATES
The example covariates from this chapter were prepared by
ISRIC (ISRIC, 2017).
#For handling raster data, we load raster package
library(raster)
#load DEM from tif file
DEM <- raster("covs/DEMENV5.tif")
plot(DEM)
The example covariates from this chapter were prepared by
ISRIC (ISRIC, 2017).
DEM
#For handling raster data, we load raster package
library(raster)
#load DEM from tif file
DEM <- raster("covs/DEMENV5.tif")
plot(DEM)
The example covariates from this chapter were prepared by
ISRIC (ISRIC, 2017).
Soil Maps
Soil maps play a crucial role for upscaling soil property data from point
locations. They can be the spatial layer for conventional upscaling, they
can also serve as a covariate in digital soil mapping.
Predicted soil property maps have lower quality in areas where the
covariates such as relief, geology and climate so not correlate well with
the dependent variable, here soil carbon stocks. This is especially true
for soils groundwater or stagnic water influence. This information is
well-represented in soil maps.
FAO, IIASA, ISRIC, ISS CAS and JRC produced a gridded 1 km soil
class map (HWSD).
Soil Maps
# load the soil map from a shapefile file
soilmap <- shapefile("MK_soilmap_simple.shp")
# plot the DEM together with the soil types
plot(DEM)
lines(soilmap)
Digitized small-scale national soil maps are the most important
spatial layer for soil property mapping. The higher its resolution,
the better soil maps contribute to high quality soil property maps -
considering that the map should cover the target area/full country
coverage.
DEM
#For handling raster data, we load raster package
library(raster)
#load DEM from tif file
DEM <- raster("covs/DEMENV5.tif")
plot(DEM)
The example covariates from this chapter were prepared by
ISRIC (ISRIC, 2017).
DEM
# the "Symbol" attribute from the vector layer will be used for the
# rasterization process. It has to be a factor
soilmap@data$Symbol <- as.factor(soilmap@data$Symbol)
#save the levels names in a character vector
Symbol.levels <- levels(soilmap$Symbol)
# The rasterization process needs a layer with the target grd
# system: spatial extent and cell size.
soilmap.r <- rasterize(x = soilmap, y = DEM, field = "Symbol")
# The DEM raster layer could be used for this.
plot(soilmap.r, col=rainbow(21))
legend("bottomright",legend = Symbol.levels, fill=rainbow(21),
cex=0.5)
Technical Steps - Rasterizing a vector layer in R
DEM
# the "Symbol" attribute from the vector layer will be used for the
# rasterization process. It has to be a factor
soilmap@data$Symbol <- as.factor(soilmap@data$Symbol)
#save the levels names in a character vector
Symbol.levels <- levels(soilmap$Symbol)
# The rasterization process needs a layer with the target grd
# system: spatial extent and cell size.
soilmap.r <- rasterize(x = soilmap, y = DEM, field = "Symbol")
# The DEM raster layer could be used for this.
plot(soilmap.r, col=rainbow(21))
legend("bottomright",legend = Symbol.levels, fill=rainbow(21),
cex=0.5)
Technical Steps - Rasterizing a vector layer in R
LAND COVER
landcover <- raster("covs/LCEE10.tif")
# Land cover is a categorical covariate, this has to be made
# explicit using function as.factor()
landcover <- as.factor(landcover)
landcover
## class : RasterLayer
## dimensions : 182, 310, 56420 (nrow, ncol, ncell)
## resolution : 0.008327968, 0.008353187 (x, y)
## extent : 20.45242, 23.03409, 40.8542, 42.37448 (xmin, xmax,
ymin, ymax)
## coord. ref. : +proj=longlat +datum=WGS84 +no_defs +ellps=WGS84
+towgs84=0,0,0
plot(landcover)
LAND COVER
landcover <- raster("covs/LCEE10.tif")
# Land cover is a categorical covariate, this has to be made
# explicit using function as.factor()
landcover <- as.factor(landcover)
landcover
## class : RasterLayer
## dimensions : 182, 310, 56420 (nrow, ncol, ncell)
## resolution : 0.008327968, 0.008353187 (x, y)
## extent : 20.45242, 23.03409, 40.8542, 42.37448 (xmin, xmax,
ymin, ymax)
## coord. ref. : +proj=longlat +datum=WGS84 +no_defs +ellps=WGS84
+towgs84=0,0,0
plot(landcover)
CLIMATE
WorldClim Climate Data are available at: www.worldclim.org
(WorldClim 1.4 (current conditions) by www.worldclim.org;
Hijmans et al., 2005. Int. J. of Clim. 25: 1965-1978. Is licensed
under a Creative Commons Attribution-ShareAlike 4.0
International License).
CLIMATE
# load the climate covariates from the raster tif files
files <- list.files(path = "covs/", pattern = "CHE3.tif",
full.names = TRUE)
# stack all the files in one RasterStack
climate <- stack(files)
# plot the first 2 layers
plot(climate[[1:2]])
CLIMATE
# load the climate covariates from the raster tif files
files <- list.files(path = "covs/", pattern = "CHE3.tif",
full.names = TRUE)
# stack all the files in one RasterStack
climate <- stack(files)
# plot the first 2 layers
plot(climate[[1:2]])
OVERLAYING SOIL DATA AND COVARIATES
# Load the processed data. This table was prepared in the previous
# chapter.
dat <- read.csv("dataproc.csv")
files <- list.files(path = "covs", pattern = "tif$",
full.names = TRUE)
covs <- stack(files)
OVERLAYING SOIL DATA AND COVARIATES
covs <- stack(covs, soilmap.r)
# correct the name for layer 14
names(covs)[14] <- "soilmap"
#mask the covariates with the country mask from the data repository
mask <- raster("data/mask.tif")
covs <- mask(x = covs, mask = mask)
plot(covs)
OVERLAYING SOIL DATA AND COVARIATES
covs <- stack(covs, soilmap.r)
# correct the name for layer 14
names(covs)[14] <- "soilmap"
#mask the covariates with the country mask from the data repository
mask <- raster("data/mask.tif")
covs <- mask(x = covs, mask = mask)
plot(covs)
OVERLAYING SOIL DATA AND COVARIATES
#upgrade points data frame to SpatialPointsDataFrame
coordinates(dat) <- ~ X + Y
# extract values from covariates to the soil points
dat <- extract(x = covs, y = dat, sp = TRUE)
# LCEE10 and soilmap are categorical variables
dat@data$LCEE10 <- as.factor(dat@data$LCEE10)
dat@data$soilmap <- as.factor(dat@data$soilmap)
#levels(soilmap) <- Symbol.levels
summary(dat@data)
OVERLAYING SOIL DATA AND COVARIATES
dat <- as.data.frame(dat)
# The points with NA values has to be removed
dat <- dat[complete.cases(dat),]
# export as a csv table
write.csv(dat, "data/MKD_RegMatrix.csv", row.names = FALSE)
OVERLAYING SOIL DATA AND COVARIATES
dat <- as.data.frame(dat)
# The points with NA values has to be removed
dat <- dat[complete.cases(dat),]
# export as a csv table
write.csv(dat, "data/MKD_RegMatrix.csv", row.names = FALSE)
NEXT >> Mapping, Modelling

More Related Content

PDF
Data preparation, depth function
 
PDF
R getting spatial
 
PDF
R data-import, data-export
 
PDF
Grouping & Summarizing Data in R
PDF
Dplyr and Plyr
PDF
Move your data (Hans Rosling style) with googleVis + 1 line of R code
PDF
Next Generation Programming in R
PDF
Data manipulation with dplyr
Data preparation, depth function
 
R getting spatial
 
R data-import, data-export
 
Grouping & Summarizing Data in R
Dplyr and Plyr
Move your data (Hans Rosling style) with googleVis + 1 line of R code
Next Generation Programming in R
Data manipulation with dplyr

What's hot (20)

PDF
Data Manipulation Using R (& dplyr)
PDF
5 R Tutorial Data Visualization
PDF
Introduction to data.table in R
PDF
Rsplit apply combine
PDF
3 R Tutorial Data Structure
PDF
Regression kriging
 
PDF
7. Data Import – Data Export
 
PDF
Scaling PostreSQL with Stado
PDF
Fun with click house window functions webinar slides 2021-08-19
PDF
Data warehouse or conventional database: Which is right for you?
PDF
PDF
Cubist
 
PDF
Introduction to spatial data analysis in r
ODP
Geospatial Data in R
PDF
Data Profiling in Apache Calcite
ODP
Scaling PostgreSQL With GridSQL
PPTX
R seminar dplyr package
PPTX
H base introduction & development
PDF
Efficient spatial queries on vanilla databases
Data Manipulation Using R (& dplyr)
5 R Tutorial Data Visualization
Introduction to data.table in R
Rsplit apply combine
3 R Tutorial Data Structure
Regression kriging
 
7. Data Import – Data Export
 
Scaling PostreSQL with Stado
Fun with click house window functions webinar slides 2021-08-19
Data warehouse or conventional database: Which is right for you?
Cubist
 
Introduction to spatial data analysis in r
Geospatial Data in R
Data Profiling in Apache Calcite
Scaling PostgreSQL With GridSQL
R seminar dplyr package
H base introduction & development
Efficient spatial queries on vanilla databases
Ad

Similar to Data preparation covariates (20)

PDF
Support Vector Machines (SVM)
 
PPTX
Transformations and actions a visual guide training
PPT
Floodplain Modeling with LiDAR-Derived Terrain
PPTX
Introduction to R
ODT
ACADILD:: HADOOP LESSON
PDF
Georastutorial
PPT
Spark training-in-bangalore
PPT
R Spatial Analysis using SP
PDF
Hadoop I/O Analysis
PDF
NCCU: Statistics in the Criminal Justice System, R basics and Simulation - Pr...
PPTX
PPTX
2. R-basics, Vectors, Arrays, Matrices, Factors
PDF
Data manipulation on r
PDF
Opensource gis development - part 4
PPTX
Samantha Wang [InfluxData] | Best Practices on How to Transform Your Data Usi...
PDF
Climate data in r with the raster package
PDF
High-Performance Graph Analysis and Modeling
PPTX
Presentation on use of r statistics
PDF
Spark + Clojure for Topic Discovery - Zalando Tech Clojure/Conj Talk
PDF
ClusterAnalysis
Support Vector Machines (SVM)
 
Transformations and actions a visual guide training
Floodplain Modeling with LiDAR-Derived Terrain
Introduction to R
ACADILD:: HADOOP LESSON
Georastutorial
Spark training-in-bangalore
R Spatial Analysis using SP
Hadoop I/O Analysis
NCCU: Statistics in the Criminal Justice System, R basics and Simulation - Pr...
2. R-basics, Vectors, Arrays, Matrices, Factors
Data manipulation on r
Opensource gis development - part 4
Samantha Wang [InfluxData] | Best Practices on How to Transform Your Data Usi...
Climate data in r with the raster package
High-Performance Graph Analysis and Modeling
Presentation on use of r statistics
Spark + Clojure for Topic Discovery - Zalando Tech Clojure/Conj Talk
ClusterAnalysis
Ad

More from FAO (20)

PPTX
Nigeria
 
PPT
Niger
 
PPT
Namibia
 
PPT
Mozambique
 
PPT
Zimbabwe takesure
 
PPT
Zimbabwe
 
PPT
Zambia
 
PPT
Togo
 
PPT
Tanzania
 
PPT
Spal presentation
 
PPT
Rwanda
 
PPT
Nigeria uponi
 
PPTX
The multi-faced role of soil in the NENA regions (part 2)
 
PPTX
The multi-faced role of soil in the NENA regions (part 1)
 
PDF
Agenda of the launch of the soil policy brief at the Land&Water Days
 
PDF
Agenda of the 5th NENA Soil Partnership meeting
 
PPTX
The Voluntary Guidelines for Sustainable Soil Management
 
PPTX
GLOSOLAN - Mission, status and way forward
 
PPTX
Towards a Global Soil Information System (GLOSIS)
 
PPTX
GSP developments of regional interest in 2019
 
Nigeria
 
Niger
 
Namibia
 
Mozambique
 
Zimbabwe takesure
 
Zimbabwe
 
Zambia
 
Togo
 
Tanzania
 
Spal presentation
 
Rwanda
 
Nigeria uponi
 
The multi-faced role of soil in the NENA regions (part 2)
 
The multi-faced role of soil in the NENA regions (part 1)
 
Agenda of the launch of the soil policy brief at the Land&Water Days
 
Agenda of the 5th NENA Soil Partnership meeting
 
The Voluntary Guidelines for Sustainable Soil Management
 
GLOSOLAN - Mission, status and way forward
 
Towards a Global Soil Information System (GLOSIS)
 
GSP developments of regional interest in 2019
 

Recently uploaded (20)

PDF
Practical Manual AGRO-233 Principles and Practices of Natural Farming
PDF
LNK 2025 (2).pdf MWEHEHEHEHEHEHEHEHEHEHE
PDF
Chinmaya Tiranga quiz Grand Finale.pdf
PPTX
A powerpoint presentation on the Revised K-10 Science Shaping Paper
PDF
LDMMIA Reiki Yoga Finals Review Spring Summer
PDF
Hazard Identification & Risk Assessment .pdf
PDF
احياء السادس العلمي - الفصل الثالث (التكاثر) منهج متميزين/كلية بغداد/موهوبين
PDF
Supply Chain Operations Speaking Notes -ICLT Program
PDF
Paper A Mock Exam 9_ Attempt review.pdf.
PDF
OBE - B.A.(HON'S) IN INTERIOR ARCHITECTURE -Ar.MOHIUDDIN.pdf
PPTX
History, Philosophy and sociology of education (1).pptx
PDF
Black Hat USA 2025 - Micro ICS Summit - ICS/OT Threat Landscape
PDF
A GUIDE TO GENETICS FOR UNDERGRADUATE MEDICAL STUDENTS
PDF
Trump Administration's workforce development strategy
PDF
Empowerment Technology for Senior High School Guide
PDF
Indian roads congress 037 - 2012 Flexible pavement
PDF
Complications of Minimal Access Surgery at WLH
PPTX
Lesson notes of climatology university.
PPTX
Final Presentation General Medicine 03-08-2024.pptx
PPTX
Final Presentation General Medicine 03-08-2024.pptx
Practical Manual AGRO-233 Principles and Practices of Natural Farming
LNK 2025 (2).pdf MWEHEHEHEHEHEHEHEHEHEHE
Chinmaya Tiranga quiz Grand Finale.pdf
A powerpoint presentation on the Revised K-10 Science Shaping Paper
LDMMIA Reiki Yoga Finals Review Spring Summer
Hazard Identification & Risk Assessment .pdf
احياء السادس العلمي - الفصل الثالث (التكاثر) منهج متميزين/كلية بغداد/موهوبين
Supply Chain Operations Speaking Notes -ICLT Program
Paper A Mock Exam 9_ Attempt review.pdf.
OBE - B.A.(HON'S) IN INTERIOR ARCHITECTURE -Ar.MOHIUDDIN.pdf
History, Philosophy and sociology of education (1).pptx
Black Hat USA 2025 - Micro ICS Summit - ICS/OT Threat Landscape
A GUIDE TO GENETICS FOR UNDERGRADUATE MEDICAL STUDENTS
Trump Administration's workforce development strategy
Empowerment Technology for Senior High School Guide
Indian roads congress 037 - 2012 Flexible pavement
Complications of Minimal Access Surgery at WLH
Lesson notes of climatology university.
Final Presentation General Medicine 03-08-2024.pptx
Final Presentation General Medicine 03-08-2024.pptx

Data preparation covariates

  • 1. FAO- Global Soil Partnership Training on Digital Soil Organic Carbon Mapping 20-24 January 2018 Tehran/Iran Yusuf YIGINI, PhD - FAO, Land and Water Division (CBL) Guillermo Federico Olmedo, PhD - FAO, Land and Water Division (CBL)
  • 4. COVARIATES The example covariates from this chapter were prepared by ISRIC (ISRIC, 2017).
  • 5. COVARIATES The example covariates from this chapter were prepared by ISRIC (ISRIC, 2017).
  • 6. #For handling raster data, we load raster package library(raster) #load DEM from tif file DEM <- raster("covs/DEMENV5.tif") plot(DEM) The example covariates from this chapter were prepared by ISRIC (ISRIC, 2017).
  • 7. DEM #For handling raster data, we load raster package library(raster) #load DEM from tif file DEM <- raster("covs/DEMENV5.tif") plot(DEM) The example covariates from this chapter were prepared by ISRIC (ISRIC, 2017).
  • 8. Soil Maps Soil maps play a crucial role for upscaling soil property data from point locations. They can be the spatial layer for conventional upscaling, they can also serve as a covariate in digital soil mapping. Predicted soil property maps have lower quality in areas where the covariates such as relief, geology and climate so not correlate well with the dependent variable, here soil carbon stocks. This is especially true for soils groundwater or stagnic water influence. This information is well-represented in soil maps. FAO, IIASA, ISRIC, ISS CAS and JRC produced a gridded 1 km soil class map (HWSD).
  • 9. Soil Maps # load the soil map from a shapefile file soilmap <- shapefile("MK_soilmap_simple.shp") # plot the DEM together with the soil types plot(DEM) lines(soilmap) Digitized small-scale national soil maps are the most important spatial layer for soil property mapping. The higher its resolution, the better soil maps contribute to high quality soil property maps - considering that the map should cover the target area/full country coverage.
  • 10. DEM #For handling raster data, we load raster package library(raster) #load DEM from tif file DEM <- raster("covs/DEMENV5.tif") plot(DEM) The example covariates from this chapter were prepared by ISRIC (ISRIC, 2017).
  • 11. DEM # the "Symbol" attribute from the vector layer will be used for the # rasterization process. It has to be a factor soilmap@data$Symbol <- as.factor(soilmap@data$Symbol) #save the levels names in a character vector Symbol.levels <- levels(soilmap$Symbol) # The rasterization process needs a layer with the target grd # system: spatial extent and cell size. soilmap.r <- rasterize(x = soilmap, y = DEM, field = "Symbol") # The DEM raster layer could be used for this. plot(soilmap.r, col=rainbow(21)) legend("bottomright",legend = Symbol.levels, fill=rainbow(21), cex=0.5) Technical Steps - Rasterizing a vector layer in R
  • 12. DEM # the "Symbol" attribute from the vector layer will be used for the # rasterization process. It has to be a factor soilmap@data$Symbol <- as.factor(soilmap@data$Symbol) #save the levels names in a character vector Symbol.levels <- levels(soilmap$Symbol) # The rasterization process needs a layer with the target grd # system: spatial extent and cell size. soilmap.r <- rasterize(x = soilmap, y = DEM, field = "Symbol") # The DEM raster layer could be used for this. plot(soilmap.r, col=rainbow(21)) legend("bottomright",legend = Symbol.levels, fill=rainbow(21), cex=0.5) Technical Steps - Rasterizing a vector layer in R
  • 13. LAND COVER landcover <- raster("covs/LCEE10.tif") # Land cover is a categorical covariate, this has to be made # explicit using function as.factor() landcover <- as.factor(landcover) landcover ## class : RasterLayer ## dimensions : 182, 310, 56420 (nrow, ncol, ncell) ## resolution : 0.008327968, 0.008353187 (x, y) ## extent : 20.45242, 23.03409, 40.8542, 42.37448 (xmin, xmax, ymin, ymax) ## coord. ref. : +proj=longlat +datum=WGS84 +no_defs +ellps=WGS84 +towgs84=0,0,0 plot(landcover)
  • 14. LAND COVER landcover <- raster("covs/LCEE10.tif") # Land cover is a categorical covariate, this has to be made # explicit using function as.factor() landcover <- as.factor(landcover) landcover ## class : RasterLayer ## dimensions : 182, 310, 56420 (nrow, ncol, ncell) ## resolution : 0.008327968, 0.008353187 (x, y) ## extent : 20.45242, 23.03409, 40.8542, 42.37448 (xmin, xmax, ymin, ymax) ## coord. ref. : +proj=longlat +datum=WGS84 +no_defs +ellps=WGS84 +towgs84=0,0,0 plot(landcover)
  • 15. CLIMATE WorldClim Climate Data are available at: www.worldclim.org (WorldClim 1.4 (current conditions) by www.worldclim.org; Hijmans et al., 2005. Int. J. of Clim. 25: 1965-1978. Is licensed under a Creative Commons Attribution-ShareAlike 4.0 International License).
  • 16. CLIMATE # load the climate covariates from the raster tif files files <- list.files(path = "covs/", pattern = "CHE3.tif", full.names = TRUE) # stack all the files in one RasterStack climate <- stack(files) # plot the first 2 layers plot(climate[[1:2]])
  • 17. CLIMATE # load the climate covariates from the raster tif files files <- list.files(path = "covs/", pattern = "CHE3.tif", full.names = TRUE) # stack all the files in one RasterStack climate <- stack(files) # plot the first 2 layers plot(climate[[1:2]])
  • 18. OVERLAYING SOIL DATA AND COVARIATES # Load the processed data. This table was prepared in the previous # chapter. dat <- read.csv("dataproc.csv") files <- list.files(path = "covs", pattern = "tif$", full.names = TRUE) covs <- stack(files)
  • 19. OVERLAYING SOIL DATA AND COVARIATES covs <- stack(covs, soilmap.r) # correct the name for layer 14 names(covs)[14] <- "soilmap" #mask the covariates with the country mask from the data repository mask <- raster("data/mask.tif") covs <- mask(x = covs, mask = mask) plot(covs)
  • 20. OVERLAYING SOIL DATA AND COVARIATES covs <- stack(covs, soilmap.r) # correct the name for layer 14 names(covs)[14] <- "soilmap" #mask the covariates with the country mask from the data repository mask <- raster("data/mask.tif") covs <- mask(x = covs, mask = mask) plot(covs)
  • 21. OVERLAYING SOIL DATA AND COVARIATES #upgrade points data frame to SpatialPointsDataFrame coordinates(dat) <- ~ X + Y # extract values from covariates to the soil points dat <- extract(x = covs, y = dat, sp = TRUE) # LCEE10 and soilmap are categorical variables dat@data$LCEE10 <- as.factor(dat@data$LCEE10) dat@data$soilmap <- as.factor(dat@data$soilmap) #levels(soilmap) <- Symbol.levels summary(dat@data)
  • 22. OVERLAYING SOIL DATA AND COVARIATES dat <- as.data.frame(dat) # The points with NA values has to be removed dat <- dat[complete.cases(dat),] # export as a csv table write.csv(dat, "data/MKD_RegMatrix.csv", row.names = FALSE)
  • 23. OVERLAYING SOIL DATA AND COVARIATES dat <- as.data.frame(dat) # The points with NA values has to be removed dat <- dat[complete.cases(dat),] # export as a csv table write.csv(dat, "data/MKD_RegMatrix.csv", row.names = FALSE)
  • 24. NEXT >> Mapping, Modelling