資源簡介
本程序利用實際的停車場高精地圖實現路徑規劃,如果需要詳細的輔助代碼庫請聯系作者
代碼片段和文件信息
import?shapefile
import?matplotlib.pyplot?as?plt
from?pythonds.graphs?import?GraphVertexPriorityQueue
from?Shortestpath?import?Shortestpath?as?sp
#======載入地圖數據文件=======
tpath?=?‘E:\\Valetparking\\map_file\\HLane.shp‘
sf?=?shapefile.Reader(tpath)
shapes?=?sf.shapes()
recds?=?sf.shapeRecords()
pnts?=?[]
g?=?Graph()
#=======載入所有坐標點========
for?i?in?range(len(shapes)):
pnts?=?pnts?+?shapes[i].points
newpnts?=?[]
[newpnts.append(i)?for?i?in?pnts?if?i?not?in?newpnts]??#刪除相同元素
#=======創建圖頂點===========
for?i?in?range(len(newpnts)):?
g.addVertex(newpnts[i])
#=======添加邊及權重=========
for?i?in?range(len(shapes)):
l?=?len(shapes[i].points)
for?j?in?range(l-1):
g.addEdge(shapes[i].points[j]shapes[i].points[j+1])
#========防止路段終點坐標與其連接路段起點坐標不一致=======
評論
共有 條評論