Get a subset of a object of class "SpatialPoints" or "SpatialPointsDataFrame" avoiding spatial clustering.
Usage
## S4 method for signature 'SpatialPoints'
sample.grid(obj, cell.size, n, bbox, ...)
## S4 method for signature 'SpatialPointsDataFrame'
sample.grid(obj, cell.size, n, bbox, ...)
Arguments
obj
"SpatialPoints*" object
cell.size
numeric; the cell size of the overlayed "SpatialGridDataFrame" in the form of c(x,y)
n
integer; specifies maximum number points in each grid
bbox
matrix; the bounding box of output "SpatialPoints" or "SpatialPointsDataFrame"; it is set the same as the obj if missing
...
other optional arguments that can be passed to over
Value
Returns a list of two objects: (1) an object of type "SpatialPoints" or "SpatialPointsDataFrame" that contains a subset of the obj, and (2) resulting grid.
Note
Spatial points are overlayed with spatial grids with a specified cell size and then get a subset from each grid with a specified number at most. If one grid has less points than the specified number, all the points are taken. If one grid has more points than the specified number, only this number of points are taken by sample. This function can be used when there are too much point observations to be handled, especially for spatially clustered observations. The total number of sampled points are determined by cell.size and n together. You will get fewer the sampled points when cell.size is larger, or/and when n is smaller. Similar sample sizes can be achieved by differen combination of cell.size and n.
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/sample.grid.Rd_%03d_medium.png", width=480, height=480)
> ### Name: sample.grid
> ### Title: sample spatial points by grids
> ### Aliases: sample.grid sample.grid.SpatialPoints
> ### sample.grid.SpatialPointsDataFrame sample.grid,SpatialPoints-method
> ### sample.grid,SpatialPointsDataFrame-method
> ### Keywords: methods
>
> ### ** Examples
>
> library(sp)
> data(isis)
> profs <- isis[["sites"]]
> coordinates(profs) <- ~ LONWGS84 + LATWGS84
> proj4string(profs) <- CRS("+proj=longlat +datum=WGS84")
> ## sample SpatialPointsDataFrame:
> #bbox <- matrix(c(-180, -90, 180, 90), nrow=2)
> prof1 <- sample.grid(profs, cell.size = c(5,5), n = 1)
> l0 <- list("sp.points", profs, pch=1, col="red")
> l1 <- list("sp.points", prof1$subset, pch="+", col="black", cex=1.2)
> spplot(prof1$grid, scales=list(draw=TRUE),
+ col.regions="grey", sp.layout=list(l0, l1))
> ## Subsampling ratio:
> round(length(prof1$subset)/length(profs)*100, 1)
[1] 21
>
>
>
>
>
> dev.off()
null device
1
>