/**
* 根据风向和风速计算风的uv分量
*/
function calcWind(v) {
calcUV = (ds, dw) => {
if (ds < 0) return {
u: 0,
v: 0
}
return {
u: ds * Math.cos((270 - dw) * Math.PI / 180),
v: ds * Math.sin((270 - dw) * Math.PI / 180)
}
}
return v.map(e => calcUV(e.wind_speed_at_ten_meters, e.wind_direction_at_ten_meters))
}
/**
* 经纬度网格划分
*/
function calcLonLat(lo1, lo2, la1, la2, nx, ny) {
const numToArr = (a1, a2, n) => {
nv = (a2-a1)/n
arr = []
while (a1 < a2) {
a1 += nv
arr.push(a1)
}
return arr
}
let arrLo = numToArr(lo1,lo2,nx)
let arrLa = numToArr(la1,la2,ny)
return {
lo: [...arrLo],
la: [...arrLa],
}
}
/**
* 经纬度网格转具体坐标
*/
function calcLonLatToMap(o) {
return o.lo.map(lo=>{
return o.la.map(la => {
return {
lo: lo,
la: la
}
})
})
}
console.log(calcLonLatToMap(calcLonLat(110,140,0,40,10,10)))
console.log(calcWind(
[
{
"wind_speed_at_ten_meters": "5.9210815",
"lon": 119.8384930475,
"wind_direction_at_ten_meters": "117.3913",
"lat": 34.5924223066666
},
{
"wind_speed_at_ten_meters": "6.0296783",
"lon": 121.1844538,
"wind_direction_at_ten_meters": "121.20606",
"lat": 33.6400016
},
{
"wind_speed_at_ten_meters": "5.560688",
"lon": 121.4182643,
"wind_direction_at_ten_meters": "112.233696",
"lat": 33.1695206
},
{
"wind_speed_at_ten_meters": "5.831649",
"lon": 122.2550822225,
"wind_direction_at_ten_meters": "117.40398",
"lat": 32.0494005919444
},
{
"wind_speed_at_ten_meters": "6.8596387",
"lon": 121.492430277777,
"wind_direction_at_ten_meters": "116.71792",
"lat": 32.7300191666666
},
{
"wind_speed_at_ten_meters": "6.8596387",
"lon": 121.323369,
"wind_direction_at_ten_meters": "116.71792",
"lat": 32.6802815
},
{
"wind_speed_at_ten_meters": "6.9308047",
"lon": 122.235778606111,
"wind_direction_at_ten_meters": "119.41637",
"lat": 32.1017966961111
},
{
"wind_speed_at_ten_meters": "6.9308047",
"lon": 122.096345000277,
"wind_direction_at_ten_meters": "119.41637",
"lat": 32.1744147483333
}
]
))
console