A quadmesh is a dense mesh describing a topologically continuous surface of 4-corner primitives. This is also known as a cell-based raster but in those contexts the corner coordinates and the continuous nature of the mesh is completely implicit. By making the dense mesh explicit we have access to every corner coordinate (not just the centres) which allows for some extra facilities over raster grids.

This package provides helpers for working with this mesh interpretation of gridded data to enable

  • arbitrary reprojection of raster cells without information loss (mesh_plot).
  • the corner-based continuous interpretation of a grid (quadmesh()).
  • the centre-based continuous interpretation of a grid (triangmesh()).
  • the corner-based discrete interpretation of a grid (dquadmesh()).
  • the centre-based discrete interpretation of a grid (dtriangmesh()).
  • easy plotting of grids in 3D visualization tools (quad or triangle primitives for rgl::shade3d).
  • fast polygonization of individual cells, in spex::polygonize.
  • barycentric interpolation from a triangle mesh (bary_index()).
  • conversion from quad to triangle primitives from the area interpretation (triangulate_quads()).


You can install:

  • the latest released version from CRAN with
  • the latest development version from Github with


Quadmesh provides a number of key features that are not readily available to more commonly used geospatial applications.

The corner-based interpretation of a grid

In raster there is an implicit “area-based” interpretion of the extent and value of every cell. Coordinates are implicit, and centre-based but the extent reflects a finite and constant width and height.

Every individual quad is described implicitly by index into the unique corner coordinates. This format is built upon the mesh3d class of the rgl package.

This separation of geometry (the 20 unique corner coordinates) and topology (12 sets of 4-index) is the key concept of a mesh and is found in many domains that involve computer graphics and modelling.

The centre-based interpretation of a grid

A quadmesh is centre-based, and each raster pixel occupies a little rectangle, but the centre-based interpretation is better described by a mesh of triangles.

Every centre point of the grid data is a node in this mesh, while the inside corners with their ambiguous value from 4 neighbouring cells are not explicit. Note that a triangulation can be top-left/bottom-right aligned as here, or bottom-left/top-right aligned, or be a mixture.

Arbitrary reprojection of raster cells

The in-built etopo data set is used to create a plot in a local map projection. Here each cell is drawn by reprojecting it directly and individually into this new coordinate system.

#>    user  system elapsed 
#>    0.51    0.08    0.60
#> 37.7 kB
#> 1.68 MB
#> 169 kB

The data size and timing benefits are more substantial for larger data sets.

We get exactly what we asked for from mesh_plot, without the complete remodelling of the data required by grid resampling.

Easy 3D plotting of grids

The quadmesh and triangmesh types are extensions of the rgl class mesh3d, and so are readily used by that package’s high level functions such as shade3d() and addNormals().

Fast polygonization of individual cells

The spex package has functions polygonize() and qm_rasterToPolygons_sp() which provide very fast conversion of raster grids to a polygon layer with 5 explicit coordinates for every cell. (stars and sf now provide an even faster version by using GDAL).

Barycentric interpolation from a triangle mesh

Using a triangulation version of a raster grid we can build an index of weightings for a new of of arbitrary coordinates to estimate the implicit value at each point as if there were continuous interpolation across each primitive.

WIP - see bary_index() function.


Have feedback/ideas? Please let me know via issues.

Many aspects of this package have developed in conjunction with the angstroms package for dealing with ROMS model output.

Please note that this project is released with a Contributor Code of Conduct. By participating in this project you agree to abide by its terms.