Function to create a polygon fishnet of specified resolution over a raster dataset. By default, the fishnet is built so that each cell corresponds to a raster cell. If the pix_for_cell argument is set, then the polygons of the fishnet are built so to include the specified number of cells in each direction. If the cellsize option is set, a fishnet of the specified resolution is created over the extent of the raster)

create_fishnet(in_obj, pix_for_cell = 1, shape = "rect",
  cellsize = NULL, exact_csize = TRUE, out_file = NULL,
  out_type = "sf", overwrite = TRUE, crop_layer = NULL,
  verbose = TRUE)

Arguments

in_obj

raster/vector file or object, or sprawlext object on which extent the fishnet should be built

pix_for_cell

numeric(1/2) (optional) 1/2 element numeric array specifying how many pixels of the #' raster will be included in each polygon of the fishnet (if only one element is provided, the #' same number of pixel is aggregated in each direction). Ignored if cellsize is not null, Default: 1

shape

character [\"rect\" \"hex\"]

cellsize

numeric(1/2) (optional) 1/2 element array specifying the dimensions of the desired #' cells in the x and y directions (if only one element is provided, the same cellsize is used in each direction), Default: NULL

out_file

logical PARAM_DESCRIPTION, Default: FALSE.

out_type

character [sf, sfc] if sf, return an sf POLYGON object, with a cell_id column. If sfc return only the geometry, default: sf

overwrite

logical PARAM_DESCRIPTION, Default: TRUE.

crop_layer

logical object of class Extent. If not null, the fishnet is cropped on this extent, without "moving" the nodes of the grid. This is useful to crop a grid created on the basis of a different raster coordinates on top of a different raster, Default: FALSE. CURRENTLY NOT IMPLEMENTED - MAY BE DEPRECATED !

verbose

logical If FALSE, processing messages are suppressed, Default: TRUE.

Value

OUTPUT_DESCRIPTION

Details

DETAILS

Examples

# create a fishnet over an input raster file and save it as a shapefile library(raster) library(sprawl) library(rasterVis)
#> Loading required package: lattice
#> Loading required package: latticeExtra
#> Loading required package: RColorBrewer
in_rast <- build_testraster(20,40,1) fishnet <- create_fishnet(in_rast)
#> create_fishnet --> Creating Fishnet over in_rast
#> crop_vect --> cropping . on extent of in_obj
#> although coordinates are longitude/latitude, st_intersection assumes that they are planar
plot_rast(in_rast, in_poly = fishnet)
fishnet <- create_fishnet(in_rast, pix_for_cell = c(4,2))
#> create_fishnet --> Creating Fishnet over in_rast
#> crop_vect --> cropping . on extent of in_obj
#> although coordinates are longitude/latitude, st_intersection assumes that they are planar
plot_rast(in_rast, in_poly = fishnet)
fishnet <- create_fishnet(in_rast, cellsize = c(25,25))
#> create_fishnet --> Creating Fishnet over in_rast
#> crop_vect --> cropping . on extent of in_obj
#> although coordinates are longitude/latitude, st_intersection assumes that they are planar
plot_rast(in_rast, in_poly = fishnet)
# using shape = "hex" gives and hexagonal grid instead fishnet <- create_fishnet(in_rast, cellsize = c(25,25), exact_csize = TRUE, shape = "hex")
#> create_fishnet --> Creating Fishnet over in_rast
#> although coordinates are longitude/latitude, st_relate_pattern assumes that they are planar
#> Error in create_fishnet(in_rast, cellsize = c(25, 25), exact_csize = TRUE, shape = "hex"): object 'fish' not found
plot_rast(in_rast, in_poly = fishnet)