python坐标轴刻度为经纬度_python各类经纬度转换
import math
import urllib
import json
x_pi = 3.14159265358979324 * 3000.0 / 180.0
pi = 3.1415926535897932384626 # π
a = 6378245.0 # 长半轴
ee = 0.00669342162296594323 # 扁率
class Geocoding:
def __init__(self, api_key):
self.api_key = api_key
def geocode(self, address):
"""
利用高德geocoding服务解析地址获取位置坐标
:param address:需要解析的地址
:return:
"""
geocoding = {'s': 'rsv3',
'key': self.api_key,
'city': '全国',
'address': address}
geocoding = urllib.urlencode(geocoding)
ret = urllib.urlopen("%s?%s" % ("http://restapi.amap.com/v3/geocode/geo", geocoding))
if ret.getcode() == 200:
res = ret.read()
json_obj = json.loads(res)
if json_obj['status'] == '1' and int(json_obj['count']) >= 1:
geocodes = json_obj['geocodes'][0]
lng = float(geocodes.get('location').split(',')[0])
lat = float(geocodes.get('location').split(',')[1])
return [lng, lat]
else:
return None
else:
return None
def gcj02_to_bd09(lng, lat):
"""
火星坐标系(GCJ-02)转百度坐标系(BD-09)
谷歌、高德——>百度
:param lng:火星坐标经度
:param lat:火星坐标纬度
:return:
"""
z = math.sqrt(lng * lng + lat * lat) + 0.00002 * math.sin(lat * x_pi)
theta = math.atan2(lat, lng) + 0.000003 * math.cos(lng * x_pi)
bd_lng = z * math.cos(theta) + 0.0065
bd_lat = z * math.sin(theta) + 0.006
return [bd_lng, bd_lat]
def bd09_to_gcj02(bd_lon, bd_lat):
"""
百度坐标系(BD-09)转火星坐标系(GCJ-02)
百度——>谷歌、高德
:param bd_lat:百度坐标纬度
:param bd_lon:百度坐标经度
:return:转换后的坐标列表形式
"""
x = bd_lon - 0.0065
y = bd_lat - 0.006
z = math.sqrt(x * x + y * y) - 0.00002 * math.sin(y * x_pi)
theta = math.atan2(y, x) - 0.000003 * math.cos(x * x_pi)
gg_lng = z * math.cos(theta)
gg_lat = z * math.sin(theta)
return [gg_lng, gg_lat]
def wgs84_to_gcj02(lng, lat):
"""
WGS84转GCJ02(火星坐标系)
:param lng:WGS84坐标系的经度
:param lat:WGS84坐标系的纬度
:return:
"""
if out_of_china(lng, lat): # 判断是否在国内
return lng, lat
dlat = _transformlat(lng - 105.0, lat - 35.0)
dlng = _transformlng(lng - 105.0, lat - 35.0)
radlat = lat / 180.0 * pi
magic = math.sin(radlat)
magic = 1 - ee * magic * magic
sqrtmagic = math.sqrt(magic)
dlat = (dlat * 180.0) / ((a * (1 - ee)) / (magic * sqrtmagic) * pi)
dlng = (dlng * 180.0) / (a / sqrtmagic * math.cos(radlat) * pi)
mglat = lat + dlat
mglng = lng + dlng
return [mglng, mglat]
def gcj02_to_wgs84(lng, lat):
"""
GCJ02(火星坐标系)转GPS84
:param lng:火星坐标系的经度
:param lat:火星坐标系纬度
:return:
"""
if out_of_china(lng, lat):
return lng, lat
dlat = _transformlat(lng - 105.0, lat - 35.0)
dlng = _transformlng(lng - 105.0, lat - 35.0)
radlat = lat / 180.0 * pi
magic = math.sin(radlat)
magic = 1 - ee * magic * magic
sqrtmagic = math.sqrt(magic)
dlat = (dlat * 180.0) / ((a * (1 - ee)) / (magic * sqrtmagic) * pi)
dlng = (dlng * 180.0) / (a / sqrtmagic * math.cos(radlat) * pi)
mglat = lat + dlat
mglng = lng + dlng
return [lng * 2 - mglng, lat * 2 - mglat]
def bd09_to_wgs84(bd_lon, bd_lat):
lon, lat = bd09_to_gcj02(bd_lon, bd_lat)
return gcj02_to_wgs84(lon, lat)
def wgs84_to_bd09(lon, lat):
lon, lat = wgs84_to_gcj02(lon, lat)
return gcj02_to_bd09(lon, lat)
def _transformlat(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 * pi) + 20.0 *
math.sin(2.0 * lng * pi)) * 2.0 / 3.0
ret += (20.0 * math.sin(lat * pi) + 40.0 *
math.sin(lat / 3.0 * pi)) * 2.0 / 3.0
ret += (160.0 * math.sin(lat / 12.0 * pi) + 320 *
math.sin(lat * pi / 30.0)) * 2.0 / 3.0
return ret
def _transformlng(lng, lat):
ret = 300.0 + lng + 2.0 * lat + 0.1 * lng * lng + \
0.1 * lng * lat + 0.1 * math.sqrt(math.fabs(lng))
ret += (20.0 * math.sin(6.0 * lng * pi) + 20.0 *
math.sin(2.0 * lng * pi)) * 2.0 / 3.0
ret += (20.0 * math.sin(lng * pi) + 40.0 *
math.sin(lng / 3.0 * pi)) * 2.0 / 3.0
ret += (150.0 * math.sin(lng / 12.0 * pi) + 300.0 *
math.sin(lng / 30.0 * pi)) * 2.0 / 3.0
return ret
def out_of_china(lng, lat):
"""
判断是否在国内,不在国内不做偏移
:param lng:
:param lat:
:return:
"""
return not (73.66 < lng < 135.05 and lat > 3.86 and lat < 53.55)
def baidu_to_google(lng, lat):
result5 = bd09_to_wgs84(float(lng), float(lat))
return result5
def google_to_baidu(lng, lat):
result5 = wgs84_to_bd09(float(lng), float(lat))
return result5
python坐标轴刻度为经纬度_python各类经纬度转换相关推荐
- python坐标轴刻度设置对数_Python实用之openpyxl坐标轴范围和对数缩放
在使用openpyxl时,坐标轴的调整就难住了小编.经过一番资料搜索,不光解决了这个问题还找到了对数缩放的方法,接下来就让我们一起看看吧~ 坐标轴最小和最大值 为了在图表上显示特定区域,可以手动设置坐 ...
- python坐标轴刻度设置对数_Python中的对数刻度
我试图以对数比例(Y轴)绘制一个图形,但我需要在Y轴上显示原始值. 我用了密码:# -*- coding: utf-8 -*- import math import matplotlib.pyplot ...
- python坐标轴刻度设置_Python Matplotlib 设置x/y坐标轴刻度
刻度设置 参考文档: xticks 命令 yticks 命令 以xticks为例: matplotlib.pyplot.xticks(args, *kwargs) 获取或者设置当前刻度位置和文本的 x ...
- python坐标轴刻度设置_Python之坐标轴刻度细化、坐标轴设置、标题图例添加
原博文 2018-03-20 16:41 − 学习python中matplotlib绘图设置坐标轴刻度.文本 http://www.jb51.net/article/134638.htm Python ...
- python坐标轴刻度设置_学习python中matplotlib绘图设置坐标轴刻度、文本
总结matplotlib绘图如何设置坐标轴刻度大小和刻度. 上代码: from pylab import * from matplotlib.ticker import MultipleLocator ...
- python坐标轴刻度设置_matplotlib命令与格式之tick坐标轴日期格式(设置日期主副刻度)...
1.横坐标设置时间格式 import matplotlib.pyplot as plt import matplotlib.dates as mdates # 配置横坐标为日期格式 plt.gca() ...
- python 坐标轴刻度 格式_matplotlib命令与格式之tick坐标轴日期格式(设置日期主副刻度)...
1.横坐标设置时间格式 import matplotlib.pyplot as plt import matplotlib.dates as mdates # 配置横坐标为日期格式 plt.gca() ...
- python二进制转十进制算法_python进制转换:十进制转二进制的用法
我们在学习python时候肯定会碰到关于进制转换,其实这是非常简单的,这个就像小学学习数学乘法口诀意义,只要记住转换口诀即可轻松应用,一起来看下具体的操作内容吧~ 一.python进制转换 dec(十 ...
- python获取经纬度_python之经纬度的获取
import xlrd from xlrd import xldate_as_tuple import json import requests import datetime import open ...
最新文章
- 《评人工智能如何走向新阶段》后记(再续8)
- VS2012生成ReactOS的VS工程失败(三)和 “ cl is not able to compile a simple test program“错误
- 计算机第二章基础知识习题,计算机基础知识习题.docx
- data:image/png;base64
- matlab 上穿,Matlab混入模式(Mixin)
- how to catch out of memory exception in c++
- 学好C++开发技术能从事哪些岗位?
- 【疾病分类】基于matlab LBP果实病害检测分类【含Matlab源码 1714期】
- 自然语言处理之中英语料库
- 机器之心深度研学社每周干货:2017年第13周
- 小米、百度、bigo 、滴滴 、快手等iOS 面试后的一次阶段性总结
- 计算机和用户账户名一样,求计算机账户与用户账户的区别与联系?
- linux aufs,Linux文件系统之aufs
- 2021年必会的3个Kubernetes工具
- 使用HTTPie测试Web服务
- 英文不好的人如何阅读外文文献?
- 傅里叶变换与拉普拉斯变换的概念理解
- (跟我一起来学区块链(1.2))之 区块链是什么?
- 电力系统GPS校时设备简介
- 7-1 圆形体体积计算器