coordconv

package module
v0.1.2 Latest Latest
Warning

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

Go to latest
Published: Oct 9, 2018 License: Unlicense Imports: 7 Imported by: 1

README

coordconv

coordconv is a manual port of the Geotrans 3.7 MGRS conversion code from C++ to Go. It also makes public the UTM and UPS converters as well as the underlying transverse mercator and polar stereographic projections.

It has been tested with 4million+ points uniformly spread across the globe and returns identical results to the standard Geotrans library. The unit tests included contain an abbreviated test table at testdata/geotrans.log with 40,000 points which was generated with the included geotrans_table_cpp. It can be modified and used to regenerate the included geotrans.log, or a more comprehensive one if desired.

Usage

Constructors are provided so you can use custom ellipsoid parameters, but defaults are provided for WGS84:

  mgrs, _ := coordconv.DefaultMGRSConverter.ConvertFromGeodetic(s2.LatLngFromDegrees(0, 0), 5)
  fmt.Println(mgrs) // 31NAA6602100000
  geo, _ := coordconv.DefaultMGRSConverter.ConvertToGeodetic("16SGC3855124838")
  fmt.Println(geo) // [33.6366624, -84.4280571]

License

The geotrans code is public domain, so in spirit this is public domain as well. I only made minor changes along the way to make it behave a bit more like like standard Go code (e.g. returning an error when the C++ code threw an exception)

Documentation

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Hemisphere

type Hemisphere byte

Hemisphere represents the hemisphere, north or south

const (
	HemisphereInvalid Hemisphere = iota
	HemisphereNorth
	HemisphereSouth
)

Hemisphere constants

type MGRS

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

MGRS is an coordinate converter to and from MGRS coordinates.

var DefaultMGRSConverter *MGRS

DefaultMGRSConverter is a WGS84 ellipsoid based MGRS converter.

func NewMGRS

func NewMGRS(ellipsoidSemiMajorAxis, ellipsoidFlattening float64,
	ellipsoidCode string) (*MGRS, error)

NewMGRS constructs an MGRS converter with ellipsoid parameters.

func (*MGRS) ConvertFromGeodetic

func (m *MGRS) ConvertFromGeodetic(geodeticCoordinates s2.LatLng, precision int) (string, error)

ConvertFromGeodetic converts Geodetic (latitude and longitude) coordinates to an MGRS coordinate string, according to the current ellipsoid parameters.

Example
package main

import (
	"fmt"

	"github.com/golang/geo/s2"
	"github.com/tzneal/coordconv"
)

func main() {
	mgrs, _ := coordconv.DefaultMGRSConverter.ConvertFromGeodetic(s2.LatLngFromDegrees(0, 0), 5)
	fmt.Println(mgrs)
}
Output:

31NAA6602100000

func (*MGRS) ConvertFromUTM

func (m *MGRS) ConvertFromUTM(utmCoordinates UTMCoord, precision int) (string, error)

ConvertFromUTM converts UTM (zone, easting, and northing) coordinates to an MGRS coordinate string, according to the current ellipsoid parameters. If any errors occur, an exception is thrown with a description of the error.

func (*MGRS) ConvertToGeodetic

func (m *MGRS) ConvertToGeodetic(mgrsorUSNGCoordinates string) (s2.LatLng, error)

ConvertToGeodetic converts an MGRS coordinate string to Geodetic (latitude and longitude) coordinates according to the current ellipsoid parameters.

Example
package main

import (
	"fmt"

	"github.com/tzneal/coordconv"
)

func main() {
	geo, _ := coordconv.DefaultMGRSConverter.ConvertToGeodetic("16SGC3855124838")
	fmt.Println(geo)
}
Output:

[33.6366624, -84.4280571]

type MapCoords

type MapCoords struct {
	Easting  float64
	Northing float64
}

MapCoords are projected map coordinates

type PolarStereographic

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

PolarStereographic provides conversions between geodetic (latitude and longitude) coordinates and Polar Stereographic (easting and northing) coordinates.

func NewPolarStereographic added in v0.1.2

func NewPolarStereographic(ellipsoidSemiMajorAxis,
	ellipsoidFlattening,
	centralMeridian,
	standardParallel,
	falseEasting,
	falseNorthing float64) (*PolarStereographic, error)

NewPolarStereographic receives the ellipsoid parameters and Polar Stereograpic (Standard Parallel) projection parameters as inputs, and sets the corresponding state variables.

func NewPolarStereographicScaleFactor added in v0.1.2

