00001
00002 from pysatel import coord
00003 from math import radians, degrees
00004 from scipy import mat, cos, sin, arctan, sqrt, pi, arctan2, linalg
00005 import math
00006 import geodesy
00007 from pyproj import Proj, transform
00008
00009 deg2rad = math.pi/180;
00010 rad2deg = 180/math.pi;
00011 radius = 6378137;
00012 ratio = 0.99664719;
00013
00014 def mpdlat(lat):
00015 return (111132.954 - 559.822*math.cos(2*lat*deg2rad) + 1.175*math.cos(4*lat*deg2rad))
00016
00017 def mpdlon(lat):
00018 return (radius*math.cos(math.atan(ratio*math.tan(lat*deg2rad)))*deg2rad);
00019
00020 def deg2meter(difflat, difflon, lat):
00021 return difflat*mpdlat(lat),difflon*mpdlon(lat);
00022
00023 def meter2deg(x, y, lat):
00024 return x/mpdlat(lat),y/mpdlon(lat);
00025
00026 def ecef2enu(X, Y, Z, lat, lon, alt):
00027 X0, Y0, Z0 = coord.geodetic2ecef(lat, lon, alt)
00028 lat, lon = radians(lat), radians(lon)
00029 mx = mat('[%f %f %f; %f %f %f; %f %f %f]' %
00030 (-sin(lon), -sin(lat) * cos(lon), cos(lat) * cos(lon), cos(lon),
00031 -sin(lat) * sin(lon), cos(lat) * sin(lon), 0, cos(lat), sin(lat)))
00032 geo = mat('[%f; %f; %f]' % (X0, Y0, Z0))
00033 res = mat('[%f; %f; %f]' % (X, Y, Z))
00034 enu = mx.transpose()*(res - geo)
00035 return enu[1], enu[0], -enu[2]
00036
00037 def ned2ecef(lat, lon, alt, n, e, d):
00038 X0, Y0, Z0 = coord.geodetic2ecef(lat, lon, alt)
00039 lat, lon = radians(lat), radians(lon)
00040
00041 pitch = math.pi/2 + lat
00042 yaw = -lon
00043
00044 my = mat('[%f %f %f; %f %f %f; %f %f %f]' %
00045 (cos(pitch), 0, -sin(pitch),
00046 0,1,0,
00047 sin(pitch), 0, cos(pitch)))
00048
00049 mz = mat('[%f %f %f; %f %f %f; %f %f %f]' %
00050 (cos(yaw), sin(yaw),0,
00051 -sin(yaw),cos(yaw),0,
00052 0,0,1))
00053
00054 mr = mat('[%f %f %f; %f %f %f; %f %f %f]' %
00055 (-cos(lon)*sin(lat), -sin(lon), -cos(lat) * cos(lon),
00056 -sin(lat)*sin(lon), cos(lon), -sin(lon)*cos(lat),
00057 cos(lat), 0, -sin(lat)))
00058
00059 geo = mat('[%f; %f; %f]' % (X0, Y0, Z0))
00060 ned = mat('[%f; %f; %f]' % (n, e, d))
00061 res = mr*ned + geo
00062 return res[0], res[1], res[2]
00063
00064 def ecef2ned(lat, lon, alt, X, Y, Z):
00065 X0, Y0, Z0 = coord.geodetic2ecef(lat, lon, alt)
00066 lat, lon = radians(lat), radians(lon)
00067
00068 mr = mat('[%f %f %f; %f %f %f; %f %f %f]' %
00069 (-cos(lon)*sin(lat), -sin(lon), -cos(lat) * cos(lon),
00070 -sin(lat)*sin(lon), cos(lon), -sin(lon)*cos(lat),
00071 cos(lat), 0, -sin(lat)))
00072
00073 geo = mat('[%f; %f; %f]' % (X0, Y0, Z0))
00074 res = mat('[%f; %f; %f]' % (X, Y, Z))
00075 res = mr.transpose()*(res - geo)
00076 return float(res[0]), res[1], res[2]
00077
00078 if __name__ == "__main__":
00079 print("Hello")
00080 latInit = 42;
00081 lonInit= 16;
00082 altInit = 1000;
00083
00084 xof = 1000;
00085 yof = 5000;
00086 zof = 1000;
00087
00088
00089 xg,yg,zg = coord.geodetic2ecef(latInit,lonInit, altInit/1000)
00090 print("IST Geo -> ECEF: {0} {1} {2}".format(xg,yg,zg))
00091 a,b,c = ecef2enu(xg, yg, zg, latInit, lonInit, altInit/1000)
00092 print("IST ECEF -> NED: {0} {1} {2}".format(a*1000,b*1000,c*1000))
00093 xg,yg,zg = coord.enu2ecef(latInit, lonInit, altInit/1000, a, b, c)
00094 print("IST NED -> ECEF: {0} {1} {2}".format(xg,yg,zg))
00095 latR,lonR = coord.ecef2geodetic(xg,yg,zg)
00096 print("IST ECEF -> Geo: {0} {1}".format(latR,lonR))
00097
00098 xg,yg,zg = coord.enu2ecef(latInit, lonInit, altInit/1000, xof/1000,yof/1000,zof/1000)
00099 print("IST NED -> ECEF 1: {0} {1} {2}".format(xg,yg,zg))
00100 latR,lonR = coord.ecef2geodetic(xg,yg,zg)
00101 print("IST NED -> Geo: {0} {1}".format(latR,lonR))
00102 xg,yg,zg = ned2ecef(latInit, lonInit, altInit/1000, xof/1000,yof/1000,zof/1000)
00103 print("IST NED -> ECEF 2: {0} {1} {2}".format(xg,yg,zg))
00104 a,b,c = ecef2ned(latInit, lonInit, altInit/1000, xg, yg, zg)
00105 print("IST Geo -> NED 2: {0} {1} {2}".format(a*1000,b*1000,c*1000))
00106
00107 a,b,c = ecef2enu(xg, yg, zg, latInit, lonInit, altInit/1000)
00108 print("IST Geo -> NED: {0} {1} {2}".format(a*1000,b*1000,c*1000))
00109
00110
00111 xg,yg,zg = coord.geodetic2ecef(latInit,lonInit, altInit)
00112 dLat,dLon = meter2deg(xof, yof, latInit)
00113 latR = latInit + dLat
00114 lonR = lonInit + dLon
00115 print("LABUST NED -> Geo: {0} {1}".format(latR,lonR))
00116 dLat = latR - latInit
00117 dLon = lonR - lonInit
00118 dx,dy = deg2meter(dLat, dLon, latInit)
00119 print("LABUST Geo -> NED: {0} {1}".format(dx,dy))
00120
00121
00122
00123 p1 = Proj(proj='latlong',ellps='WGS84', datum='WGS84')
00124 p2 = Proj(proj='geocent', ellps='WGS84', datum='WGS84')
00125 p3 = Proj(proj="sterea", lat_0=latInit, lon_0=lonInit, k_0=1.0, x_0=0, y_0=0, ellps="WGS84", datum="WGS84")
00126 xg,yg,zg = transform(p1,p2,lonInit,latInit,altInit, radians=False)
00127 print("Proj Geo -> ECEF: {0} {1} {2}".format(xg,yg,zg))
00128 b,a,c = transform(p3,p2,yof,xof,zof, radians=False)
00129 print("Proj NED -> Geo: {0} {1} {2}".format(a,b,c))
00130 a,b,c = transform(p2,p1,b,a,c, radians=False)
00131 print("Proj Geo -> NED: {0} {1} {2}".format(a,b,c))
00132
00133
00134 lonR,latR,altR = transform(p2,p3,xg,yg,zg, radians=False)
00135 print("Proj ECEF -> Geo: {0} {1}".format(latR,lonR))
00136
00137
00138
00139
00140
00141
00142
00143
00144