2013-05-06 18:17:35 +04:00
|
|
|
package proj
|
|
|
|
|
|
|
|
import (
|
2013-08-29 17:44:15 +04:00
|
|
|
"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) {
|
|
|
|
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) {
|
|
|
|
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)
|
|
|
|
}
|