2017-09-01 36 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分析进行一些计算,有时,除了某些库的文档外,很难找到信息。 非常感谢您的帮助! –

相关问题