proj4go

package module
v0.0.2 Latest Latest
Warning

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

Go to latest
Published: Sep 9, 2020 License: BSD-3-Clause Imports: 5 Imported by: 2

README

proj4go

Native Go implementation of Proj4 based on proj4js

Work in progress.

  • Only sinusoidal, mercator, equidistant and miller implemented.

  • Work on parsing proj4 strings is not complete.

  • Testing is performed against the C Proj4 library.

Help and pull requests are welcome!

Documentation

Index

Constants

View Source
const (
	C00 = 1.0
	C02 = 0.25
	C04 = 0.046875
	C06 = 0.01953125
	C08 = 0.01068115234375
	C22 = 0.75
	C44 = 0.46875
	C46 = 0.01302083333333333333
	C48 = 0.00712076822916666666
	C66 = 0.36458333333333333333
	C68 = 0.00569661458333333333
	C88 = 0.3076171875
)
View Source
const (
	PJD_3PARAM  = 1
	PJD_7PARAM  = 2
	PJD_WGS84   = 4 // WGS84 or equivalent
	PJD_NODATUM = 5 // WGS84 or equivalent
	SEC_TO_RAD  = 4.84813681109535993589914102357e-6
	HALF_PI     = math.Pi / 2
	SIXTH       = 0.1666666666666666667
	RA4         = 0.04722222222222222222
	RA6         = 0.02215608465608465608
	EPSLN       = 1.0e-6
	EPSLN2      = 1.0e-6
	D2R         = 0.01745329251994329577
	R2D         = 57.29577951308232088
	FORTPI      = math.Pi / 4
	TWO_PI      = math.Pi * 2
	// SPI is slightly greater than Math.PI, so values that exceed the -180..180
	// degree range by a tiny amount don't get wrapped. This prevents points that
	// have drifted from their original location along the 180th meridian (due to
	// floating point error) from changing their sign.
	SPI = 3.14159265359
)
View Source
const MAXITER = 20

Variables

