twpayne / go-proj

Package proj provides an interface to proj.org.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

go-proj

GoDoc

Package go-proj provides an interface to PROJ.

Features

  • High performance bulk transformation of coordinates.
  • Idiomatic Go API, including complete error handling.
  • Supports PROJ versions 6 and upwards.
  • Compatible with all geometry libraries.
  • Automatically handles C memory management.
  • Well tested.

Install

$ go get github.com/twpayne/go-proj/v10

You must also install the PROJ development headers and libraries. These are typically in the package libproj-dev on Debian-like systems, proj-devel on RedHat-like systems, and proj in Homebrew.

Example

func ExamplePJ_Forward() {
	pj, err := proj.NewCRSToCRS("EPSG:4326", "EPSG:3857", nil)
	if err != nil {
		panic(err)
	}

	// Convert Zürich's WGS84 latitude/longitude to Web Mercator.
	zurichEPSG4326 := proj.NewCoord(47.374444, 8.541111, 408, 0)
	zurichEPSG3857, err := pj.Forward(zurichEPSG4326)
	if err != nil {
		panic(err)
	}
	fmt.Printf("x=%.6f y=%.6f z=%.6f", zurichEPSG3857.X(), zurichEPSG3857.Y(), zurichEPSG3857.Z())
	// Output: x=950792.127329 y=6003408.475803 z=408.000000
}

Comparisons with other PROJ bindings

There are many existing bindings for PROJ. Generally speaking, these:

  • Only transform one coordinate a time, making them extremely slow when transforming large number of coordinates.

  • Are tied to a single geometry representation.

  • Do not handle errors during transformation.

  • Are no longer maintained.

These existing bindings include:

License

MIT

About

Package proj provides an interface to proj.org.

License:MIT License


Languages

Language:Go 96.1%Language:C 3.9%