闭合导线近似平差及坐标计算

事先声明,本人所写代码用于学习,原代码撰写者@张爱烂(同时也是我的室友)

以后也会发表一些我抄写的代码,也不是为了给谁看,就当作一种学习的证明吧

#数据准备
D_list=[]#测站距离
obs_degree_list=[]#观测角的弧度

import math
def dms_to_radians(degree):
    #获取度分秒
    degrees_str=degree[0]
    minutes_str=degree[1]
    seconds_str=degree[2]
    #转化为数字
    degrees=float(degrees_str)
    minutes=float(minutes_str)
    seconds=float(seconds_str)
    #计算弧度
    radians=math.radians(degrees+(minutes/60)+(seconds/3600))
    return radians

n=8#测站数
user_input="T"#确定观测角方向,输入T(左角)或F(右角)
with open("C:\\Users\\hp\\Desktop\\example.txt","r") as f:
    #读取第一行数据
    first_line = f.readline().strip()
    #读取第二行数据
    second_line = f.readline().strip()
    #读取第三行数据以后的数据
    for line in f:
        items_list=[]#储存观测角
        v_degree=[]#储存竖直角
        #按分割符拆分每一行数据
        data=line.strip()
        data=data.split(',')
        print(data)
        #读取前三个元素和第四个元素
        item1,item2,item3,item4=data[0],data[1],data[2],data[3]
        items_list.append(item1)
        items_list.append(item2)
        items_list.append(item3)
        obs_degree_list.append(dms_to_radians(items_list))
        D_list.append(float(item4))

    a12=[]
    a12=first_line.split(',')
    print("起始方位角:",a12)
    a12=dms_to_radians(a12)

    J_x_1,J_y_1=second_line.split(',')
    J_x_1,J_y_1=float(J_x_1),float(J_y_1)
    print("起始点测站坐标:",J_x_1,",",J_y_1)
    print("测站距离:",D_list)
    print("观测角弧度:",obs_degree_list)
    b_list=obs_degree_list

    #计算方位角闭合差
    sum_b=sum(b_list)
    f_b=sum_b-((n-2)*math.pi)
    print("\n方位角闭合差为:",f_b)
    f_b_limit=(400/3600)*(math.pi/180)*math.sqrt(n)
    print("理论限差为:",f_b_limit)
    f_b_abs=abs(f_b)
    if(f_b_abs<f_b_limit):
        print("\n小于图根极限差")
    else:
        print("\n大于图根极限差,重测")

    V=-f_b/n
    print("\n方位角改正数:",V)
    b_list_new=list(map(lambda x:x+V,b_list))
    print("\n改正后各观测角:",b_list_new)

    #3.计算各边方位角
    b_list_cal=b_list_new[1:]+b_list_new[:1]
    a_list=[]
    a_list.append(a12)
    i=0
    while i<=n-2:
        if user_input=="T":
            a_j=a_list[i]+b_list_cal[i]-math.pi
        elif user_input=="F":
            a_j=a_list[i]-b_list_cal[i]+math.pi
        a_list.append(a_j)
        i+=1
    print("各边方位角:",a_list)
    #4.计算各边坐标增量
    cos_a_list=list(map(lambda x:math.cos(x),a_list))
    sin_a_list=list(map(lambda x:math.sin(x),a_list))
    import numpy as np
    array1=np.array(cos_a_list)
    array2=np.array(sin_a_list)
    array3=np.array(D_list)
    diff_x=np.multiply(array1,array3)
    diff_y=np.multiply(array2,array3)
    print("\nx坐标增量:",diff_x)
    print("y坐标增量:",diff_y)
    #5.计算导线闭合差
    f_x=sum(diff_x)
    f_y=sum(diff_y)
    f=math.sqrt(f_x**2+f_y**2)
    K=f/sum(D_list)
    print("\n导线相对闭合差:\n",K)
    if(K<(1/4000)):
        print("牛逼")
    else:
        print("垃圾")

    #6.分配坐标增量闭合差
    v_x_list=list(map(lambda x:(-f_x/sum(D_list))*x,D_list))
    v_y_list=list(map(lambda x:(-f_y/sum(D_list))*x,D_list))
    print("\nx轴坐标增量闭合差:",v_x_list)
    print("\ny轴坐标增量:",v_y_list)
    diff_x_new=[]
    diff_y_new=[]
    for x,y in zip(diff_x,v_x_list):
        diff_x_new.append(x+y)
    for x,y in zip(diff_y,v_y_list):
        diff_y_new.append(x+y)
    print("\nx轴坐标增量:",diff_x_new)
    print("\ny轴坐标增量:",diff_y_new)

    #7.计算各点坐标
    J_x=[]
    J_x.append(J_x_1)
    i=0
    while(i<n-2):
        J_x_j=diff_x_new[i]+J_x[i]
        J_x.append(J_x_j)
        i+=1
    J_y=[]
    J_y.append(J_y_1)
    i=0
    while(i<n-2):
        J_y_j=diff_y_new
        J_y.append(J_y_1)
        i+=1

    #8.输出各点坐标
    i=0
    result=[[x,y] for x,y in zip(J_x,J_y)]
    for items in result:
        print("\n测站点%d坐标:"%(i+1),items)
    result[-1][-1]+=diff_x_new[n-1]
    result[-1][-2]+=diff_y_new[n-1]
    print("\n测站点1坐标:",result[n-1])