getgrid: Transform a Polygon Layer to a Grid

Description Usage Arguments Value Examples

View source: R/getgrid.R

Description

Transform a polygon layer to a regular grid data.frame.

Usage

1
getgrid(x, cellsize, var)

Arguments

x

an sf polygon layer.

cellsize

size of the side of a grid cell.

var

name of the variable to transform to the grid. It can be a vector of names.

Value

A data frame is returned.

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
library(linemap)
library(sf)
Bretagne <- st_read(system.file("gpkg/geofla.gpkg", package = "linemap"),
                    layer = "Bretagne")
France <- st_read(system.file("gpkg/geofla.gpkg", package = "linemap"),
                  layer = "France")
# example on an extract of dataset
cotedarmor <- Bretagne[Bretagne$CODE_DEPT == 22, ]
cota <- getgrid(x = cotedarmor, cellsize = 1750, var = "POPULATION")
opar <- par(mar = c(0,0,0,0))
plot(st_geometry(France), col="lightblue3", border = NA, bg = "lightblue2",
     xlim = c(min(cota$X), max(cota$X)), ylim= c(min(cota$Y), max(cota$Y)))
linemap(x = cota, var = "POPULATION", k = 5, threshold = 1,
        col = "lightblue3", border = "white", lwd = 0.8,
        add = TRUE)
par(opar)



# example on the full dataset
Bretagne_grid <- getgrid(x = Bretagne, cellsize = 1750, var = "POPULATION")
opar <- par(mar = c(0,0,0,0))
plot(st_geometry(France), col="lightblue3", border = NA, bg = "lightblue2",
     xlim = range(Bretagne_grid$X), ylim= range(Bretagne_grid$Y))
linemap(x = Bretagne_grid, var = "POPULATION", k = 5, threshold = 1,
        col = "lightblue3", border = "white", lwd = 0.8,
        add = TRUE)
par(opar)

linemap documentation built on Jan. 19, 2021, 5:06 p.m.