2013-01-19 16:50:44 +04:00
|
|
|
package model
|
|
|
|
|
|
|
|
import "code.google.com/p/goprotobuf/proto"
|
|
|
|
import "log"
|
|
|
|
|
2013-01-28 10:55:34 +04:00
|
|
|
// type Node struct {
|
|
|
|
// Id int64
|
|
|
|
// Tags map[string]string
|
|
|
|
// Lon uint32
|
|
|
|
// Lat uint32
|
|
|
|
// }
|
2013-01-19 16:50:44 +04:00
|
|
|
|
|
|
|
const COORD_FACTOR float64 = 11930464.7083 // ((2<<31)-1)/360.0
|
|
|
|
|
|
|
|
func coordToInt(coord float64) uint32 {
|
|
|
|
return uint32((coord + 180.0) * COORD_FACTOR)
|
|
|
|
}
|
|
|
|
|
|
|
|
func intToCoord(coord uint32) float64 {
|
|
|
|
return float64((float64(coord) / COORD_FACTOR) - 180.0)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (this *Node) WgsCoord() (lon float64, lat float64) {
|
2013-01-28 10:55:34 +04:00
|
|
|
lon = intToCoord(this.GetLong())
|
|
|
|
lat = intToCoord(this.GetLat())
|
2013-01-19 16:50:44 +04:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
func (this *Node) FromWgsCoord(lon float64, lat float64) {
|
2013-01-28 10:55:34 +04:00
|
|
|
longInt := coordToInt(lon)
|
|
|
|
latInt := coordToInt(lat)
|
|
|
|
this.Long = &longInt
|
|
|
|
this.Lat = &latInt
|
2013-01-19 16:50:44 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
func (this *Way) Marshal() []byte {
|
|
|
|
data, err := proto.Marshal(this)
|
|
|
|
if err != nil {
|
|
|
|
log.Fatal("marshaling error: ", err)
|
|
|
|
}
|
|
|
|
return data
|
|
|
|
}
|