wgs84

package module
v1.1.7 Latest Latest
Warning

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

Go to latest
Published: Mar 7, 2023 License: MIT Imports: 3 Imported by: 12

README

wgs84

Build Status go.dev reference Go Report Card golangci-lint Codecov tippin.me GitHub tag (latest SemVer)

A zero-dependency Go package for coordinate transformations.

go get github.com/wroge/wgs84

Usage

east, north, h := wgs84.LonLat().To(wgs84.ETRS89UTM(32)).Round(2)(9, 52, 0)
// 500000 5.76103821e+06 0

east, north, h := wgs84.To(wgs84.WebMercator())(9, 52, 0)
// 1.0018754171394621e+06 6.800125454397305e+06 -9.313225746154785e-10

epsg := wgs84.EPSG()

lon, lat, h := wgs84.ETRS89UTM(32).To(epsg.Code(4326)).Round(3)(500150, 5761200, 0)
// 9.002 52.001 0

// EPSG-Codes covering the coordinate {longitude: 9, latitude: 52}:
codes := epsg.CodesCover(9, 52)
// [25832 4314 32632 4978 4258 31467 4326 3857 900913]

Features

  • Helmert Transformation
  • Web Mercator
  • Lambert Conformal Conic
  • Transverse Mercator (UTM)
  • EPSG-Code Coverage
  • ...
  • Easily expandable through simple Interfaces

Documentation

Index

Constants

View Source
const (
	// A is the major axis from the WGS84 spheroid.
	A = 6378137

	// A is the inverse flattening from the WGS84 spheroid.
	Fi = 298.257223563
)

Variables

View Source
var (
	// ErrNoCoordinateReferenceSystem is a nil CoordinateReferenceSystem warning.
	ErrNoCoordinateReferenceSystem = errors.New("crs not specified")
	// ErrOutOfBounds is a transformation out of the Area interface boundings.
	ErrOutOfBounds = errors.New("coordinate is out of bounds")
)

Functions

This section is empty.

Types

type Airy added in v0.4.0

type Airy struct{}

Airy is a spheroid used by several geodetic datums.

func (Airy) A added in v1.1.5

func (Airy) A() float64

A returns the major axis of the spheroid.

func (Airy) Fi added in v1.1.5

func (Airy) Fi() float64

Fi returns the inverse Flattening of the spheroid.

type Area added in v0.4.3

type Area interface {
	Contains(lon, lat float64) bool
}

Area interface is used to describe the Bounding Box of a Coordinate Reference System.

It is implemented by the AreaFunc.

type AreaFunc added in v0.4.3

type AreaFunc func(lon, lat float64) bool

AreaFunc implements the Contains method of the Area interface.

Returns true if nil.

Returns false for latitudes with an absolute over 90 and longitudes over 180.

func (AreaFunc) Contains added in v0.4.3

func (a AreaFunc) Contains(lon, lat float64) bool

Contains method is the implementation of the Area interface.

Returns false for latitudes with an absolute over 90 and longitudes over 180.

type Bessel added in v0.4.0

type Bessel struct{}

Bessel is a spheroid used by several geodetic datums.

func (Bessel) A added in v1.1.5

func (Bessel) A() float64

A returns the major axis of the spheroid.

func (Bessel) Fi added in v1.1.5

func (Bessel) Fi() float64

Fi returns the inverse Flattening of the spheroid.

type Clarke1866 added in v1.1.5

type Clarke1866 struct{}

Clarke1866 is a spheroid used by several geodetic datums.

func (Clarke1866) A added in v1.1.5

func (Clarke1866) A() float64

A returns the major axis of the spheroid.

func (Clarke1866) Fi added in v1.1.5

func (Clarke1866) Fi() float64

Fi returns the inverse Flattening of the spheroid.

type CoordinateReferenceSystem

type CoordinateReferenceSystem interface {
	ToWGS84(a, b, c float64) (x0, y0, z0 float64)
	FromWGS84(x0, y0, z0 float64) (a, b, c float64)
	Area
}

CoordinateReferenceSystem is the core interface of this package.

It is a coordinate reference system that precisely locates a point on the earth's surface.

type Datum added in v0.1.0

type Datum struct {
	Spheroid       Spheroid
	Transformation Transformation
	Area           Area
}

Datum represents a Geodetic Datum like WGS84, ETRS89 or NAD83.

