Title: | Discrete Global Grids |
---|---|
Description: | Spatial analyses involving binning require that every bin have the same area, but this is impossible using a rectangular grid laid over the Earth or over any projection of the Earth. Discrete global grids use hexagons, triangles, and diamonds to overcome this issue, overlaying the Earth with equally-sized bins. This package provides utilities for working with discrete global grids, along with utilities to aid in plotting such data. |
Authors: | Richard Barnes [aut], Kevin Sahr [aut, cph], Gerald Evenden [cph], Angus Johnson [cph], Frank Warmerdam [cph], Even Rouault [cph], Lian Song [ctb], Sebastian Krantz [ctb, cre] |
Maintainer: | Sebastian Krantz <[email protected]> |
License: | AGPL (>= 3) |
Version: | 3.1.0 |
Built: | 2024-10-30 06:46:04 UTC |
Source: | https://github.com/r-barnes/dggridr |
This is a generic function that is used to determine an appropriate resolution given an area, cell spacing, or correlated length scale. It does so by extracting the appropriate length/area column and searching it for a value close to the input.
dg_closest_res( dggs, col, val, round = "nearest", show_info = TRUE, metric = TRUE )
dg_closest_res( dggs, col, val, round = "nearest", show_info = TRUE, metric = TRUE )
dggs |
A dggs object from dgconstruct() |
col |
Column in which to search for a close value. Should be: area_km, spacing_km, or cls_km. |
val |
The value to search for |
round |
What direction to search in. Must be nearest, up, or down. |
show_info |
Print the area, spacing, and CLS of the chosen resolution. |
metric |
Whether input and output should be in metric (TRUE) or imperial (FALSE) |
A number representing the grid resolution
library(dggridR) dggs <- dgconstruct(res=20) res <- dg_closest_res(dggs,'area_km',1) dggs <- dgsetres(dggs,res)
library(dggridR) dggs <- dgconstruct(res=20) res <- dg_closest_res(dggs,'area_km',1) dggs <- dgsetres(dggs,res)
Determine an appropriate grid resolution based on a desired cell area.
dg_closest_res_to_area( dggs, area, round = "nearest", show_info = TRUE, metric = TRUE )
dg_closest_res_to_area( dggs, area, round = "nearest", show_info = TRUE, metric = TRUE )
dggs |
A dggs object from dgconstruct() |
area |
The desired area of the grid's cells |
round |
What direction to search in. Must be nearest, up, or down. |
show_info |
Print the area, spacing, and CLS of the chosen resolution. |
metric |
Whether input and output should be in metric (TRUE) or imperial (FALSE) |
A number representing the grid resolution
library(dggridR) dggs <- dgconstruct(res=20) res <- dg_closest_res_to_area(dggs,1) dggs <- dgsetres(dggs,res)
library(dggridR) dggs <- dgconstruct(res=20) res <- dg_closest_res_to_area(dggs,1) dggs <- dgsetres(dggs,res)
The characteristic length scale (CLS) is the diameter of a spherical cap of the same area as a cell of the specified resolution.
dg_closest_res_to_cls( dggs, cls, round = "nearest", show_info = TRUE, metric = TRUE )
dg_closest_res_to_cls( dggs, cls, round = "nearest", show_info = TRUE, metric = TRUE )
dggs |
A dggs object from dgconstruct() |
cls |
The desired CLS of the cells. |
round |
What direction to search in. Must be nearest, up, or down. |
show_info |
Print the area, spacing, and CLS of the chosen resolution. |
metric |
Whether input and output should be in metric (TRUE) or imperial (FALSE) |
A number representing the grid resolution
library(dggridR) dggs <- dgconstruct(res=20) res <- dg_closest_res_to_cls(dggs,1) dggs <- dgsetres(dggs,res)
library(dggridR) dggs <- dgconstruct(res=20) res <- dg_closest_res_to_cls(dggs,1) dggs <- dgsetres(dggs,res)
Determine an appropriate grid resolution based on a desired spacing between the center of adjacent cells.
dg_closest_res_to_spacing( dggs, spacing, round = "nearest", show_info = TRUE, metric = TRUE )
dg_closest_res_to_spacing( dggs, spacing, round = "nearest", show_info = TRUE, metric = TRUE )
dggs |
A dggs object from dgconstruct() |
spacing |
The desired spacing between the center of adjacent cells |
round |
What direction to search in. Must be nearest, up, or down. |
show_info |
Print the area, spacing, and CLS of the chosen resolution. |
metric |
Whether input and output should be in metric (TRUE) or imperial (FALSE) |
A number representing the grid resolution
library(dggridR) dggs <- dgconstruct(res=20) res <- dg_closest_res_to_spacing(dggs,1) dggs <- dgsetres(dggs,res)
library(dggridR) dggs <- dgconstruct(res=20) res <- dg_closest_res_to_spacing(dggs,1) dggs <- dgsetres(dggs,res)
This environment is used to control global features of the dggridR package. At the moment the only option is 'dg_debug' which, when set to TRUE provides extensive outputs useful for tracking down bugs.
dg_env
dg_env
An object of class environment
of length 1.
Convert data from internal dggrid functions into something useful: an sp object or a data frame
dg_process_polydata(polydata)
dg_process_polydata(polydata)
polydata |
Polygons generated by dggrid. These will be converted. |
Returns an sf object.
This variable points to a shapefile containing the national border of South Africa
dg_shpfname_south_africa()
dg_shpfname_south_africa()
A filename of a shapefile containing the national border of South Africa
Returns the coordinates constituting the boundary of a specified set of cells. Duplicates are eliminated to reduce processing and storage requirements.
dgcellstogrid(dggs, cells, savegrid = NA, return_sf = TRUE)
dgcellstogrid(dggs, cells, savegrid = NA, return_sf = TRUE)
dggs |
A dggs object from dgconstruct() |
cells |
The cells to get the boundaries of |
savegrid |
If savegrid is set to a file path, then a shapefile containing the grid is written to that path and the filename is returned. No other manipulations are done. Default: NA (do not save grid, return it) |
return_sf |
logical. If |
Returns an sf object.
If !is.na(savegrid)
, returns a filename.
library(dggridR) data(dgquakes) #Construct a grid with cells about ~1000 miles wide dggs <- dgconstruct(spacing=1000,metric=FALSE) dgquakes$cell <- dgGEO_to_SEQNUM(dggs,dgquakes$lat,dgquakes$lon)$seqnum #Get grid cells for the earthquakes identified grid <- dgcellstogrid(dggs, dgquakes$cell)
library(dggridR) data(dgquakes) #Construct a grid with cells about ~1000 miles wide dggs <- dgconstruct(spacing=1000,metric=FALSE) dgquakes$cell <- dgGEO_to_SEQNUM(dggs,dgquakes$lat,dgquakes$lon)$seqnum #Get grid cells for the earthquakes identified grid <- dgcellstogrid(dggs, dgquakes$cell)
Construct a discrete global grid system (dggs) object
dgconstruct( projection = "ISEA", aperture = 3, topology = "HEXAGON", res = NA, precision = 7, area = NA, spacing = NA, cls = NA, resround = "nearest", metric = TRUE, show_info = TRUE, azimuth_deg = 0, pole_lat_deg = 58.28252559, pole_lon_deg = 11.25 )
dgconstruct( projection = "ISEA", aperture = 3, topology = "HEXAGON", res = NA, precision = 7, area = NA, spacing = NA, cls = NA, resround = "nearest", metric = TRUE, show_info = TRUE, azimuth_deg = 0, pole_lat_deg = 58.28252559, pole_lon_deg = 11.25 )
projection |
Type of grid to use. Options are: ISEA and FULLER. Default: ISEA3H |
aperture |
How finely subsequent resolution levels divide the grid. Options are: 3, 4. Not all options work with all projections and topologies. Default: 3 |
topology |
Shape of cell. Options are: HEXAGON, DIAMOND, TRIANGLE. Default: HEXAGON |
res |
Resolution. Must be in the range [0,30]. Larger values represent finer resolutions. Appropriate resolutions can be found with dg_closest_res_to_area(), dg_closest_res_to_spacing(), and dg_closest_res_to_cls(). Default is 9, which corresponds to a cell area of ~2600 sq km and a cell spacing of ~50 km. Only one of res, area, length, or cls should be used. |
precision |
Round output to this number of decimal places. Must be in the range [0,30]. Default: 7. |
area |
The desired area of the grid's cells. Only one of res, area, length, or cls should be used. |
spacing |
The desired spacing between the center of adjacent cells. Only one of res, area, length, or cls should be used. |
cls |
The desired CLS of the cells. Only one of res, area, length, or cls should be used. |
resround |
What direction to search in. Must be nearest, up, or down. |
metric |
Whether input and output should be in metric (TRUE) or imperial (FALSE) |
show_info |
Print the area, spacing, and CLS of the chosen resolution. |
azimuth_deg |
Rotation in degrees of grid about its pole, value in [0,360]. Default=0. |
pole_lat_deg |
Latitude in degrees of the pole, value in [-90,90]. Default=58.28252559. |
pole_lon_deg |
Longitude in degrees of the pole, value in [-180,180]. Default=11.25. |
Returns a dggs object which can be passed to other dggridR functions
library(dggridR) dggs <- dgconstruct(res=20) dggs <- dgconstruct(area=5,metric=FALSE)
library(dggridR) dggs <- dgconstruct(res=20) dggs <- dgconstruct(area=5,metric=FALSE)
Note: If you have a high-resolution grid this may take a very long time to execute.
dgearthgrid(dggs, savegrid = NA, return_sf = TRUE)
dgearthgrid(dggs, savegrid = NA, return_sf = TRUE)
dggs |
A dggs object from dgconstruct(). |
savegrid |
If savegrid is set to a file path, then a shapefile containing the grid is written to that path and the filename is returned. No other manipulations are done. Default: NA (do not save grid, return it) |
return_sf |
logical. If |
Returns an sf object.
If !is.na(savegrid)
, returns a filename.
library(dggridR) dggs <- dgconstruct(res=20) res <- dg_closest_res_to_spacing(dggs,spacing=1000,round='down',metric=FALSE) dggs <- dgsetres(dggs,res) gridfilename <- dgearthgrid(dggs,savegrid=tempfile(fileext=".shp")) #Save directly to a file
library(dggridR) dggs <- dgconstruct(res=20) res <- dg_closest_res_to_spacing(dggs,spacing=1000,round='down',metric=FALSE) dggs <- dgsetres(dggs,res) gridfilename <- dgearthgrid(dggs,savegrid=tempfile(fileext=".shp")) #Save directly to a file
Uses a discrete global grid system to convert between GEO and GEO (see vignette for details)
dgGEO_to_GEO(dggs, in_lon_deg, in_lat_deg)
dgGEO_to_GEO(dggs, in_lon_deg, in_lat_deg)
dggs |
A dggs object from dgconstruct() |
in_lon_deg |
Vector of longitude, in degrees |
in_lat_deg |
Vector of latitude, in degrees |
Returns a dggs object which can be passed to other dggridR functions
## Not run: library(dggridR) dggs <- dgconstruct(res=20) dgGEO_to_GEO(dggs, in_lon_deg, in_lat_deg) ## End(Not run)
## Not run: library(dggridR) dggs <- dgconstruct(res=20) dgGEO_to_GEO(dggs, in_lon_deg, in_lat_deg) ## End(Not run)
Uses a discrete global grid system to convert between GEO and PLANE (see vignette for details)
dgGEO_to_PLANE(dggs, in_lon_deg, in_lat_deg)
dgGEO_to_PLANE(dggs, in_lon_deg, in_lat_deg)
dggs |
A dggs object from dgconstruct() |
in_lon_deg |
Vector of longitude, in degrees |
in_lat_deg |
Vector of latitude, in degrees |
Returns a dggs object which can be passed to other dggridR functions
## Not run: library(dggridR) dggs <- dgconstruct(res=20) dgGEO_to_PLANE(dggs, in_lon_deg, in_lat_deg) ## End(Not run)
## Not run: library(dggridR) dggs <- dgconstruct(res=20) dgGEO_to_PLANE(dggs, in_lon_deg, in_lat_deg) ## End(Not run)
Uses a discrete global grid system to convert between GEO and PROJTRI (see vignette for details)
dgGEO_to_PROJTRI(dggs, in_lon_deg, in_lat_deg)
dgGEO_to_PROJTRI(dggs, in_lon_deg, in_lat_deg)
dggs |
A dggs object from dgconstruct() |
in_lon_deg |
Vector of longitude, in degrees |
in_lat_deg |
Vector of latitude, in degrees |
Returns a dggs object which can be passed to other dggridR functions
## Not run: library(dggridR) dggs <- dgconstruct(res=20) dgGEO_to_PROJTRI(dggs, in_lon_deg, in_lat_deg) ## End(Not run)
## Not run: library(dggridR) dggs <- dgconstruct(res=20) dgGEO_to_PROJTRI(dggs, in_lon_deg, in_lat_deg) ## End(Not run)
Uses a discrete global grid system to convert between GEO and Q2DD (see vignette for details)
dgGEO_to_Q2DD(dggs, in_lon_deg, in_lat_deg)
dgGEO_to_Q2DD(dggs, in_lon_deg, in_lat_deg)
dggs |
A dggs object from dgconstruct() |
in_lon_deg |
Vector of longitude, in degrees |
in_lat_deg |
Vector of latitude, in degrees |
Returns a dggs object which can be passed to other dggridR functions
## Not run: library(dggridR) dggs <- dgconstruct(res=20) dgGEO_to_Q2DD(dggs, in_lon_deg, in_lat_deg) ## End(Not run)
## Not run: library(dggridR) dggs <- dgconstruct(res=20) dgGEO_to_Q2DD(dggs, in_lon_deg, in_lat_deg) ## End(Not run)
Uses a discrete global grid system to convert between GEO and Q2DI (see vignette for details)
dgGEO_to_Q2DI(dggs, in_lon_deg, in_lat_deg)
dgGEO_to_Q2DI(dggs, in_lon_deg, in_lat_deg)
dggs |
A dggs object from dgconstruct() |
in_lon_deg |
Vector of longitude, in degrees |
in_lat_deg |
Vector of latitude, in degrees |
Returns a dggs object which can be passed to other dggridR functions
## Not run: library(dggridR) dggs <- dgconstruct(res=20) dgGEO_to_Q2DI(dggs, in_lon_deg, in_lat_deg) ## End(Not run)
## Not run: library(dggridR) dggs <- dgconstruct(res=20) dgGEO_to_Q2DI(dggs, in_lon_deg, in_lat_deg) ## End(Not run)
Uses a discrete global grid system to convert between GEO and SEQNUM (see vignette for details)
dgGEO_to_SEQNUM(dggs, in_lon_deg, in_lat_deg)
dgGEO_to_SEQNUM(dggs, in_lon_deg, in_lat_deg)
dggs |
A dggs object from dgconstruct() |
in_lon_deg |
Vector of longitude, in degrees |
in_lat_deg |
Vector of latitude, in degrees |
Returns a dggs object which can be passed to other dggridR functions
## Not run: library(dggridR) dggs <- dgconstruct(res=20) dgGEO_to_SEQNUM(dggs, in_lon_deg, in_lat_deg) ## End(Not run)
## Not run: library(dggridR) dggs <- dgconstruct(res=20) dgGEO_to_SEQNUM(dggs, in_lon_deg, in_lat_deg) ## End(Not run)
Gets a grid's resolution and cell property info as a data frame.
dggetres(dggs)
dggetres(dggs)
dggs |
A dggs object from dgconstruct() |
A data frame containing the resolution levels, number of cells, area of those cells, intercell spacing, and characteristic length scale of the cells. All values are in kilometres.
library(dggridR) dggs <- dgconstruct(res=20) dggetres(dggs)
library(dggridR) dggs <- dgconstruct(res=20) dggetres(dggs)
dggs objects have many settings. This returns all of them, along with info about the grid being specified.
dginfo(dggs)
dginfo(dggs)
dggs |
A dggs object from dgconstruct() |
No return. All info is printed to the screen.
library(dggridR) dggs <- dgconstruct(res=20) dginfo(dggs)
library(dggridR) dggs <- dgconstruct(res=20) dginfo(dggs)
Cells are labeled 1-N. This function returns N. This is useful if you want to choose cells from the dggs randomly.
dgmaxcell(dggs, res = NA)
dgmaxcell(dggs, res = NA)
dggs |
A dggs object from dgconstruct() |
res |
If NA, use the resolution specified by the dggs. Otherwise, override the resolution. |
The maximum cell id.
#Choose a set of cells randomly distributed over the Earth library(dggridR) dggs <- dgconstruct(spacing=1000, metric=FALSE, resround='down') N <- 100 #Number of cells maxcell <- dgmaxcell(dggs) #Get maximum cell id cells <- sample(1:maxcell, N, replace=FALSE) #Choose random cells grid <- dgcellstogrid(dggs,cells) #Get grid
#Choose a set of cells randomly distributed over the Earth library(dggridR) dggs <- dgconstruct(spacing=1000, metric=FALSE, resround='down') N <- 100 #Number of cells maxcell <- dgmaxcell(dggs) #Get maximum cell id cells <- sample(1:maxcell, N, replace=FALSE) #Choose random cells grid <- dgcellstogrid(dggs,cells) #Get grid
Uses a discrete global grid system to convert between PROJTRI and GEO (see vignette for details)
dgPROJTRI_to_GEO(dggs, in_tnum, in_tx, in_ty)
dgPROJTRI_to_GEO(dggs, in_tnum, in_tx, in_ty)
dggs |
A dggs object from dgconstruct() |
in_tnum |
Vector of triangle numbers |
in_tx |
Vector of triangle x values |
in_ty |
Vector of triangle y values |
Returns a dggs object which can be passed to other dggridR functions
## Not run: library(dggridR) dggs <- dgconstruct(res=20) dgPROJTRI_to_GEO(dggs, in_tnum, in_tx, in_ty) ## End(Not run)
## Not run: library(dggridR) dggs <- dgconstruct(res=20) dgPROJTRI_to_GEO(dggs, in_tnum, in_tx, in_ty) ## End(Not run)
Uses a discrete global grid system to convert between PROJTRI and PLANE (see vignette for details)
dgPROJTRI_to_PLANE(dggs, in_tnum, in_tx, in_ty)
dgPROJTRI_to_PLANE(dggs, in_tnum, in_tx, in_ty)
dggs |
A dggs object from dgconstruct() |
in_tnum |
Vector of triangle numbers |
in_tx |
Vector of triangle x values |
in_ty |
Vector of triangle y values |
Returns a dggs object which can be passed to other dggridR functions
## Not run: library(dggridR) dggs <- dgconstruct(res=20) dgPROJTRI_to_PLANE(dggs, in_tnum, in_tx, in_ty) ## End(Not run)
## Not run: library(dggridR) dggs <- dgconstruct(res=20) dgPROJTRI_to_PLANE(dggs, in_tnum, in_tx, in_ty) ## End(Not run)
Uses a discrete global grid system to convert between PROJTRI and PROJTRI (see vignette for details)
dgPROJTRI_to_PROJTRI(dggs, in_tnum, in_tx, in_ty)
dgPROJTRI_to_PROJTRI(dggs, in_tnum, in_tx, in_ty)
dggs |
A dggs object from dgconstruct() |
in_tnum |
Vector of triangle numbers |
in_tx |
Vector of triangle x values |
in_ty |
Vector of triangle y values |
Returns a dggs object which can be passed to other dggridR functions
## Not run: library(dggridR) dggs <- dgconstruct(res=20) dgPROJTRI_to_PROJTRI(dggs, in_tnum, in_tx, in_ty) ## End(Not run)
## Not run: library(dggridR) dggs <- dgconstruct(res=20) dgPROJTRI_to_PROJTRI(dggs, in_tnum, in_tx, in_ty) ## End(Not run)
Uses a discrete global grid system to convert between PROJTRI and Q2DD (see vignette for details)
dgPROJTRI_to_Q2DD(dggs, in_tnum, in_tx, in_ty)
dgPROJTRI_to_Q2DD(dggs, in_tnum, in_tx, in_ty)
dggs |
A dggs object from dgconstruct() |
in_tnum |
Vector of triangle numbers |
in_tx |
Vector of triangle x values |
in_ty |
Vector of triangle y values |
Returns a dggs object which can be passed to other dggridR functions
## Not run: library(dggridR) dggs <- dgconstruct(res=20) dgPROJTRI_to_Q2DD(dggs, in_tnum, in_tx, in_ty) ## End(Not run)
## Not run: library(dggridR) dggs <- dgconstruct(res=20) dgPROJTRI_to_Q2DD(dggs, in_tnum, in_tx, in_ty) ## End(Not run)
Uses a discrete global grid system to convert between PROJTRI and Q2DI (see vignette for details)
dgPROJTRI_to_Q2DI(dggs, in_tnum, in_tx, in_ty)
dgPROJTRI_to_Q2DI(dggs, in_tnum, in_tx, in_ty)
dggs |
A dggs object from dgconstruct() |
in_tnum |
Vector of triangle numbers |
in_tx |
Vector of triangle x values |
in_ty |
Vector of triangle y values |
Returns a dggs object which can be passed to other dggridR functions
## Not run: library(dggridR) dggs <- dgconstruct(res=20) dgPROJTRI_to_Q2DI(dggs, in_tnum, in_tx, in_ty) ## End(Not run)
## Not run: library(dggridR) dggs <- dgconstruct(res=20) dgPROJTRI_to_Q2DI(dggs, in_tnum, in_tx, in_ty) ## End(Not run)
Uses a discrete global grid system to convert between PROJTRI and SEQNUM (see vignette for details)
dgPROJTRI_to_SEQNUM(dggs, in_tnum, in_tx, in_ty)
dgPROJTRI_to_SEQNUM(dggs, in_tnum, in_tx, in_ty)
dggs |
A dggs object from dgconstruct() |
in_tnum |
Vector of triangle numbers |
in_tx |
Vector of triangle x values |
in_ty |
Vector of triangle y values |
Returns a dggs object which can be passed to other dggridR functions
## Not run: library(dggridR) dggs <- dgconstruct(res=20) dgPROJTRI_to_SEQNUM(dggs, in_tnum, in_tx, in_ty) ## End(Not run)
## Not run: library(dggridR) dggs <- dgconstruct(res=20) dgPROJTRI_to_SEQNUM(dggs, in_tnum, in_tx, in_ty) ## End(Not run)
Uses a discrete global grid system to convert between Q2DD and GEO (see vignette for details)
dgQ2DD_to_GEO(dggs, in_quad, in_qx, in_qy)
dgQ2DD_to_GEO(dggs, in_quad, in_qx, in_qy)
dggs |
A dggs object from dgconstruct() |
in_quad |
Vector of quad numbers |
in_qx |
Vector of quadrant x values |
in_qy |
Vector of quadrant y values |
Returns a dggs object which can be passed to other dggridR functions
## Not run: library(dggridR) dggs <- dgconstruct(res=20) dgQ2DD_to_GEO(dggs, in_quad, in_qx, in_qy) ## End(Not run)
## Not run: library(dggridR) dggs <- dgconstruct(res=20) dgQ2DD_to_GEO(dggs, in_quad, in_qx, in_qy) ## End(Not run)
Uses a discrete global grid system to convert between Q2DD and PLANE (see vignette for details)
dgQ2DD_to_PLANE(dggs, in_quad, in_qx, in_qy)
dgQ2DD_to_PLANE(dggs, in_quad, in_qx, in_qy)
dggs |
A dggs object from dgconstruct() |
in_quad |
Vector of quad numbers |
in_qx |
Vector of quadrant x values |
in_qy |
Vector of quadrant y values |
Returns a dggs object which can be passed to other dggridR functions
## Not run: library(dggridR) dggs <- dgconstruct(res=20) dgQ2DD_to_PLANE(dggs, in_quad, in_qx, in_qy) ## End(Not run)
## Not run: library(dggridR) dggs <- dgconstruct(res=20) dgQ2DD_to_PLANE(dggs, in_quad, in_qx, in_qy) ## End(Not run)
Uses a discrete global grid system to convert between Q2DD and PROJTRI (see vignette for details)
dgQ2DD_to_PROJTRI(dggs, in_quad, in_qx, in_qy)
dgQ2DD_to_PROJTRI(dggs, in_quad, in_qx, in_qy)
dggs |
A dggs object from dgconstruct() |
in_quad |
Vector of quad numbers |
in_qx |
Vector of quadrant x values |
in_qy |
Vector of quadrant y values |
Returns a dggs object which can be passed to other dggridR functions
## Not run: library(dggridR) dggs <- dgconstruct(res=20) dgQ2DD_to_PROJTRI(dggs, in_quad, in_qx, in_qy) ## End(Not run)
## Not run: library(dggridR) dggs <- dgconstruct(res=20) dgQ2DD_to_PROJTRI(dggs, in_quad, in_qx, in_qy) ## End(Not run)
Uses a discrete global grid system to convert between Q2DD and Q2DD (see vignette for details)
dgQ2DD_to_Q2DD(dggs, in_quad, in_qx, in_qy)
dgQ2DD_to_Q2DD(dggs, in_quad, in_qx, in_qy)
dggs |
A dggs object from dgconstruct() |
in_quad |
Vector of quad numbers |
in_qx |
Vector of quadrant x values |
in_qy |
Vector of quadrant y values |
Returns a dggs object which can be passed to other dggridR functions
## Not run: library(dggridR) dggs <- dgconstruct(res=20) dgQ2DD_to_Q2DD(dggs, in_quad, in_qx, in_qy) ## End(Not run)
## Not run: library(dggridR) dggs <- dgconstruct(res=20) dgQ2DD_to_Q2DD(dggs, in_quad, in_qx, in_qy) ## End(Not run)
Uses a discrete global grid system to convert between Q2DD and Q2DI (see vignette for details)
dgQ2DD_to_Q2DI(dggs, in_quad, in_qx, in_qy)
dgQ2DD_to_Q2DI(dggs, in_quad, in_qx, in_qy)
dggs |
A dggs object from dgconstruct() |
in_quad |
Vector of quad numbers |
in_qx |
Vector of quadrant x values |
in_qy |
Vector of quadrant y values |
Returns a dggs object which can be passed to other dggridR functions
## Not run: library(dggridR) dggs <- dgconstruct(res=20) dgQ2DD_to_Q2DI(dggs, in_quad, in_qx, in_qy) ## End(Not run)
## Not run: library(dggridR) dggs <- dgconstruct(res=20) dgQ2DD_to_Q2DI(dggs, in_quad, in_qx, in_qy) ## End(Not run)
Uses a discrete global grid system to convert between Q2DD and SEQNUM (see vignette for details)
dgQ2DD_to_SEQNUM(dggs, in_quad, in_qx, in_qy)
dgQ2DD_to_SEQNUM(dggs, in_quad, in_qx, in_qy)
dggs |
A dggs object from dgconstruct() |
in_quad |
Vector of quad numbers |
in_qx |
Vector of quadrant x values |
in_qy |
Vector of quadrant y values |
Returns a dggs object which can be passed to other dggridR functions
## Not run: library(dggridR) dggs <- dgconstruct(res=20) dgQ2DD_to_SEQNUM(dggs, in_quad, in_qx, in_qy) ## End(Not run)
## Not run: library(dggridR) dggs <- dgconstruct(res=20) dgQ2DD_to_SEQNUM(dggs, in_quad, in_qx, in_qy) ## End(Not run)
Uses a discrete global grid system to convert between Q2DI and GEO (see vignette for details)
dgQ2DI_to_GEO(dggs, in_quad, in_i, in_j)
dgQ2DI_to_GEO(dggs, in_quad, in_i, in_j)
dggs |
A dggs object from dgconstruct() |
in_quad |
Vector of quad numbers |
in_i |
Vector of quadrant i values |
in_j |
Vector of quadrant j values |
Returns a dggs object which can be passed to other dggridR functions
## Not run: library(dggridR) dggs <- dgconstruct(res=20) dgQ2DI_to_GEO(dggs, in_quad, in_i, in_j) ## End(Not run)
## Not run: library(dggridR) dggs <- dgconstruct(res=20) dgQ2DI_to_GEO(dggs, in_quad, in_i, in_j) ## End(Not run)
Uses a discrete global grid system to convert between Q2DI and PLANE (see vignette for details)
dgQ2DI_to_PLANE(dggs, in_quad, in_i, in_j)
dgQ2DI_to_PLANE(dggs, in_quad, in_i, in_j)
dggs |
A dggs object from dgconstruct() |
in_quad |
Vector of quad numbers |
in_i |
Vector of quadrant i values |
in_j |
Vector of quadrant j values |
Returns a dggs object which can be passed to other dggridR functions
## Not run: library(dggridR) dggs <- dgconstruct(res=20) dgQ2DI_to_PLANE(dggs, in_quad, in_i, in_j) ## End(Not run)
## Not run: library(dggridR) dggs <- dgconstruct(res=20) dgQ2DI_to_PLANE(dggs, in_quad, in_i, in_j) ## End(Not run)
Uses a discrete global grid system to convert between Q2DI and PROJTRI (see vignette for details)
dgQ2DI_to_PROJTRI(dggs, in_quad, in_i, in_j)
dgQ2DI_to_PROJTRI(dggs, in_quad, in_i, in_j)
dggs |
A dggs object from dgconstruct() |
in_quad |
Vector of quad numbers |
in_i |
Vector of quadrant i values |
in_j |
Vector of quadrant j values |
Returns a dggs object which can be passed to other dggridR functions
## Not run: library(dggridR) dggs <- dgconstruct(res=20) dgQ2DI_to_PROJTRI(dggs, in_quad, in_i, in_j) ## End(Not run)
## Not run: library(dggridR) dggs <- dgconstruct(res=20) dgQ2DI_to_PROJTRI(dggs, in_quad, in_i, in_j) ## End(Not run)
Uses a discrete global grid system to convert between Q2DI and Q2DD (see vignette for details)
dgQ2DI_to_Q2DD(dggs, in_quad, in_i, in_j)
dgQ2DI_to_Q2DD(dggs, in_quad, in_i, in_j)
dggs |
A dggs object from dgconstruct() |
in_quad |
Vector of quad numbers |
in_i |
Vector of quadrant i values |
in_j |
Vector of quadrant j values |
Returns a dggs object which can be passed to other dggridR functions
## Not run: library(dggridR) dggs <- dgconstruct(res=20) dgQ2DI_to_Q2DD(dggs, in_quad, in_i, in_j) ## End(Not run)
## Not run: library(dggridR) dggs <- dgconstruct(res=20) dgQ2DI_to_Q2DD(dggs, in_quad, in_i, in_j) ## End(Not run)
Uses a discrete global grid system to convert between Q2DI and Q2DI (see vignette for details)
dgQ2DI_to_Q2DI(dggs, in_quad, in_i, in_j)
dgQ2DI_to_Q2DI(dggs, in_quad, in_i, in_j)
dggs |
A dggs object from dgconstruct() |
in_quad |
Vector of quad numbers |
in_i |
Vector of quadrant i values |
in_j |
Vector of quadrant j values |
Returns a dggs object which can be passed to other dggridR functions
## Not run: library(dggridR) dggs <- dgconstruct(res=20) dgQ2DI_to_Q2DI(dggs, in_quad, in_i, in_j) ## End(Not run)
## Not run: library(dggridR) dggs <- dgconstruct(res=20) dgQ2DI_to_Q2DI(dggs, in_quad, in_i, in_j) ## End(Not run)
Uses a discrete global grid system to convert between Q2DI and SEQNUM (see vignette for details)
dgQ2DI_to_SEQNUM(dggs, in_quad, in_i, in_j)
dgQ2DI_to_SEQNUM(dggs, in_quad, in_i, in_j)
dggs |
A dggs object from dgconstruct() |
in_quad |
Vector of quad numbers |
in_i |
Vector of quadrant i values |
in_j |
Vector of quadrant j values |
Returns a dggs object which can be passed to other dggridR functions
## Not run: library(dggridR) dggs <- dgconstruct(res=20) dgQ2DI_to_SEQNUM(dggs, in_quad, in_i, in_j) ## End(Not run)
## Not run: library(dggridR) dggs <- dgconstruct(res=20) dgQ2DI_to_SEQNUM(dggs, in_quad, in_i, in_j) ## End(Not run)
A data frame with 19914 observations on the following 4 variables.
time
Time of the quake. Example: 2015-12-31T23:39:28.940Z
lat
Latitude of the epicenter. Example: -7.0711
lon
Longitude of the epicenter. Example: -173.5178
mag
Magnitude of the quake. Example: 3.2
data(dgquakes)
data(dgquakes)
data frame
The USGS Earthquake Hazards Program (https://earthquake.usgs.gov/earthquakes/search/).
Note: This may generate odd results for very large rectangles, because putting rectangles on spheres is weird... as you should know, if you're using this package.
dgrectgrid( dggs, minlat = -1, minlon = -1, maxlat = -1, maxlon = -1, cellsize = 0.1, ... )
dgrectgrid( dggs, minlat = -1, minlon = -1, maxlat = -1, maxlon = -1, cellsize = 0.1, ... )
dggs |
A dggs object from dgconstruct() |
minlat |
Minimum latitude of region of interest |
minlon |
Minimum longitude of region of interest |
maxlat |
Maximum latitude of region of interest |
maxlon |
Maximum longitude of region of interest |
cellsize |
Distance, in degrees, between the sample points used to generate the grid. Small values yield long generation times while large values may omit cells. |
... |
Further arguments passed to |
Returns an sf object.
If !is.na(savegrid)
, returns a filename.
library(dggridR) dggs <- dgconstruct(spacing=1000,metric=FALSE,resround='down') #Get grid cells for the conterminous United States grid <- dgrectgrid(dggs, minlat=24.7433195, minlon=-124.7844079, maxlat=49.3457868, maxlon=-66.9513812)
library(dggridR) dggs <- dgconstruct(spacing=1000,metric=FALSE,resround='down') #Get grid cells for the conterminous United States grid <- dgrectgrid(dggs, minlat=24.7433195, minlon=-124.7844079, maxlat=49.3457868, maxlon=-66.9513812)
Saves a generated grid to a shapefile
dgsavegrid(grid, shpfname)
dgsavegrid(grid, shpfname)
grid |
Grid to be saved |
shpfname |
File to save the grid to |
The filename the grid was saved to
Uses a discrete global grid system to convert between SEQNUM and GEO (see vignette for details)
dgSEQNUM_to_GEO(dggs, in_seqnum)
dgSEQNUM_to_GEO(dggs, in_seqnum)
dggs |
A dggs object from dgconstruct() |
in_seqnum |
Globally unique number identifying the surface polygon |
Returns a dggs object which can be passed to other dggridR functions
## Not run: library(dggridR) dggs <- dgconstruct(res=20) dgSEQNUM_to_GEO(dggs, in_seqnum) ## End(Not run)
## Not run: library(dggridR) dggs <- dgconstruct(res=20) dgSEQNUM_to_GEO(dggs, in_seqnum) ## End(Not run)
Uses a discrete global grid system to convert between SEQNUM and PLANE (see vignette for details)
dgSEQNUM_to_PLANE(dggs, in_seqnum)
dgSEQNUM_to_PLANE(dggs, in_seqnum)
dggs |
A dggs object from dgconstruct() |
in_seqnum |
Globally unique number identifying the surface polygon |
Returns a dggs object which can be passed to other dggridR functions
## Not run: library(dggridR) dggs <- dgconstruct(res=20) dgSEQNUM_to_PLANE(dggs, in_seqnum) ## End(Not run)
## Not run: library(dggridR) dggs <- dgconstruct(res=20) dgSEQNUM_to_PLANE(dggs, in_seqnum) ## End(Not run)
Uses a discrete global grid system to convert between SEQNUM and PROJTRI (see vignette for details)
dgSEQNUM_to_PROJTRI(dggs, in_seqnum)
dgSEQNUM_to_PROJTRI(dggs, in_seqnum)
dggs |
A dggs object from dgconstruct() |
in_seqnum |
Globally unique number identifying the surface polygon |
Returns a dggs object which can be passed to other dggridR functions
## Not run: library(dggridR) dggs <- dgconstruct(res=20) dgSEQNUM_to_PROJTRI(dggs, in_seqnum) ## End(Not run)
## Not run: library(dggridR) dggs <- dgconstruct(res=20) dgSEQNUM_to_PROJTRI(dggs, in_seqnum) ## End(Not run)
Uses a discrete global grid system to convert between SEQNUM and Q2DD (see vignette for details)
dgSEQNUM_to_Q2DD(dggs, in_seqnum)
dgSEQNUM_to_Q2DD(dggs, in_seqnum)
dggs |
A dggs object from dgconstruct() |
in_seqnum |
Globally unique number identifying the surface polygon |
Returns a dggs object which can be passed to other dggridR functions
## Not run: library(dggridR) dggs <- dgconstruct(res=20) dgSEQNUM_to_Q2DD(dggs, in_seqnum) ## End(Not run)
## Not run: library(dggridR) dggs <- dgconstruct(res=20) dgSEQNUM_to_Q2DD(dggs, in_seqnum) ## End(Not run)
Uses a discrete global grid system to convert between SEQNUM and Q2DI (see vignette for details)
dgSEQNUM_to_Q2DI(dggs, in_seqnum)
dgSEQNUM_to_Q2DI(dggs, in_seqnum)
dggs |
A dggs object from dgconstruct() |
in_seqnum |
Globally unique number identifying the surface polygon |
Returns a dggs object which can be passed to other dggridR functions
## Not run: library(dggridR) dggs <- dgconstruct(res=20) dgSEQNUM_to_Q2DI(dggs, in_seqnum) ## End(Not run)
## Not run: library(dggridR) dggs <- dgconstruct(res=20) dgSEQNUM_to_Q2DI(dggs, in_seqnum) ## End(Not run)
Uses a discrete global grid system to convert between SEQNUM and SEQNUM (see vignette for details)
dgSEQNUM_to_SEQNUM(dggs, in_seqnum)
dgSEQNUM_to_SEQNUM(dggs, in_seqnum)
dggs |
A dggs object from dgconstruct() |
in_seqnum |
Globally unique number identifying the surface polygon |
Returns a dggs object which can be passed to other dggridR functions
## Not run: library(dggridR) dggs <- dgconstruct(res=20) dgSEQNUM_to_SEQNUM(dggs, in_seqnum) ## End(Not run)
## Not run: library(dggridR) dggs <- dgconstruct(res=20) dgSEQNUM_to_SEQNUM(dggs, in_seqnum) ## End(Not run)
Set the resolution of a dggs object
dgsetres(dggs, res)
dgsetres(dggs, res)
dggs |
A dggs object from dgconstruct(). |
res |
Resolution. Must be in the range [0,30]. Larger values represent finer resolutions. Appropriate resolutions can be found with dg_closest_res_to_area(), dg_closest_res_to_spacing(), and dg_closest_res_to_cls(). Default is 9, which corresponds to a cell area of ~2600 sq km and a cell spacing of ~50 km. Default: 9. |
Returns a dggs object which can be passed to other dggridR functions
library(dggridR) dggs <- dgconstruct(res=20) dggs <- dgsetres(dggs,10)
library(dggridR) dggs <- dgconstruct(res=20) dggs <- dgsetres(dggs,10)
Returns the coordinates constituting the boundary of a set of cells which intersect or are contained by a polygon (or polygons) specified in a shapefile. Note that grid cells are also generated for holes in the shapefile's polygon(s).
Note that coordinates in the shapefile must be rounded to check polygon intersections. Currently this round preserves eight decimal digits of precision.
The eighth decimal place is worth up to 1.1 mm of precision: this is good for charting the motions of tectonic plates and the movements of volcanoes. Permanent, corrected, constantly-running GPS base stations might be able to achieve this level of accuracy.
In other words: you should be just fine with this level of precision.
dgshptogrid(dggs, shpfname, cellsize = 0.1, ...)
dgshptogrid(dggs, shpfname, cellsize = 0.1, ...)
dggs |
A dggs object from dgconstruct() |
shpfname |
Either a sf data frame or the file name of the shapefile. Filename should end with '.shp'. |
cellsize |
Distance, in degrees, between the sample points used to generate the grid. Small values yield long generation times while large values may omit cells. |
... |
Further arguments passed to |
Returns an sf object.
If !is.na(savegrid)
, returns a filename.
## Not run: library(dggridR) dggs <- dgconstruct(spacing=25, metric=FALSE, resround='nearest') south_africa_grid <- dgshptogrid(dggs,dg_shpfname_south_africa()) ## End(Not run)
## Not run: library(dggridR) dggs <- dgconstruct(spacing=25, metric=FALSE, resround='nearest') south_africa_grid <- dgshptogrid(dggs,dg_shpfname_south_africa()) ## End(Not run)
Verify that a dggs object has appropriate values
dgverify(dggs)
dgverify(dggs)
dggs |
The dggs object to be verified |
The function has no return value. A stop signal is raised if the object is misspecified
library(dggridR) dggs <- dgconstruct(res=20) dgverify(dggs)
library(dggridR) dggs <- dgconstruct(res=20) dgverify(dggs)