Last active
February 19, 2021 04:34
-
-
Save wroge/e2160c1483a083997accf49009e7b08a to your computer and use it in GitHub Desktop.
Calculate EPSG-Code
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| package main | |
| import ( | |
| "fmt" | |
| "math" | |
| "github.com/wroge/wgs84" | |
| ) | |
| func main() { | |
| // Unknown coordinates | |
| east := 3.5687498033587863e+06 | |
| north := 5.763376666923903e+06 | |
| h1 := -44.092825065366924 | |
| // WGS84 coordinates | |
| longitude := 10.0 | |
| latitude := 52.0 | |
| h2 := 0.0 | |
| score := math.MaxFloat64 | |
| result := 0 | |
| epsg := wgs84.EPSG() | |
| codes := epsg.CodesCover(longitude, latitude) | |
| for _, code := range codes { | |
| crs := epsg.Code(code) | |
| lon, lat, h := wgs84.Transform(crs, wgs84.LonLat())(east, north, h1) | |
| s := math.Abs(longitude-lon) + math.Abs(latitude-lat) + math.Abs(h2-h) | |
| if s < score { | |
| score = s | |
| result = code | |
| } | |
| } | |
| fmt.Printf("EPSG-Code: %d, Score: %v\n", result, score) | |
| // EPSG-Code: 31467, Score: 0.0042770297423793124 | |
| } |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
https://play.golang.org/p/9_0MS8fEzl-