Skip to content
mbostock edited this page Jun 4, 2012 · 100 revisions

WikiAPI ReferenceGeoGeo Projections

Mercator

The spherical Mercator projection is commonly used by tiled mapping libraries (such as OpenLayers and Leaflet). It is conformal; however, it introduces severe area distortion at world scale and thus is not recommended for choropleths.

# d3.geo.mercator()

Construct a new spherical Mercator projection with the default scale (500) and translate ([480, 250]). The default Mercator projection is appropriate for displaying the entire world in a 960×500 area.

# mercator(location)

The forward projection: returns a two-element array [x, y] given the input [longitude, latitude].

# mercator.invert(point)

The inverse projection: returns a two-element array [longitude, latitude] given the input [x, y].

# mercator.scale([scale])

Get or set the projection’s scale factor. If scale is specified, sets the projection’s scale factor to the specified value and returns the projection. If scale is not specified, returns the current scale factor which defaults to 500. The scale factor corresponds linearly to the distance between projected points. Note that scale factors may not be consistent across projection types (e.g., Mercator and Albers).

# mercator.translate([offset])

Get or set the projection's translation offset. If offset is specified, sets the projection’s translation offset to the specified two-element array [x, y] and returns the projection. If offset is not specified, returns the current translation offset which defaults to [480, 250]. The translation offset determines the pixel coordinates of the origin ([0, 0] in longitude and latitude). The default value is designed to place null island at the center of a 960×500 area.

Albers

The Albers equal-area projection is highly recommended for choropleths as it does not preserves the relative areas of geographic features. However, you must determine appropriate parallels and origin.

# d3.geo.albers()

Construct a new Albers equal-area conic projection with the default scale (1000), translate ([480, 250]), origin ([-98, 38]) and parallels ([29.5, 45.5]). The default Albers projection is appropriate for displaying the United States in a 960×500 area. The parallels of 29.5º and 45.5º were chosen by the USGS in their 1970 National Atlas.

# albers(location)

The forward projection: returns a two-element array [x, y] given the input [longitude, latitude].

# albers.invert(point)

The inverse projection: returns a two-element array [longitude, latitude] given the input [x, y].

# albers.origin([origin])

Get or set the projection’s origin. If origin is specified, sets the projection’s origin to the specified two-element array [longitude, latitude] and returns the projection. If origin is not specified, returns the current origin, which defaults to [-98, 38] (Hutchinson, Kansas). To minimize the distortion of parallel lines, the origin should be chosen to be near the center of the region of interest.

# albers.*parallels([parallels])

Get or set the projection’s two standard parallels. If parallels is specified, sets the projection’s parallels to the specified two-element array of latitudes and returns the projection. If parallels is not specified, returns the current parallels, which default to [29.5, 45.5]. To minimize the distortion of parallel lines, the parallels should surround the origin and cover the region of interest.

# albers.scale([scale])

Get or set the projection’s scale factor. If scale is specified, sets the projection’s scale factor to the specified value and returns the projection. If scale is not specified, returns the current scale factor which defaults to 500. The scale factor corresponds linearly to the distance between projected points. Note that scale factors may not be consistent across projection types (e.g., Mercator and Albers).

# albers.translate([offset])

Get or set the projection's translation offset. If offset is specified, sets the projection’s translation offset to the specified two-element array [x, y] and returns the projection. If offset is not specified, returns the current translation offset which defaults to [480, 250]. The translation offset determines the pixel coordinates of the origin. The default value is designed to place Hutchinson, Kansas at the center of a 960×500 area.

Albers USA (Composite)

# d3.geo.albersUsa()

Construct a new composite Albers projection for the United States.

# albersUsa(position)

Project the specified position.

# albersUsa.scale([scale])

Get or set the projection's scale factor.

# albersUsa.translate([offset])

Get or set the projection's translate offset.

Azimuthal

# d3.geo.azimuthal()

Construct a new Azimuthal (orthographic or stereographic) projection.

# azimuthal(position)

Project the specified position.

# azimuthal.mode([mode])

Get or set the projection's mode (orthographic or stereographic).

# azimuthal.origin([origin])

Get or set the projection's origin.

# azimuthal.scale([scale])

Get or set the projection's scale factor.

# azimuthal.translate([offset])

Get or set the projection's translate offset.

Clone this wiki locally