Giter Site home page Giter Site logo

wroge / wgs84 Goto Github PK

View Code? Open in Web Editor NEW
124.0 2.0 17.0 16.08 MB

A zero-dependency Go package for coordinate transformations.

License: MIT License

Go 100.00%
coordinate-converter wgs84 epsg etrs89 osgb36 web-mercator utm longitude latitude geodetic-datum

wgs84's Introduction

WGS84 - Coordinate Transformations

github.com/wroge/wgs84/v2

I am currently in the process of rewriting the package. Some things will change and some new features will be added. One of these features is the support of NTv2 grid transformations and other projections, such as Krovak. If you would like to help or have any comments, please report them in the issues.

Web Mercator

package main

import (
	"fmt"

	"github.com/wroge/wgs84/v2"
)

func main() {
	transform := wgs84.Transform(wgs84.EPSG(4326), wgs84.EPSG(3857)).Round(3)

	east, north, _ := transform(10, 50, 0)

	fmt.Println(east, north)
	// 1.113194908e+06 6.446275841e+06

	// echo 10 50 | cs2cs +init=epsg:4326 +to +init=epsg:3857 -d 3
	// 1113194.908     6446275.841
}

OSGB

package main

import (
	"fmt"

	"github.com/wroge/wgs84/v2"
)

func main() {
	transform := wgs84.Transform(wgs84.EPSG(4326), wgs84.EPSG(27700)).Round(3)

	east, north, h := transform(-2.25, 52.25, 0)

	fmt.Println(east, north, h)
	// 383029.296 261341.615 0

	// echo -2.25 52.25 | cs2cs +init=epsg:4326 +to +init=epsg:27700 -d 3
	// 383029.296 261341.615 0.000
}

wgs84's People

Contributors

lgln-mw avatar murphy214 avatar stefanb avatar wroge avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

wgs84's Issues

transform result accuracy

Here's my code

type spheroid struct {
	a, fi float64
}

func (s spheroid) A() float64 {
	return s.a
}

func (s spheroid) Fi() float64 {
	return s.fi
}

func main() {
	test := wgs84.Datum{
		Spheroid: spheroid{
			a:  6378137,
			fi: 298.257222101,
		},
		Area: wgs84.AreaFunc(func(lon, lat float64) bool {
			if lon < 118.5 || lon > 121.5 || lat < 24.43 || lat > 53.33 {
				return false
			}
			return true
		}),
	}

	proj := test.TransverseMercator(120, 0, 1, 500000, 0)

	epsg := wgs84.EPSG()
	epsg.Add(4549, proj)

	transform := wgs84.Transform(epsg.Code(4549), wgs84.LonLat())
	f1, f2, f3 := transform(478077, 4025869, 0)
	fmt.Println(f1, f2, f3)

}

wkt for epsg:4549

PROJCS["CGCS2000 / 3-degree Gauss-Kruger CM 120E",
    GEOGCS["China Geodetic Coordinate System 2000",
        DATUM["China_2000",
            SPHEROID["CGCS2000",6378137,298.257222101,
                AUTHORITY["EPSG","1024"]],
            AUTHORITY["EPSG","1043"]],
        PRIMEM["Greenwich",0,
            AUTHORITY["EPSG","8901"]],
        UNIT["degree",0.0174532925199433,
            AUTHORITY["EPSG","9122"]],
        AUTHORITY["EPSG","4490"]],
    PROJECTION["Transverse_Mercator"],
    PARAMETER["latitude_of_origin",0],
    PARAMETER["central_meridian",120],
    PARAMETER["scale_factor",1],
    PARAMETER["false_easting",500000],
    PARAMETER["false_northing",0],
    UNIT["metre",1,
        AUTHORITY["EPSG","9001"]],
    AUTHORITY["EPSG","4549"]]

With my code I got result is [119.75572865201768, 36.36317346481494, -3.6767683923244476e-05]
But What I got form epsg.io was [119.7557287, 36.3631738], and from gdaltransform was [119.755728654111, 36.3631737608256, 0]

So I am wandering what makes these differences? Is there any problems?

generating factories out of WKT v1 (geotools epsg.properties)

hi,

i'm toying with the idea of tapping into geotools wkt epsg.properties and script/generate transformation factories for each definition. or simply parse wkt1, not decided yet.

perhaps parameterize MGI -> helmert with parameters from TOWGS84 definitions.
and then instrument transverseMercator with PROPERTY values.

how do you see it, would it be working approach en mass? what would "area" function be then?

WIP v2

I would like to change the API a little. So this is my first draft for v2: https://github.com/wroge/wgs84/tree/v2

Anyone who is interested can take a look at it. I am open to criticism.

go get github.com/wroge/wgs84/v2

geometric altitude to wgs84 altitude

Hi, I am very new to gis, but if I have lat, long, and a geometric altitude (above mean sea level), can I use this package to convert the geometric altitude to the wgs84 altitude?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.