Wgs84转cgcs2000c++代码
时间: 2023-03-15 12:46:18 浏览: 225
您可以使用PROJ 来实现WGS84到CGCS2000C的转换,其代码为:+proj=tmerc +lon_0=117 +lat_0=0 +k=1 +x_0=500000 +y_0=0 +ellps=GRS80 +units=m +no_defs +towgs84=0,0,0,0,0,0,0 +a=6378140 +rf=298.257 +to_meter=1。
相关问题
wgs84转CGCS2000 c++代码
您可以使用以下的 C 代码将 WGS84 坐标转换为 CGCS2000 坐标:
```c
#include <stdio.h>
#include <math.h>
const double a = 6378137.0; // WGS84 椭球长半轴
const double f = 1 / 298.257223563; // WGS84 椭球扁率
const double b = a * (1 - f); // WGS84 椭球短半轴
const double e2 = (pow(a,2) - pow(b, 2)) / pow(a, 2); // WGS84 椭球第一偏心率的平方
const double a_cgcs = 6378137.0; // CGCS2000 椭球长半轴
const double f_cgcs = 1 / 298.257222101; // CGCS2000 椭球扁率
const double b_cgcs = a_cgcs * (1 - f_cgcs); // CGCS2000 椭球短半轴
const double e2_cgcs = (pow(a_cgcs, 2) - pow(b_cgcs, 2)) / pow(a_cgcs,2); // CGCS2000 椭球第一偏心率的平方
double deg2rad(double degree) {
return degree * M_PI / 180.0;
}
double rad2deg(double radian) {
return radian * 180.0 / M_PI;
}
void wgs84ToCgcs2000(double lon_wgs84, double lat_wgs84, double height_wgs84,
double *lon_cgcs, double *lat_cgcs, double *height_cgcs) {
double lon_rad = deg2rad(lon_wgs84);
double lat_rad = deg2rad(lat_wgs84);
double N = a_cgcs / sqrt(1 - e2_cgcs * pow(sin(lat_rad), 2));
double X = (N + height_wgs84) * cos(lat_rad) * cos(lon_rad);
double Y = (N + height_wgs84) * cos(lat_rad) * sin(lon_rad);
double Z = (N * (1 - e2_cgcs) + height_wgs84) * sin(lat_rad);
double p = sqrt(pow(X, 2) + pow(Y, 2));
if (p < 1e-10) {
*lon_cgcs = 0;
*lat_cgcs = 0;
*height_cgcs = Z;
} else {
double theta = atan(Z / (p * (1 - e2_cgcs)));
double sin_theta = sin(theta);
double cos_theta = cos(theta);
*lon_cgcs = atan(Y / X);
*lat_cgcs = atan((Z + b_cgcs * e2_cgcs * pow(sin_theta, 3)) /
(p - a_cgcs * e2_cgcs * pow(cos_theta, 3)));
*height_cgcs = p / cos(*lat_cgcs) - a_cgcs / sqrt(1 - e2_cgcs * pow(sin(*lat_cgcs), 2));
}
*lon_cgcs = rad2deg(*lon_cgcs);
*lat_cgcs = rad2deg(*lat_cgcs);
}
int main() {
double lon_wgs84 = 116.3976;
double lat_wgs84 = 39.9037;
double height_wgs84 = 0.0;
double lon_cgcs, lat_cgcs, height_cgcs;
wgs84ToCgcs2000(lon_wgs84, lat_wgs84, height_wgs84, &lon_cgcs, &lat_cgcs, &height_cgcs);
printf("CGCS2000 坐标:\n");
printf("经度:%f\n", lon_cgcs);
printf("纬度:%f\n", lat_cgcs);
printf("高程:%f\n", height_cgcs);
return 0;
}
```
给出Java代码 wgs84转cgcs2000
以下是Java代码示例,用于将WGS84坐标转换为CGCS2000坐标:
```
import com.jhlabs.map.proj.Projection;
import com.jhlabs.map.proj.ProjectionFactory;
import com.jhlabs.map.proj.WGS84;
import java.awt.geom.Point2D;
public class WGS84ToCGCS2000 {
private static final double WGS84_A = 6378137.0;
private static final double WGS84_F = 1.0 / 298.257223563;
private static final double WGS84_E2 = 2 * WGS84_F - WGS84_F * WGS84_F;
private static final double WGS84_M0 = 0.9996;
private static final double CGCS2000_A = 6378137.0;
private static final double CGCS2000_F = 1.0 / 298.257222101;
private static final double CGCS2000_E2 = 2 * CGCS2000_F - CGCS2000_F * CGCS2000_F;
private static final double CGCS2000_M0 = 1.0;
public static double[] wgs84ToCGCS2000(double latitude, double longitude) {
double[] xy = new double[2];
Projection projection = ProjectionFactory.fromPROJ4Specification(
"+proj=tmerc +ellps=GRS80 +datum=CGCS2000 +lon_0=117 +lat_0=0 +k=1 +x_0=500000 +y_0=0 +units=m");
Point2D.Double wgs84Point = new Point2D.Double(longitude, latitude);
Point2D.Double cgcs2000Point = new Point2D.Double();
projection.transform(new WGS84(), wgs84Point, cgcs2000Point);
xy[0] = cgcs2000Point.getX();
xy[1] = cgcs2000Point.getY();
return xy;
}
public static void main(String[] args) {
double latitude = 39.9042;
double longitude = 116.4074;
double[] xy = wgs84ToCGCS2000(latitude, longitude);
System.out.println("CGCS2000 X: " + xy[0]);
System.out.println("CGCS2000 Y: " + xy[1]);
}
}
```
这个代码使用了Java库“proj.4”,它是一个广泛使用的坐标转换库。在代码中,我们首先定义了WGS84和CGCS2000的椭球体参数,然后创建了一个投影对象,该对象将WGS84坐标转换为CGCS2000坐标。最后,我们使用main方法测试了代码,并将结果打印到控制台。