根據線拐點的表格坐標信息批量生成奧維地圖軌跡


`# 根據線拐點的表格坐標信息批量生成奧維地圖軌跡####
'''

  • 功能用途介紹:

    • 如何根據野外標記的坐標信息,在奧維地圖上繪制軌跡和拐點標簽
    • 優點:可以批量在奧維地圖上標記多條軌跡路線,和標記拐點標簽,並可修改點標簽的大小、顏色,線的寬度。
    • 用途:可以根據野外調查的實際點位繪制工作軌跡,進行質量檢查。
  • 模塊使用方法:

    • 運行環境:采用python編程語言,在PyCharm開發平台運行。

    • 前期准備:

      • Windows系統安裝xlrd庫:cmd.exe-->pip3 install xlrd

      • excel表格原始數據格式:

name xyh color width LineName Pnum a ln
101 113.823035001277,25.1556843733412,0 ff00ff80 2 L1 1 1 L1-
102 113.822375077267,25.1563570638673,0 ff00ff80 2 L1 2 2 L1-
103 113.82171504702,25.1570297539114,0 ff00ff80 2 L1 3 3 L1-
104 113.821055106587,25.1577023495313,0 ff00ff80 2 L1 4 4 L1-
201 113.82039506199,25.1583750348307,0 ff00ff80 2 L2 1 5 L2-
202 113.819735109284,25.1590477158692,0 ff00ff80 2 L2 2 6 L2-
203 113.819075050336,25.1597203964229,0 ff00ff80 2 L2 3 7 L2-
204 113.818415083279,25.160393072716,0 ff00ff80 2 L2 4 8 L2-
205 113.817755106973,25.1610656564729,0 ff00ff80 2 L2 5 9 L2-
301 113.817095026497,25.1617383299062,0 ff00ff80 2 L3 1 10 L3-
302 113.816435037913,25.1624109990793,0 ff00ff80 2 L3 2 11 L3-
401 113.815774943083,25.1630836677642,0 ff00ff80 2 L4 1 12 L4-
402 113.815114938074,25.1637562420257,0 ff00ff80 2 L4 2 13 L4-
403 113.814454828889,25.164428905961,0 ff00ff80 2 L4 3 14 L4-
404 113.813794811597,25.1651015656366,0 ff00ff80 2 L4 4 15 L4-
405 113.813134787128,25.1657742229374,0 ff00ff80 2 L4 5 16 L4-

  • 模塊運行:
    • 點擊“運行”
    • 輸入:輸入Excel表格數據存儲路徑
    • 結果保存到模塊目錄下,文件名為:“ 坐標轉奧維結果.kml”
    • 將“ line坐標轉奧維地圖線結果.kml”導入到奧維地圖軟件,即完成點位標記
      '''

效果如下:

'''

  • 研發團隊:廣核智造研發小組 組長:bisonQue 研發日期:2020年7月3日
    '''
    import xlrd

行 Row 列 Column 這是Excel里面的規范表述!

便簽繪制函數

def placemark(name, color, scale, xyh):
msg3 = '''
%s %s ''' % (
name, color, scale, xyh)
return msg3
# print(msg3)
# with open("坐標轉奧維結果.kmz", "w+", encoding="utf-8") as f:
# f.write(msg3)

繪制多段線函數

def placemarkForLine(name, color, width, xyhlist):
msgLine = '''< Placemark >< name > %s < / name > < Style > < LineStyle > < color > %s < / color > < width > %s < / width > < / LineStyle >< / Style >< LineString >< coordinates > %s< / coordinates >< / LineString >< / Placemark >
'''% (name, color, width, xyhlist)
msgLine ='''

%s

%s
'''% (name, color, width, xyhlist)
return msgLine
# print(msg3)
# with open("坐標轉奧維結果.kmz", "w+", encoding="utf-8") as f:
#     f.write(msg3)

def strcount(a): # a為字符串參數 字符串中的所有元素的出現次數
b = {} # 定義一個空字典
c = len(a) # 求出字符串的長度
i = 0
while i < c:
if a[i] in b:
b[a[i]] += 1
else:
b[a[i]] = 1
i += 1
# 遍歷字典
# for item in b.items():
# print(item)
# b.pop(a[0])
print(b)
return b

def all_list(arr): # list中的count,獲取所有元素的出現次數
result = {}
for i in set(arr):
result[i] = arr.count(i)
return result

main

if name == 'main': # 主函數入庫類似c的main函數
# read_xlrd(excelFile=excelFile) #執行函數
with open("line坐標轉奧維地圖線結果.kml", "w+", encoding="utf-8") as f:
msg1 = ''' OvitalMap_20200629_213234 仁化項目奧維點 '''
f.write(msg1.strip('\n'))

    excelFile = 'line.xls'  # excle文件路徑名稱
    # excelFile = str(input("請輸入Excel表格數據存儲路徑,例如:E:/2020仁化礦山調查項目2020年/RHZB.xls,輸入完路徑按回車鍵,路徑為:"))

    data = xlrd.open_workbook(excelFile)
    # 默認讀取第1張sheet表
    table = data.sheet_by_index(0)  # 或者table = data.sheet_by_name('工作表1')
標記線上的拐點
    rowNum = 0
    colNum = 0
    Name = ""
    Xyh = ""
    Color = ""
    Scale = ""

    for rowNum in range(table.nrows):  # 每行地址循環
        # for colNum in range(table.ncols):
        for colNum in range(table.ncols):
            nameValue = table.row_values(rowNum)[colNum]
            if rowNum > 0 and colNum==0:
                Name= nameValue      #標簽名字
            elif rowNum > 0 and colNum==1:
                Xyh = nameValue        #標簽坐標
            elif rowNum > 0 and colNum==2:
                Color = nameValue     #標簽顏色
            elif rowNum > 0 and colNum == 3:
                Scale = nameValue     #標簽大小
            else:
                pass
        f.write(placemark(Name, Color,Scale, Xyh).strip('\n'))
獲取線名稱放入列表
    xyzValue = ""
    res = ""
    a = []
    b = []
    list_l1 = []  # 用於提取線名稱,按linename循環
    list_l2 = []  # 用於計算某條線出現的次數,終止循環
    for rowNum in range(table.nrows):  # 每行地址循環
        # for colNum in range(table.ncols):
        for colNum in range(table.ncols):
            nameValue = table.row_values(rowNum)[colNum]
            L = table.row_values
            if colNum == 7 and rowNum > 0:
                lname = L(rowNum)[7]
                list_l1.append(lname)
                list_l2.append(L(rowNum)[4])
    # 提取線段名稱,用於判斷
    # print("list_l1:", list_l1)  #list_l1: ['L1-', 'L1-', 'L1-', 'L1-', 'L2-', 'L2-', 'L2-', 'L2-', 'L2-', 'L3-', 'L3-']
    # print("list_l2:", list_l2) #list_l2: ['L1', 'L1', 'L1', 'L1', 'L2', 'L2', 'L2', 'L2', 'L2', 'L3', 'L3']
    dict_count= all_list(list_l2)
    # print("dict_count:",dict_count)  # {'l3': 2, 'l1': 5, 'l2': 4}
    llist_l1 = set(list_l1)
    llist_l1 = list(set(list_l1))
    llist_l1.sort(key=list_l1.index)
    y = ''.join(llist_l1)
    lineName = y.split('-')
    lineName.pop()  # 刪掉最后一個空字符
    # print("lineName:",lineName)   #['l1', 'l2', 'l3']
    # print(len(lineName)) #3
    # for i in range(len(lineName)):
    # print(lineName[i])     #l1     l2         l3
繪制多段線
    for i in range(len(lineName)):  # len(lineName)循環次數是線的種類
        count=0
        j=0
        a = []
        for rowNum in range(table.nrows):  # 每行地址循環
            colNum = 1
            nameValue = table.row_values(rowNum)[colNum]
            L = table.row_values
            if L(rowNum)[4] == lineName[i] :
               count+=1
               j+=1
               res = L(rowNum)[1]
               a.append(res)
               a.append(" ")
               name=L(rowNum)[4]
               color=L(rowNum)[2]
               width=L(rowNum)[3]
        xyhlist=''.join(a)
        f.write(placemarkForLine(name, color, width, xyhlist))
輸出結尾部分
    msg2 = '''</Folder></Document></kml>'''
    f.write(msg2.strip('\n'))
python打印輸出

with open("line坐標轉奧維地圖線結果.kml", "r", encoding="utf-8") as f1:
print(f1.read())
print("程序運行成功!結果保存到:line坐標轉奧維地圖線結果.kml")
############################ end ############################`


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM