btb_ptsToGrid {btb} | R Documentation |
Compute a grid from centroid points
Description
Function to compute a grid (regular or not) from centroid points.
(Fonction permettant de générer une grille (régulière ou non) à partir de centroïdes)
Usage
btb_ptsToGrid(
pts,
sEPSG = NA,
iCellSize = NULL,
names_centro = c("x_centro", "y_centro"),
inspire = F
)
Arguments
pts |
A simple (Un simple |
sEPSG |
EPSG code of projection ( (code EPSG de la projection ( |
iCellSize |
Cell size of the grid. If this argument is provided, the grid is regular. (Taille des carreaux de la grille. Si cet argument est fourni, la grille est régulière.) |
names_centro |
(character vector)
|
inspire |
(boolean) : if TRUE, returns a column for Inspire grid names. |
Value
Returns an object of class sf
and data.frame
.
(Retourne un objet de classe sf
et data.frame
.)
Examples
# example 1 - regular grid
pts <- data.frame(x_centro = c(100, 100, 300, 300, 500),
y_centro = c(100, 300, 100, 300, 100))
carResult <- btb_ptsToGrid(pts = pts, sEPSG = "2154", iCellSize = 200)
# write_sf(obj = carResult, dsn = "regularGrid.shp", delete_layer = TRUE)
# example 2 - irregular grid
pts <- data.frame(x = c(50, 50, 150, 150, 300)
, y = c(50, 150, 50, 150, 100)
, iCellSize = c(50, 50, 50, 50, 100))
carResult <- btb_ptsToGrid(pts = pts, sEPSG = "2154",names_centro=c("x","y"))
# write_sf(obj = carResult, dsn = "irregularGrid.shp", delete_layer = TRUE)
# Exemple 3 : sf points (no epsg)
pts <- data.frame(x = c(100, 100, 300, 300, 500), y = c(100, 300, 100, 300, 100))
pts <- sf::st_as_sf(pts,coords=c("x","y"))
carResult <- btb_ptsToGrid(pts = pts, sEPSG = "2154", iCellSize = 200)
# Exemple 3 : sf points (no epsg)
pts <- data.frame(x = c(100, 100, 300, 300, 500),
y = c(100, 300, 100, 300, 100))
pts <- sf::st_as_sf(pts,coords=c("x","y"),crs=2154)
carResult <- btb_ptsToGrid(pts = pts, sEPSG = "2154", iCellSize = 200)