It implements the Spheroid, Transformation and Area interface.

By default it behaves like a WGS84 Datum.

func DHDN2001 added in v0.1.0

func DHDN2001() Datum

DHDN2001 provides a Datum similar to the Deutsches Hauptdreiecksnetz 2001.

It's based on the Bessel Spheroid and a 7-parameter-Helmert-Transformation with the parameters: 598.1, 73.7, 418.2, 0.202, 0.045, -2.455, 6.7.

https://epsg.io/1776

It is used in Germay.

func ETRS89 added in v0.1.0

func ETRS89() Datum

ETRS89 provides a Datum similar to the European Terrestrial Reference System 1989.

It's based on the GRS80 Spheroid.

It is used in Europe.

func Helmert added in v0.4.0

func Helmert(a, fi, tx, ty, tz, rx, ry, rz, ds float64) Datum

Helmert provides a Datum specified through the major axis and the inverse flattening of a spheroid and the 7 parameters of a Helmert- Transformation.

func MGI added in v0.5.6

func MGI() Datum

MGI provides a Datum similar to the Militar-Geographische Institut.

It's based on the Bessel Spheroid and a 7-parameter-Helmert-Transformation with the parameters: 577.326,90.129,463.919,5.137,1.474,5.297,2.4232.

https://epsg.io/1618

It is used in Austria.

func NAD83 added in v0.4.6

func NAD83() Datum

NAD83 provides a Datum similar to the North American Datum 1983.

It's based on the GRS80 Spheroid.

It is used in North-America.

func OSGB36 added in v0.1.0

func OSGB36() Datum

OSGB36 provides a Datum similar to the Ordnance Survey Great Britain 1936.

It's based on the Airy Spheroid and a 7-parameter-Helmert-Transformation with the parameters: 446.448,-125.157,542.06,0.15,0.247,0.842,-20.489.

https://epsg.io/1314

It is used in Great Britain.

func RGF93 added in v0.1.0

func RGF93() Datum

RGF93 provides a Datum similar to the Réseau géodésique français 1993.

It's based on the GRS80 Spheroid.

It is used in France.

func WGS84 added in v0.3.2

func WGS84() Datum

WGS84 provides a Datum similar to the World Geodetic System 1984.

It's based on the WGS84 Spheroid.

It is used worldwide.

func (Datum) A added in v0.5.0

func (d Datum) A() float64

A returns the major axis of the implemented Spheroid.

If nil it returns the major axis of the WGS84 Spheroid.

func (Datum) AlbersEqualAreaConic added in v0.5.0

func (d Datum) AlbersEqualAreaConic(lonf, latf, lat1, lat2, eastf, northf float64) ProjectedReferenceSystem

AlbersEqualAreaConic is a projected Coordinate Reference System.

func (Datum) Contains added in v0.4.3

func (d Datum) Contains(lon, lat float64) bool

Contains method is the implementation of the Area interface.

Returns false for latitudes with an absolute over 90 and longitudes over 180.

Returns true if nil.

func (Datum) Fi added in v0.5.0

func (d Datum) Fi() float64

Fi returns the inverse flattening of the implemented Spheroid.

If nil it returns the inverse flattening of the WGS84 Spheroid.

func (Datum) Forward added in v0.5.0

func (d Datum) Forward(x, y, z float64) (x0, y0, z0 float64)

Forward transforms geocentric coordinates to WGS84.

Returns x, y, z if nil.

func (Datum) Inverse added in v0.5.0

func (d Datum) Inverse(x0, y0, z0 float64) (x, y, z float64)

Inverse transforms geocentric coordinates from WGS84.

Returns x0, y0, z0 if nil.

func (Datum) LambertAzimuthalEqualArea added in v1.1.1

func (d Datum) LambertAzimuthalEqualArea(lonf, latf, eastf, northf float64) ProjectedReferenceSystem

func (Datum) LambertConformalConic2SP added in v0.5.0

func (d Datum) LambertConformalConic2SP(lonf, latf, lat1, lat2, eastf, northf float64) ProjectedReferenceSystem

LambertConformalConic2SP is a projected Coordinate Reference System.

func (Datum) LonLat added in v0.5.0

func (d Datum) LonLat() GeographicReferenceSystem

LonLat is a geographic Coordinate Reference System.

