当前位置:网站首页>电子地图坐标系统研究整理
电子地图坐标系统研究整理
2022-06-28 02:34:00 【雪中亮】
「博客搬家」 新地址: 简书
本文由文末的参考链接整理、整合、修改而成
1. 电子地图坐标系统简介
- WGS-84 坐标系:即地球坐标系,国际经纬度坐标标准
- GCJ-02 坐标系:即火星坐标系,WGS84 坐标系经加密后的坐标系,国测局制定。
- BD-09 坐标系:即百度坐标系,GCJ02 坐标系经加密后的坐标系。
GCJ-02 坐标系统,就是在标准的 WGS-84 坐标系统上进行了人为的偏移,比如 Google 地图、腾讯 SOSO 地图等就是直接使用了国家 GCJ-02 坐标系统,我们有一个不成文的说法,前者叫地球坐标,后者叫火星坐标,并且,火星坐标是无法转换成地球坐标的「网上虽然有一定的方法,但基本上都是基于偏移数据库,精度较高的数据库需要购买,当然这都是一种破解手段」。
所有的电子地图、导航设备,都需要加入国家保密插件。
第一步,地图公司测绘地图,测绘完成后,送到国家测绘局,将真实坐标的电子地图,加密成“火星坐标”,这样的地图才是可以出版和发布的,然后才可以让 GPS 公司处理。
第二步,所有的 GPS 公司,只要需要汽车导航的,需要用到导航电子地图的,都需要在软件中加入国家保密算法,将 COM 口读出来的真实的坐标信号,加密转换成国家要求的保密的坐标。这样,GPS 导航仪和导航电子地图就可以完全匹配,GPS 也就可以正常工作了。
| API | 坐标系 |
|---|---|
| 百度地图 API | 百度坐标 |
| 腾讯搜搜地图 API | 火星坐标 |
| 搜狐搜狗地图 API | 搜狗坐标 |
| 阿里云地图 API | 火星坐标 |
| 图吧 MapBar 地图 API | 图吧坐标 |
| 高德 MapABC 地图 API | 火星坐标 |
| 灵图 51ditu 地图 API | 火星坐标 |
- 注1:百度地图使用百度坐标,支持从地球坐标和火星坐标导入成百度坐标,但无法导出。并且批量坐标转换一次只能转换20个(待验证)。
- 注2:搜狗地图支持直接显示地球坐标,支持地球坐标、火星坐标、百度坐标导入成搜狗坐标,同样,搜狗坐标也无法导出。
说完坐标系统,我们自然能够知道这里的问题,通过以下问题,来说说我对此的研究。
2、各个坐标系的相互转换
2.1 火星坐标系「GCJ-02」与百度坐标系「BD-09」的转换算法
其中 bd_encrypt 将 GCJ-02 坐标转换成 BD-09 坐标, bd_decrypt 反之。
void bd_encrypt(double gg_lat, double gg_lon, double &bd_lat, double &bd_lon)
{
double x = gg_lon, y = gg_lat;
double z = sqrt(x * x + y * y) + 0.00002 * sin(y * x_pi);
double theta = atan2(y, x) + 0.000003 * cos(x * x_pi);
bd_lon = z * cos(theta) + 0.0065;
bd_lat = z * sin(theta) + 0.006;
}
void bd_decrypt(double bd_lat, double bd_lon, double &gg_lat, double &gg_lon)
{
double x = bd_lon - 0.0065, y = bd_lat - 0.006;
double z = sqrt(x * x + y * y) - 0.00002 * sin(y * x_pi);
double theta = atan2(y, x) - 0.000003 * cos(x * x_pi);
gg_lon = z * cos(theta);
gg_lat = z * sin(theta);
} 2.2 地球坐标系「WGS-84」到火星坐标系「GCJ-02」的转换算法
WGS-84 到 GCJ-02 的转换「即 GPS 加偏」算法
using System;
namespace Navi
{
class EvilTransform
{
const double pi = 3.14159265358979324;
//
// Krasovsky 1940
//
// a = 6378245.0, 1/f = 298.3
// b = a * (1 - f)
// ee = (a^2 - b^2) / a^2;
const double a = 6378245.0;
const double ee = 0.00669342162296594323;
//
// World Geodetic System ==> Mars Geodetic System
public static void transform(double wgLat, double wgLon, out double mgLat, out double mgLon)
{
if (outOfChina(wgLat, wgLon))
{
mgLat = wgLat;
mgLon = wgLon;
return;
}
double dLat = transformLat(wgLon - 105.0, wgLat - 35.0);
double dLon = transformLon(wgLon - 105.0, wgLat - 35.0);
double radLat = wgLat / 180.0 * pi;
double magic = Math.Sin(radLat);
magic = 1 - ee * magic * magic;
double sqrtMagic = Math.Sqrt(magic);
dLat = (dLat * 180.0) / ((a * (1 - ee)) / (magic * sqrtMagic) * pi);
dLon = (dLon * 180.0) / (a / sqrtMagic * Math.Cos(radLat) * pi);
mgLat = wgLat + dLat;
mgLon = wgLon + dLon;
}
static bool outOfChina(double lat, double lon)
{
if (lon < 72.004 || lon > 137.8347)
return true;
if (lat < 0.8293 || lat > 55.8271)
return true;
return false;
}
static double transformLat(double x, double y)
{
double ret = -100.0 + 2.0 * x + 3.0 * y + 0.2 * y * y + 0.1 * x * y + 0.2 * Math.Sqrt(Math.Abs(x));
ret += (20.0 * Math.Sin(6.0 * x * pi) + 20.0 * Math.Sin(2.0 * x * pi)) * 2.0 / 3.0;
ret += (20.0 * Math.Sin(y * pi) + 40.0 * Math.Sin(y / 3.0 * pi)) * 2.0 / 3.0;
ret += (160.0 * Math.Sin(y / 12.0 * pi) + 320 * Math.Sin(y * pi / 30.0)) * 2.0 / 3.0;
return ret;
}
static double transformLon(double x, double y)
{
double ret = 300.0 + x + 2.0 * y + 0.1 * x * x + 0.1 * x * y + 0.1 * Math.Sqrt(Math.Abs(x));
ret += (20.0 * Math.Sin(6.0 * x * pi) + 20.0 * Math.Sin(2.0 * x * pi)) * 2.0 / 3.0;
ret += (20.0 * Math.Sin(x * pi) + 40.0 * Math.Sin(x / 3.0 * pi)) * 2.0 / 3.0;
ret += (150.0 * Math.Sin(x / 12.0 * pi) + 300.0 * Math.Sin(x / 30.0 * pi)) * 2.0 / 3.0;
return ret;
}
}
} 以上参考自:http://www.xue5.com/Mobile/iOS/679842.html
2.3 百度在线转换API
http://api.map.baidu.com/ag/coord/convert?from=0&to=4&x=longitude&y=latitude
from: 来源坐标系「0 表示 WGS-84 坐标;2 表示GCJ-02 坐标」
to: 转换后的坐标「4 表示 BD-09 坐标,即百度地图使用的行」
x: 经度
y: 纬度
请求之后会返回一串 Json
{
"error":0,
"x":"MTIxLjUwMDIyODIxNDk2",
"y":"MzEuMjM1ODUwMjYwMTE3"
}
error:是结果是否出错标志位,0 表示成功
x: 坐标系 2 时为经度,4 时为纬度(Base64编码)
y: 坐标系 4 时为经度,2 时为纬度(Base64编码)什么情况,经纬度居然还加密?那接下来也只好见招拆招了
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.net.URL;
import java.net.URLConnection;
import com.sun.org.apache.xerces.internal.impl.dv.util.Base64;
public class BaiduAPIConverter extends Thread {
public static void testPost(String x, String y) throws IOException {
try {
URL url = new URL("http://api.map.baidu.com/ag/coord/convert?from=2&to=4&x="+ x + "&y=" + y);
URLConnection connection = url.openConnection();
connection.setDoOutput(true);
OutputStreamWriter out = new OutputStreamWriter(connection.getOutputStream(), "utf-8");
// remember to clean up
out.flush();
out.close();
// 一旦发送成功,用以下方法就可以得到服务器的回应:
String sCurrentLine, sTotalString;
sCurrentLine = sTotalString = "";
InputStream l_urlStream;
l_urlStream = connection.getInputStream();
BufferedReader l_reader = new BufferedReader(new InputStreamReader(l_urlStream));
while ((sCurrentLine = l_reader.readLine()) != null) {
if (!sCurrentLine.equals(""))
sTotalString += sCurrentLine;
}
sTotalString = sTotalString.substring(1, sTotalString.length() - 1);
String[] results = sTotalString.split("\\,");
if (results.length == 3) {
if (results[0].split("\\:")[1].equals("0")) {
String mapX = results[1].split("\\:")[1];
String mapY = results[2].split("\\:")[1];
mapX = mapX.substring(1, mapX.length() - 1);
mapY = mapY.substring(1, mapY.length() - 1);
mapX = new String(Base64.decode(mapX));
mapY = new String(Base64.decode(mapY));
System.out.println("\t" + mapX + "\t" + mapY);
}
}
sleep(10000);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
/** * @param args * @throws IOException */
public static void main(String[] args) throws IOException {
testPost("120.151379", "30.184678");
System.out.println("ok");
}
} 到这里也差不多好了,主要的代码都写出来了,其他的您就自己写吧。
以上参考自:http://scalpel.me/archives/136
2.4 百度内置转换方法,可以不局限于百度定位 SDK
在百度地图中取得 WGS-84 坐标,调用如下方法:
BMapManager.getLocationManager().setLocationCoordinateType(MKLocationManager.MK_COORDINATE_WGS84);这样从百度 API 中取得的坐标就是 WGS-84 了,可是这种坐标如果显示到百度地图上就会偏移,也就是说取出一个坐标,原封不动的显示上去就偏移了,所以为了显示也是正常就需要在绘制到百度地图上之前转换成 BD-09 。
转换成 BD-09,调用方法:
GeoPoint wgs84;
GeoPoint bd09= CoordinateConvert.bundleDecode(CoordinateConvert.fromWgs84ToBaidu(wgs84));这里实在不明白为何要设计成 CoordinateConvert.fromWgs84ToBaidu(wgs84) 返回了一个 Bundle,所以还需要 CoordinateConvert.bundleDecode() 再转成 GeoPoint 。
3. 参考文章
边栏推荐
- 基于流的深度生成模型
- 如何编写简洁代码?(上)
- 【522. 最长特殊序列 II】
- 新手开哪家的证券账户是比较好?股票开户安全吗
- [issue 21] face to face experience of golang engineer recruited by Zhihu Society
- A16z:元宇宙解锁游戏基础设施中的新机遇
- 剑指 Offer 47. 礼物的最大价值(DP)
- 多快好省,低门槛AI部署工具FastDeploy测试版来了!
- 用于 C# 的 SQL 基本语法总结
- R language penalty logistic regression, linear discriminant analysis LDA, generalized additive model GAM, multiple adaptive regression splines Mars, KNN, quadratic discriminant analysis QDA, decision
猜你喜欢

如何获取GC(垃圾回收器)的STW(暂停)时间?

【PaddleDetection】ModuleNotFoundError: No module named ‘paddle‘

被校园暴力,性格内向的马斯克凄惨而励志的童年

s32ds跳转到DefaultISR

根据Explain查看sql执行计划,对SQL进行优化

service实现类里面为何一直报红
![[iptables & ICMP] description of ICMP Protocol in iptables default policy](/img/9d/85027ea0b0bc9c6494ba41daed9f38.png)
[iptables & ICMP] description of ICMP Protocol in iptables default policy

Hot! Yolov6's fast and accurate target detection framework is open source (with source code download)

PPT制作小技巧

访问网站提示:您未被授权查看该页恢复办法
随机推荐
如何编写简洁代码?(上)
QEMU monitor usage
读书,使人内心宁静
文档问题
2022 electrician (elementary) recurrent training question bank and online simulation examination
无代码软件发展简史及未来趋势
Redis搭建集群【简单】
Importer un fichier Excel, résoudre le problème de sauter les cellules vides et de ne pas lire, et avancer l'indice, et retourner Blank As NULL Red
Is it safe to buy stocks and open an account through the account opening link of the broker manager? Want to open an account for stock trading
Inference optimization implementation of tensorrt model
Severe Tire Damage:世界上第一个在互联网上直播的摇滚乐队
根据Explain查看sql执行计划,对SQL进行优化
新手开哪家的证券账户是比较好?股票开户安全吗
Hot! Yolov6's fast and accurate target detection framework is open source (with source code download)
抓包整理外篇fiddler————了解工具栏[一]
s32ds跳转到DefaultISR
apache、iis6、ii7独立ip主机屏蔽限制ip访问
2022电工(初级)复训题库及在线模拟考试
Set drop-down options on Excel files
The first in the industry! MOS sub evaluation model for subjective video quality experience that can run on mobile devices!