IT박스

위도 또는 경도를 미터로 변환하는 방법?

itboxs 2020. 7. 30. 10:13
반응형

위도 또는 경도를 미터로 변환하는 방법?


표준 NMEA 형식의 위도 또는 경도 판독 값을 가진 경우 해당 판독 값을 미터로 변환하는 쉬운 방법 / 수식이 있습니까? 그러면 Java (J9)로 구현할 수 있습니까?

편집 : 좋아, 내가하고 싶은 일은 쉽게 불가능한 것처럼 보이지만 실제로하고 싶은 것은 :

위도 및 경도의 포인트가 있고 사용자의 위도 및 경도가 사용자에게 웨이 포인트와 합리적으로 가까운 거리 내에 있음을 사용자에게 알려주는 방법을 쉽게 비교할 수 있습니까? 나는 합리적인 주제라는 것을 알고 있지만 이것은 쉽게 할 수 있거나 여전히 지나치게 수학적인가?


다음은 자바 스크립트 함수입니다.

function measure(lat1, lon1, lat2, lon2){  // generally used geo measurement function
    var R = 6378.137; // Radius of earth in KM
    var dLat = lat2 * Math.PI / 180 - lat1 * Math.PI / 180;
    var dLon = lon2 * Math.PI / 180 - lon1 * Math.PI / 180;
    var a = Math.sin(dLat/2) * Math.sin(dLat/2) +
    Math.cos(lat1 * Math.PI / 180) * Math.cos(lat2 * Math.PI / 180) *
    Math.sin(dLon/2) * Math.sin(dLon/2);
    var c = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1-a));
    var d = R * c;
    return d * 1000; // meters
}

설명 : https://en.wikipedia.org/wiki/Haversine_formula

haversine 공식은 경도와 위도를 고려하여 구의 두 점 사이의 원거리를 결정합니다.


간단한 공식을 찾고 있다면 지구가 둘레가 40075km 인 구라고 가정하면 가장 간단한 방법 일 것입니다.

위도 1 °의 미터 단위 길이 = 항상 111.32km

경도 1 °의 길이 (미터) = 40075 km * 코스 (위도) / 360


두 좌표 사이의 짧은 거리를 근사하기 위해 http://en.wikipedia.org/wiki/Lat-lon 에서 수식을 사용했습니다 .

m_per_deg_lat = 111132.954 - 559.822 * cos( 2 * latMid ) + 1.175 * cos( 4 * latMid);
m_per_deg_lon = 111132.954 * cos ( latMid );

.

아래 코드에서 나는 wikipedia의 공식과의 관계를 보여주기 위해 원시 숫자를 남겼습니다.

double latMid, m_per_deg_lat, m_per_deg_lon, deltaLat, deltaLon,dist_m;

latMid = (Lat1+Lat2 )/2.0;  // or just use Lat1 for slightly less accurate estimate


m_per_deg_lat = 111132.954 - 559.822 * cos( 2.0 * latMid ) + 1.175 * cos( 4.0 * latMid);
m_per_deg_lon = (3.14159265359/180 ) * 6367449 * cos ( latMid );

deltaLat = fabs(Lat1 - Lat2);
deltaLon = fabs(Lon1 - Lon2);

dist_m = sqrt (  pow( deltaLat * m_per_deg_lat,2) + pow( deltaLon * m_per_deg_lon , 2) );

Wikipedia 항목에 따르면 거리 계산은 세로 100km의 경우 0.6m, 위도 100km의 경우 1cm 이내이지만 정확도가 가까운 곳에서는 사용하기에 적합하지 않은 것으로 확인되지 않았습니다.


위도와 경도는 거리가 아닌 점을 지정하므로 질문은 다소 의미가 없습니다. 두 개의 (lat, lon) 점 사이의 최단 거리에 대해 문의하는 경우 원거리에 관한 Wikipedia 기사참조하십시오 .


지구는 성가 시게 불규칙한 표면이므로이를 정확하게 수행하는 간단한 공식은 없습니다. 대략적인 지구 모델로 살고 좌표를 투영해야합니다. 일반적으로이 모델에 사용 된 모델은 WGS 84 입니다. 이것은 GPS 장치가 일반적으로 똑같은 문제를 해결하기 위해 사용하는 것입니다.

NOAA는 자신의 웹 사이트 에서이 문제 를 해결 하기 위해 다운로드 할 수있는 소프트웨어를 가지고 있습니다 .


이것을 쉽게 만들어주는 많은 도구가 있습니다. 참조 monjardin의 대답 관련 기능에 대한 자세한 내용을.

그러나이를 수행하는 것이 반드시 어려운 것은 아닙니다. Java를 사용하는 것처럼 들리므로 GDAL 과 같은 것을 살펴 보는 것이 좋습니다 . 루틴에 대한 Java 랩퍼를 제공하며 Lat / Lon (지리 좌표)에서 UTM (투영 된 좌표계) 또는 기타 합리적인지도 투영으로 변환하는 데 필요한 모든 도구가 있습니다.

