kmlファイルから地面オーバーレイの角の緯度/経度を計算する
-
06-07-2019 - |
質問
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
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 ) );
戻るのは簡単なはずですが、私はそこに着かずにこれに何時間も使いました。ヒントはありますか?
解決
緯度が上がると、経度の線は互いに近づきます。たとえば、北極の近くでは、緯線はほとんど接触しています。したがって、緯度の差を調整し、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のテーブルとの違いを説明できるでしょう。
所属していません StackOverflow