Пример #1
0
 def ned2ecef(self, ned, origin):
     """
     Converts ned local tangent plane coordinates into ecef coordinates
     using origin as the ecef point of tangency.
     Input: ned - (north, east, down) in (m, m, m)
         origin - (x0, y0, z0) in (m, m, m)
     Output: ecef - (x, y, z) in (m, m, m)
     """
     llaOrigin = self.ecef2lla(origin)
     lat = geo.deg2rad(llaOrigin[0])
     lon = geo.deg2rad(llaOrigin[1])
     Rt2e = array([[-sin(lat)*cos(lon), -sin(lon), -cos(lat)*cos(lon)],
                   [-sin(lat)*sin(lon), cos(lon), -cos(lat)*sin(lon)],
                   [cos(lat), 0., -sin(lat)]])
     return list(dot(Rt2e, array(ned)) + array(origin))
Пример #2
0
 def ned2ecef(self, ned, origin):
     """
     Converts ned local tangent plane coordinates into ecef coordinates
     using origin as the ecef point of tangency.
     Input: ned - (north, east, down) in (m, m, m)
         origin - (x0, y0, z0) in (m, m, m)
     Output: ecef - (x, y, z) in (m, m, m)
     """
     llaOrigin = self.ecef2lla(origin)
     lat = geo.deg2rad(llaOrigin[0])
     lon = geo.deg2rad(llaOrigin[1])
     Rt2e = array([[-sin(lat)*cos(lon), -sin(lon), -cos(lat)*cos(lon)],
                   [-sin(lat)*sin(lon), cos(lon), -cos(lat)*sin(lon)],
                   [cos(lat), 0., -sin(lat)]])
     return list(dot(Rt2e, array(ned)) + array(origin))
Пример #3
0
 def lla2ecef(self, lla):
     """
     Convert lat, lon, alt to Earth-centered, Earth-fixed coordinates.
     Input: lla - (lat, lon, alt) in (decimal degrees, decimal degees, m)
     Output: ecef - (x, y, z) in (m, m, m)
     """
     # Decompose the input
     lat = geo.deg2rad(lla[0])
     lon = geo.deg2rad(lla[1])
     alt = lla[2]
     # Calculate length of the normal to the ellipsoid
     N = self.a / sqrt(1 - (self.e * sin(lat))**2)
     # Calculate ecef coordinates
     x = (N + alt) * cos(lat) * cos(lon)
     y = (N + alt) * cos(lat) * sin(lon)
     z = (N * (1 - self.e**2) + alt) * sin(lat)
     # Return the ecef coordinates
     return (x, y, z)
Пример #4
0
 def lla2ecef(self, lla):
     """
     Convert lat, lon, alt to Earth-centered, Earth-fixed coordinates.
     Input: lla - (lat, lon, alt) in (decimal degrees, decimal degees, m)
     Output: ecef - (x, y, z) in (m, m, m)
     """
     # Decompose the input
     lat = geo.deg2rad(lla[0])
     lon = geo.deg2rad(lla[1])
     alt = lla[2]
     # Calculate length of the normal to the ellipsoid
     N = self.a / sqrt(1 - (self.e * sin(lat))**2)
     # Calculate ecef coordinates
     x = (N + alt) * cos(lat) * cos(lon)
     y = (N + alt) * cos(lat) * sin(lon)
     z = (N * (1 - self.e**2) + alt) * sin(lat)
     # Return the ecef coordinates
     return (x, y, z)
Пример #5
0
    def ecef2ned(self, ecef, origin):
        """
        Converts ecef coordinates into local tangent plane where the
        origin is the origin in ecef coordinates.
        Input: ecef - (x, y, z) in (m, m, m)
            origin - (x0, y0, z0) in (m, m, m)
        Output: ned - (north, east, down) in (m, m, m)
        """
        # print('ecef = ', ecef)
        # print('origin = ', origin)

        llaOrigin = self.ecef2lla(origin)
        lat = geo.deg2rad(llaOrigin[0])
        lon = geo.deg2rad(llaOrigin[1])
        Re2t = array([[-sin(lat) * cos(lon), -sin(lat) * sin(lon),
                       cos(lat)], [-sin(lon), cos(lon), 0],
                      [-cos(lat) * cos(lon), -cos(lat) * sin(lon), -sin(lat)]])

        # print('type ecef = %s' % type(ecef))
        # print('type origin = %s' % type(origin))
        return list(dot(Re2t, array(ecef) - array(origin)))
