An S4 class representing a hexagonal grid specification. Stores all parameters needed for grid operations.
Usage
# S4 method for class 'HexGridInfo'
x$name
# S4 method for class 'HexGridInfo'
n_cells(x)
# S4 method for class 'HexGridInfo'
names(x)
# S4 method for class 'HexGridInfo'
show(object)
# S4 method for class 'HexGridInfo'
summary(object, ...)
# S3 method for class 'hexify_grid_summary'
print(x, ...)
# S4 method for class 'HexGridInfo'
as.list(x, ...)
# S3 method for class 'HexGridInfo'
st_as_sf(x, ...)
# S3 method for class 'HexGridInfo'
st_crs(x, ...)
# S4 method for class 'HexGridInfo,missing'
plot(
x,
y,
surface = c("sphere", "solid", "net"),
center = c(lon = 15, lat = 32),
projection = c("orthographic", "perspective"),
distance = NULL,
tilt = 0,
rotation = 0,
fov = NULL,
cells = NULL,
land = TRUE,
ocean_fill = "#F4F6F8",
land_fill = "#C9D0D6",
land_border = "#8C969F",
land_lwd = 0.4,
grid_border = "#0072B2",
grid_lwd = 0.8,
face_edges = NULL,
edge_col = "black",
edge_lwd = 1.1,
layout = "plane",
seams = FALSE,
seam_col = "#D55E00",
seam_lwd = 1.6,
graticule = FALSE,
graticule_col = "#9AA3AB",
graticule_lwd = 0.5,
distortion = c("none", "angular", "areal"),
tissot = FALSE,
tissot_col = "#2E3439",
tissot_lwd = 0.8,
parents = NULL,
parent_col = "#1B2A38",
parent_lwd = 1.8,
area_legend = FALSE,
tabs = FALSE,
step = 0.01,
main = NULL,
...
)Arguments
- x
A HexGridInfo object; for
print(), a grid summary assummary()returns one- name
Slot name
- object
A HexGridInfo object
- ...
For
st_as_sf(), passed on togrid_global; forst_crs(), passed on tosf::st_crs(); ignored by the other methods- y
Ignored
- surface
"sphere","solid"or"net"."solid"draws the flat faces of the grid's polyhedron (the icosahedron, or the octahedron or tetrahedron of a grid built on it). The solid and the net need an ISEA grid; an H3 grid is drawn on the sphere.- center
Point the view looks down on: a preset name from
globe_centersorc(lon, lat).- projection
"orthographic"or"perspective".- distance
Distance of the untilted perspective camera from the sphere's centre, in sphere radii; greater than 1.
NULLuses 3. A geostationary satellite sits at about 6.6 Earth radii.- tilt
Degrees the perspective camera swings about the point at
center, between -90 and 90, keeping its range ofdistance - 1radii to that point. Positive values move the camera towards the bottom of the view, so it looks towards the top.- rotation
Degrees the view turns about the line of sight; positive values turn north clockwise.
- fov
Field of view of the perspective camera in degrees, across the square the plot shows, centred on
center; below 170.NULLframes the whole visible sphere instead.- cells
Cell IDs to draw.
NULLdraws every cell of the grid.- land
TRUEfor the built-inhexify_world,FALSEfor none, or an sf/sfc object of polygons.- ocean_fill
Fill colour of the surface.
- land_fill
Fill colour of land;
NAleaves land unfilled.- land_border
Colour of country outlines;
NAdraws none.- land_lwd
Line width of country outlines.
- grid_border
Colour of cell boundaries.
- grid_lwd
Line width of cell boundaries.
- face_edges
Draw the edges of the solid's faces.
NULLdraws them for an ISEA grid; H3 is built on an icosahedron of its own, so its grid takes none.- edge_col
Colour of face edges.
- edge_lwd
Line width of face edges.
- layout
For
surface = "net", the layout of the faces: a namenet_layouttakes, or ahexify_netobject it built for this grid.- seams
For
surface = "net", draw the cuts of the net: the sides of its pieces across which the map is not continuous, including its outline.- seam_col
Colour of seams.
- seam_lwd
Line width of seams.
- graticule
FALSEfor none,TRUEfor meridians and parallels every 30 degrees, or a number of degrees between them.- graticule_col
Colour of the graticule.
- graticule_lwd
Line width of the graticule.
- distortion
"none","angular"for the maximum angular deformation of the face projection, or"areal"for its areal scale (1 everywhere on Snyder's equal-area projection). Needs an ISEA grid; a colour bar is drawn along the bottom.- tissot
FALSEfor none,TRUEfor Tissot ellipses at points about 30 degrees apart, or a number of degrees between them. Each ellipse is the image of a circle a fifth of that spacing in radius. Drawn on the net and the solid.- tissot_col
Colour of Tissot ellipses.
- tissot_lwd
Line width of Tissot ellipses.
- parents
Resolutions up whose cell outlines are drawn over the cells, such as
1or1:2;NULLfor none.- parent_col
Colour of parent outlines, recycled over
parents.- parent_lwd
Line width of parent outlines, recycled over
parents.- area_legend
For
surface = "net"of a grid on Snyder's equal-area projection, draw one hexagonal cell of each drawn resolution at the scale of the map, labelled with its area.- tabs
For
surface = "net", draw glue tabs on the seams.- step
Spacing of the points along a cell boundary, as a fraction of a face edge.
- main
Plot title.
Value
show(): the object, invisibly, after printing one line naming the gridsummary(): a list of classhexify_grid_summarycarryinggrid_type,aperture,resolution,area_km2,diagonal_km,crs,radius_km,earth,orientation(c(vert0_lon, vert0_lat, azimuth), empty for H3),projection(NAfor H3),polyhedron(NAfor H3),ellipsoid(c(a_km, f), empty for a grid on the sphere) andn_cells; printing it lists every property and returns it invisibly$: the value of the requested slotnames(): character vector of slot namesn_cells(): the number of cells the grid containsas.list(): a named list of slot valuesplot(): the grid, invisiblyst_as_sf(): an sf object of the grid's global cell setst_crs(): an object of classcrs, assf::st_crs()returns: an Earth grid gives 'WGS84', a grid on another body a longlat CRS on the sphere of its radius
Details
Create HexGridInfo objects using the hex_grid constructor function.
Do not use new("HexGridInfo", ...) directly.
The aperture can be "3", "4", "7" for grids that refine by one aperture at every level; a family name such as "4/3" or "4/7", which refines by the first aperture for the first floor(resolution / 2) levels and by the second for the rest; or one aperture per level, "4,4,7,3". The separator tells the two apart: "4,7" and the family "4/7" are the same grid at resolution 2, but their grids one level coarser are "4" and "7".
For H3 grids, the aperture is fixed at "7" and resolution ranges from 0 to 15.
Slots
apertureCharacter. Grid aperture: "3", "4", "7", a mixed family such as "4/3" or "4/7", or one aperture per resolution level ("4,4,7,3").
resolutionInteger. Grid resolution level: for ISEA 0-30 for aperture 3, 0-29 for aperture 4, 0-21 for aperture 7 on the icosahedron (cell IDs fit in 64 bits); 0-15 for H3.
area_km2Numeric. Cell area in square kilometers.
diagonal_kmNumeric. Centre spacing in kilometers: the short (flat-to-flat) diagonal of a regular hexagon of area
area_km2, \(\sqrt{2A/\sqrt{3}}\).crsInteger or character. Coordinate reference system: an EPSG code, or a 'PROJ' or 'WKT' string. Defaults to 'WGS84' on Earth, and to a longlat CRS on the sphere of
radius_kmon any other body.grid_typeCharacter. Grid system: "isea" (default) or "h3".
radius_kmNumeric. Radius of the body the grid covers, in kilometers.
NAreads as Earth's mean radius.orientationNumeric. Where an ISEA grid's solid sits:
c(vert0_lon, vert0_lat, azimuth)in degrees, vertex 0 and the azimuth of vertex 1 seen from it. Empty for H3 grids, whose orientation H3 fixes.projectionCharacter. How an ISEA-family grid projects each face of its solid onto its plane triangle: "isea" (Snyder's equal-area projection), "ivea" (van Leeuwen and Strebe's vertex-oriented equal-area projection) or "fuller" (Fuller's projection). Empty for H3 grids.
polyhedronCharacter. The solid an ISEA-family grid is built on: "icosahedron" or "octahedron". Empty for H3 grids.
ellipsoidNumeric. The ellipsoid of revolution an ISEA-family grid reads geodetic latitude on,
c(a_km, f): semi-major axis in km and flattening. Empty for a grid that reads latitude on the sphere, and for H3 grids.
Plotting a grid
plot() draws the cells of a grid in 3D, seen from above a chosen point: on the
sphere, or on the flat faces of the solid the grid is built on. All
surfaces take their cell boundaries from the same points, so a cell on the
solid is the cell on the sphere folded flat.
surface = "net" lays the faces out flat, by default in the PLANE
layout of DGGRID (hexify_cell_to_plane gives cell centres in
the same coordinates); layout picks another, such as Van de Sande's
Gosper World on the octahedron (see net_layout). A cell on a
cut of the net is drawn in parts, one on each side. The net is drawn
without a camera, so center, projection, distance,
tilt, rotation and fov apply to the other two
surfaces.
distortion colours the surface by the distortion of the face
projection that maps the sphere onto the faces (see
projection_distortion), and tissot draws Tissot's
indicatrix on the faces: the ellipse each small circle of the sphere maps
to. With graticule on the net, Snyder's projection shows small bends
in the meridians and parallels where they cross the arcs from each face's
centre to its corners.
parents draws the outlines of the cells some resolutions up over
the grid's own cells, to show the hierarchy. On a net of an equal-area
grid, area_legend draws one cell at the scale of the map, with its
area, and the same for each resolution parents draws. tabs
adds glue tabs along the seams of a net, one on each pair of edges glued
together, so a printed net (for example through pdf) folds into
the solid (Carr et al. 1997).
The view is an orthographic projection by default: parallel lines of sight,
so the whole near half of the sphere shows. projection =
"perspective" places a camera distance sphere radii from the
sphere's centre, above center; it sees a smaller cap, and nearer
cells appear larger. tilt swings that camera about the point at
center, which it keeps looking at, so the surface is seen at a slant
with the horizon towards the top; by default the plot frames the whole
visible sphere. fov sets how wide
the camera sees, and rotation turns the view about the line of sight
in either projection.
References
Carr, D. B., Kahn, R., Sahr, K., Olsen, A. R. (1997). ISEA discrete global grids. Statistical Computing & Graphics Newsletter 8(2/3): 31-39.
See also
hex_grid for the constructor function,
HexData-class for hexified data objects
grid_global for the cells as sf polygons,
projection_distortion, net_cells
Examples
grid <- hex_grid(area_km2 = 100000)
grid
summary(grid)
summary(grid)$n_cells
n_cells(grid)
grid$resolution
st_crs(grid)
# Every cell of a coarse grid as sf polygons
cells_sf <- st_as_sf(hex_grid(resolution = 2))
grid <- hex_grid(resolution = 3, aperture = 3)
plot(grid)
plot(grid, surface = "solid")
plot(grid, surface = "solid", land = FALSE, center = "pacific")
plot(grid, projection = "perspective", distance = 2, center = "europe")
plot(grid, surface = "solid", projection = "perspective",
distance = 2.5, tilt = 25, rotation = 30)
plot(grid, surface = "net")
octa <- hex_grid(resolution = 3, aperture = 4, polyhedron = "octahedron",
orientation = "gosper")
plot(octa, surface = "net", layout = "gosper", seams = TRUE, graticule = TRUE)
# \donttest{
# Distortion of the face projections, with Tissot's indicatrix
plot(grid, surface = "net", land = FALSE, distortion = "angular",
tissot = TRUE, graticule = 15, cells = numeric(0))
fuller <- hex_grid(resolution = 3, aperture = 3, projection = "fuller")
plot(fuller, distortion = "areal", land = FALSE, cells = numeric(0))
# Two resolutions with an area legend, and a net to print and fold
fine <- hex_grid(resolution = 4, aperture = 3)
plot(fine, surface = "net", land = FALSE, parents = 1, area_legend = TRUE)
plot(grid, surface = "net", layout = "land", land = FALSE, seams = TRUE,
tabs = TRUE)
# }