Learn R Programming

mapi (version 1.1.4)

MAPI_GridHexagonal: Function MAPI_GridHexagonal

Description

Build a grid of hexagonal cells according to samples coordinates and a given halfwidth cell value provided by users (can be computed using MAPI_EstimateHalfwidth). If coordinates are in angular units (eg. longitude/latitude) MAPI will try to build a worldwide "discrete global grid system" using package 'dggridR'. As the 'dggridR' package is no more available on CRAN, this feature have been removed and an error is thrown in this case. See https://github.com/r-barnes/dggridR for more informations. As an alternative, grids (levels 1 to 11) are downloadable from MAPI website.

Usage

MAPI_GridHexagonal(samples, crs, hw, buf = 0)

Value

a spatial object of class 'sf' including the x and y coordinates of cell centers, cell geometry (polygons) and cell id (gid).

Arguments

samples

a data.frame with names and geographical coordinates of samples. Column names must be: 'ind', 'x', 'y'. Optional column 'errRad' with an error radius for sample locations (eg. GPS uncertainty).

crs

coordinate reference system: integer with the EPSG code, or character with proj4string. When using dummy coordinates (eg. simulation output) you may use EPSG:3857 for example. This allows computation but, of course, has no geographical meaning.

hw

Halfwidth : side length of hexagonal cells.

buf

optional. This parameter allows to expand or shrink the grid by a number of units in the same reference system as the sample geographical coordinates (0 by default, ignored for worldwide grids).

Examples

Run this code
data("samples")
# Builds a grid of hexagonal cells according to samples coordinates (columns x and y) 
# using the EPSG:3857 projection and an halfwidth cell value of hw=250m.
grid <- MAPI_GridHexagonal(samples, crs=3857, hw=250)

Run the code above in your browser using DataLab