carto

package
v0.56.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 20, 2025 License: MIT Imports: 4 Imported by: 0

README

carto package

Documentation

Package carto provides cartography functionality for working with and making maps.

This includes:

  • Various projections between angular coordinates (longitude and latitude) and planar coordinates (x and y).

  • Earth radius definitions.

See godoc for the full package documentation.


The following section shows supported projections. The code used to generate the images in this section can be found here.

Equirectangular projection

Standard parallels are set to 36°N and 36°S. This configuration of the Equirectangular projection is also known as the Marinus (of Tyre) projection.

Equirectangular projection

Web Mercator projection

This is the full zoom 0 tile of the Web Mercator projection.

Web Mercator projection

Lambert Cylindrical Equal Area projection

The central meridian is set to 0°E.

Lambert Cylindrical Equal Area projection

Sinusoidal projection

The central meridian is set to 0°E.

Sinusoidal projection

Orthographic projection

Centered on North America at 45°N, 105°W.

Orthographic projection

Azimuthal Equidistant projection

Centered at Sydney, Australia at 151°E, 34°S.

Azimuthal Equidistant projection

Equidistant Conic projection

Standard parallels are set to 30°N and 60°N. The central meridian is set to 0°E.

Equidistant Conic projection

Albers Equal Area Conic projection

Standard parallels are set to 30°N and 60°N. The central meridian is set to 0°E.

Albers Equal Area Conic projection

Lambert Conformal Conic projection

Standard parallels are set to 30°N and 60°N. The central meridian is set to 0°E.

Lambert Conformal Conic projection

Documentation

Overview

Package carto provides cartography functionality for working with and making maps.

This includes:

  • Various projections between angular coordinates (longitude and latitude) and planar coordinates (x and y).

  • Earth radius definitions.

Index

Constants

View Source
const (
	// WGS84EllipsoidEquatorialRadiusM is the radius of the WGS84 ellipsoid at
	// the equator.
	WGS84EllipsoidEquatorialRadiusM = 6378137.0

	// WGS84EllipsoidPolarRadiusM is the radius of the WGS84 ellipsoid at the poles.
	WGS84EllipsoidPolarRadiusM = 6356752.314245

	// WGS84EllipsoidMeanRadiusM is the mean radius of the WGS84 ellipsoid.
	WGS84EllipsoidMeanRadiusM = (2*WGS84EllipsoidEquatorialRadiusM + WGS84EllipsoidPolarRadiusM) / 3
)

Variables

This section is empty.

Functions

This section is empty.

Types

type AlbersEqualAreaConic

type AlbersEqualAreaConic struct {
	// contains filtered or unexported fields
}

AlbersEqualAreaConic allows projecting (longitude, latitude) coordinates to (x, y) pairs via the Albers equal area conic projection.

The Albers equal area conic projection is a conic projection that is:

  • Configured by setting two standard parallels.
  • Equal area.
  • Not conformal, but preserves shape locally at the standard parallels.

func NewAlbersEqualAreaConic

func NewAlbersEqualAreaConic(earthRadius float64) *AlbersEqualAreaConic

NewAlbersEqualAreaConic returns a new AlbersEqualAreaConic projection with the given earth radius. The standard parallels are set to 30 and 60 degrees north.

func (*AlbersEqualAreaConic) Forward

func (c *AlbersEqualAreaConic) Forward(lonlat geom.XY) geom.XY

Forward converts a (longitude, latitude) pair expressed in degrees to a projected (x, y) pair.

func (*AlbersEqualAreaConic) Reverse

func (c *AlbersEqualAreaConic) Reverse(xy geom.XY) geom.XY

Reverse converts a projected (x, y) pair to a (longitude, latitude) pair expressed in degrees.

func (*AlbersEqualAreaConic) SetOrigin

func (c *AlbersEqualAreaConic) SetOrigin(origin geom.XY)

SetOrigin sets the origin of the projection to the given (longitude, latitude) pair. The origin has projected coordinates (0, 0).

func (*AlbersEqualAreaConic) SetStandardParallels

func (c *AlbersEqualAreaConic) SetStandardParallels(lat1, lat2 float64)

SetStandardParallels sets the standard parallels of the projection to the given latitudes expressed in degrees.

type AzimuthalEquidistant

type AzimuthalEquidistant struct {
	// contains filtered or unexported fields
}