func (Datum) TransverseMercator added in v0.5.0

func (d Datum) TransverseMercator(lonf, latf, scale, eastf, northf float64) ProjectedReferenceSystem

TransverseMercator is a projected Coordinate Reference System.

func (Datum) WebMercator added in v0.5.0

func (d Datum) WebMercator() ProjectedReferenceSystem

WebMercator is a projected Coordinate Reference System.

func (Datum) XYZ added in v0.5.0

XYZ is a geocentric Coordinate Reference System.

type Func

type Func func(a, b, c float64) (a2, b2, c2 float64)

Func is returned by the To methods of the CoordinateReferenceSystem's in this package and the Transform function.

func From

From provides the transformation of coordinates from a Coordinate Reference System to WGS84 geographic coordinates.

func To

To provides the transformation of WGS84 geographic coordinates to another Coordinate Reference System.

func Transform added in v0.4.0

func Transform(from, to CoordinateReferenceSystem) Func

Transform provides a transformation between CoordinateReferenceSystems.

func (Func) Round

func (f Func) Round(precision float64) Func

Round can round the resulting values to a specific precision.

type GRS80 added in v0.4.0

type GRS80 struct{}

GRS80 is a spheroid used by several geodetic datums.

func (GRS80) A added in v1.1.5

func (GRS80) A() float64

A returns the major axis of the spheroid.

func (GRS80) Fi added in v1.1.5

func (GRS80) Fi() float64

Fi returns the inverse Flattening of the spheroid.

type GeocentricReferenceSystem added in v0.5.0

type GeocentricReferenceSystem struct {
	Datum Datum
}

GeocentricReferenceSystem represents a geocentric Coordinate Reference System.

func XYZ

XYZ is a geocentric Coordinate Reference System similar to https://epsg.io/4978

func (GeocentricReferenceSystem) Contains added in v0.5.0

func (crs GeocentricReferenceSystem) Contains(lon, lat float64) bool

Contains method is the implementation of the Area interface.

func (GeocentricReferenceSystem) From added in v0.5.7

From provides the transformation from another CoordinateReferenceSystem.

func (GeocentricReferenceSystem) FromWGS84 added in v0.5.0

func (crs GeocentricReferenceSystem) FromWGS84(x0, y0, z0 float64) (x, y, z float64)

FromWGS84 method is one method of the CoordinateReferenceSystem interface.

func (GeocentricReferenceSystem) SafeFrom added in v0.5.7

SafeFrom provides the transformation from another CoordinateReferenceSystem with errors.

func (GeocentricReferenceSystem) SafeTo added in v0.5.2

SafeTo provides the transformation to another CoordinateReferenceSystem with errors.

func (GeocentricReferenceSystem) To added in v0.5.0

To provides the transformation to another CoordinateReferenceSystem.

func (GeocentricReferenceSystem) ToWGS84 added in v0.5.0

func (crs GeocentricReferenceSystem) ToWGS84(x, y, z float64) (x0, y0, z0 float64)

ToWGS84 method is one method of the CoordinateReferenceSystem interface.

type GeographicReferenceSystem added in v0.5.0

type GeographicReferenceSystem struct {
	Datum Datum
}

GeographicReferenceSystem represents a geographic Coordinate Reference System.

func LonLat

LonLat is a geographic Coordinate Reference System similar to https://epsg.io/4326

func (GeographicReferenceSystem) Contains added in v0.5.0

func (crs GeographicReferenceSystem) Contains(lon, lat float64) bool

Contains method is the implementation of the Area interface.

func (GeographicReferenceSystem) From added in v0.5.7

From provides the transformation from another CoordinateReferenceSystem.

func (GeographicReferenceSystem) FromWGS84 added in v0.5.0

func (crs GeographicReferenceSystem) FromWGS84(x0, y0, z0 float64) (lon, lat, h float64)

FromWGS84 method is one method of the CoordinateReferenceSystem interface.

func (GeographicReferenceSystem) SafeFrom added in v0.5.7

SafeFrom provides the transformation from another CoordinateReferenceSystem with errors.

func (GeographicReferenceSystem) SafeTo added in v0.5.2

SafeTo provides the transformation to another CoordinateReferenceSystem with errors.

func (GeographicReferenceSystem) To added in v0.5.0

To provides the transformation to another CoordinateReferenceSystem.

