像控点取平均值

import xlrd
import numpy
from tkinter import messagebox
path = r"C:\Users\Administrator\Desktop\杭州绕城西复平面.xls"
wb = xlrd.open_workbook(path)
ws = wb.sheet_by_index(0)
cordingDict = dict()

def rrd(point,f):
    if f == 0:
        point = str(int(f))
    elif f>0:
        SP = str(numpy.around(point,f))
        sy = SP.split(".")
        n = len(sy[1])
        if n<f:
            sj = f - n
            point = sy[0]+"."+sy[1]+"0"*sj
        else:
            point = SP
    elif f<0:
        pass
    return point

for n in range(ws.nrows):
    cordingDict.update({ws.cell_value(n,0):""})

oP = list(cordingDict.keys())

with open(r"C:\Users\Administrator\Desktop\GC_XK.TXT","w") as f:
    for vb in oP:
        coordList = []
        for n in range(ws.nrows):
            cell = ws.row_values(n)
            if vb == cell[0]:
                coordList.append(cell)
        coordX = 0
        coordY = 0
        coordZ = 0

        for coord in coordList:

            coordX += coord[1]
            coordY += coord[2]
            coordZ += coord[3]

        ds = len(coordList)
        x = coordX/ds
        y = coordY/ds
        z = coordZ/ds

        for jc in coordList:
            k = abs(x - jc[1])
            hj = abs(y - jc[2])
            kl = abs(z - jc[3])
            if k > 0.011 or hj > 0.011 or kl > 0.011:
                print("点号< %s >误差超限"%vb,k,hj,kl)

        newCoord = [str(vb),",", rrd(x,3),",",rrd(y,3),",",rrd(z,3),"\n"]

        f.writelines(newCoord)
f.close()

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值