AzimuthalEquidistant allows projecting (longitude, latitude) coordinates to (x, y) pairs via the azimuthal equidistant projection.

The azimuthal equidistant projection is a projection that is:

  • Configured by setting a center point.
  • Equidistant. Distances from the center point are correctly scaled.
  • Azimuthal. Directions from the center point are correctly preserved.
  • Not conformal, but preserves shape locally at the center point.
  • Not equal area, but preserves area locally at the center point.

func NewAzimuthalEquidistant

func NewAzimuthalEquidistant(earthRadius float64) *AzimuthalEquidistant

NewAzimuthalEquidistant returns a new AzimuthalEquidistant projection with the given earth radius.

func (*AzimuthalEquidistant) Forward

func (a *AzimuthalEquidistant) Forward(lonLat geom.XY) geom.XY

Forward converts a (longitude, latitude) pair expressed in degrees to a projected (x, y) pair.

func (*AzimuthalEquidistant) Reverse

func (a *AzimuthalEquidistant) Reverse(xy geom.XY) geom.XY

Reverse converts a projected (x, y) pair to a (longitude, latitude) pair expressed in degrees.

func (*AzimuthalEquidistant) SetCenter

func (a *AzimuthalEquidistant) SetCenter(centerLonLat geom.XY)

SetCenterLonLat sets the center of the projection to the given (longitude, latitude) pair. The center have projected coordinates (0, 0) and be the center of the circular map.

type EquidistantConic

type EquidistantConic struct {
	// contains filtered or unexported fields
}

EquidistantConic allows projecting (longitude, latitude) coordinates to (x, y) pairs via the equidistant conic projection.

The equidistant conic projection is a conic projection that is:

  • Configured by setting two standard parallels.
  • Not equidistant, but has correctly scaled distance along all meridians and the two standard parallels.
  • Not conformal, but preserves shape locally at the standard parallels.
  • Not equal area, but preserves area locally at the standard parallels.

func NewEquidistantConic

func NewEquidistantConic(earthRadius float64) *EquidistantConic

NewEquidistantConic returns a new EquidistantConic projection with the given earth radius.

func (*EquidistantConic) Forward

func (c *EquidistantConic) Forward(lonlat geom.XY) geom.XY

Forward converts a (longitude, latitude) pair expressed in degrees to a projected (x, y) pair.

func (*EquidistantConic) Reverse

func (c *EquidistantConic) Reverse(xy geom.XY) geom.XY

Reverse converts a projected (x, y) pair to a (longitude, latitude) pair expressed in degrees.

func (*EquidistantConic) SetOrigin

func (c *EquidistantConic) SetOrigin(lonLat geom.XY) *EquidistantConic

SetOrigin sets the origin of the projection to the given (longitude, latitude) pair. The origin have projected coordinates (0, 0).

func (*EquidistantConic) SetStandardParallels

func (c *EquidistantConic) SetStandardParallels(lat1, lat2 float64) *EquidistantConic

SetStandardParallels sets the standard parallels of the projection to the given latitudes expressed in degrees.

type Equirectangular

type Equirectangular struct {
	// contains filtered or unexported fields
}

Equirectangular allows projecting (longitude, latitude) coordinates to (x, y) pairs via the equirectangular projection.

The equirectangular projection is a cylindrical projection that is:

  • Configured by setting the central meridian and two standard parallels that are symmetric about the equator.
  • Not equal area, but preserves area locally at the standard parallels.
  • Not conformal, but preserves shape locally at the standard parallels.
  • Not equidistant, but preserves distance locally at the standard parallels.

func NewEquirectangular

func NewEquirectangular(earthRadius float64) *Equirectangular

NewEquirectangular returns a new Equirectangular projection with the given earth radius.

func (*Equirectangular) Forward

func (e *Equirectangular) Forward(lonLat geom.XY) geom.XY

Forward converts a (longitude, latitude) pair expressed in degrees to a projected (x, y) pair.

func (*Equirectangular) Reverse

func (e *Equirectangular) Reverse(xy geom.XY) geom.XY

Reverse converts a projected (x, y) pair to a (longitude, latitude) pair expressed in degrees.

func (*Equirectangular) SetCentralMeridian

func (e *Equirectangular) SetCentralMeridian(lon float64)

SetCentralMeridian sets the central meridian of the projection to the given longitude expressed in degrees.

func (*Equirectangular) SetStandardParallels

