Javatpoint Logo
Javatpoint Logo

Geographies in D3.js

The geospatial coordinates are commonly used for population data or weather. D3.js provides three essential tools for any geographic data, which are listed below:

  • Paths
  • Projections
  • Streams

Paths: These tools are used to generate ultimate pixels.

Projections: The projection tools can change the sphere coordinates towards Cartesian Coordinates.

Streams: These tools can be used to speed-up things.

The following two terminologies are important to learn before learn the D3.js geographies:

  • D3 Geo Path
  • Projections

D3 Geo Path

The D3 Geo Path is a type of generator for geographic path. GeoJSON produces a data string of SVG path or delivers the path towards a Canvas. The Canvas is suggested for interactive and dynamic projections for improving the performance. We can call a function to produce the Data Generator of D3 Geo Path, which is as follows:

The above function permits us to choose which Projection Map we wish to apply for conversion from Coordinates Geo to Coordinates Cartesian.

If we wish to display India's map details, we can use a path which is illustrated below:

The projection in d3 geographies is discussed as follows:


The projection converts the spherical geometry polygonal to the planar geometry polygonal.

The D3 gives some projection implementation, which is as follows:

Azimuthal: This projection can project any sphere on a plane directly.

Composite: The composite projection consists of various projections composed in a single display.

Conic: It projects any sphere on the cone, and that cone will be unrolled over the plane.

Cylindrical: This projection can project a sphere on the containing cylinder after that, that cylinder will be unrolled over the plane.

To design any new projection, we can apply a function written below:

The above function can build any new projection through a specified raw project projection. The function project holds the latitude and longitude of the provided points inside the radians.

We can use the projection inside our code as mentioned below:

Let's explain the projections which are mentioned in the above projection:

d3.geo.orthographic()- This projection is a type of azimuthal projection. It is suitable to show an individual hemisphere; the perspective's point is at the infinity.

d3.geo.gnomonic()- It is also a type of azimuthal projection and it can project various circles same as the straight lines.

d3.geo.equirectangular()- An equirectangular projection is most simplest geographic projection. This projection is not any conformal and not any equal area, but sometimes it is applied on the raster data.

d3.geo.mercator()- This projection is most widely used projection. It is applied by libraries of tiled mapping.

Next TopicTimer API in D3.js

Youtube For Videos Join Our Youtube Channel: Join Now

Help Others, Please Share

facebook twitter pinterest

Learn Latest Tutorials


Trending Technologies

B.Tech / MCA