javascript - 了解从 lon., lat. 的无证转换。地球表面坐标到图像的 x, y 坐标
问题描述
我尝试在从天气提供商收到的天气雷达图像上实现一些功能。在提供者网站上,我发现了一个函数,可以将用户输入的坐标转换为图像中的像素坐标。因为所有变量都是匿名的并且代码没有记录,所以我无法弄清楚该函数是如何工作的。我对坐标参考系统知之甚少,并且地图图像的 CRS 是未知的,因此我需要建议。
在下面的代码中,您可以看到我的代码分析进度。我花了将近一天的时间试图弄清楚 un25 代表什么变量。不成功。我不能盲目地将整个功能粘贴到我的项目中我需要了解背后的理论。
function lonlat2xy(lonUsrD, latUsrD) { //user input position in lon a lat in degrees
var oneRadOfDegree = 57.29577951308232; // for conversion of degrees to rads
var latPragR = 50.008 / oneRadOfDegree; //lat. of base station, default position in rads
var lonPragR = 14.447 / oneRadOfDegree; //lon. of base station, default position in rads
var leftPragPx = 301.5; // length from left side of image to base station in px
var topPragPx = 217.5; // length from top side of image to base station in px
var ratioMap = 1.0; //ratio of the map (always 1 for thos example)
var radiusEarth = 6378.144; //radius of Earth
var pi1 = 3.141592653589793; //pi
var pi2 = 6.283185307179586; //2pi
var pi05 = 1.570796326794897; //0.5pi
var lonUsrRNeg = -1 * (lonUsrD / oneRadOfDegree); //inversed user lon. position in rads
var latUsrR = latUsrD / oneRadOfDegree; //user lat. position in rads
var lonPragRNeg = -1 * lonPragR; //inversed base station lon. position in rads
var latPragR1 = latPragR; //base station lat. position in rads
//?????? No idea what this formula does
var un25 = (Math[sin](latUsrR) * Math[sin](latPragR1)) + (Math[cos](latUsrR) * Math[cos](latPragR1) * Math[cos](lonUsrRNeg - lonPragRNeg));
sin()
//??????
var un26 = Math[acos](un25);
un25 = Math[sin](latUsrR) - (Math[sin](latPragR1) * un25);
var un27 = (Math[cos](latPragR1) * Math[sin](un26));
if (un27 != 0) {
un25 = un25 / un27;
} else {
un25 = 0;
}
var un28 = Math[acos](un25);
var lonDiffPragUsr = lonUsrRNeg - lonPragRNeg;
if ((lonUsrRNeg > lonPragRNeg) && (lonDiffPragUsr < pi1)) {
un28 = pi2 - un28;
}
var un2a = un26;
var un2b = un28;
var xPxImg, yPxImg, un2e;
if (un2a < pi05) {
un2e = Math[tan](un2a);
xPxImg = un2e * Math[sin](un2b);
yPxImg = un2e * Math[cos](un2b);
} else {
xPxImg = 0;
yPxImg = 0;
}
//[xy]PxImg - wrong name - I dont know what exactly this var represent
xPxImg = leftPragPx + (xPxImg * radiusEarth) / ratioMap; //IMG-x = (IMGx prazske stanice) + ((2PI*(pixN/pix360)) * polomer zeme)/ 1 ... ratio
yPxImg = topPragPx - ((yPxImg * radiusEarth) / ratioMap);
//Clear part from here
var xPxImgRo = Math[round](xPxImg); //Round IMG-x
var yPxImgRo = Math[round](yPxImg); //Round IMG-y
out_xy = new Array(2); //create array for rturn
out_xy[0] = xPxImgRo;
out_xy[1] = yPxImgRo;
return out_xy;
}
网址
供应商应用程序:http: //portal.chmi.cz/files/portal/docs/meteo/rad/data_jsradview.html
坐标转换图片示例:http: //portal.chmi.cz/files/portal/docs/meteo/rad/data_tr_png_1km/pacz23.z_max3d.20190824.1100.0.png
解决方案
我能够找到这个文件https://core.ac.uk/download/pdf/44390425.pdf 据我所知,这都是关于球面投影的。您可以尝试朝那个方向发展,以找到更多的理论背景。
更多链接:
推荐阅读
- c# - 在 Visual Studio(不是 VS Code)中为 C# 代码添加自定义缩进
- amazon-web-services - API 网关与 Lambda 和 DynamoDB 的集成
- anylogic - 任何逻辑的统计数据
- awk - awk 为测试元素创建一个列表
- django - 'str' 和 'int' 的实例之间不支持 /formpage '>' 处的 TypeError 错误也特定于 form.is_valid
- git - 从存储库推送和拉取
- r - 努力理解 Q1 计算
- python - 使用 Python Beautiful Soup 在 Web 抓取中提取价值
- python - 检查numpy数组窗口中的元素是否有限的更快方法
- azure - 是否可以通过用户租户上的 ARM 模板在 Azure 上自动注册应用程序?