| Title: | Map projections |
|---|---|
| Description: | Applies cartographic projections to spatial data frames containing geographic coordinates. Projection methods are based on the D3.js ecosystem <doi:10.1109/TVCG.2011.185> and use spherical geometry rather than ellipsoidal geodesic models. |
| Authors: | Nicolas Lambert [aut, cre] (ORCID: <https://orcid.org/0000-0003-4976-6560>) |
| Maintainer: | Nicolas Lambert <[email protected]> |
| License: | GPL (>= 3) |
| Version: | 0.1.0 |
| Built: | 2026-06-10 15:25:48 UTC |
| Source: | https://github.com/riatelab/planisphere |
Render a complete planisphere from a projected object created with project().
The display includes the projected sphere outline, graticule, and geographic features.
display(x, title = NULL, extent = NULL)display(x, title = NULL, extent = NULL)
x |
A list returned by
|
title |
Character string. Optional title to add to the plot. Default is NULL. |
extent |
object. A spatial extent used to clip or define the mapping area ('sf', 'sfc', or 'bbox'). |
The visualization follows the D3.js spherical projection model used in the package. The rendering order is: 1. Sphere background 2. Graticule 3. Projected landmass (basemap) 4. Sphere outline
All geometries are expected to be already projected in spherical coordinates. This function is intended for fast visualization and exploration of D3-based projections.
a base R plot.
library(sf) world <- st_read( system.file("gpkg/land.gpkg", package = "planisphere"), quiet = TRUE ) result <- planisphere::project( x = world, proj = "Eckert1", additional_layers = TRUE ) planisphere::display(result)library(sf) world <- st_read( system.file("gpkg/land.gpkg", package = "planisphere"), quiet = TRUE ) result <- planisphere::project( x = world, proj = "Eckert1", additional_layers = TRUE ) planisphere::display(result)
Creates a gallery of projected world maps using the projections available in planisphere. By default, a random sample of projections is selected from the projection registry and displayed in a multi-panel layout.
gallery( projections = NULL, sample = 12, ncol = 4, title = TRUE, verbose = TRUE )gallery( projections = NULL, sample = 12, ncol = 4, title = TRUE, verbose = TRUE )
projections |
Character vector of projection names. If 'NULL', projections are selected from 'registry()'. |
sample |
Integer. Number of projections to display when 'projections = NULL'. Ignored if 'projections' is provided. Set to 'NULL' to display all available projections. |
ncol |
Integer. Number of columns in the gallery layout. |
title |
Logical. Should projection names be displayed as titles? |
verbose |
Logical. Display progress messages while rendering projections. |
The function uses the bundled world land dataset and applies each selected projection through [project()]. Maps are displayed using [display()] in a base R graphics layout.
Draws a gallery of projected maps in the current graphics device and returns 'NULL' invisibly.
# Display a random sample of 12 projections gallery(verbose = FALSE) # Display selected projections gallery( projections = c( "Mercator", "Robinson", "Orthographic", "EqualEarth" ), ncol = 2, verbose = FALSE )# Display a random sample of 12 projections gallery(verbose = FALSE) # Display selected projections gallery( projections = c( "Mercator", "Robinson", "Orthographic", "EqualEarth" ), ncol = 2, verbose = FALSE )
Create a new V8 JavaScript context preloaded with the D3.js geospatial stack.
new_v8_context( libs = c("https://cdn.jsdelivr.net/npm/d3@7", "https://cdn.jsdelivr.net/npm/d3-geo@3", "https://cdn.jsdelivr.net/npm/d3-geo-polygon@2", "https://cdn.jsdelivr.net/npm/d3-geo-projection@4"), verbose = TRUE )new_v8_context( libs = c("https://cdn.jsdelivr.net/npm/d3@7", "https://cdn.jsdelivr.net/npm/d3-geo@3", "https://cdn.jsdelivr.net/npm/d3-geo-polygon@2", "https://cdn.jsdelivr.net/npm/d3-geo-projection@4"), verbose = TRUE )
libs |
Character vector of JavaScript library URLs to load. By default, libraries are loaded from the jsDelivr CDN. Users may replace these with local files, pinned versions, or alternative CDNs. |
verbose |
Logical. If TRUE, prints loading status for each library. |
This function initializes a fresh V8 JavaScript runtime and automatically loads the latest versions of the required D3.js libraries from the jsDelivr CDN.
The following JavaScript libraries are loaded by default:
- d3 (core library): https://cdn.jsdelivr.net/npm/d3 - d3-geo (spherical geometry and geographic projections): https://cdn.jsdelivr.net/npm/d3-geo - d3-geo-projection (extended cartographic projections): https://cdn.jsdelivr.net/npm/d3-geo-projection - d3-geo-polygon (spherical polygon clipping): https://cdn.jsdelivr.net/npm/d3-geo-polygon
These libraries are fetched dynamically at runtime from the jsDelivr CDN, ensuring that the most recent compatible versions are used unless explicitly overridden via the 'libs' argument.
All projections computed in this environment rely on D3.js spherical geometry, where the Earth is modeled as a sphere rather than an ellipsoid. This allows fast and consistent computation of map projections and geometric transformations.
A V8 JavaScript context with the D3.js geospatial stack loaded and ready for cartographic computations.
ct <- planisphere::new_v8_context() # Then: library(sf) world <- st_read( system.file("gpkg/land.gpkg", package = "planisphere"), quiet = TRUE ) out <- planisphere::project(x = world, proj = "InterruptedBoggs", ct = ct)ct <- planisphere::new_v8_context() # Then: library(sf) world <- st_read( system.file("gpkg/land.gpkg", package = "planisphere"), quiet = TRUE ) out <- planisphere::project(x = world, proj = "InterruptedBoggs", ct = ct)
A wrapper around D3.js for cartographic projections to design and visualize world maps (planispheres). Projections are computed using D3.js spherical geometry rather than ellipsoidal geodesic models.
Maintainer: Nicolas Lambert [email protected] (ORCID)
Authors:
Nicolas Lambert [email protected] (ORCID)
Useful links:
Report bugs at https://github.com/riatelab/planisphere/issues
Projects spatial data using D3.js geographic projections executed in a V8 JavaScript context. The projection is performed in spherical coordinates, following D3.js design principles, where the Earth is modeled as a sphere rather than an ellipsoid.
project( x, proj = "geoAzimuthalEqualArea", rotate = NULL, reflectX = NULL, reflectY = NULL, scale = 500, center = NULL, parallel = NULL, parallels = NULL, clipExtent = NULL, clip = TRUE, graticule = c(10, 10), additional_layers = FALSE, verbose = FALSE, ct = .planisphere$ct, ... )project( x, proj = "geoAzimuthalEqualArea", rotate = NULL, reflectX = NULL, reflectY = NULL, scale = 500, center = NULL, parallel = NULL, parallels = NULL, clipExtent = NULL, clip = TRUE, graticule = c(10, 10), additional_layers = FALSE, verbose = FALSE, ct = .planisphere$ct, ... )
x |
An |
proj |
A D3 projection name or constructor (e.g. "geoInterruptedHomolosine"). |
rotate |
Rotation parameters passed to the projection. |
reflectX |
Logical; whether to reflect the projection on the X axis. |
reflectY |
Logical; whether to reflect the projection on the Y axis. |
scale |
Projection scale factor (D3 spherical scale, not planar CRS units). |
center |
Optional projection center. |
parallel |
Optional standard parallel of the projection |
parallels |
Optional standard parallels of the projection |
clipExtent |
Projection’s viewport clip extent to the specified bounds in pixels |
clip |
If TRUE, clips the projected geometries to the projected sphere. |
graticule |
Numeric vector of longitude/latitude step size for graticule generation. |
additional_layers |
Logical. If TRUE, adds graticule and sphere layers. In this case, the function returns a list. If FALSE (default), it returns a spatial data frame. |
verbose |
Logical. Display messages |
ct |
A custom V8 JavaScript context if needed. See |
... |
Additional parameters passed to the projection builder. |
D3 geographic projections are based on spherical geometry. All transformations assume a perfect sphere, which differs from traditional GIS pipelines that often rely on ellipsoidal datums (e.g., WGS84). As a result, this function is primarily intended for visualization and cartographic rendering rather than high-precision geodetic computation.
If additionalLayers = FALSE, a single sf object corresponding to the projected basemap.
If additionalLayers = TRUE, a list of sf objects:
basemap: projected input geometries
sphere: outline of the projected globe
graticule: projected graticule lines
library(sf) world <- st_read( system.file("gpkg/land.gpkg", package = "planisphere"), quiet = TRUE ) result <- planisphere::project(x = world, proj = "InterruptedBoggs")library(sf) world <- st_read( system.file("gpkg/land.gpkg", package = "planisphere"), quiet = TRUE ) result <- planisphere::project(x = world, proj = "InterruptedBoggs")
Returns the list of available map projections registered in planisphere. Projections are organized into thematic families to facilitate exploration and selection.
By default, all projections are returned as a single sorted character vector. Alternatively, a specific family of projections can be requested.
registry(type = NULL)registry(type = NULL)
type |
Character. Optional projection family. Must be one of: "cylindrical", "conic", "azimuthal", "perspective", "pseudocylindrical", "interrupted", "polyhedral", "quincuncial", "regional", "pseudoazimuthal", "miscellaneous". |
A sorted unique character vector of projection names. If 'type' is provided, only projections belonging to the selected family are returned.
# List all available projections # List cylindrical projections registry(type = "cylindrical") # Explore regional projections registry("regional") # Visualize polyhedral projections gallery(projections = registry("polyhedral"), verbose = FALSE)# List all available projections # List cylindrical projections registry(type = "cylindrical") # Explore regional projections registry("regional") # Visualize polyhedral projections gallery(projections = registry("polyhedral"), verbose = FALSE)