从 kml 文件计算地面覆盖物角点的纬度/经度
我需要找到 kml 文件中以 php 或 javascript 给出的地面覆盖层的经纬度角点。
即,对于一个具体的示例,我需要从:
<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 ) );
应该很容易返回,但我已经用了几个小时而没有到达那里。有什么建议吗?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您需要使用球面三角函数,它是球面几何以获得完全精确度。然而,由于您只处理球体的一小部分,因此如果您记住一件事,欧几里德几何就可以了。
随着纬度的增加,经线变得更加靠近。例如,在北极附近,纬线几乎相连。因此,调节你的纬度差异,通过乘以 cos(纬度) 因子来减小它们。这将为您的应用程序提供足够好的准确性。
我的
$squish
变量是我提到的 cos(lat)。对水平长度的相对部分进行了去挤压。正弦表如下所示:也许 tttppp 可以解释与 tttppp 表的差异。
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.
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:Perhaps tttppp could account for the differences from tttppp's table.