func (e *Equirectangular) SetStandardParallels(lat float64)

SetStandardParallels sets the standard parallels of the projection to the given latitude and its negative, expressed in degrees. E.g. providing 35 will set the standard parallels to 35 and -35.

type LambertConformalConic

type LambertConformalConic struct {
	// contains filtered or unexported fields
}

LambertConformalConic allows projecting (longitude, latitude) coordinates to (x, y) pairs via the Lambert conformal conic projection.

The Lambert conformal conic projection is a conic projection that is:

  • Configured by setting two standard parallels.
  • Conformal. Shape is preserved locally at all points.
  • Not equal area, but preserves area locally at the standard parallels.
  • Not equidistant, but preserves distance locally along the standard parallels.

func NewLambertConformalConic

func NewLambertConformalConic(earthRadius float64) *LambertConformalConic

NewLambertConformalConic returns a new LambertConformalConic projection with the given earth radius.

func (*LambertConformalConic) Forward

func (c *LambertConformalConic) Forward(lonlat geom.XY) geom.XY

Forward converts a (longitude, latitude) pair expressed in degrees to a projected (x, y) pair.

func (*LambertConformalConic) Reverse

func (c *LambertConformalConic) Reverse(xy geom.XY) geom.XY

Reverse converts a projected (x, y) pair to a (longitude, latitude) pair expressed in degrees.

func (*LambertConformalConic) SetOrigin

func (c *LambertConformalConic) SetOrigin(origin geom.XY)

SetOrigin sets the origin of the projection to the given (longitude, latitude) pair. The origin have projected coordinates (0, 0).

func (*LambertConformalConic) SetStandardParallels

func (c *LambertConformalConic) SetStandardParallels(lat1, lat2 float64)

SetStandardParallels sets the standard parallels of the projection to the given latitudes expressed in degrees.

type LambertCylindricalEqualArea

type LambertCylindricalEqualArea struct {
	// contains filtered or unexported fields
}

LambertCylindricalEqualArea allows projecting (longitude, latitude) coordinates to (x, y) pairs via the Lambert cylindrical equal area projection.

The Lambert cylindrical equal area projection is a cylindrical projection that is:

  • Configured by setting the central meridian.
  • Equal area.
  • Not conformal, but preserves shape locally along the equator.
  • Not equidistant, but preserves distance along the equator.

func NewLambertCylindricalEqualArea

func NewLambertCylindricalEqualArea(radius float64) *LambertCylindricalEqualArea

NewLambertCylindricalEqualArea returns a new LambertCylindricalEqualArea projection with the given earth radius.

func (*LambertCylindricalEqualArea) Forward

func (c *LambertCylindricalEqualArea) Forward(lonLat geom.XY) geom.XY

Forward converts a (longitude, latitude) pair expressed in degrees to a projected (x, y) pair.

func (*LambertCylindricalEqualArea) Reverse

func (c *LambertCylindricalEqualArea) Reverse(xy geom.XY) geom.XY

Reverse converts a projected (x, y) pair to a (longitude, latitude) pair expressed in degrees.

func (*LambertCylindricalEqualArea) SetCentralMeridian

func (c *LambertCylindricalEqualArea) SetCentralMeridian(lon float64)

SetCentralMeridian sets the central meridian of the projection to the given longitude expressed in degrees.

type Orthographic

type Orthographic struct {
	// contains filtered or unexported fields
}

Orthographic allows projecting (longitude, latitude) coordinates to (x, y) pairs via the orthographic projection.

The orthographic projection projects the sphere onto a tangent plane with a point of perspective that is infinitely far away. It gives a view of the earth as seen from outer space.

It is:

  • Configured by setting the center of the projection.
  • Not conformal, equal area or equidistant, but preserves shape, area, and distance locally at the center of the projection.

func NewOrthographic

func NewOrthographic(radius float64) *Orthographic

NewOrthographic returns a new Orthographic projection with the given earth radius.

func (*Orthographic) Forward

func (m *Orthographic) Forward(lonLat geom.XY) geom.XY

Forward converts a (longitude, latitude) pair expressed in degrees to a projected (x, y) pair.

func (*Orthographic) Reverse

func (m *Orthographic) Reverse(xy geom.XY) geom.XY

Reverse converts a projected (x, y) pair to a (longitude, latitude) pair expressed in degrees.

func (*Orthographic) SetCenter

