簡體   English   中英

python中X和Y的經度和緯度

[英]Latitude and Longitude to X and Y in python

我使用的是Google Maps上的圖片,大小約為200x200英尺(房屋和房屋的大小)。 我的目標是要有一個輸入坐標(例如[37.211817,-86.682670]),可以使用自己的數學運算符在我拍攝的Google Maps圖片上放置一個標記。 我已經看過並嘗試了許多方法。 我只是想取一個緯度/經度,並按比例將其放在X和Y大的正方形中。

好的,我找到了答案,我將分享它,因為它似乎比我預期的要復雜。 解決方案是將GPS坐標順時針旋轉90°,然后在Y軸上執行反射。 ->(y,-x)+>(x,-y)。

編輯

是的,所有要做的就是翻轉x和y。 是lat-lon,不是lon-lat。

然后,這是一個適合您的屏幕的簡單縮放比例公式。 這是代碼:

top_left_raw = GPS_COORD
bottom_right_raw = GPS_COORD
maprect = [0,0,400,500] # Picture of map's width and height

def translate(pos):
    #rot = (pos[1], pos[0]*-1)
    #reflect = (rot[0], rot[1]*-1)
    #return reflect
    return (pos[1], pos[0])

def gps_to_coord(pos):
    pos1 = translate((pos[0]-top_left_raw[0], pos[1]-top_left_raw[1]))
    pos2 = translate((bottom_right_raw[0] - top_left_raw[0], bottom_right_raw[1] - top_left_raw[1]))
    x = (maprect[2]*pos1[0]) / pos2[0]
    y = (maprect[3]*pos1[1]) / pos2[1]
    return (x,y)

gps_to_coord(GPS_COORD)

為了簡單起見,我們假設GPS坐標可以線性縮放到另一個坐標系。 您將需要圖像上最左上角的點和最右下角的GPS坐標:

偽代碼:

input: gps_marker

let gps1 = lat/lon of location corresponding to top left of image.
let gps2 = lat/lon of location corresponding to bottom right of image.

let x_offset = (gps_marker.lon - gps1.lon)/(gps2.lon - gps1.lon) * image.width
let y_offset = (gps_marker.lat - gps1.lat)/(gps2.lat - gps1.lat) * image.height

// x_offset and y_offset are the x,y for your marker within the image.

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM