buffer.dist: Derive buffer distances to a set of points

Description Usage Arguments Note Author(s) See Also Examples

Description

Derive buffer distances using the raster::distance function, so that these can be used as predictors for spatial prediction i.e. to account for spatial proximity to low, medium and high values.

Usage

1
2
## S4 method for signature 'SpatialPointsDataFrame,SpatialPixelsDataFrame'
buffer.dist(observations, predictionDomain, classes, width, ...)

Arguments

observations

object of class "SpatialPointsDataFrame" containing observations of the target variable

predictionDomain

object of class "SpatialPixelsDataFrame"; prediction domain for which distances are estimated

classes

factor; split of the points

width

numeric; maximum search radius

...

other optional arguments that can be passed to raster::distance

Note

Number of breaks (numeric resolution) should be higher than the number of bins, for example, estimated for the histogram display. Machine learning techniques can be quite sensitive to blunders / artifacts in the input point data, hence use with caution. Deriving buffer distances for large rasters can be time-consuming.

Author(s)

Tomislav Hengl

See Also

fit.gstatModel

Examples

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
library(sp)
library(raster)
library(gstat)
library(randomForest)
library(quantregForest)
library(plotKML)
library(scales)
library(ranger)

## Load the Meuse data set:
demo(meuse, echo=FALSE)

## Not run: 
## Soil organic matter (distance from any to all points):
grid.dist0 <- buffer.dist(meuse["om"], meuse.grid[1], as.factor(1:nrow(meuse)))
dn0 <- paste(names(grid.dist0), collapse="+")
fm0 <- as.formula(paste("om ~", dn0))
m0 <- fit.gstatModel(meuse, fm0, grid.dist0, 
    method="ranger", rvgm=NULL)
rk.m0 <- predict(m0, grid.dist0)
plot(rk.m0)
dev.off()
x = importance(m0@regModel)
plot(x)
## not always most practical to calculate distance to each point

## End(Not run)

## Soil organic matter with breaks:
classes <- cut(meuse$om, breaks=seq(0, 17, length=8))
## are these optimal splits?
grid.dist <- buffer.dist(meuse["om"], meuse.grid[1], classes)
plot(stack(grid.dist))
## quantregForest as a 'replacement' for kriging:
dn <- paste(names(grid.dist), collapse="+")
fm <- as.formula(paste("om ~", dn))
m <- fit.gstatModel(meuse, fm, grid.dist, 
    method="quantregForest", rvgm=NULL)
plot(m)
dev.off()
## Residual variogram shows no spatial structure
rk.m <- predict(m, grid.dist)
plot(rk.m)
dev.off()
## prediction error:
plot(sqrt(raster(rk.m@predicted[2])))
points(meuse, pch="+")
## Not run: 
plotKML(rk.m@predicted["om"], colour_scale = SAGA_pal[[1]])
kml(meuse, file.name="om_points.kml", colour=om, labels=meuse$om)
kml_View("om_points.kml")
meuse$classes <- classes
plotKML(meuse["classes"])

## End(Not run)

## Not run: 
## Combining geographical and feature space covariates:
meuse.gridT <- meuse.grid
meuse.gridT@data <- cbind(meuse.grid@data, grid.dist@data)
fm1 <- as.formula(paste("om ~", dn, "+soil+dist+ffreq"))
m1 <- fit.gstatModel(meuse, fm1, meuse.gridT, 
     method="quantregForest", rvgm=NULL)
## no need to fit variogram in this case
plot(m1)
dev.off()
rk.m1 <- predict(m1, meuse.gridT)
plot(rk.m1)
varImpPlot(m1@regModel)
dev.off()
plotKML(rk.m1@predicted["om"], 
   file.name="rk_combined.kml", 
   colour_scale = SAGA_pal[[1]])

## End(Not run)

## Not run: 
## Example with zinc:
classes2 <- cut(meuse$zinc, 
   breaks=seq(min(meuse$zinc), max(meuse$zinc), length=10))
grid.dist2 <- buffer.dist(meuse["zinc"], meuse.grid[1], classes2)
dn2 <- paste(names(grid.dist2), collapse="+")
meuse.gridT2 <- meuse.grid
meuse.gridT2@data <- cbind(meuse.grid@data, grid.dist2@data)
fm2 <- as.formula(paste("zinc ~", dn2, "+soil+dist+ffreq"))
m2 <- fit.gstatModel(meuse, fm2, meuse.gridT2, 
      method="quantregForest", rvgm=NULL)
varImpPlot(m2@regModel)
rk.m2 <- predict(m2, meuse.gridT2)
plot(rk.m2)
dev.off()
## prediction error:
plot(raster(rk.m2@predicted[2]))
plotKML(rk.m2@predicted["zinc"], 
    file.name="rk_combined_zinc.kml", 
    colour_scale = SAGA_pal[[1]])
kml(meuse, colour=zinc, 
    file.name="zinc_points.kml", labels=meuse$zinc)
kml_View("zinc_points.kml")

## End(Not run)

GSIF documentation built on May 2, 2019, 5:44 p.m.

Related to buffer.dist in GSIF...