UTM은 미터이므로 작업하기가 쉽기 때문에 좋습니다. 그러나 제대로 작동하려면 적절한 UTM 영역가져와야합니다 . 위도 / 경도 쌍에 적합한 영역을 찾기 위해 인터넷 검색을 통해 사용할 수있는 간단한 코드가 있습니다.


bh-의 함수 의 R 버전은 다음과 같습니다 .

measure <- function(lon1,lat1,lon2,lat2) {
    R <- 6378.137                                # radius of earth in Km
    dLat <- (lat2-lat1)*pi/180
    dLon <- (lon2-lon1)*pi/180
    a <- sin((dLat/2))^2 + cos(lat1*pi/180)*cos(lat2*pi/180)*(sin(dLon/2))^2
    c <- 2 * atan2(sqrt(a), sqrt(1-a))
    d <- R * c
    return (d * 1000)                            # distance in meters
}

1 해리 (1852 미터)는 적도에서 1 의 경도 로 정의됩니다 . 그러나 변환이 실제로 이해되도록 작업중인 맵 투영 ( UTM 참조) 을 정의해야합니다 .


이를 계산하는 데는 몇 가지 방법이 있습니다. 그들 모두는 반지름이 지구 중 하나 인 구형 삼각법의 근접성을 사용합니다.

try http://www.movable-type.co.uk/scripts/latlong.html for a bit of methods and code in different languages.


    'below is from
'http://www.zipcodeworld.com/samples/distance.vbnet.html
Public Function distance(ByVal lat1 As Double, ByVal lon1 As Double, _
                         ByVal lat2 As Double, ByVal lon2 As Double, _
                         Optional ByVal unit As Char = "M"c) As Double
    Dim theta As Double = lon1 - lon2
    Dim dist As Double = Math.Sin(deg2rad(lat1)) * Math.Sin(deg2rad(lat2)) + _
                            Math.Cos(deg2rad(lat1)) * Math.Cos(deg2rad(lat2)) * _
                            Math.Cos(deg2rad(theta))
    dist = Math.Acos(dist)
    dist = rad2deg(dist)
    dist = dist * 60 * 1.1515
    If unit = "K" Then
        dist = dist * 1.609344
    ElseIf unit = "N" Then
        dist = dist * 0.8684
    End If
    Return dist
End Function
Public Function Haversine(ByVal lat1 As Double, ByVal lon1 As Double, _
                         ByVal lat2 As Double, ByVal lon2 As Double, _
                         Optional ByVal unit As Char = "M"c) As Double
    Dim R As Double = 6371 'earth radius in km
    Dim dLat As Double
    Dim dLon As Double
    Dim a As Double
    Dim c As Double
    Dim d As Double
    dLat = deg2rad(lat2 - lat1)
    dLon = deg2rad((lon2 - lon1))
    a = Math.Sin(dLat / 2) * Math.Sin(dLat / 2) + Math.Cos(deg2rad(lat1)) * _
            Math.Cos(deg2rad(lat2)) * Math.Sin(dLon / 2) * Math.Sin(dLon / 2)
    c = 2 * Math.Atan2(Math.Sqrt(a), Math.Sqrt(1 - a))
    d = R * c
    Select Case unit.ToString.ToUpper
        Case "M"c
            d = d * 0.62137119
        Case "N"c
            d = d * 0.5399568
    End Select
    Return d
End Function
Private Function deg2rad(ByVal deg As Double) As Double
    Return (deg * Math.PI / 180.0)
End Function
Private Function rad2deg(ByVal rad As Double) As Double
    Return rad / Math.PI * 180.0
End Function

To convert latitude and longitude in x and y representation you need to decide what type of map projection to use. As for me, Elliptical Mercator seems very well. Here you can find an implementation (in Java too).


Based on average distance for degress in the Earth.

1° = 111km;

Converting this for radians and dividing for meters, take's a magic number for the RAD, in meters: 0.000008998719243599958;

then:

const RAD = 0.000008998719243599958;
Math.sqrt(Math.pow(lat1 - lat2, 2) + Math.pow(long1 - long2, 2)) / RAD;

If its sufficiently close you can get away with treating them as coordinates on a flat plane. This works on say, street or city level if perfect accuracy isnt required and all you need is a rough guess on the distance involved to compare with an arbitrary limit.


If you want a simple solution then use the Haversine formula as outlined by the other comments. If you have an accuracy sensitive application keep in mind the Haversine formula does not guarantee an accuracy better then 0.5% as it is assuming the earth is a circle. To consider that Earth is a oblate spheroid consider using Vincenty's formulae. Additionally, I'm not sure what radius we should use with the Haversine formula: {Equator: 6,378.137 km, Polar: 6,356.752 km, Volumetric: 6,371.0088 km}.


You need to convert the coordinates to radians to do the spherical geometry. Once converted, then you can calculate a distance between the two points. The distance then can be converted to any measure you want.

참고URL : https://stackoverflow.com/questions/639695/how-to-convert-latitude-or-longitude-to-meters

반응형