func NewPolarStereographicScaleFactor(ellipsoidSemiMajorAxis,
	ellipsoidFlattening,
	centralMeridian,
	scaleFactor float64, hemisphere Hemisphere,
	falseEasting,
	falseNorthing float64) (*PolarStereographic, error)

NewPolarStereographicScaleFactor ellipsoid parameters and Polar Stereograpic (Scale Factor) projection parameters as inputs, and sets the corresponding state variables.

func (*PolarStereographic) ConvertFromGeodetic

func (p *PolarStereographic) ConvertFromGeodetic(geodeticCoordinates s2.LatLng) (MapCoords, error)

ConvertFromGeodetic converts geodetic coordinates (latitude and longitude) to Polar Stereographic coordinates (easting and northing), according to the current ellipsoid and Polar Stereographic projection parameters.

func (*PolarStereographic) ConvertToGeodetic

func (p *PolarStereographic) ConvertToGeodetic(mapProjectionCoordinates MapCoords) (s2.LatLng, error)

ConvertToGeodetic converts Polar Stereographic coordinates (easting and northing) to geodetic coordinates (latitude and longitude) according to the current ellipsoid and Polar Stereographic projection Parameters.

type TransverseMercator

type TransverseMercator struct {
	TranMercFalseNorthing float64 // False northing in meters
	// contains filtered or unexported fields
}

TransverseMercator provides conversions between Geodetic coordinates (latitude and longitude) and Transverse Mercator projection coordinates (easting and northing).

func NewTransverseMercator

func NewTransverseMercator(ellipsoidSemiMajorAxis, ellipsoidFlattening, centralMeridian,
	latitudeOfTrueScale, falseEasting, falseNorthing, scaleFactor float64,
	ellipsoidCode string) (*TransverseMercator, error)

NewTransverseMercator constructs a new TransverseMercator converter.

type UPS

type UPS struct {
	UPSOriginLatitude float64
	// contains filtered or unexported fields
}

UPS is a UPS coordinate converter

var DefaultUPSConverter *UPS

DefaultUPSConverter is a WGS84 ellipsoid based UPS converter.

func NewUPS

func NewUPS(ellipsoidSemiMajorAxis, ellipsoidFlattening float64) (*UPS, error)

NewUPS construct a new UPS converter with the specified ellipsoid parameters.

func (*UPS) ConvertFromGeodetic

func (u *UPS) ConvertFromGeodetic(geodeticCoordinates s2.LatLng) (UPSCoord, error)

ConvertFromGeodetic converts a geodetic coordinate to a UPS coordinate.

func (*UPS) ConvertToGeodetic

func (u *UPS) ConvertToGeodetic(upsCoordinates UPSCoord) (s2.LatLng, error)

ConvertToGeodetic converts UPS (hemisphere, easting, and northing) coordinates to geodetic (latitude and longitude) coordinates according to the current ellipsoid parameters.

type UPSCoord

type UPSCoord struct {
	Hemisphere Hemisphere
	Easting    float64
	Northing   float64
}

UPSCoord is a UPS coordinate with a specified easting/northing in meters and hemisphere.

type UTM

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

UTM is a UTM coordinate converter

var DefaultUTMConverter *UTM

DefaultUTMConverter is a WGS84 ellipsoid based UTM converter.

func NewUTM

func NewUTM() (*UTM, error)

NewUTM constructs a new UTM converter for the WGS84 ellipsoid

func NewUTM2

func NewUTM2(ellipsoidSemiMajorAxis, ellipsoidFlattening float64,
	ellipsoidCode string, override int) (*UTM, error)

NewUTM2 receives the ellipsoid parameters and UTM zone override parameter as inputs, and sets the corresponding state variables. override is the UTM override zone, 0 indicates no override.

func (*UTM) ConvertFromGeodetic

func (u *UTM) ConvertFromGeodetic(geodeticCoordinates s2.LatLng, utmZoneOverride int) (UTMCoord, error)

ConvertFromGeodetic converts geodetic (latitude and longitude) coordinates to UTM projection (zone, hemisphere, easting and northing) coordinates according to the current ellipsoid and UTM zone override parameters.

func (*UTM) ConvertToGeodetic

func (u *UTM) ConvertToGeodetic(utmCoordinates UTMCoord) (s2.LatLng, error)

ConvertToGeodetic converts UTM projection (zone, hemisphere, easting and northing) coordinates to geodetic(latitude and longitude) coordinates, according to the current ellipsoid parameters.

type UTMCoord

type UTMCoord struct {
	Zone       int
	Hemisphere Hemisphere
	Easting    float64
	Northing   float64
}

UTMCoord is a UTM coordinate

Jump to

Keyboard shortcuts

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