地理:大地2000坐标转经纬度

查看 91|回复 7
作者:zjg121   
对文件夹下所有.txt文件中的数据进行转换:文本文件中大地坐标的格式(xxxxxxx.xxx xxxxxx.xxx),其中数据格式:X小数点前7位数,小数点后3位数;中间一个空格;Y小数点前6位数,小数点后3位数。
[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}')

坐标系, 经纬度

什么也不是   

https://epsg.io/transform#s_srs= ... amp;x=NaN&y=NaN  这应该也是可以的。
Marken888   

感谢分享转换方法!
jacky520510   

没有具体的算法呀
bxw00004   

感谢分享转换方法!
11414   

感谢分享
xuchaobo6132   

试了一下,不错
HR741158   

先收藏学习
您需要登录后才可以回帖 登录 | 立即注册

返回顶部