coordconv

package module
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Oct 8, 2018 License: Unlicense Imports: 7 Imported by: 5

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

Constants

This section is empty.

Variables

View Source
var Latitude_Band_Table = [20]Latitude_Band{
	{letterC, 1100000.0, -72.0, -80.5, 0.0},
	{letterD, 2000000.0, -64.0, -72.0, 2000000.0},
	{letterE, 2800000.0, -56.0, -64.0, 2000000.0},
	{letterF, 3700000.0, -48.0, -56.0, 2000000.0},
	{letterG, 4600000.0, -40.0, -48.0, 4000000.0},
	{letterH, 5500000.0, -32.0, -40.0, 4000000.0},
	{letterJ, 6400000.0, -24.0, -32.0, 6000000.0},
	{letterK, 7300000.0, -16.0, -24.0, 6000000.0},
	{letterL, 8200000.0, -8.0, -16.0, 8000000.0},
	{letterM, 9100000.0, 0.0, -8.0, 8000000.0},
	{letterN, 0.0, 8.0, 0.0, 0.0},
	{letterP, 800000.0, 16.0, 8.0, 0.0},
	{letterQ, 1700000.0, 24.0, 16.0, 0.0},
	{letterR, 2600000.0, 32.0, 24.0, 2000000.0},
	{letterS, 3500000.0, 40.0, 32.0, 2000000.0},
	{letterT, 4400000.0, 48.0, 40.0, 4000000.0},
	{letterU, 5300000.0, 56.0, 48.0, 4000000.0},
	{letterV, 6200000.0, 64.0, 56.0, 6000000.0},
	{letterW, 7000000.0, 72.0, 64.0, 6000000.0},
	{letterX, 7900000.0, 84.5, 72.0, 6000000.0}}

Functions

This section is empty.

Types

type CoordinateSystem

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

type Hemisphere

type Hemisphere byte
const (
	HemisphereInvalid Hemisphere = iota
	HemisphereNorth
	HemisphereSouth
)

type Latitude_Band

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

type MGRS

type MGRS struct {
	CoordinateSystem

	MGRSEllipsoidCode string
	// 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.

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.

type MapCoords

type MapCoords struct {
	Easting  float64
	Northing float64
}

type PolarStereographic

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

func MakePolarStereographic1

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

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

func MakePolarStereographicScaleFactor

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

MakePolarStereographicScaleFactor 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 {
	CoordinateSystem

	TranMercFalseNorthing float64 // False northing in meters
	// contains filtered or unexported fields
}

func NewTransverseMercator

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

type UPS

type UPS struct {
	CoordinateSystem
	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 {
	CoordinateSystem
	// 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