与えられた緯度/経度位置の境界ボックスを計算するにはどうすればいいですか? 質問する

与えられた緯度/経度位置の境界ボックスを計算するにはどうすればいいですか? 質問する

緯度と経度で定義された場所を指定しました。次に、その地点から例えば 10 キロメートル以内の境界ボックスを計算します。

境界ボックスは、latmin、lngmin、latmax、lngmax として定義する必要があります。

この製品を使うにはこれが必要ですパノラミオAPI

これらのポイントを獲得する方法を知っている人はいますか?

編集:皆さん、私は緯度と経度を入力として受け取り、境界ボックスを緯度最小値と経度最小値、緯度最大値と緯度最小値として返す数式/関数を探しています。Mysql、php、c#、javascript は問題ありませんが、疑似コードでも問題ないはずです。

編集:私は2点間の距離を示す解決策を探しているのではない

ベストアンサー1

地球の表面を、指定された緯度における WGS84 楕円体によって与えられた半径を持つ球体として局所的に近似することを提案します。latMin と latMax の正確な計算には楕円関数が必要であり、精度が大幅に向上することはないと思われます (WGS84 自体は近似値です)。

私の実装は次のとおりです (Python で書かれていますが、テストしていません)。

# degrees to radians
def deg2rad(degrees):
    return math.pi*degrees/180.0
# radians to degrees
def rad2deg(radians):
    return 180.0*radians/math.pi

# Semi-axes of WGS-84 geoidal reference
WGS84_a = 6378137.0  # Major semiaxis [m]
WGS84_b = 6356752.3  # Minor semiaxis [m]

# Earth radius at a given latitude, according to the WGS-84 ellipsoid [m]
def WGS84EarthRadius(lat):
    # http://en.wikipedia.org/wiki/Earth_radius
    An = WGS84_a*WGS84_a * math.cos(lat)
    Bn = WGS84_b*WGS84_b * math.sin(lat)
    Ad = WGS84_a * math.cos(lat)
    Bd = WGS84_b * math.sin(lat)
    return math.sqrt( (An*An + Bn*Bn)/(Ad*Ad + Bd*Bd) )

# Bounding box surrounding the point at given coordinates,
# assuming local approximation of Earth surface as a sphere
# of radius given by WGS84
def boundingBox(latitudeInDegrees, longitudeInDegrees, halfSideInKm):
    lat = deg2rad(latitudeInDegrees)
    lon = deg2rad(longitudeInDegrees)
    halfSide = 1000*halfSideInKm

    # Radius of Earth at given latitude
    radius = WGS84EarthRadius(lat)
    # Radius of the parallel at given latitude
    pradius = radius*math.cos(lat)

    latMin = lat - halfSide/radius
    latMax = lat + halfSide/radius
    lonMin = lon - halfSide/pradius
    lonMax = lon + halfSide/pradius

    return (rad2deg(latMin), rad2deg(lonMin), rad2deg(latMax), rad2deg(lonMax))

編集: 次のコードは、(度、素数、秒) を度 + 度の小数に変換し、その逆も行います (テストされていません)。

def dps2deg(degrees, primes, seconds):
    return degrees + primes/60.0 + seconds/3600.0

def deg2dps(degrees):
    intdeg = math.floor(degrees)
    primes = (degrees - intdeg)*60.0
    intpri = math.floor(primes)
    seconds = (primes - intpri)*60.0
    intsec = round(seconds)
    return (int(intdeg), int(intpri), int(intsec))

おすすめ記事