Пример #6
0
    def ecef2ned(self, ecef, origin):
        """
        Converts ecef coordinates into local tangent plane where the
        origin is the origin in ecef coordinates.
        Input: ecef - (x, y, z) in (m, m, m)
            origin - (x0, y0, z0) in (m, m, m)
        Output: ned - (north, east, down) in (m, m, m)
        """
        # print('ecef = ', ecef)
        # print('origin = ', origin)

        llaOrigin = self.ecef2lla(origin)
        lat = geo.deg2rad(llaOrigin[0])
        lon = geo.deg2rad(llaOrigin[1])
        Re2t = array([[-sin(lat)*cos(lon), -sin(lat)*sin(lon), cos(lat)],
                      [-sin(lon), cos(lon), 0],
                      [-cos(lat)*cos(lon), -cos(lat)*sin(lon), -sin(lat)]])

        # print('type ecef = %s' % type(ecef))
        # print('type origin = %s' % type(origin))
        return list(dot(Re2t, array(ecef) - array(origin)))
Пример #7
0
 def lla2utm(self, lla):
     """
     Converts lat, lon, alt to Universal Transverse Mercator coordinates
     Input: lla - (lat, lon, alt) in (decimal degrees, decimal degrees, m)
     Output: utm - (easting, northing, upping) in (m, m, m)
         info - (zone, scale factor)
     Algorithm from:
         Snyder, J. P., Map Projections-A Working Manual, U.S. Geol. Surv.
             Prof. Pap., 1395, 1987
     Code segments from pygps project, Russ Nelson
     """
     # Decompose lla
     lat = lla[0]
     lon = lla[1]
     alt = lla[2]
     # Determine the zone number
     zoneNumber = int((lon + 180.) / 6) + 1
     # Special zone for Norway
     if (56. <= lat < 64.) and (3. <= lon < 12.):
         zoneNumber = 32
     # Special zones for Svalbard
     if 72. <= lat < 84.:
         if 0. <= lon < 9.:
             zoneNumber = 31
         elif 9. <= lon < 21.:
             zoneNumber = 33
         elif 21. <= lon < 33.:
             zoneNumber = 35
         elif 33. <= lon < 42.:
             zoneNumber = 37
     # Format the zone
     zone = "%d%c" % (zoneNumber, self.utmLetterDesignator(lat))
     # Determine longitude origin
     lonOrigin = (zoneNumber - 1) * 6 - 180 + 3
     # Convert to radians
     latRad = geo.deg2rad(lat)
     lonRad = geo.deg2rad(lon)
     lonOriginRad = geo.deg2rad(lonOrigin)
     # Conversion constants
     k0 = 0.9996
     eSquared = self.e**2
     ePrimeSquared = eSquared / (1. - eSquared)
     N = self.a / sqrt(1. - eSquared * sin(latRad)**2)
     T = tan(latRad)**2
     C = ePrimeSquared * cos(latRad)**2
     A = (lonRad - lonOriginRad) * cos(latRad)
     M = self.a * ((1. - eSquared / 4. - 3. * eSquared**2 / 64. -
                    5. * eSquared**3 / 256) * latRad -
                   (3. * eSquared / 8. + 3. * eSquared**2 / 32. +
                    45. * eSquared**3 / 1024.) * sin(2. * latRad) +
                   (15. * eSquared**2 / 256. + 45. * eSquared**3 / 1024.) *
                   sin(4. * latRad) -
                   (35. * eSquared**3 / 3072.) * sin(6. * latRad))
     M0 = 0.
     # Calculate coordinates
     x = k0 * N * (A + (1 - T + C) * A**3 / 6. +
                   (5. - 18. * T + T**2 + 72. * C - 58. * ePrimeSquared) *
                   A**5 / 120.) + 500000.
     y = k0 * (M - M0 + N * tan(latRad) *
               (A**2 / 2. + (5. - T + 9. * C + 4. * C**2) * A**4 / 24. +
                (61. - 58. * T + T**2 + 600. * C - 330. * ePrimeSquared) *
                A**6 / 720.))
     # Calculate scale factor
     k = k0 * (1 + (1 + C) * A**2 / 2. +
               (5. - 4. * T + 42. * C + 13. * C**2 - 28. * ePrimeSquared) *
               A**4 / 24. + (61. - 148. * T + 16. * T**2) * A**6 / 720.)
     utm = [x, y, alt]
     info = [zone, k]
     return utm, info
