地理坐标系:GCJ02和BD09互转

地理坐标系介绍

主流地理坐标系、投影坐标系和投影方法的区别和联系_ 一只博客-CSDN博客https://blog.csdn.net/qq_42276781/article/details/122597363

关于坐标系的转换,可以参考如下两个开源项目gcoord和coordtransform

GitHub - hujiulong/gcoord: 地理坐标系转换工具https://github.com/hujiulong/gcoordGitHub - wandergis/coordtransform: 提供了百度坐标(BD09)、国测局坐标(火星坐标,GCJ02)、和WGS84坐标系之间的转换https://github.com/wandergis/coordtransform我将gcoord中的GCJ02和BD09互转的代码改写成了C语言的形式,便于大家理解。

#include<stdio.h>
#include<math.h>
#include<stdlib.h>
#define PI 3.1415926535897932384626
double baiduFactor = (PI * 3000.0) / 180.0;

double* BD09ToGCJ02(double lon_BD, double lat_BD){
	double *GCJ = (double *)malloc(2*sizeof(double));
	double x = lon_BD - 0.0065;
	double y = lat_BD - 0.006;
	double z = sqrt(x * x + y * y) - 0.00002 * sin(y * baiduFactor);
	double theta = atan2(y, x) - 0.000003 * cos(x * baiduFactor);
	GCJ[0] = z * cos(theta);
	GCJ[1] = z * sin(theta);
	return GCJ;
}

double* GCJ02ToBD09(double lon_GCJ, double lat_GCJ){
	double *BD = (double *)malloc(2*sizeof(double));
	double z = sqrt(lon_GCJ * lon_GCJ + lat_GCJ * lat_GCJ) + 0.00002 * sin(lat_GCJ * baiduFactor);
	double theta = atan2(lat_GCJ, lon_GCJ) + 0.000003 * cos(lon_GCJ * baiduFactor);
	BD[0] = z * cos(theta) + 0.0065;
	BD[1] = z * sin(theta) + 0.006;
	return BD;
}

//test
int main(){
	double lon = 116.487762;
	double lat = 39.991447;
	double *p = BD09ToGCJ02(lon, lat);
	printf("%.10f, %.10f", p[0], p[1]);
} 

  • 1
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
当然,下面是一个使用Java编写的BD09GCJ02坐标系的代码示例: ```java import java.math.BigDecimal; public class CoordinateConverter { private static final double x_PI = 3.14159265358979324 * 3000.0 / 180.0; private static final double PI = 3.1415926535897932384626; private static final double a = 6378245.0; private static final double ee = 0.00669342162296594323; public static Point convertBD09ToGCJ02(double bdLat, double bdLng) { double x = bdLng - 0.0065; double y = bdLat - 0.006; double z = Math.sqrt(x * x + y * y) - 0.00002 * Math.sin(y * x_PI); double theta = Math.atan2(y, x) - 0.000003 * Math.cos(x * x_PI); double ggLng = z * Math.cos(theta); double ggLat = z * Math.sin(theta); return new Point(ggLat, ggLng); } public static class Point { private final double latitude; private final double longitude; public Point(double latitude, double longitude) { this.latitude = latitude; this.longitude = longitude; } public double getLatitude() { return latitude; } public double getLongitude() { return longitude; } } } ``` 你可以使用上面的代码将BD09坐标系的经纬度换为GCJ02坐标系的经纬度。使用方法如下: ```java double bdLat = 39.908723; double bdLng = 116.397496; CoordinateConverter.Point point = CoordinateConverter.convertBD09ToGCJ02(bdLat, bdLng); System.out.println("GCJ02坐标系:"); System.out.println("Latitude: " + point.getLatitude()); System.out.println("Longitude: " + point.getLongitude()); ``` 请注意,这段代码仅提供了BD09GCJ02换,如果你需要其他坐标系换,你可能需要查找相应的算法或库。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

Toblerone_Wind

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值