2025-09-21 02:40:42 +08:00

34 lines
736 B
Go

package radarfetch
import (
"fmt"
"math"
)
func BuildCMAURL(base string, date int, hour int, minute int, z int, y int, x int) string {
yyyy := date / 10000
mm := (date / 100) % 100
dd := date % 100
return fmt.Sprintf("%s/tiles/China/RADAR_L3_MST_CREF_GISJPG_Tiles_CR/%04d%02d%02d/%02d/%02d/%d/%d/%d.bin",
trimSlash(base), yyyy, mm, dd, hour, minute, z, y, x)
}
func Bounds4326(z, y, x int) (west, south, east, north, resDeg float64) {
step := 360.0 / math.Ldexp(1.0, z)
west = -180.0 + float64(x)*step
east = west + step
south = -90.0 + float64(y)*step
north = south + step
resDeg = step / 256.0
return
}
func trimSlash(s string) string {
n := len(s)
for n > 0 && s[n-1] == '/' {
s = s[:n-1]
n--
}
return s
}