给出Java代码 wgs84转cgcs2000
时间: 2023-11-04 13:06:00 浏览: 112
以下是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方法测试了代码,并将结果打印到控制台。
阅读全文