Пример #8
0
 def lla2utm(self, lla):
     """
     Converts lat, lon, alt to Universal Transverse Mercator coordinates
     Input: lla - (lat, lon, alt) in (decimal degrees, decimal degrees, m)
     Output: utm - (easting, northing, upping) in (m, m, m)
         info - (zone, scale factor)
     Algorithm from:
         Snyder, J. P., Map Projections-A Working Manual, U.S. Geol. Surv.
             Prof. Pap., 1395, 1987
     Code segments from pygps project, Russ Nelson
     """
     # Decompose lla
     lat = lla[0]
     lon = lla[1]
     alt = lla[2]
     # Determine the zone number
     zoneNumber = int((lon+180.)/6) + 1
     # Special zone for Norway
     if (56. <= lat < 64.) and (3. <= lon < 12.):
         zoneNumber = 32
     # Special zones for Svalbard
     if 72. <= lat < 84.:
         if 0. <= lon < 9.:
             zoneNumber = 31
         elif 9. <= lon < 21.:
             zoneNumber = 33
         elif 21. <= lon < 33.:
             zoneNumber = 35
         elif 33. <= lon < 42.:
             zoneNumber = 37
     # Format the zone
     zone = "%d%c" % (zoneNumber, self.utmLetterDesignator(lat))
     # Determine longitude origin
     lonOrigin = (zoneNumber - 1) * 6 - 180 + 3
     # Convert to radians
     latRad = geo.deg2rad(lat)
     lonRad = geo.deg2rad(lon)
     lonOriginRad = geo.deg2rad(lonOrigin)
     # Conversion constants
     k0 = 0.9996
     eSquared = self.e**2
     ePrimeSquared = eSquared/(1.-eSquared)
     N = self.a/sqrt(1.-eSquared*sin(latRad)**2)
     T = tan(latRad)**2
     C = ePrimeSquared*cos(latRad)**2
     A = (lonRad - lonOriginRad)*cos(latRad)
     M = self.a*(
         (1. -
             eSquared/4. -
             3.*eSquared**2/64. -
             5.*eSquared**3/256)*latRad -
         (3.*eSquared/8. +
             3.*eSquared**2/32. +
             45.*eSquared**3/1024.)*sin(2.*latRad) +
         (15.*eSquared**2/256. +
             45.*eSquared**3/1024.)*sin(4.*latRad) -
         (35.*eSquared**3/3072.)*sin(6.*latRad))
     M0 = 0.
     # Calculate coordinates
     x = k0*N*(
         A+(1-T+C)*A**3/6. +
         (5.-18.*T+T**2+72.*C-58.*ePrimeSquared)*A**5/120.) + 500000.
     y = k0*(
         M-M0+N*tan(latRad)*(
             A**2/2. +
             (5.-T+9.*C+4.*C**2)*A**4/24. +
             (61.-58.*T+T**2+600.*C-330.*ePrimeSquared)*A**6/720.))
     # Calculate scale factor
     k = k0*(1 +
             (1+C)*A**2/2. +
             (5.-4.*T+42.*C+13.*C**2-28.*ePrimeSquared)*A**4/24. +
             (61.-148.*T+16.*T**2)*A**6/720.)
     utm = [x, y, alt]
     info = [zone, k]
     return utm, info