func (m *Orthographic) SetCenter(centerLonLat geom.XY)

SetCenter sets the center of the projection to the given (longitude, latitude) pair. The center have projected coordinates (0, 0) and be the center of the circular map.

type Sinusoidal

type Sinusoidal struct {
	// contains filtered or unexported fields
}

Sinusoidal allows projecting (longitude, latitude) coordinates to (x, y) pairs via the sinusoidal projection.

The sinusoidal projection is a pseudocylindrical projection that is:

  • Configured by setting the central meridian.
  • Equal area.
  • Not conformal, but preserves shape locally along the central meridian and equator.
  • Not equidistant, but preserves distance locally along all parallels and the central meridian.

func NewSinusoidal

func NewSinusoidal(earthRadius float64) *Sinusoidal

NewSinusoidal returns a new Sinusoidal projection with the given earth radius.

func (*Sinusoidal) Forward

func (c *Sinusoidal) Forward(lonLat geom.XY) geom.XY

Forward converts a (longitude, latitude) pair expressed in degrees to a projected (x, y) pair.

func (*Sinusoidal) Reverse

func (c *Sinusoidal) Reverse(xy geom.XY) geom.XY

Reverse converts a projected (x, y) pair to a (longitude, latitude) pair expressed in degrees.

func (*Sinusoidal) SetCentralMeridian

func (c *Sinusoidal) SetCentralMeridian(lon float64)

SetCentralMeridian sets the central meridian of the projection to the given longitude expressed in degrees.

type UTM added in v0.54.0

type UTM struct {
	// contains filtered or unexported fields
}

UTM allows projecting (longitude, latitude) coordinates to (x, y) pairs via a UTM (Universal Transverse Mercator) projection.

There are 60 UTM zones, each covering 6 degrees of longitude. There is a different set of projections for the northern and southern hemispheres, resulting in 120 distinct UTM projections in total.

UTM projections are:

  • Configured by a UTM zone and hemisphere designator.
  • Conformal, but not equal area or equidistant. Despite not being equal area or equidistant, area and distance are only degrade a small amount within the bounds of a particular UTM zone.

func NewUTMFromCode added in v0.54.0

func NewUTMFromCode(code string) (*UTM, error)

NewUTMFromCode creates a UTM projection using the given UTM zone and hemisphere code. Codes are composed the zone (with leading zero to pad to 2 digits) and an N or S designator. E.g. "06N" and "56S".

func NewUTMFromLocation added in v0.54.0

func NewUTMFromLocation(lonlat geom.XY) (*UTM, error)

NewUTMFromLocation creates a UTM projection using the appropriate UTM zone and hemisphere for the given location.

func (*UTM) Code added in v0.54.0

func (u *UTM) Code() string

Code returns the UTM code for this projection, which is the zone (with leading zero to pad to 2 digits) and an N or S designator. E.g. "06N" and "56S".

func (*UTM) Forward added in v0.54.0

func (u *UTM) Forward(lonlat geom.XY) geom.XY

Forward converts a (longitude, latitude) pair expressed in degrees to a projected (easting, northing) pair expressed in meters.

func (*UTM) Reverse added in v0.54.0

func (u *UTM) Reverse(xy geom.XY) geom.XY

Reverse converts a projected (easting, northing) pair expressed in meters to a (longitude, latitude) pair expressed in degrees.

type WebMercator

type WebMercator struct {
	// contains filtered or unexported fields
}

WebMercator is a variant of the Web Mercator projection that is used for web maps. The projection maps between (latitude, longitude) pairs expressed in degrees, and (x, y) pairs. The x and y coordinates are in the range 0 to 2^zoom, where zoom is the zoom level of the map.

The x coordinate increases from left to right, and the y coordinate increases from top to bottom.

It is:

  • Conformal (shape is preserved locally at all points).
  • Not equal area.
  • Not equidistant.

func NewWebMercator

func NewWebMercator(zoom int) *WebMercator

NewWebMercator returns a new WebMercator projection with the given zoom.

func (*WebMercator) Forward

func (m *WebMercator) Forward(lonlat geom.XY) geom.XY

Forward converts a (longitude, latitude) pair expressed in degrees to a projected (x, y) pair.

func (*WebMercator) Reverse

func (m *WebMercator) Reverse(xy geom.XY) geom.XY

Reverse converts a projected (x, y) pair to a (longitude, latitude) pair expressed in degrees.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL