我想将 gps 坐标(纬度、经度)转换为 ENU(est、north、up)坐标。
我知道关于这个问题的理论,但我没有时间来实现它,所以我问是否存在 java 代码来做到这一点!
谢谢
在本出版物中,有很多关于主题的信息。此外还有一个 Matlab 代码 - 这是一个很好的起点。
相关部分(来自 SP Drake 的“Converting GPS Coordinates (Φλh) to Navigation Coordinates (ENU)”):
只是一个简单的 Java 实现将 GPS 坐标转换为 ENU 坐标。
public List<Double> convertGpsToECEF(double lat, double longi, float alt) {
double a=6378.1;
double b=6356.8;
double N;
double e= 1-(Math.pow(b, 2)/Math.pow(a, 2));
N= a/(Math.sqrt(1.0-(e*Math.pow(Math.sin(Math.toRadians(lat)), 2))));
double cosLatRad=Math.cos(Math.toRadians(lat));
double cosLongiRad=Math.cos(Math.toRadians(longi));
double sinLatRad=Math.sin(Math.toRadians(lat));
double sinLongiRad=Math.sin(Math.toRadians(longi));
double x =(N+0.001*alt)*cosLatRad*cosLongiRad;
double y =(N+0.001*alt)*cosLatRad*sinLongiRad;
double z =((Math.pow(b, 2)/Math.pow(a, 2))*N+0.001*alt)*sinLatRad;
List<Double> ecef= new ArrayList<>();
ecef.add(x);
ecef.add(y);
ecef.add(z);
return ecef;
}
public List<Double> convertECEFtoENU(List<Double> ecefUser, List<Double> ecefPOI, double lat, double longi){
double cosLatRad=Math.cos(Math.toRadians(lat));
double cosLongiRad=Math.cos(Math.toRadians(longi));
double sinLatRad=Math.sin(Math.toRadians(lat));
double sinLongiRad=Math.sin(Math.toRadians(longi));
List<Double> vector = new ArrayList<>();
vector.add(ecefUser.get(0)-ecefPOI.get(0));
vector.add(ecefUser.get(1)-ecefPOI.get(1));
vector.add(ecefUser.get(2)-ecefPOI.get(2));
double e= vector.get(0)*(-sinLongiRad)+vector.get(0)*(cosLongiRad);
double n= vector.get(0)*(-sinLatRad)*(cosLongiRad)+vector.get(1)*(-sinLatRad)*(sinLongiRad)+vector.get(2)*cosLatRad;
double u= vector.get(0)*(cosLatRad)*(cosLongiRad)+vector.get(1)*(cosLatRad)*(sinLongiRad)+vector.get(2)*sinLatRad;
List<Double> enu= new ArrayList<>();
enu.add(e);
enu.add(n);
enu.add(u);
return enu;
}
我找到了一个简单的方法。它使用的想法是,它可能是一个足够好的近似值,可以将地球视为“平坦”
/**
* @param origin
* @return Local (ENU) coordinates
*/
public void computeLocal(Coordinates target) {
if(this.geod==null) computeGeodetic();
SimpleMatrix R = rotationMatrix(this);
enu = R.mult(target.minusXYZ(this));
}
另请参见TopocentricCoordinates.java
public void computeTopocentric(Coordinates origin, Coordinates target) {
origin.computeLocal(target);
double E = origin.getE();//enu.get(0);
double N = origin.getN();//enu.get(1);
double U = origin.getU();//enu.get(2);
其他解决方案是:
public static double[] fatCoordinates(double lat,double lon){
double phi = Math.toRadians(lat);
double lambda = Math.toRadians(lon);
double e2 = Math.pow(WGS_E,2);
double Rn = WGS_A / Math.sqrt(1 - e2 * Math.pow(Math.sin(phi), 2));
double[] XYZ = new double[3];
XYZ[0] = Rn * Math.cos(phi) * Math.cos(lambda);
XYZ[1] = Rn * Math.cos(phi) * Math.sin(lambda);
XYZ[2] = Rn * (1 - e2) * Math.sin(phi);
return XYZ;
}
和
public static final double WGS_A = 6378137.0;
public static final double WGS_E = 0.0818191908426;