[Python] 纯文本查看 复制代码from pyproj import Proj, Transformer
import os
import re
def process_file(file_path):
with open(file_path, 'r') as f:
content = f.read()
# 使用正则表达式匹配大地2000坐标数据
pattern = r'\d{7}\.\d{3}\s\d{6}\.\d{3}'
coordinates = re.findall(pattern, content)
return coordinates
def batch_process_files(folder_path):
result = []
for root, dirs, files in os.walk(folder_path):
for file in files:
if file.endswith('.txt'):
file_path = os.path.join(root, file)
coordinates = process_file(file_path)
result.extend(coordinates)
return result
def convert_coordinates(coordinates):
in_proj = Proj('epsg:4543') # 输入坐标系:大地2000(EPSG:4535)
out_proj = Proj('epsg:4326') # 输出坐标系:WGS84经纬度(EPSG:4326)
transformer = Transformer.from_proj(in_proj, out_proj)
converted_coordinates = []
for coordinate in coordinates:
x, y = map(float, coordinate.split())
lon, lat = transformer.transform(x, y)
converted_coordinates.append((lon, lat))
return converted_coordinates
if __name__ == '__main__':
folder_path = r'D:\Users\31394\Downloads' # 替换为你的文件夹路径
coordinates = batch_process_files(folder_path)
converted_coordinates = convert_coordinates(coordinates)
for lon, lat in converted_coordinates:
print(f'经度:{lat}, 纬度:{lon}')
[i]
转换单个数据[Python] 纯文本查看 复制代码from pyproj import Proj, transform
# 创建两个坐标系对象
in_proj = Proj('epsg:4543') # 输入坐标系:大地2000(EPSG:4535)
out_proj = Proj('epsg:4326') # 输出坐标系:WGS84经纬度(EPSG:4326)
# 转换坐标
x, y = 3858741.796, 599773.616 # 大地2000坐标系下的坐标
lon, lat = transform(in_proj, out_proj, x, y)
print(f'经度:{lat}, 纬度:{lon}')