func (GeographicReferenceSystem) ToWGS84 added in v0.5.0

func (crs GeographicReferenceSystem) ToWGS84(lon, lat, h float64) (x0, y0, z0 float64)

ToWGS84 method is one method of the CoordinateReferenceSystem interface.

type ProjectedReferenceSystem added in v0.5.0

type ProjectedReferenceSystem struct {
	Datum      Datum
	Projection Projection
	Area       Area
}

ProjectedReferenceSystem represents a projected Coordinate Reference System.

func DHDN2001GK added in v0.3.0

func DHDN2001GK(zone float64) ProjectedReferenceSystem

DHDN2001GK represents projected Coordinate Reference System's similar to https://epsg.io/31467

func ETRS89AustriaLambert added in v0.5.6

func ETRS89AustriaLambert() ProjectedReferenceSystem

ETRS89AustriaLambert represents projected Coordinate Reference System's similar to https://epsg.io/3416

func ETRS89LambertAzimuthalEqualArea added in v1.1.1

func ETRS89LambertAzimuthalEqualArea() ProjectedReferenceSystem

func ETRS89UTM added in v0.3.0

func ETRS89UTM(zone float64) ProjectedReferenceSystem

ETRS89UTM represents projected Coordinate Reference System's similar to https://epsg.io/25832

func MGIAustriaGKM28 added in v0.5.6

func MGIAustriaGKM28() ProjectedReferenceSystem

MGIAustriaGKM28 represents projected Coordinate Reference System's similar to https://epsg.io/31257

func MGIAustriaGKM31 added in v0.5.6

func MGIAustriaGKM31() ProjectedReferenceSystem

MGIAustriaGKM31 represents projected Coordinate Reference System's similar to https://epsg.io/31258

func MGIAustriaGKM34 added in v0.5.6

func MGIAustriaGKM34() ProjectedReferenceSystem

MGIAustriaGKM34 represents projected Coordinate Reference System's similar to https://epsg.io/31259

func MGIAustriaLambert added in v0.5.6

func MGIAustriaLambert() ProjectedReferenceSystem

MGIAustriaLambert represents projected Coordinate Reference System's similar to https://epsg.io/31287

func MGIAustriaM28 added in v0.5.6

func MGIAustriaM28() ProjectedReferenceSystem

MGIAustriaM28 represents projected Coordinate Reference System's similar to https://epsg.io/31284

func MGIAustriaM31 added in v0.5.6

func MGIAustriaM31() ProjectedReferenceSystem

MGIAustriaM31 represents projected Coordinate Reference System's similar to https://epsg.io/31285

func MGIAustriaM34 added in v0.5.6

func MGIAustriaM34() ProjectedReferenceSystem

MGIAustriaM34 represents projected Coordinate Reference System's similar to https://epsg.io/31286

func NAD83AlabamaEast added in v0.5.0

func NAD83AlabamaEast() ProjectedReferenceSystem

NAD83AlabamaEast is a projected Coordinate Reference System similar to https://epsg.io/6355

func NAD83AlabamaWest added in v0.5.0

func NAD83AlabamaWest() ProjectedReferenceSystem

NAD83AlabamaWest is a projected Coordinate Reference System similar to https://epsg.io/6356

func NAD83CaliforniaAlbers added in v0.5.0

func NAD83CaliforniaAlbers() ProjectedReferenceSystem

NAD83CaliforniaAlbers is a projected Coordinate Reference System similar to https://epsg.io/6414

func OSGB36NationalGrid added in v0.3.0

func OSGB36NationalGrid() ProjectedReferenceSystem

OSGB36NationalGrid is a projected Coordinate Reference System similar to https://epsg.io/27700

func RGF93CC added in v0.3.0

func RGF93CC(lat float64) ProjectedReferenceSystem

RGF93CC represents projected Coordinate Reference System's similar to https://epsg.io/3950

func RGF93FranceLambert added in v0.3.0

func RGF93FranceLambert() ProjectedReferenceSystem

RGF93FranceLambert is a projected Coordinate Reference System similar to https://epsg.io/2154

func UTM

func UTM(zone float64, northern bool) ProjectedReferenceSystem

UTM represents projected Coordinate Reference System's similar to https://epsg.io/32632 or https://epsg.io/32732

func WebMercator

func WebMercator() ProjectedReferenceSystem

