Learn R Programming

SpatialPosition (version 2.1.2)

CreateGrid: Create a Regularly Spaced Points Grid

Description

This function creates a regular grid of points from the extent of a given spatial object and a given resolution.

Usage

CreateGrid(w, resolution, returnclass = "sp")

Value

The output of the function is a regularly spaced points grid with the extent of w.

Arguments

w

sp or sf object; the spatial extent of this object is used to create the regular grid.

resolution

numeric; resolution of the grid (in map units). If resolution is not set, the grid will contain around 7500 points. (optional)

returnclass

"sp" or "sf"; class of the returned object.

See Also

CreateDistMatrix

Examples

Run this code
# Create a grid of paris extent and 200 meters
# resolution
library(SpatialPosition)
library(sf)
data(hospital)
mygrid <- CreateGrid(w = paris, resolution = 200, returnclass = "sf")
plot(st_geometry(mygrid), cex = 0.1, pch = ".")
plot(st_geometry(paris), border="red", lwd = 2, add = TRUE)

Run the code above in your browser using DataLab