What is d3-geo-projection?
The d3-geo-projection npm package is an extension of the D3.js library that provides a variety of geographic projections. It allows you to transform geographic coordinates into a variety of different map projections, which can be used for data visualization, cartography, and geographic analysis.
What are d3-geo-projection's main functionalities?
Azimuthal Equidistant Projection
This feature allows you to create an Azimuthal Equidistant projection, which is useful for showing distances from a central point.
const d3 = require('d3-geo-projection');
const projection = d3.geoAzimuthalEquidistant();
const coordinates = projection([0, 0]);
console.log(coordinates);
Mercator Projection
This feature allows you to create a Mercator projection, which is commonly used for navigation maps.
const d3 = require('d3-geo-projection');
const projection = d3.geoMercator();
const coordinates = projection([0, 0]);
console.log(coordinates);
Orthographic Projection
This feature allows you to create an Orthographic projection, which is useful for creating a globe-like view of the Earth.
const d3 = require('d3-geo-projection');
const projection = d3.geoOrthographic();
const coordinates = projection([0, 0]);
console.log(coordinates);
Other packages similar to d3-geo-projection
proj4
Proj4 is a library for performing cartographic transformations. It supports a wide range of projections and is highly configurable. Compared to d3-geo-projection, proj4 is more focused on the mathematical transformations and less on the visualization aspects.
leaflet
Leaflet is a popular open-source JavaScript library for mobile-friendly interactive maps. While it does not provide as many projection options as d3-geo-projection, it is highly effective for creating interactive maps with a variety of base layers and overlays.
mapbox-gl
Mapbox GL JS is a JavaScript library that uses WebGL to render interactive maps from vector tiles and Mapbox styles. It offers fewer projection options compared to d3-geo-projection but excels in rendering performance and interactive features.
Extended Geographic Projections
airy
| aitoff
| albers *
| albersUsa *
|
armadillo
| august
| azimuthalEqualArea *
| azimuthalEquidistant *
|
baker
| berghaus
| boggs
| bonne
|
bromley
| chamberlin
| collignon
| conicEqualArea *
|
conicConformal *
| conicEquidistant *
| craig
| craster
|
cylindricalEqualArea
| cylindricalStereographic
| eckert1
| eckert2
|
eckert3
| eckert4
| eckert5
| eckert6
|
eisenlohr
| equirectangular *
| fahey
| gilbert
|
gingery
| ginzburg4
| ginzburg5
| ginzburg6
|
ginzburg8
| ginzburg9
| gnomonic *
| gringorten
|
guyou
| hammer
| hammerRetroazimuthal
| healpix
|
hill
| homolosine
| kavrayskiy7
| lagrange
|
larrivee
| laskowski
| littrow
| loximuthal
|
mercator *
| miller
| modifiedStereographic
| mollweide
|
mtFlatPolarParabolic
| mtFlatPolarQuartic
| mtFlatPolarSinusoidal
| naturalEarth
|
nellHammer
| orthographic *
| patterson
| peirceQuincuncial
|
polyconic
| polyhedron.butterfly
| polyhedron.waterman
| rectangularPolyconic
|
robinson
| satellite
| sinuMollweide
| sinusoidal
|
stereographic *
| times
| twoPointAzimuthal
| twoPointEquidistant
|
transverseMercator *
| vanDerGrinten
| vanDerGrinten2
| vanDerGrinten3
|
vanDerGrinten4
| wagner4
| wagner6
| wagner7
|
wiechel
| winkel3
|
Projections:
- aitoff - Aitoff
- airy - Airy’s minimum-error azimuthal
- albers - Albers equal-area conic
- armadillo - Armadillo
- august - August conformal
- azimuthalEqualArea - Lambert azimuthal equal-area
- azimuthalEquidistant - azimuthal equidistant
- baker - Baker Dinomic
- berghaus - Berghaus Star
- boggs - Boggs eumorphic
- bonne - Bonne
- bromley - Bromley
- chamberlin - Chamberlin trimetric
- collignon - Collignon
- conicConformal - Lambert conformal conic
- conicEquidistant - conic equidistant
- craig - Craig retroazimuthal
- craster - Craster parabolic
- cylindricalEqualArea - cylindrical equal-area, Gall–Peters, Hobo–Dyer, Tobler world-in-a-square
- cylindricalStereographic - cylindrical stereographic, Gall’s stereographic
- eckert1 - Eckert I
- eckert2 - Eckert II
- eckert3 - Eckert III
- eckert4 - Eckert IV
- eckert5 - Eckert V
- eckert6 - Eckert VI
- eisenlohr - Eisenlohr conformal
- equirectangular - Equirectangular (Plate Carrée), Cassini
- fahey - Fahey
- foucaut - Foucaut
- gilbert - Gilbert’s two-world perspective (Note: this wraps a projection such as d3.geo.orthographic.)
- gingery - Gingery
- ginzburg4 - Ginzburg IV
- ginzburg5 - Ginzburg V
- ginzburg6 - Ginzburg VI
- ginzburg8 - Ginzburg VIII
- ginzburg9 - Ginzburg IX
- gnomonic - gnomonic
- gringorten - Gringorten
- guyou - Guyou hemisphere-in-a-square
- hammer - Hammer, Eckert–Greifendorff, quartic authalic, Briesemeister
- hammerRetroazimuthal - Hammer retroazimuthal
- healpix - HEALPix
- hill - Hill eucyclic, Maurer No. 73
- homolosine - Goode homolosine
- kavrayskiy7 - Kavrayskiy VII
- lagrange - Lagrange conformal
- larrivee - Larrivée
- laskowski - Laskowski tri-optimal
- littrow - Littrow
- loximuthal - loximuthal
- mercator - Mercator
- miller - Miller
- modifiedStereographic - modified stereographic
- mollweide - Mollweide, Atlantis
- mtFlatPolarParabolic - McBryde–Thomas flat-polar parabolic
- mtFlatPolarQuartic - McBryde–Thomas flat-polar quartic
- mtFlatPolarSinusoidal - McBryde–Thomas flat-polar sinusoidal
- naturalEarth - Natural Earth
- nellHammer - Nell–Hammer
- orthographic - orthographic
- patterson - patterson
- peirceQuincuncial - Pierce quincuncial
- polyconic - polyconic
- rectangularPolyconic - rectangular polyconic
- robinson - Robinson
- satellite - satellite (tilted perpsective)
- sinusoidal - sinusoidal
- sinuMollweide - Sinu-Mollweide
- stereographic - stereographic
- times - Times
- transverseMercator - transverse Mercator
- twoPointAzimuthal - two-point azimuthal
- twoPointEquidistant - two-point equidistant
- vanDerGrinten - Van der Grinten
- vanDerGrinten2 - Van der Grinten II
- vanDerGrinten3 - Van der Grinten III
- vanDerGrinten4 - Van der Grinten IV
- wagner4 - Wagner IV, Putniṇš P2´
- wagner6 - Wagner VI
- wagner7 - Wagner VII
- wiechel - Wiechel
- winkel3 - Winkel tripel
This plugin also provides d3.geo.interrupt, which can be used to create arbitrary interrupted projections from a given raw projection. For example, see Philbrick’s interrupted Sinu-Mollweide.
This plugin requires D3 3.0 or greater. To use the official hosted version, include the projection plugin after including D3:
<script src="http://d3js.org/d3.v3.min.js" charset="utf-8"></script>
<script src="http://d3js.org/d3.geo.projection.v0.min.js" charset="utf-8"></script>
Alternatively, you can clone this repo, download the zipball, or right-click d3.geo.projection.v0.min.js and save.
To use this plugin within a Node.js context, you can npm install d3 d3-geo-projection
and then say:
var d3 = require("d3");
require("d3-geo-projection")(d3);
Subsequently, d3.geo
will contain all the extended projections.
Defining a New Projection
First define your raw projection function:
function cosinusoidal(λ, φ) {
return [λ * Math.sin(φ), φ];
}
cosinusoidal.invert = function(x, y) {
return [x / Math.sin(y), y];
};
Then create a constructor using d3.geo.projection:
d3.geo.cosinusoidal = function() {
return d3.geo.projection(cosinusoidal);
};
You can optionally expose the raw projection to facilitate composite projections:
(d3.geo.cosinusoidal = function() {
return d3.geo.projection(cosinusoidal);
}).raw = cosinusoidal;