从kml文件计算地面覆盖角落的纬度/经度 [英] Calculate lat/lng of corners of ground overlay from kml-file

查看:140
本文介绍了从kml文件计算地面覆盖角落的纬度/经度的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

即,对于我需要的特定示例:

 < 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
净重: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));

应该很容易找回来,但我已经用了几个小时而没有到达那里。任何提示?

解决方案

您需要使用球形三角法,是球形几何的一部分完全准确。然而,由于你只处理球体的一小部分,所以如果你还记得一件事情,欧几里德几何就会做。随着纬度的增加,经度线越来越近一起。例如,在北极附近,纬线几乎接触。因此,要处理你的纬度差异,通过多因素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拉特)我提到。有水平长度的相对部分去除。正弦表看起来像这样:

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

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


I need to find the corners in lat/lng of a ground overlay given in a kml-file either in php or javascript.

I.e. for a specific example I need to get from:

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

to corner coordinates

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

I can get the other way (approximately at least, php code given) by

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

Should be easy to get back, but I've used hours for this without getting there. Any tips?

解决方案

You need to use spherical trigonometry, part of spherical geometry for full accuracy. However, since you are dealing with only a small piece of the sphere, euclidian geometry will do if you remember one thing.

As latitude increases, the lines of longitude get closer together. For example, near the North Pole, the latitude lines are almost touching. So condition your latitude differences, diminishing them by mulitlying by a factor of cos(latitude). That will give you good enough accuracy for your app.

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

My $squish variable is the cos(lat) I mentioned. There is de-squishing for the relative part of horizontal lengths. The sine table looks like this:

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)

Perhaps tttppp could account for the differences from tttppp's table.

这篇关于从kml文件计算地面覆盖角落的纬度/经度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