proj

package module
v2.0.0-...-6c8a5f5 Latest Latest
Warning

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

Go to latest
Published: Oct 6, 2022 License: MIT Imports: 7 Imported by: 0

README

go-proj

Description

PROJ wrapper for the transformation of points between different coorinate reference systems.

Changes

v2 version of this package requires Proj > 4. The API of this package changed, please check the documentation. You need to set the environment PROJ_USE_PROJ4_INIT_RULES=YES if you want to use Proj.4 init strings (+init=epsg:xxx) with backwards compatible axis orientation.

Installation

This package can be installed with the go get command:

go get github.com/omniscale/go-proj/v2

This package requires proj (libproj-dev on Ubuntu/Debian, proj in Homebrew).

Documentation

API documentation can be found here: http://godoc.org/github.com/omniscale/go-proj/v2

License

MIT, see LICENSE file.

Author

Oliver Tonnhofer

Documentation

Overview

Package proj transforms coordinates with Proj.

// New Proj by EPSG code.
wgs84, err := proj.NewEPSG(4326)
if err != nil {
	log.Fatal(err)
}

// Proj by definition string.
utm32, err := proj.New("epsg:25832")
if err != nil {
	log.Fatal(err)
}

pts := []proj.Coord{
	proj.XY(53.2, 8.15),
	proj.XY(52.32, 9.12),
}

// Transform all coordinates to UTM 32 (in-place).
if err := wgs84.Transform(utm32, pts); err != nil {
	log.Fatal(err)
}

// All coordinates are expected to be in EPSG axis order.
// Call NormalizeForVisualization if your coordinates are always in lon/lat, E/N order.
wgs84.NormalizeForVisualization()
if err := wgs84.Transform(utm32, []proj.Coord{proj.XY(8.15, 53.2)}); err != nil {
	log.Fatal(err)
}

// Transformer from src to dst projection.
transf, err := proj.NewTransformer("epsg:25832", "epsg:3857")
if err != nil {
	log.Fatal(err)
}
if err := transf.Transform(pts); err != nil {
	log.Fatal(err)
}

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Coord

type Coord struct {
	X, Y float64
	Z    float64
	T    float64
}

func XY

func XY(x, y float64) Coord

type Proj

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

Proj represents a single coordinate reference system.

func New

func New(init string) (*Proj, error)

New initializes new projection with a proj init string (e.g. "epsg:4326", or "+proj=longlat +datum=WGS84 +no_defs").

func NewEPSG

func NewEPSG(epsgCode int) (*Proj, error)

NewEPSG initializes a new projection by the numeric EPSG code.

func (*Proj) Description

func (p *Proj) Description() string

Definition returns projection description.

func (*Proj) Free

func (p *Proj) Free()

Free deallocates the projection immediately. Proj will be deallocated on garbage collection otherwise.

func (*Proj) IsLatLong

func (p *Proj) IsLatLong() bool

IsLatLong returns whether the projection uses lat/long coordinates, instead projected.

func (*Proj) NormalizeForVisualization

func (p *Proj) NormalizeForVisualization() error

NormalizeForVisualization converts axis order so that coordinates are always x/y or long/lat axis order. The EPSG axis order is ignored when calling Transform.

func (*Proj) String

func (p *Proj) String() string

func (*Proj) Transform

func (p *Proj) Transform(dst *Proj, pts []Coord) error

Transform coordinates to dst projection. Transforms coordinates in-place.

func (*Proj) UnitName

func (p *Proj) UnitName() string

Unit returns the unit name of the first axis. Can return degree, meter or foot, but also long names like 'US survey foot'. Returns empty string if there is no unit name, or if there was an error.

type Transformer

type Transformer struct {
	Src *Proj
	Dst *Proj
}

Transformer projects coordinates from Src to Dst.

func NewEPSGTransformer

func NewEPSGTransformer(srcEPSG, dstEPSG int) (Transformer, error)

NewEPSGTransformer initializes a new transformer with src and dst projection by the numeric EPSG code.

func NewTransformer

func NewTransformer(initSrc, initDst string) (Transformer, error)

NewTransformer initializes new transformer with src and dst projection with a full proj4 init string (e.g. "+proj=longlat +datum=WGS84 +no_defs").

func (*Transformer) NormalizeForVisualization

func (t *Transformer) NormalizeForVisualization() error

func (*Transformer) Transform

func (t *Transformer) Transform(pts []Coord) error

Transform coordinates fron src to dst projection. Transforms coordinates in-place.

Jump to

Keyboard shortcuts

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