View Source
var Datums map[string]Datum = map[string]Datum{
	"wgs84":         Datum{[]float64{0, 0, 0}, "WGS84", "WGS84"},
	"ch1903":        Datum{[]float64{674.374, 15.056, 405.346}, "bessel", "swiss"},
	"ggrs87":        Datum{[]float64{-199.87, 74.79, 246.62}, "GRS80", "Greek_Geodetic_Reference_System_1987"},
	"nad83":         Datum{[]float64{0, 0, 0}, "GRS80", "North_American_Datum_1983"},
	"potsdam":       Datum{[]float64{606.0, 23.0, 413.0}, "bessel", "Potsdam Rauenberg 1950 DHDN"},
	"carthage":      Datum{[]float64{-263.0, 6.0, 431.0}, "clark80", "Carthage 1934 Tunisia"},
	"hermannskogel": Datum{[]float64{653.0, -212.0, 449.0}, "bessel", "Hermannskogel"},
	"osni52":        Datum{[]float64{482.530, -130.596, 564.557, -1.042, -0.214, -0.631, 8.15}, "airy", "Irish National"},
	"ire65":         Datum{[]float64{482.530, -130.596, 564.557, -1.042, -0.214, -0.631, 8.15}, "mod_airy", "Ireland 1965"},
	"rassadiran":    Datum{[]float64{-133.63, -157.5, -158.62}, "intl", "Rassadiran"},
	"nzgd49":        Datum{[]float64{59.47, -5.04, 187.44, 0.47, -0.1, 1.024, -4.5993}, "intl", "New Zealand Geodetic Datum 1949"},
	"osgb36":        Datum{[]float64{446.448, -125.157, 542.060, 0.1502, 0.2470, 0.8421, -20.4894}, "airy", "Airy 1830"},
	"s_jtsk":        Datum{[]float64{589, 76, 480}, "bessel", "S-JTSK (Ferro)"},
	"beduaram":      Datum{[]float64{-106, -87, 188}, "clrk80", "Beduaram"},
	"gunung_segara": Datum{[]float64{-403, 684, 41}, "bessel", "Gunung Segara Jakarta"},
	"rnb72":         Datum{[]float64{106.869, -52.2978, 103.724, -0.33657, 0.456955, -1.84218, 1}, "intl", "Reseau National Belge 1972"},
}
View Source
var Ellipsoids map[string]Ellipsoid = map[string]Ellipsoid{
	"MERIT":    {/* contains filtered or unexported fields */},
	"SGS85":    {/* contains filtered or unexported fields */},
	"GRS80":    {/* contains filtered or unexported fields */},
	"IAU76":    {/* contains filtered or unexported fields */},
	"airy":     {/* contains filtered or unexported fields */},
	"APL4":     {/* contains filtered or unexported fields */},
	"NWL9D":    {/* contains filtered or unexported fields */},
	"mod_airy": {/* contains filtered or unexported fields */},
	"andrae":   {/* contains filtered or unexported fields */},
	"aust_SA":  {/* contains filtered or unexported fields */},
	"GRS67":    {/* contains filtered or unexported fields */},
	"bessel":   {/* contains filtered or unexported fields */},
	"bess_nam": {/* contains filtered or unexported fields */},
	"clrk66":   {/* contains filtered or unexported fields */},
	"clrk80":   {/* contains filtered or unexported fields */},
	"clrk58":   {/* contains filtered or unexported fields */},
	"CPM":      {/* contains filtered or unexported fields */},
	"delmbr":   {/* contains filtered or unexported fields */},
	"engelis":  {/* contains filtered or unexported fields */},
	"evrst30":  {/* contains filtered or unexported fields */},
	"evrst48":  {/* contains filtered or unexported fields */},
	"evrst56":  {/* contains filtered or unexported fields */},
	"evrst69":  {/* contains filtered or unexported fields */},
	"evrstSS":  {/* contains filtered or unexported fields */},
	"fschr60":  {/* contains filtered or unexported fields */},
	"fschr60m": {/* contains filtered or unexported fields */},
	"fschr68":  {/* contains filtered or unexported fields */},
	"helmert":  {/* contains filtered or unexported fields */},
	"hough":    {/* contains filtered or unexported fields */},
	"intl":     {/* contains filtered or unexported fields */},
	"kaula":    {/* contains filtered or unexported fields */},
	"lerch":    {/* contains filtered or unexported fields */},
	"mprts":    {/* contains filtered or unexported fields */},
	"new_intl": {/* contains filtered or unexported fields */},
	"plessis":  {/* contains filtered or unexported fields */},
	"krass":    {/* contains filtered or unexported fields */},
	"SEasia":   {/* contains filtered or unexported fields */},
	"walbeck":  {/* contains filtered or unexported fields */},
	"WGS60":    {/* contains filtered or unexported fields */},
	"WGS66":    {/* contains filtered or unexported fields */},
	"WGS72":    {/* contains filtered or unexported fields */},
	"WGS84":    {/* contains filtered or unexported fields */},
	"sphere":   {/* contains filtered or unexported fields */},
}
View Source
var PrimeMeridiams map[string]float64 = map[string]float64{
	"greenwich": 0.0,
	"lisbon":    -9.131906111111,
	"paris":     2.337229166667,
	"bogota":    -74.080916666667,
	"madrid":    -3.687938888889,
	"rome":      12.452333333333,
	"bern":      7.439583333333,
	"jakarta":   106.807719444444,
	"ferro":     -17.666666666667,
	"brussels":  4.367975,
	"stockholm": 18.058277777778,
	"athens":    23.7163375,
	"oslo":      10.722916666667,
}

Functions

func AdjustLat

func AdjustLat(x float64) float64

func AdjustLon

func AdjustLon(x float64) float64

func Asinz

func Asinz(phi float64) float64

func Eccentricity

func Eccentricity(a, b float64, RA bool) (float64, float64, float64)

func Forwards

func Forwards(dst string, pts []geo.Point) error

func Inverse

func Inverse(dst string, pts []geo.Point) error

func Phi2z

func Phi2z(eccent, ts float64) (float64, error)

func PjInvml

func PjInvml(arg, es float64, en []float64) float64

func Pjen

func Pjen(es float64) []float64

func Pjml

func Pjml(phi, sphi, cphi float64, en []float64) float64

func Sphere

func Sphere(a, b, rf float64, ellps string, sphere bool) (float64, float64, float64, bool)

func Transform

func Transform(src, dst string, pts []geo.Point) error

func Tsfnz

func Tsfnz(eccent, phi, sinphi float64) float64

Types

type AEA

type AEA struct {
	Ellipsoid
	// contains filtered or unexported fields
}

func NewAEA

func NewAEA(proj4 Proj4Params) *AEA

func (*AEA) Forward

func (e *AEA) Forward(pts []geo.Point) error

func (*AEA) Inverse

func (e *AEA) Inverse(pts []geo.Point) error

type Coverage

type Coverage struct {
	geo.BoundingBox
	Proj4 string
}

func (Coverage) Transform

func (c Coverage) Transform(dstProj4 string) (Coverage, error)

type Datum

type Datum struct {
	ToWGS84 []float64
	Ellipse string
	Name    string
}

type Ellipsoid

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

func NewEllipsoid

func NewEllipsoid(params Proj4Params) (Ellipsoid, error)

