从kml文件计算地面叠加角的纬度/经度

时间:2009-10-26 12:40:33

标签: php javascript geometry kml

我需要在php或javascript中的kml文件中找到地面叠加层的lat / lng中的角点。

即。对于我需要得到的具体例子:

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

到角坐标

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  ) );

应该很容易回来,但我已经花了好几个小时没有到达那里。有什么提示吗?

1 个答案:

答案 0 :(得分:4)

您需要使用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表的差异。

相关问题