PHP 中的圆生成器在国际日期变更线上失败

问题描述 投票:0回答:1

我有一个圆生成器,可以围绕纬度和经度绘制 KML 圆。它对于我输入的 99% 的坐标都可以正常工作,但是如果位置靠近国际日期变更线,它就会在绘图上阻塞。 我想知道是否有人处理过这个问题并可以提供解决方案。

这是我的循环,如果我使用坐标,我正在使用 19.282494,166.636650 我围绕这一点的半径是 1047NM,因为它围绕它穿过国际日期的点迭代 线。这是当它经过 0 度和 180 度时的输出,看起来很窒息

<coordinates>166.63665,36.70122262,30 170.33929602,36.39506383,30 173.86075879,35.49288317,30 177.04308391,34.04103068,30 179.76710126,32.10928643,30 -178.04299159,29.78247231,30 -176.42417943,27.15263215,30 -175.38386586,24.31316399,30 -174.90965799,21.35519771,30 -174.97725208,18.36580524,30 -175.55559428,15.42737555,30 -176.60947581,12.617518,30 -178.10014056,10.00900144,30 -179.98458741,7.66939861,30 177.7857603,5.66025581,30 175.26638245,4.0357509,30 172.52041272,2.84094525,30 169.61836825,2.10986796,30 166.63665,1.86376538,30 163.65493175,2.10986796,30 160.75288728,2.84094525,30 158.00691755,4.0357509,30 155.4875397,5.66025581,30 153.25788741,7.66939861,30 151.37344056,10.00900144,30 149.88277581,12.617518,30 148.82889428,15.42737555,30 148.25055208,18.36580524,30 148.18295799,21.35519771,30 148.65716586,24.31316399,30 149.69747943,27.15263215,30 151.31629159,29.78247231,30 153.50619874,32.10928643,30 156.23021609,34.04103068,30 159.41254121,35.49288317,30 162.93400398,36.39506383,30 166.63665,36.70122262,30 </coordinates>
foreach($ap as $name)
{
    $name=trim(strtoupper($name));
    $circleLat = $airport[$name][0];
    $circleLon = $airport[$name][1];
    $circleRadius = $_GET['circleRadius']*1852;
    $circlePrecision = mostPrecision($circleLat, $circleLon, $circleRadius);
    $coordinatesList = "";
    // Code based on Google Earth community posting by 'ink_polaroid'
    // http://bbs.keyhole.com/ubb/showflat.php/Cat/0/Number/23634/an//page//vc/1
    $num_points = 36;
    $delta_pts = 360/$num_points;
    // convert coordinates to radians
    $lat = deg2rad(floatval($circleLat));
    $lon = deg2rad(floatval($circleLon));
    $d = $circleRadius;
    $d_rad = $d/6378137; // convert dist to angular distance in radians
    // loop around the compass, appending coordinates of each vertex
    for($i=0; $i<=$num_points; $i++) {  
      $radial = deg2rad($i*$delta_pts);
      $lat_rad = asin(sin($lat)*cos($d_rad) + cos($lat)*sin($d_rad)*cos($radial));
      $dlon_rad = atan2(sin($radial)*sin($d_rad)*cos($lat), cos($d_rad)-sin($lat)*sin($lat_rad));
      $lon_rad = fmod(($lon+$dlon_rad + M_PI), 2*M_PI) - M_PI;
      $coordinatesList .= Round(rad2deg($lon_rad),$circlePrecision).",".Round(rad2deg($lat_rad),$circlePrecision).",30 ";
    }

TIA 史蒂夫

php math geolocation gis
1个回答
0
投票

我已经简化了你的代码很多,只是绕着机场的坐标转了一圈。

foreach($ap as $name)
{
    $name=trim(strtoupper($name));
    $circleLat = $airport[$name][0];
    $circleLon = $airport[$name][1];
    $circleRadius = $_GET['circleRadius']*1852;
    $circlePrecision = mostPrecision($circleLat, $circleLon, $circleRadius);
    $coordinatesList = "";
    // Code based on Google Earth community posting by 'ink_polaroid'
    // http://bbs.keyhole.com/ubb/showflat.php/Cat/0/Number/23634/an//page//vc/1
    $num_points = 36;
    $delta_pts = 360/$num_points;
    // convert coordinates to radians
    $lat = deg2rad(floatval($circleLat));
    $lon = deg2rad(floatval($circleLon));
    $d = $circleRadius;
    $d_rad = $d/6378137; // convert dist to angular distance in radians
    // loop around the compass, appending coordinates of each vertex
    for($i=0; $i<=$num_points; $i++) {  
      $radial = deg2rad($i*$delta_pts);
      $lonCircle = $d_rad*sin($radial);
      $latCircle = $d_rad*cos($radial);
      $coordinatesList .= Round(rad2deg($lon+$lonCircle),$circlePrecision).",".
                          Round(rad2deg($lat+$latCircle),$circlePrecision).",30 ";
    }
}

返回:

166.63665,36.70122,30
169.66138,36.43659,30
172.59421,35.65074,30
175.34601,34.36756,30
177.83319,32.62601,30
179.98017,30.47904,30
181.72171,27.99186,30
183.0049,25.24005,30
183.79075,22.30722,30
184.05538,19.28249,30
183.79075,16.25776,30
183.0049,13.32494,30
181.72171,10.57313,30
179.98017,8.08595,30
177.83319,5.93897,30
175.34601,4.19743,30
172.59421,2.91424,30
169.66138,2.1284,30
166.63665,1.86377,30
163.61192,2.1284,30
160.67909,2.91424,30
157.92729,4.19743,30
155.44011,5.93897,30
153.29313,8.08595,30
151.55159,10.57313,30
150.2684,13.32494,30
149.48255,16.25776,30
149.21792,19.28249,30
149.48255,22.30722,30
150.2684,25.24005,30
151.55159,27.99186,30
153.29313,30.47904,30
155.44011,32.62601,30
157.92729,34.36756,30
160.67909,35.65074,30
163.61192,36.43659,30
166.63665,36.70122,30

当然,没有返回值,为了清楚起见,返回值仅存在于结果中。请参阅(这个小提琴)[https://3v4l.org/YfbuD]。

我不知道这是否真的适用于您的 Keyhole 标记语言应用程序,这是您需要尝试的。

© www.soinside.com 2019 - 2024. All rights reserved.