簡體   English   中英

根據點和方位在Geopandas幾何邊上找到內部距離

[英]Find distance inside on a Geopandas geometry edge, based on points and bearing

我正在嘗試使用Geopandas對.shp中的某些數據進行地理處理。

我想在幾何邊中找到一個點,給定一個軸承和其中的一個初始點。

由於該算法將處理大量迭代(每點大約十次),因此我該如何以優化的方式進行操作?

圖片

這取決於您要堅持lon / lat還是可以切換到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)

在此處輸入圖片說明

暫無
暫無

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

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