我試圖根據點terrestical度量創建河流橫截面配置文件。當試圖用一系列具有通用id的點創建Shapely LineString
時,我意識到給定點的順序非常重要,因爲LineString
只會連接給定點的「索引」(列表中的連接點給出的順序爲) 。下面的代碼說明了默認行爲:許多2D點之間的最短路徑(Shapely LineString內的旅行推銷員?)
from shapely.geometry import Point, LineString
import geopandas as gpd
import numpy as np
import matplotlib.pyplot as plt
# Generate random points
x=np.random.randint(0,100,10)
y=np.random.randint(0,50,10)
data = zip(x,y)
# Create Point and default LineString GeoSeries
gdf_point = gpd.GeoSeries([Point(j,k) for j,k in data])
gdf_line = gpd.GeoSeries(LineString(zip(x,y)))
# plot the points and "default" LineString
ax = gdf_line.plot(color='red')
gdf_point.plot(marker='*', color='green', markersize=5,ax=ax)
這將產生圖像:
問:是否有內勻稱任何內置的方法,將自動創建最邏輯(又名:最短,最不復雜,最不是十字交叉,......)通過給定的隨機2D點列表?
下面你可以找到所需的線(綠色)與默認(紅色)相比。
假設你不知道訂單或鄰居的時間提前,你可以嘗試建立每個節點都連接到所有其他節點的圖形,然後搜索「簡單路徑」,並與相同數量的選擇路徑作爲節點的數量的步驟,然後選擇最短的這些?這需要網絡X中的['all_simple_paths'](https://networkx.readthedocs.io/en/stable/reference/generated/networkx.algorithms.simple_paths.all_simple_paths.html#networkx.algorithms.simple_paths.all_simple_paths) 。 – shongololo
哇,看起來很有希望!將看看這個。 –
小修正:路徑長度將是節點 - 1 – shongololo