def LatLonHgt2XYZ(self, lat, lon, h):
        """LatLonHgt2XYZ(lat, lon, h) --> (x, y, z)

        lat       is the latitude (deg)
        lon       is the longitude (deg)
        h         is the heigh (m)

        (x, y, z) is a tuple of ECEF coordinates (m)
        """
        N = self.N(lat)
        cos_lat = cosd(lat)
        return (cos_lat * cosd(lon) * (N + h), cos_lat * sind(lon) * (N + h),
                sind(lat) * ((1 - self.e2) * N + h))
Exemple #2
0
def bearing(lat1, lon1, lat2, lon2):
    """hdg = bearing(lat1, lon1, lat2, lon2)

    lat1, lon1  are the latitude and longitude of the starting point
    lat2, lon2  are the latitude and longitude of the ending point

    hdg is the bearing (heading), in degrees, linking the start to the end.
    """
    from isceobj.Util.geo.trig import sind, cosd, arctand2
    dlat = (lat2 - lat1)
    dlon = (lon2 - lon1)
    y = sind(dlon) * cosd(lat2)
    x = cosd(lat1) * sind(lat2) - sind(lat1) * cosd(lat2) * cosd(dlon)

    return arctand2(y, x)
def ecef2llh_iterative(ellipsoid_of_revolution, x, y, z, iters=10):
    """ecef2llh(ellipsoid_of_revolution, x, y, z [,iters=10])--> (lat, lon, hgt)

    Input:
    ------
    ellipsoid_of_revolution  an Ellipsoid instance
    x
    y           ECEF coordiantes (singleton, or array, or whatever
    z

    KeyWord:
    --------
    iters      controls the number of iteration in the loop to compute the
               latitude.

    Ouput:
    -----
    lat       is the latitude (deg)
    lon       is the longitude (deg)
    h         is the heigh (m)
    """
    lon = arctan2(y, x) * 180 / np.pi
    p = (x**2 + y**2)**0.5
    r = (x**2 + y**2 + z**2)**0.5

    phi = arctan2(p, z)
    while iters > 0:
        RN = ellipsoid_of_revolution.N(phi * 180 / np.pi)
        h = (p / np.cos(phi)) - RN
        phi = arctan(
            (z / p) / (1 - ellipsoid_of_revolution.e2 * RN / (RN + h)))
        iters -= 1
        pass

    phi *= 180 / np.pi
    h = p / cosd(phi) - ellipsoid_of_revolution.N(phi)

    return (phi, lon, h)
    def great_circle(self, lat1, lon1, lat2, lon2):
        """s, alpha1, alpha2 = great_circle(lat1, lon1, lat2, lon2)

        (lat1, lon1)    p1's location
        (lat2, lon2)    p2's location

        s               distance along great circle
        alpha1          heading at p1
        alpha2          heading at p2
        """
        phi1, L1, phi2, L2 = lat1, lon1, lat2, lon2

        a = self.a
        f = self.f
        b = (1 - f) * a
        U1 = self.common2reduced(phi1)  # aka beta1
        U2 = self.common2reduced(phi2)
        L = L2 - L1

        lam = L

        delta_lam = 100000.

        while abs(delta_lam) > 1.e-10:
            sin_sigma = ((cosd(U2) * sind(lam))**2 +
                         (cosd(U1) * sind(U2) -
                          sind(U1) * cosd(U2) * cosd(lam))**2)**0.5
            cos_sigma = sind(U1) * sind(U2) + cosd(U1) * cosd(U2) * cosd(lam)
            sigma = arctan2(sin_sigma, cos_sigma)

            sin_alpha = cosd(U1) * cosd(U2) * sind(lam) / sin_sigma
            cos2_alpha = 1 - sin_alpha**2

            cos_2sigma_m = cos_sigma - 2 * sind(U1) * sind(U2) / cos2_alpha

            C = (f / 16.) * cos2_alpha * (4. + f * (4 - 3 * cos2_alpha))

            lam_new = (np.radians(L) + (1 - C) * f * sin_alpha *
                       (sigma + C * sin_sigma * (cos_2sigma_m + C * cos_sigma *
                                                 (-1 + 2 * cos_2sigma_m**2))))

            lam_new *= 180 / np.pi

            delta_lam = lam_new - lam
            lam = lam_new
            pass

        u2 = cos2_alpha * (a**2 - b**2) / b**2

        A_ = 1 + u2 / 16384 * (4096 + u2 * (-768 + u2 * (320 - 175 * u2)))
        B_ = u2 / 1024 * (256 + u2 * (-128 + u2 * (74 - 47 * u2)))

        delta_sigma = B_ * sin_sigma * (cos_2sigma_m - (1 / 4.) * B_ *
                                        (cos_sigma *
                                         (-1 + 2 * cos_2sigma_m**2)) -
                                        (1 / 6.) * B_ * cos_2sigma_m *
                                        (-3 + 4 * sin_sigma**2) *
                                        (-3 + 4 * cos_2sigma_m**2))

        s = b * A_ * (sigma - delta_sigma)

        alpha_1 = 180 * arctan2(
            cosd(U2) * sind(lam),
            cosd(U1) * sind(U2) - sind(U1) * cosd(U2) * cosd(lam)) / np.pi

        alpha_2 = 180 * arctan2(
            cosd(U1) * sind(lam),
            -sind(U1) * cosd(U2) + cosd(U1) * sind(U2) * cosd(lam)) / np.pi

        return s, alpha_1, alpha_2
 def R(self, lat):
     return (((self.a**2 * cosd(lat))**2 + (self.b**2 * sind(lat))**2) /
             ((self.a * cosd(lat))**2 + (self.b * sind(lat))**2))**0.5
 def local_radius_of_curvature(self, lat, hdg):
     """local_radius_of_curvature(lat, hdg)"""
     return 1. / (cosd(hdg)**2 / self.M(lat) + sind(hdg)**2 / self.N(lat))
 def normal_radius_of_curvature(self, lat):
     """East Radius (eastRad): Normal radius of curvature (N), meters for
     latitude in degrees """
     return (self.a**2 / ((self.a * cosd(lat))**2 +
                          (self.b * sind(lat))**2)**0.5)
 def meridional_radius_of_curvature(self, lat):
     """North Radius (northRad): Meridional radius of curvature (M),
     meters for latitude in degress """
     return ((self.a * self.b)**2 / ((self.a * cosd(lat))**2 +
                                     (self.b * sind(lat))**2)**1.5)
 def longitude_degree_length(self, lat):
     """Length of a degree of longitude (deg-->m)"""
     from isceobj.Util.geo.trig import cosd
     return np.radians(cosd(lat) * self.normal_radius_of_curvature(lat))
Exemple #10
0
 def n_vector(self):
     """Compute a Vector instance representing the N-Vector"""
     from isceobj.Util.geo.trig import sind, cosd
     return euclid.Vector(
         cosd(self.lat) * cosd(self.lon),
         cosd(self.lat) * sind(self.lon), sind(self.lat))