吾爱破解 - LCG - LSG |安卓破解|病毒分析|www.52pojie.cn

 找回密码
 注册[Register]

QQ登录

只需一步,快速开始

查看: 821|回复: 7
收起左侧

[Python 原创] 地理:大地2000坐标转经纬度

[复制链接]
zjg121 发表于 2024-4-3 15:19
本帖最后由 zjg121 于 2024-4-3 16:06 编辑

对文件夹下所有.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}')





转换单个数据
[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}')

免费评分

参与人数 1吾爱币 +7 热心值 +1 收起 理由
苏紫方璇 + 7 + 1 欢迎分析讨论交流,吾爱破解论坛有你更精彩!

查看全部评分

发帖前要善用论坛搜索功能,那里可能会有你要找的答案或者已经有人发布过相同内容了,请勿重复发帖。

什么也不是 发表于 2024-4-3 15:53
Marken888 发表于 2024-4-3 15:47
jacky520510 发表于 2024-4-3 15:52
bxw00004 发表于 2024-4-3 17:50
感谢分享转换方法!
11414 发表于 2024-4-3 20:47
感谢分享
xuchaobo6132 发表于 2024-4-5 22:45
试了一下,不错
HR741158 发表于 2024-4-14 02:54
先收藏学习
您需要登录后才可以回帖 登录 | 注册[Register]

本版积分规则 警告:本版块禁止灌水或回复与主题无关内容,违者重罚!

快速回复 收藏帖子 返回列表 搜索

RSS订阅|小黑屋|处罚记录|联系我们|吾爱破解 - LCG - LSG ( 京ICP备16042023号 | 京公网安备 11010502030087号 )

GMT+8, 2024-5-14 20:22

Powered by Discuz!

Copyright © 2001-2020, Tencent Cloud.

快速回复 返回顶部 返回列表