public static Point WGS84ToCGS2000(double xCoordinates, double yCoordinates)
{
if (xCoordinates <= 0.0000001 || yCoordinates <= 0.0000001) {
return null;
}
int ProjNo = 0;
Point point = new Point(xCoordinates, yCoordinates);
if (CheckIsWGS84Coordinates(xCoordinates, yCoordinates)) {
point = Wgs84ToCgs2000(point, ProjNo);
} else {
if (!String.valueOf(point.getX()).startsWith(String.valueOf(ProjNo))) {
}
}
return point;
}
public static Point Wgs84ToCgs2000(Point sourcePoint, int ProjNo) {
if (sourcePoint == null) {
}
Point targetPoint = GaussProjCal(sourcePoint, ProjNo);
return targetPoint;
}
public static Point GaussProjCal(Point sourcePoint, int ProjNo) {
Point point = GaussProjCal(sourcePoint.getX(), sourcePoint.getY(), EarthParam.CGS2000.A, EarthParam.CGS2000.F, ProjNo);
return point;
}
private static Point GaussProjCal(double longitude, double latitude, double a, double f, int ProjNo) {
int ZoneWide;
double longitude1, latitude1, longitude0, latitude0, X0, Y0, xval, yval;
double e2, ee, NN, T, C, A, M, iPI;
iPI = Math.PI / 180;
ZoneWide = 3;
if (ProjNo == 0) {
ProjNo = (int) Math.round(longitude / ZoneWide);
}
longitude0 = ProjNo * ZoneWide;
longitude0 = longitude0 * iPI;
latitude0 = 0;
longitude1 = longitude * iPI;
latitude1 = latitude * iPI;
e2 = 2 * f - f * f;
ee = e2 * (1.0 - e2);
NN = a / Math.sqrt(1.0 - e2 * Math.sin(latitude1) * Math.sin(latitude1));
T = Math.tan(latitude1) * Math.tan(latitude1);
C = ee * Math.cos(latitude1) * Math.cos(latitude1);
A = (longitude1 - longitude0) * Math.cos(latitude1);
M = a * ((1 - e2 / 4 - 3 * e2 * e2 / 64 - 5 * e2 * e2 * e2 / 256) * latitude1 - (3 * e2 / 8 + 3 * e2 * e2 / 32 + 45 * e2 * e2 * e2 / 1024) * Math.sin(2 * latitude1)
+ (15 * e2 * e2 / 256 + 45 * e2 * e2 * e2 / 1024) * Math.sin(4 * latitude1) - (35 * e2 * e2 * e2 / 3072) * Math.sin(6 * latitude1));
xval = NN * (A + (1 - T + C) * A * A * A / 6 + (5 - 18 * T + T * T + 72 * C - 58 * ee) * A * A * A * A * A / 120);
yval = M + NN * Math.tan(latitude1) * (A * A / 2 + (5 - T + 9 * C + 4 * C * C) * A * A * A * A / 24
+ (61 - 58 * T + T * T + 600 * C - 330 * ee) * A * A * A * A * A * A / 720);
X0 = 1000000L * (ProjNo) + 500000L;
Y0 = 0;
xval = xval + X0;
yval = yval + Y0;
return new Point(xval, yval);
}
public static boolean CheckIsWGS84Coordinates(double xCoordinates, double yCoordinates) {
boolean res = false;
if (xCoordinates < 360 && xCoordinates != 0 && yCoordinates < 360 && yCoordinates != 0) {
res = true;
}
return res;
}
public double getBigDecimal(double para) {
BigDecimal b = new BigDecimal(para);
double pi1 = b.setScale(3, java.math.BigDecimal.ROUND_HALF_UP).doubleValue();
return pi1;
}
@Test
void test4() {
Point point = WGS84ToCGS2000(111.591111974096, 32.3265852655767);
double bigDecimal = getBigDecimal(point.getX());
double bigDecimal1 = getBigDecimal(point.getY());
System.out.println(bigDecimal);
System.out.println(bigDecimal1);
System.out.println("X:" + point.getX() + " Y:" + point.getY());
}
public class EarthParam {
public class CGS2000{
public static final double A = 6378137;
public static final double F = 1.0 / 298.257222101;
}
public class WGS84{
public static final double A = 6378137;
public static final double F = 1.0 / 298.257223563;
}
public class XIAN80{
public static final double A = 6378140;
public static final double F = 1.0 / 298.25722101;
}
public class BJ54{
public static final double A = 6378245.0;
public static final double F = 1.0 / 298.257;
}