一个python代码
一个python代码
import os import numpy as np import re from pathlib import Path output_folder='./data' filename_lineEdge = r'./data/fx0022/dom1lines_Edge.txt' filename_jgw = r'./data/fx0022/test/dom1.jgw' #读取线段文件 data = [] i = 0 with open(filename_lineEdge, 'r') as f: lines = f.readlines() for item in lines: #print(item.strip()) out = re.sub(r"\s{2,}", " ", item).strip() #print(out) res = out.split(" ") if i == 0: data = np.expand_dims(res, axis=0) i = i + 1 else: data = np.concatenate((data, np.expand_dims(res, axis=0)), axis=0) data = np.array(data).astype(np.float64) print(data.shape) #读取jgw文件 if os.path.isfile(filename_jgw): with open(filename_jgw, 'r') as fjpw: lines_jgw = fjpw.readlines() resolution = float(lines_jgw[0]) topleftX = float(lines_jgw[4]) topleftY = float( lines_jgw[5]) else: resolution = 1.0 topleftX = 0 topleftY = 0 print(resolution) print(topleftX) print(topleftY) #坐标变换 f_newEdge= output_folder+'/{}{}'.format(str(Path(filename_lineEdge).stem),'_edge.txt') with open(f_newEdge,'w' ) as newlineEdgeFile: for element in data: print(element) fromX=topleftX+element[2]*resolution fromY=topleftY-element[0]*resolution toX=topleftX+element[3]*resolution toY=topleftY-element[1]*resolution new_Line=[fromX, fromY, toX, toY] print('转换后{}'.format(new_Line)) newlineEdgeFile.writelines('{} {} {} {}\n'.format(fromY,toY,fromX,toX))
作者:太一吾鱼水
文章未经说明均属原创,学习笔记可能有大段的引用,一般会注明参考文献。
欢迎大家留言交流,转载请注明出处。