是否有数学计算可以通过谷歌的 Elevation API 定义点 A 和点 B 之间是否存在可见性?

Posted

技术标签:

【中文标题】是否有数学计算可以通过谷歌的 Elevation API 定义点 A 和点 B 之间是否存在可见性?【英文标题】:Is there a mathematical calculation to define if there is visibility between a point A and a point B via google's Elevation API? 【发布时间】:2020-07-31 19:51:18 【问题描述】:

有没有办法通过 google API 获取海拔剖面数据来检查两点之间是否存在视线?

例如我可以通过此链接获得海拔剖面:https://maps.googleapis.com/maps/api/elevation/json?path=36.578581,-118.291994|36.23998,-116.83171&samples=10&key=YOUR_API_KEY

结果是一个 10 点的 json,位于两点之间,其地面高程,例如:

    
   "results" : [
      
         "elevation" : 4411.94189453125,
         "location" : 
            "lat" : 36.578581,
            "lng" : -118.291994
         ,
         "resolution" : 19.08790397644043
      ,
      
         "elevation" : 1658.561645507812,
         "location" : 
            "lat" : 36.54183904164596,
            "lng" : -118.1291141726249
         ,
         "resolution" : 9.543951988220215
      ,
      
         "elevation" : 1085.295776367188,
         "location" : 
            "lat" : 36.50487579522382,
            "lng" : -117.966389550823
         ,
         "resolution" : 9.543951988220215
      ,
      
         "elevation" : 1491.4912109375,
         "location" : 
            "lat" : 36.46769177008888,
            "lng" : -117.8038207060907
         ,
         "resolution" : 9.543951988220215
      ,
      
         "elevation" : 1583.762817382812,
         "location" : 
            "lat" : 36.43028747728768,
            "lng" : -117.6414082023003
         ,
         "resolution" : 9.543951988220215
      ,
      
         "elevation" : 488.8834228515625,
         "location" : 
            "lat" : 36.39266342953181,
            "lng" : -117.4791525957044
         ,
         "resolution" : 9.543951988220215
      ,
      
         "elevation" : 933.0382080078125,
         "location" : 
            "lat" : 36.35482014117158,
            "lng" : -117.3170544349424
         ,
         "resolution" : 9.543951988220215
      ,
      
         "elevation" : 1657.123779296875,
         "location" : 
            "lat" : 36.31675812816988,
            "lng" : -117.1551142610472
         ,
         "resolution" : 9.543951988220215
      ,
      
         "elevation" : 1074.835205078125,
         "location" : 
            "lat" : 36.27847790807609,
            "lng" : -116.9933326074523
         ,
         "resolution" : 9.543951988220215
      ,
      
         "elevation" : -84.51690673828125,
         "location" : 
            "lat" : 36.23998,
            "lng" : -116.83171
         ,
         "resolution" : 9.543951988220215
      
   ],
   "status" : "OK"

是否有数学公式可以检查A点和B点是否可以看到?

我需要用 php 编写代码。

谢谢大家。

【问题讨论】:

你说这10个点在A点和B点之间,那么它们都和经过A点和B点的线在同一条线上吗? 是的,这些点在同一条线上。 【参考方案1】:

鉴于您正在处理沿直线的 2 个点,我认为处理此问题的最简单方法是从 2D 角度查看它,其中 x 轴指的是您的样本编号,y-轴是指您的海拔高度。

然后我们假设如果结果 n 处的高程高于直线,则视线被破坏。

地点:

(x1, y1) = (1, 4411.94)

(x2, y2) = (10, -84.51)

这是一张绘制结果的图片,并在其上绘制了从一点到另一点的线:

我们可以看到样本 8 和 9 的视线被破坏了。

下面是找到相同的代码。它使用直线的基本方程:y = mx + c

$results_json  = json_decode('"results":["elevation":4411.94189453125,"location":"lat":36.578581,"lng":-118.291994,"resolution":19.08790397644043,"elevation":1658.561645507812,"location":"lat":36.54183904164596,"lng":-118.1291141726249,"resolution":9.543951988220215,"elevation":1085.295776367188,"location":"lat":36.50487579522382,"lng":-117.966389550823,"resolution":9.543951988220215,"elevation":1491.4912109375,"location":"lat":36.46769177008888,"lng":-117.8038207060907,"resolution":9.543951988220215,"elevation":1583.762817382812,"location":"lat":36.43028747728768,"lng":-117.6414082023003,"resolution":9.543951988220215,"elevation":488.8834228515625,"location":"lat":36.39266342953181,"lng":-117.4791525957044,"resolution":9.543951988220215,"elevation":933.0382080078125,"location":"lat":36.35482014117158,"lng":-117.3170544349424,"resolution":9.543951988220215,"elevation":1657.123779296875,"location":"lat":36.31675812816988,"lng":-117.1551142610472,"resolution":9.543951988220215,"elevation":1074.835205078125,"location":"lat":36.27847790807609,"lng``":-116.9933326074523,"resolution":9.543951988220215,"elevation":-84.51690673828125,"location":"lat":36.23998,"lng":-116.83171,"resolution":9.543951988220215],"status":"OK"');

$x1 = 0;
$x2 = count($results_json->results);

$y1 = $results_json->results[0]->elevation;
$y2 = $results_json->results[$x2 - 1]->elevation; // last result in results array

$m = ($y2 - $y1) / ($x2 - $x1); // slope of the line
$c = $y2 - ($m * $x2);

$i = 0;
foreach ($results_json->results as $result)
    $elevation_of_straight_line = ($m * $i) + $c;
    $elevation_of_result = $result->elevation;
    if ($elevation_of_result > $elevation_of_straight_line)
        echo 'line of sight broken';
        echo 'Elevation of sample index '.$i.' = '.$elevation_of_result;
        echo 'Elevation of line of sight = '.$elevation_of_straight_line;
    
    $i++;

这消除了从 3D 角度看待这个问题所带来的复杂性。尽管对于地球曲率起作用的情况,这有其缺点。 这也应该可以扩展到任意数量的样本。

【讨论】:

嗨罗斯,谢谢,我有一个问题:视线的最后一个标高点与最后一个点的地面标高不同 嘿 Uccio,是的,我也注意到了这一点。根据谷歌的文档:“地球表面上所有位置的海拔数据都可用,包括海底的深度位置(返回负值)”developers.google.com/maps/documentation/elevation/intro 似乎有点奇怪,纬度低于可见水平,但我想这是可能的

以上是关于是否有数学计算可以通过谷歌的 Elevation API 定义点 A 和点 B 之间是否存在可见性?的主要内容,如果未能解决你的问题,请参考以下文章

是否可以使用谷歌的人api加载联系人图片?

你是否了解谷歌的无头浏览器?

两个纬度/经度点之间的谷歌地图距离计算?

机器学习谷歌的速成课程

JavaScript中的简单浮点数学

除了谷歌的TensorFlow,这些开源机器学习项目也很值得收藏!