4

特定の中心点 (緯度/経度) の正確な境界ボックスを計算できる PHP ライブラリ/PHP スクリプトを探しています。

楕円体式 (f.ex. WGS84) を使用すると、すばらしいでしょう。ライブラリが必要なのはわかっていますが、見つけることができません。

4

2 に答える 2

8

// ベアリング ビットの後の関数が間違っています。次のようになります。

function getBoundingBox($lat_degrees,$lon_degrees,$distance_in_miles) {

    $radius = 3963.1; // of earth in miles

    // bearings - FIX   
    $due_north = deg2rad(0);
    $due_south = deg2rad(180);
    $due_east = deg2rad(90);
    $due_west = deg2rad(270);

    // convert latitude and longitude into radians 
    $lat_r = deg2rad($lat_degrees);
    $lon_r = deg2rad($lon_degrees);

    // find the northmost, southmost, eastmost and westmost corners $distance_in_miles away
    // original formula from
    // http://www.movable-type.co.uk/scripts/latlong.html

    $northmost  = asin(sin($lat_r) * cos($distance_in_miles/$radius) + cos($lat_r) * sin ($distance_in_miles/$radius) * cos($due_north));
    $southmost  = asin(sin($lat_r) * cos($distance_in_miles/$radius) + cos($lat_r) * sin ($distance_in_miles/$radius) * cos($due_south));

    $eastmost = $lon_r + atan2(sin($due_east)*sin($distance_in_miles/$radius)*cos($lat_r),cos($distance_in_miles/$radius)-sin($lat_r)*sin($lat_r));
    $westmost = $lon_r + atan2(sin($due_west)*sin($distance_in_miles/$radius)*cos($lat_r),cos($distance_in_miles/$radius)-sin($lat_r)*sin($lat_r));


    $northmost = rad2deg($northmost);
    $southmost = rad2deg($southmost);
    $eastmost = rad2deg($eastmost);
    $westmost = rad2deg($westmost);

    // sort the lat and long so that we can use them for a between query        
    if ($northmost > $southmost) { 
        $lat1 = $southmost;
        $lat2 = $northmost;

    } else {
        $lat1 = $northmost;
        $lat2 = $southmost;
    }


    if ($eastmost > $westmost) { 
        $lon1 = $westmost;
        $lon2 = $eastmost;

    } else {
        $lon1 = $eastmost;
        $lon2 = $westmost;
    }

    return array($lat1,$lat2,$lon1,$lon2);
}

http://xoxco.com/clickable/php-getboundingboxのおかげで、この関数を取得しました。

于 2010-06-30T11:56:59.497 に答える
1

これは、バウンディング ボックスが一方の方向に東西に、もう一方の方向に南北に延びていると仮定すると、比較的簡単に解決できる問題です。緯度と経度を独立して行うことができます。

緯度については、ポイントを西から東に並べ替えます。その時点で、リストを循環バッファーとして扱う必要があります。各ポイントをテストして、次のポイントが最も遠いポイントを見つける必要があります。したがって、10 点が0から9であると仮定すると、45が最も離れている場合、緯度バウンディング ボックスは5ラウンドから4になります。それらをwおよび a eと呼びます

経度については、最北端と最南端を見つけて、それらを a nと a sと呼ぶだけです。

a wと a eの経度と a nと a s の緯度は、境界ボックスを定義します。

于 2010-04-13T08:34:35.587 に答える