Converts an object of class "SoilProfileCollection" or "SpatialPointsDataFrame" to an object of class "geosamples" with all measurements broken into individual records. Geosamples are standardized spatially and temporally referenced samples from the Earth's surface.
URI specifying the metadata registry (web-service that carries all metadata connected to the certain method ID and/or sample ID)
sample.area
standard sample area in square meters (assumed to be 1 by 1 m)
mxd
maximum depth of interest in meters
TimeSpan.begin
vector of class "POSIXct"; begin of the measurement period
TimeSpan.end
vector of class "POSIXct"; end of the measurement period
Value
Returns an object of type "geosamples". Many columns required by the "geosamples" class might be not available and will result in NA values. To ensure compatibility, when building an object of type "SoilProfilesCollection", use some standard naming convention to attach attributes to each measurement (horizons and sites slots in the "SoilProfileCollection-class"):
"locationError"
can be used to attach location errors in meters to each spatial location
"sampleArea"
can be used to attach spatial support to each measurement (usually 1 by 1 meter)
"measurementError"
can be used to attach specific measurement errors to each measurement in both site and horizons table
"IGSN"
can be used to attach the unique identifier (International Geo Sample Number) to each specific observation (corresponds to the "observationid" column)
library(aqp)
library(plyr)
library(rgdal)
library(sp)
# sample profile from Nigeria:
lon = 3.90; lat = 7.50; time = as.POSIXct("1978", format="%Y")
id = "ISRIC:NG0017"; TAXNFAO8 = "LXp"
top = c(0, 18, 36, 65, 87, 127)
bottom = c(18, 36, 65, 87, 127, 181)
ORCDRC = c(18.4, 4.4, 3.6, 3.6, 3.2, 1.2)
methodid = c("TAXNFAO8", "ORCDRC")
description = c("FAO 1988 classification system group",
"Method of Walkley-Black (Org. matter = Org. C x 1.72)")
units = c("FAO 1988 classes", "permille")
detectionLimit = c(as.character(NA), "0.1")
# prepare a SoilProfileCollection:
prof1 <- join(data.frame(id, top, bottom, ORCDRC),
data.frame(id, lon, lat, time, TAXNFAO8), type='inner')
depths(prof1) <- id ~ top + bottom
site(prof1) <- ~ lon + lat + time + TAXNFAO8
coordinates(prof1) <- ~ lon + lat + time
proj4string(prof1) <- CRS("+proj=longlat +datum=WGS84")
# add measurement errors:
attr(prof1@horizons$ORCDRC, "measurementError") <- c(1.5, 0.5, 0.5, 0.5, 0.5, 0.5)
attr(prof1@sp@coords, "locationError") <- 1500
# add the metadata:
prof1@metadata <- data.frame(methodid, description, units, detectionLimit)
# convert to geosamples:
x <- as.geosamples(prof1)
x
# print only the sampled values of ORCDRC:
ORCDRC <- subset(x, "ORCDRC")
ORCDRC[,c("sampleid", "altitude", "observedValue")]
# convert object of type SpatialPointsDataFrame:
data(meuse)
# prepare columns:
names(meuse)[which(names(meuse)=="x")] = "longitude"
names(meuse)[which(names(meuse)=="y")] = "latitude"
meuse$altitude = -.15
meuse$time = unclass(as.POSIXct("1992-01-01"))
coordinates(meuse) <- ~ longitude + latitude + altitude + time
proj4string(meuse) <- CRS("+init=epsg:28992")
library(plotKML)
hm <- reproject(meuse[,c("zinc", "copper")])
hm.geo <- as.geosamples(hm)
hm.geo
Results
R version 3.3.1 (2016-06-21) -- "Bug in Your Hair"
Copyright (C) 2016 The R Foundation for Statistical Computing
Platform: x86_64-pc-linux-gnu (64-bit)
R is free software and comes with ABSOLUTELY NO WARRANTY.
You are welcome to redistribute it under certain conditions.
Type 'license()' or 'licence()' for distribution details.
R is a collaborative project with many contributors.
Type 'contributors()' for more information and
'citation()' on how to cite R or R packages in publications.
Type 'demo()' for some demos, 'help()' for on-line help, or
'help.start()' for an HTML browser interface to help.
Type 'q()' to quit R.
> library(GSIF)
GSIF version 0.5-2 (2016-06-25)
URL: http://gsif.r-forge.r-project.org/
> png(filename="/home/ddbj/snapshot/RGM3/R_CC/result/GSIF/as.geosamples.Rd_%03d_medium.png", width=480, height=480)
> ### Name: as.geosamples
> ### Title: Converts an object to geosamples class
> ### Aliases: as.geosamples as.geosamples,SoilProfileCollection-method
> ### as.geosamples,SpatialPointsDataFrame-method
> ### Keywords: methods
>
> ### ** Examples
>
> library(aqp)
This is aqp 1.9.3
> library(plyr)
> library(rgdal)
Loading required package: sp
rgdal: version: 1.1-10, (SVN revision 622)
Geospatial Data Abstraction Library extensions to R successfully loaded
Loaded GDAL runtime: GDAL 1.11.3, released 2015/09/16
Path to GDAL shared files: /usr/share/gdal/1.11
Loaded PROJ.4 runtime: Rel. 4.9.2, 08 September 2015, [PJ_VERSION: 492]
Path to PROJ.4 shared files: (autodetected)
Linking to sp version: 1.2-3
> library(sp)
> # sample profile from Nigeria:
> lon = 3.90; lat = 7.50; time = as.POSIXct("1978", format="%Y")
> id = "ISRIC:NG0017"; TAXNFAO8 = "LXp"
> top = c(0, 18, 36, 65, 87, 127)
> bottom = c(18, 36, 65, 87, 127, 181)
> ORCDRC = c(18.4, 4.4, 3.6, 3.6, 3.2, 1.2)
> methodid = c("TAXNFAO8", "ORCDRC")
> description = c("FAO 1988 classification system group",
+ "Method of Walkley-Black (Org. matter = Org. C x 1.72)")
> units = c("FAO 1988 classes", "permille")
> detectionLimit = c(as.character(NA), "0.1")
> # prepare a SoilProfileCollection:
> prof1 <- join(data.frame(id, top, bottom, ORCDRC),
+ data.frame(id, lon, lat, time, TAXNFAO8), type='inner')
Joining by: id
> depths(prof1) <- id ~ top + bottom
Warning message:
converting IDs from factor to character
> site(prof1) <- ~ lon + lat + time + TAXNFAO8
> coordinates(prof1) <- ~ lon + lat + time
> proj4string(prof1) <- CRS("+proj=longlat +datum=WGS84")
> # add measurement errors:
> attr(prof1@horizons$ORCDRC, "measurementError") <- c(1.5, 0.5, 0.5, 0.5, 0.5, 0.5)
> attr(prof1@sp@coords, "locationError") <- 1500
> # add the metadata:
> prof1@metadata <- data.frame(methodid, description, units, detectionLimit)
> # convert to geosamples:
> x <- as.geosamples(prof1)
> x
Registry : NA
Variables : ORCDRC, TAXNFAO8
Total samples : 7
Unique locations : 1
Mean location error : 1500
Min longitude : 3.9
Max longitude : 3.9
Min latitude : 7.5
Max latitude : 7.5
Total area (app.) : 0 (square-km)
> # print only the sampled values of ORCDRC:
> ORCDRC <- subset(x, "ORCDRC")
> ORCDRC[,c("sampleid", "altitude", "observedValue")]
sampleid altitude observedValue
2 ISRIC:NG0017 -0.090 18.4
3 ISRIC:NG0017 -0.270 4.4
4 ISRIC:NG0017 -0.505 3.6
5 ISRIC:NG0017 -0.760 3.6
6 ISRIC:NG0017 -1.070 3.2
7 ISRIC:NG0017 -1.540 1.2
>
> # convert object of type SpatialPointsDataFrame:
> data(meuse)
> # prepare columns:
> names(meuse)[which(names(meuse)=="x")] = "longitude"
> names(meuse)[which(names(meuse)=="y")] = "latitude"
> meuse$altitude = -.15
> meuse$time = unclass(as.POSIXct("1992-01-01"))
> coordinates(meuse) <- ~ longitude + latitude + altitude + time
> proj4string(meuse) <- CRS("+init=epsg:28992")
> library(plotKML)
plotKML version 0.5-6 (2016-05-02)
URL: http://plotkml.r-forge.r-project.org/
> hm <- reproject(meuse[,c("zinc", "copper")])
Reprojecting to +proj=longlat +datum=WGS84 ...
> hm.geo <- as.geosamples(hm)
> hm.geo
Registry : NA
Variables :
Total samples : 310
Unique locations : 155
Mean location error : NA
Min longitude : 5.72319
Max longitude : 5.76304
Min latitude : 50.95661
Max latitude : 50.99156
Total area (app.) : 9.983 (square-km)
>
>
>
>
>
> dev.off()
null device
1
>