2017/05/21 05:13
1/3
Importing and formatting soil data in R
Importing and formatting soil data in R
Edited by: T. Hengl, D. Beaudette and G.B.M. Heuvelink
Part of: ISRIC Spring School
This tutorial reviews soil data classes and functions for R: how to organize and reformat soil data in R
for spatial analysis, how to import soil data to R, how to export data and plot it in Google Earth. To
learn more about the Global Soil Information Facilities (GSIF), visit the main project page. Some of the
functions listed below are described in detail within the GSIF package for R.
Download this tutorial as R script.
Video
Converting texture-by-hand classes to fractions
In the following example we look at how to convert texture-by-hand estimated classes to texture
fractions i.e. sand, silt and clay content in %. We focus on the USDA texture-by-hand classes. There
classes are embedded in the soiltexture package kindly contributed by Julien Moeys. The USDA
texture triangle can be accessed by:
> library(soiltexture)
Loading required package: sp
Loading required package: MASS
'soiltexture' loaded.
> TT.plot(class.sys = "USDA.TT")
GSIF (tutorials) - http://gsif.isric.org/
Last update: 2017/02/23 14:50
wiki:soil_data
http://gsif.isric.org/doku.php/wiki:soil_data
Soil texture triangle based on the USDA system. Generated using the soiltexture package in R.
We can also print out a table with all class names and vertices numbers that defines each class:
> TT.classes.tbl(class.sys="USDA.TT", collapse=", ")
[1,]
[2,]
[3,]
[4,]
[5,]
[6,]
[7,]
[8,]
[9,]
[10,]
[11,]
[12,]
[1,]
[2,]
[3,]
[4,]
[5,]
[6,]
[7,]
[8,]
[9,]
[10,]
[11,]
[12,]
abbr
name
"Cl"
"clay"
"SiCl"
"silty clay"
"SaCl"
"sandy clay"
"ClLo"
"clay loam"
"SiClLo" "silty clay loam"
"SaClLo" "sandy clay loam"
"Lo"
"loam"
"SiLo"
"silty loam"
"SaLo"
"sandy loam"
"Si"
"silt"
"LoSa"
"loamy sand"
"Sa"
"sand"
points
"24, 1, 5, 6, 2"
"2, 6, 7"
"1, 3, 4, 5"
"5, 4, 10, 11, 12, 6"
"6, 12, 13, 7"
"3, 8, 9, 10, 4"
"10, 9, 16, 17, 11"
"11, 17, 22, 23, 18, 19, 13, 12"
"8, 14, 21, 22, 17, 16, 9"
"18, 23, 26, 19"
"14, 15, 20, 21"
"15, 25, 20"
So knowing that the soil texture classes are defined geometrically, a logical estimate of the texture
http://gsif.isric.org/
Printed on 2017/05/21 05:13
2017/05/21 05:13
3/3
Importing and formatting soil data in R
fractions from a class is to take the geometric centre of each polygon in the texture triangle. To
estimate where the geometric centre is, we can for example use the functionality in the sp package.
We start by creating a SpatialPolygons object, for which we have to calculate coordinates in the
xy space and bind polygons one by one:
> vert <- TT.vertices.tbl(class.sys = "USDA.TT")
> vert$x <- 1-vert$SAND+(vert$SAND-(1-vert$SILT))*0.5
> vert$y <- vert$CLAY*sin(pi/3)
> USDA.TT <- data.frame(TT.classes.tbl(class.sys = "USDA.TT", collapse = ",
"))
> TT.pnt <- as.list(rep(NA, length(USDA.TT$name)))
> poly.lst <- as.list(rep(NA, length(USDA.TT$name)))
> for(i in 1:length(USDA.TT$name)){
+
## strip the vertices numbers:
+
TT.pnt[[i]] <- as.integer(strsplit(unclass(paste(USDA.TT[i, "points"])),
", ")[[1]])
+
## create a list of polygons:
+
poly.lst[[i]] <- vert[TT.pnt[[i]],c("x","y")]
+
## add extra point:
+
poly.lst[[i]] <- Polygons(list(Polygon(rbind(poly.lst[[i]],
poly.lst[[i]][1,]))), ID=i)
+ }
> ## convert texture triangle to a spatial object:
> poly.sp <- SpatialPolygons(poly.lst, proj4string=CRS(as.character(NA)))
> poly.USDA.TT <- SpatialPolygonsDataFrame(poly.sp,
data.frame(ID=USDA.TT$name), match.ID=FALSE)
The resulting object now contains also slots of type labpt which is exactly the geometric gravity
point of the first polygon automatically derived by the SpatialPolygons function.
>
GSIF (tutorials) - http://gsif.isric.org/
© Copyright 2025 Paperzz