根据线拐点的表格坐标信息批量生成奥维地图轨迹

Posted quezesheng

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了根据线拐点的表格坐标信息批量生成奥维地图轨迹相关的知识,希望对你有一定的参考价值。

技术图片

`# 根据线拐点的表格坐标信息批量生成奥维地图轨迹####
‘‘‘

  • 功能用途介绍:

    • 如何根据野外标记的坐标信息,在奥维地图上绘制轨迹和拐点标签
    • 优点:可以批量在奥维地图上标记多条轨迹路线,和标记拐点标签,并可修改点标签的大小、颜色,线的宽度。
    • 用途:可以根据野外调查的实际点位绘制工作轨迹,进行质量检查。
  • 模块使用方法:

    • 运行环境:采用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(‘ ‘))

    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(‘
‘))
获取线名称放入列表
    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(‘
‘))
python打印输出

with open("line坐标转奥维地图线结果.kml", "r", encoding="utf-8") as f1:
print(f1.read())
print("程序运行成功!结果保存到:line坐标转奥维地图线结果.kml")
############################ end ############################`



























































以上是关于根据线拐点的表格坐标信息批量生成奥维地图轨迹的主要内容,如果未能解决你的问题,请参考以下文章

suffer根据CGCS2000坐标利用散点图生成奥维坐标

使用Baidu地图API写一个个人移动轨迹的Android app,请问谁会呢?

百度地图API 如何根据现有坐标集合生成曲线轨迹?

一个不得不说的地图软件《奥维互动地图》

在arcgis中如何批量提取点的坐标?

怎么把经纬度批量导入地图,然后得到,这些经纬度的具体地址