"""
坐标转换工具类
"""
import math
from pyproj import Proj, transform, Transformer
import os
from warnings import simplefilter
simplefilter(action='ignore', category=FutureWarning)
simplefilter(action='ignore', category=DeprecationWarning)
# 坐标转换
class TransCoordinates:
"""
WGS84,BD09、GCJ02(火星坐标系)和UTM坐标系相互转换
"""
def __init__(self, longitude, latitude):
"""
初始化
:param longitude: 经度:float
:param latitude: 纬度:float
"""
self.longitude = longitude
self.latitude = latitude
self.pi = 3.1415926535897932384626 # π
self.x_pi = 3.14159265358979324 * 3000.0 / 180.0
self.a = 6378245.0 # 长半轴
self.ee = 0.00669342162296594323 # 偏心率平方
def out_of_china(self, longitude, latitude):
"""
判断经纬度是否在国内
:return: 在:True,不在:False
"""
return not (73.66 < longitude < 135.05 and 3.86 < latitude < 53.55)
def _transformlat(self, lng, lat):
"""
纬度转换
"""
ret = -100.0 + 2.0 * lng + 3.0 * lat + 0.2 * lat * lat + \
0.1 * lng * lat + 0.2 * math.sqrt(math.fabs(lng))
ret += (20.0 * math.sin(6.0 * lng * self.pi) + 20.0 *
math.sin(2.0 * lng * self.pi)) * 2.0 / 3.0
ret += (20.0 * math.sin(lat * self.pi) + 40.0 *
math.sin(lat / 3.0 * self.pi)) * 2.0 / 3.0
ret += (160.0 * math.sin(lat / 12.0
python ,经纬度坐标转换 WGS84,BD09、GCJ02(火星坐标系)和UTM坐标系相互转换
最新推荐文章于 2025-06-07 14:57:10 发布