WebMercator is a projected Coordinate Reference System similar to https://epsg.io/3857

func (ProjectedReferenceSystem) Contains added in v0.5.0

func (crs ProjectedReferenceSystem) Contains(lon, lat float64) bool

Contains method is the implementation of the Area interface.

func (ProjectedReferenceSystem) From added in v0.5.7

From provides the transformation from another CoordinateReferenceSystem.

func (ProjectedReferenceSystem) FromWGS84 added in v0.5.0

func (crs ProjectedReferenceSystem) FromWGS84(x0, y0, z0 float64) (east, north, h float64)

FromWGS84 method is one method of the CoordinateReferenceSystem interface.

func (ProjectedReferenceSystem) SafeFrom added in v0.5.7

SafeFrom provides the transformation from another CoordinateReferenceSystem with errors.

func (ProjectedReferenceSystem) SafeTo added in v0.5.2

SafeTo provides the transformation to another CoordinateReferenceSystem with errors.

func (ProjectedReferenceSystem) To added in v0.5.0

To provides the transformation to another CoordinateReferenceSystem.

func (ProjectedReferenceSystem) ToWGS84 added in v0.5.0

func (crs ProjectedReferenceSystem) ToWGS84(east, north, h float64) (x0, y0, z0 float64)

ToWGS84 method is one method of the CoordinateReferenceSystem interface.

type Projection added in v0.4.0

type Projection interface {
	ToLonLat(east, north float64, s Spheroid) (lon, lat float64)
	FromLonLat(lon, lat float64, s Spheroid) (east, north float64)
}

Projection interface is used by the several Projected Coordinate Reference System's in this package.

It is easy to expand the package with additional Projections through this interface.

type Repository added in v0.3.0

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

Repository holds the EPSG-Codes and CoordinateReferenceSystems.

func EPSG added in v0.1.0

func EPSG() *Repository

EPSG returns a Repository for dealing with several EPSG-Codes and CoordinateReferenceSystems.

func (*Repository) Add added in v0.3.0

func (r *Repository) Add(c int, crs CoordinateReferenceSystem)

Add an EPSG-Code to the Repository.

func (*Repository) Code added in v0.3.0

Code returns a CoordinateReferenceSystem of a specific EPSG-Code.

func (*Repository) Codes added in v0.3.0

func (r *Repository) Codes() []int

Codes returns all available codes.

func (*Repository) CodesCover added in v0.4.7

func (r *Repository) CodesCover(lon, lat float64) []int

CodesCover returns all Codes covering a specific geographic WGS84 location.

func (*Repository) SafeCode added in v1.1.6

func (r *Repository) SafeCode(c int) (CoordinateReferenceSystem, error)

Code returns a CoordinateReferenceSystem of a specific EPSG-Code.

func (*Repository) SafeTransform added in v0.5.2

func (r *Repository) SafeTransform(from, to int) SafeFunc

SafeTransform transforms coordinates from one EPSG-Code to another with errors.

func (*Repository) Transform added in v0.5.2

func (r *Repository) Transform(from, to int) Func

Transform transforms coordinates from one EPSG-Code to another.

type SafeFunc added in v0.5.2

type SafeFunc func(a, b, c float64) (a2, b2, c2 float64, err error)

SafeFunc is returned by the SafeTo methods of the CoordinateReferenceSystem's in this package and the SafeTransform function.

func SafeTransform added in v0.5.2

func SafeTransform(from, to CoordinateReferenceSystem) SafeFunc

SafeTransform provides a transformation between CoordinateReferenceSystems with errors.

func (SafeFunc) Round added in v0.5.2

func (f SafeFunc) Round(precision float64) SafeFunc

Round can round the resulting values to a specific precision.

type Spheroid added in v0.0.2

type Spheroid interface {
	A() float64
	Fi() float64
}

Spheroid interface represents an ellipsoid of revolution used by geodetic datums.

It is specified by the major axis and the inverse flattening.

type Transformation added in v0.0.2

type Transformation interface {
	Forward(x, y, z float64) (x0, y0, z0 float64)
	Inverse(x0, y0, z0 float64) (x, y, z float64)
}

Transformation interface represents the transformation of geocentric coordinates To and From WGS84.

The Forward method is used to transform coordinates to the WGS84 System..

Jump to

Keyboard shortcuts

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