2017-09-01 45 views

回答

1

這取決於你是否要堅持經度/緯度或您可以切換到投影座標系統,如UTM;還有你的意思是bearing。假設投影座標和compass bearing(從北向的順時針方向:0-360)的一種可能方式是沿軸承方向繪製一條線,其長度足以與多邊形相交併計算交點的座標。

比方說,我們在柏林含區的多邊形GeoDataFrame:

berlin 
# 
# bbox_east bbox_north bbox_south bbox_west geometry place_name 
# 0 13.429402 52.540407 52.504037 13.36586 POLYGON ((389163.2519209321 5821873.324153989,... Mitte, Berlin, Deutschland 

計算幾何的質心的X/Y(可以是任何點,這裏我用的質心爲代表的想法):

x = berlin.centroid.geometry.item().x 
y = berlin.centroid.geometry.item().y 

以下函數就可以計算出新點的座標:

from shapely.geometry import LineString, LinearRing 

def find_point(polygon, x, y , bearing): 

    east, south, west, north = polygon.bounds 
    line_length = max(abs(east-west), abs(north-south)) * 2 

    new_x = x + (np.sin(np.deg2rad(bearing)) * line_length) 
    new_y = y + (np.cos(np.deg2rad(bearing)) * line_length) 

    l = LineString([[x,y], [new_x, new_y]]) 
    lr = LinearRing(polygon.exterior.coords) 
    intersections = lr.intersection(l) 

    return intersections.x, intersections.y 

與我們的輸入數據試試:

x_, y_ = find_point(berlin.geometry[0], x, y, 120) 

fig, ax = plt.subplots() 

berlin.plot(ax=ax) 
plt.scatter(x_, y_) 
plt.scatter(x,y) 

enter image description here

+0

正是我一直在尋找。事實上,該算法接收WGS84中的數據,然後將其轉換爲UTM。軸承正是你所回答的! 我正在嘗試學習Python到地理處理,並對wind fetch和wave-oriented分析進行一些計算,有時,除了某些庫的文檔外,很難找到信息。 非常感謝您的幫助! –

相關問題