Transforms irregularly spaced xyz data into a raster object suitable to create a bathy object with regularly spaced longitudes and latitudes.
griddify(xyz, nlon, nlat)
Arguments
xyz: 3-column matrix or data.frame containing (in this order) arbitrary longitude, latitude and altitude/depth values.
nlon: integer. The number of unique regularly-spaced longitude values that will be used to create the grid.
nlat: integer. The number of unique regularly-spaced latitude values that will be used to create the grid.
Details
griddify takes anys dataset with irregularly spaced xyz data and transforms it into a raster object (i.e. a grid) with user specified dimensions. griddify relies on several functions from the raster package, especially rasterize and resample. If a cell of the user-defined grig does not contain any depth/altitude value in the original xyz matrix/data.frame, a NA is added in that cell. A bilinear interpolation is then applied in order to fill in most of the missing cells. For cells of the user-defined grig containing more than one depth/altitude value in the original xyz matrix/data.frame, the mean depth/altitude value is computed.
Returns
The output of griddify is an object of class raster, with nlon unique longitude values and nlat unique latitude values.
# load irregularly spaced xyz datadata(irregular)head(irregular)# use griddify to create a 40x60 gridreg <- griddify(irregular, nlon =40, nlat =60)# switch to class "bathy"class(reg)bat <- as.bathy(reg)summary(bat)# Plot the new bathy object and overlay the original data pointsplot(bat, image =TRUE, lwd =0.1)points(irregular$lon, irregular$lat, pch =19, cex =0.3, col = col2alpha(3))