php - 从 kml 文件计算地面覆盖 Angular 的纬度/经度

标签 php javascript geometry kml

我需要在 php 或 javascript 中的 kml 文件中找到地面叠加层的纬度/经度 Angular 。

即对于一个具体的例子,我需要从:

  <LatLonBox>
    <north>60.406505416667</north>
    <south>60.400570555556</south>
    <east>5.3351572222222</east>
    <west>5.3190577777778</west>
    <rotation>3.7088732260919</rotation>
  </LatLonBox>

转 Angular 坐标

SW: 60.400316388889;5.3194425
SE: 60.400824722222;5.3355405555556
NE: 60.406759444444;5.3347738888889
NW: 60.406251388889;5.3186730555556

我可以通过以下方式获得另一种方式(大约至少,给出 php 代码)

$w=($nw_lng+$sw_lng)/2;
$e=($ne_lng+$se_lng)/2;
$n=($ne_lat+$nw_lat)/2;
$s=($se_lat+$sw_lat)/2;
$rot= rad2deg (atan ( ( $nw_lng - $sw_lng ) / ($sw_lat - $nw_lat ) / 2  ) );

应该很容易回来,但我已经花了好几个小时才回来。有什么建议吗?

最佳答案

您需要使用 spherical trigonometry , 的一部分 spherical geometry为了完全准确。但是,由于您只处理球体的一小部分,如果您记住一件事,欧几里德几何就可以了。

随着纬度的增加,经度线靠得更近。例如,在北极附近,纬线几乎是接触的。因此,调节您的纬度差异,通过乘以 cos(纬度)因子来减少它们。这将为您的应用提供足够好的准确性。

 $n = 60.406505416667;
 $s = 60.400570555556;
 $e = 5.3351572222222;
 $w = 5.3190577777778;
 $rotn = 3.7088732260919;

 $a = ($e + $w) / 2.0;
 $b = ($n + $s) / 2.0;
 $squish = cos(deg2rad($b));
 $x = $squish * ($e - $w) / 2.0;
 $y = ($n - $s) / 2.0;

 $ne = array(
   $a + ($x * cos(deg2rad($rotn)) - $y * sin(deg2rad($rotn))) /$squish,
   $b + $x * sin(deg2rad($rotn)) + $y *cos(deg2rad($rotn))
   );
 $nw = array(
   $a - ($x * cos(deg2rad($rotn)) + $y * sin(deg2rad($rotn))) /$squish,
   $b - $x * sin(deg2rad($rotn)) + $y *cos(deg2rad($rotn))
   );
 $sw = array(
   $a - ($x * cos(deg2rad($rotn)) - $y * sin(deg2rad($rotn))) /$squish,
   $b - $x * sin(deg2rad($rotn)) - $y *cos(deg2rad($rotn))
   );
 $se = array(
   $a + ($x * cos(deg2rad($rotn)) + $y * sin(deg2rad($rotn))) /$squish,
   $b + $x * sin(deg2rad($rotn)) - $y *cos(deg2rad($rotn))
   );
 print_r(array(
 'sw'=>$sw,
 'se'=>$se,
 'ne'=>$ne,
 'nw'=>$nw,
 ));

我的 $squish 变量是我提到的 cos(lat)。水平长度的相对部分有去挤压。正弦表如下所示:

NE: (a + x cos A - y sin A, b + x sin A + y cos A)
NW: (a - x cos A - y sin A, b - x sin A + y cos A)
SW: (a - x cos A + y sin A, b - x sin A - y cos A)
SE: (a + x cos A + y sin A, b + x sin A - y cos A)

也许 tttppp 可以解释与 tttppp 表格的差异。

关于php - 从 kml 文件计算地面覆盖 Angular 的纬度/经度,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1624574/

相关文章:

php - 使用 PHP 在 URL 中获取名称

javascript - HTML/PHP 在我填充的地方设置选项值 select from array

javascript - 如何将值数组传递给自动完成选项

javascript - 圆坐标到 Javascript 中的数组

java - 基于Java的圆计算器的问题

php - MySQL和PHP解析奇怪的字符串

php - 验证元素是否已准备好在 php 的 foreach() 循环中使用的最佳方法是什么?

javascript - 为什么在 jquery 中动态创建的复选框定义属性的顺序会影响其值?

javascript - combineLatest<{ [id : string]: Book }, string[]> 这是什么?

展平 3D 三角形带的算法