地理坐标系介绍
主流地理坐标系、投影坐标系和投影方法的区别和联系_ 一只博客-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]);
}