imposm3/proj/proj.go

31 lines
691 B
Go
Raw Normal View History

2013-05-06 18:17:35 +04:00
package proj
import (
2014-08-04 17:19:35 +04:00
"github.com/omniscale/imposm3/element"
2013-05-06 18:17:35 +04:00
"math"
)
const pole = 6378137 * math.Pi // 20037508.342789244
func WgsToMerc(long, lat float64) (x, y float64) {
2013-05-06 18:17:35 +04:00
x = long * pole / 180.0
y = math.Log(math.Tan((90.0+lat)*math.Pi/360.0)) / math.Pi * pole
return x, y
}
func MercToWgs(x, y float64) (long, lat float64) {
2013-05-06 18:17:35 +04:00
long = 180.0 * x / pole
lat = 180.0 / math.Pi * (2*math.Atan(math.Exp((y/pole)*math.Pi)) - math.Pi/2)
return long, lat
}
2013-05-08 18:45:14 +04:00
func NodesToMerc(nodes []element.Node) {
2013-05-10 12:08:00 +04:00
for i, nd := range nodes {
nodes[i].Long, nodes[i].Lat = WgsToMerc(nd.Long, nd.Lat)
2013-05-08 18:45:14 +04:00
}
}
2013-05-15 15:21:31 +04:00
func NodeToMerc(node *element.Node) {
node.Long, node.Lat = WgsToMerc(node.Long, node.Lat)
2013-05-15 15:21:31 +04:00
}