type Equi

type Equi struct {
	Ellipsoid
	// contains filtered or unexported fields
}

func NewEqui

func NewEqui(proj4 Proj4Params) *Equi

func (*Equi) Forward

func (e *Equi) Forward(pts []geo.Point) error

func (*Equi) Inverse

func (e *Equi) Inverse(pts []geo.Point) error

type LonLat

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

func NewLonLat

func NewLonLat(proj4 Proj4Params) *LonLat

func (*LonLat) Forward

func (m *LonLat) Forward(pts []geo.Point) error

func (*LonLat) Inverse

func (m *LonLat) Inverse(pts []geo.Point) error

type Merc

type Merc struct {
	Ellipsoid
	// contains filtered or unexported fields
}

func NewMerc

func NewMerc(proj4 Proj4Params) *Merc

func (*Merc) Forward

func (e *Merc) Forward(pts []geo.Point) error

func (*Merc) Inverse

func (e *Merc) Inverse(pts []geo.Point) error

type Miller

type Miller struct {
	Ellipsoid
	// contains filtered or unexported fields
}

func NewMiller

func NewMiller(proj4 Proj4Params) *Miller

func (*Miller) Forward

func (m *Miller) Forward(pts []geo.Point) error

func (*Miller) Inverse

func (m *Miller) Inverse(pts []geo.Point) error

type Proj4Params

type Proj4Params struct {
	Proj      string  `json:"proj"`
	Ellipsoid string  `json:"ellps"`
	Datum     string  `json:"datum"`
	Units     string  `json:"units"`
	A         float64 `json:"a"`
	B         float64 `json:"b"`
	X0        float64 `json:"x_0"`
	Y0        float64 `json:"y_0"`
	Lat0      float64 `json:"lat_0"`
	Lat1      float64 `json:"lat_1"`
	Lat2      float64 `json:"lat_2"`
	Lon0      float64 `json:"lon_0"`
	LatTS     float64 `json:"lat_ts"`
	K         float64 `json:"k"`
	Zone      int     `json:"zone"`
	Authalic  bool    `json:"R_A"`
	NoDefs    bool    `json:"no_defs"`
	NadGrids  string  `json:"nadgrids"`
}

func ParseProj4String

func ParseProj4String(input string) (Proj4Params, error)

type ProjGeometry

type ProjGeometry struct {
	geo.Geometry
	Proj4 string
}

func (ProjGeometry) Transform

func (rg ProjGeometry) Transform(dstProj4 string) (ProjGeometry, error)

type Projection

type Projection interface {
	Forward([]geo.Point) error
	Inverse([]geo.Point) error
}
type Point struct {
	X, Y float64
}
func Pt(x, y float64) Point {
	return Point{x, y}
}
type BoundingBox struct {
	Min, Max Point
}
func BBox(x0, y0, x1, y1 float64) BoundingBox {
	if x0 > x1 {
		x0, x1 = x1, x0
	}
	if y0 > y1 {
		y0, y1 = y1, y0
	}
	return BoundingBox{Point{x0, y0}, Point{x1, y1}}
}
type Coverage struct {
	BoundingBox
	Proj4 string
}
func (c Coverage) Transform(dstProj4 string) (Coverage, error) {
	pts := []Point{{c.Min.X, c.Min.Y}, {c.Max.X, c.Min.Y}, {c.Max.X, c.Max.Y}, {c.Min.X, c.Max.Y}}
	err := Transform(dstProj4, c.Proj4, pts)
	if err != nil {
		return Coverage{}, err
	}

	minX := math.MaxFloat64
	maxX := math.SmallestNonzeroFloat64
	minY := math.MaxFloat64
	maxY := math.SmallestNonzeroFloat64

	for _, pt := range pts {
		if pt.X < minX {
			minX = pt.X
		}
		if pt.X > maxX {
			maxX = pt.X
		}
		if pt.Y < minY {
			minY = pt.Y
		}
		if pt.Y > maxY {
			maxY = pt.Y
		}
	}

	bBox := BoundingBox{Pt(minX, minY), Pt(maxX, maxY)}

	return Coverage{bBox, dstProj4}, nil
}

func NewProjection

func NewProjection(proj4Str string) (Projection, error)

type Sinu

type Sinu struct {
	Ellipsoid

	Cx, Cy float64
	// contains filtered or unexported fields
}

func NewSinu

func NewSinu(proj4 Proj4Params) *Sinu

func (*Sinu) Forward

func (s *Sinu) Forward(pts []geo.Point) error

func (*Sinu) Inverse

func (s *Sinu) Inverse(pts []geo.Point) error

Jump to

Keyboard shortcuts

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