| 1 |
/* |
| 2 |
* (C) Copyright 1996- ECMWF. |
| 3 |
* |
| 4 |
* This software is licensed under the terms of the Apache Licence Version 2.0 |
| 5 |
* which can be obtained at http://www.apache.org/licenses/LICENSE-2.0. |
| 6 |
* In applying this licence, ECMWF does not waive the privileges and immunities |
| 7 |
* granted to it by virtue of its status as an intergovernmental organisation |
| 8 |
* nor does it submit to any jurisdiction. |
| 9 |
*/ |
| 10 |
|
| 11 |
|
| 12 |
#include "LambertAzimuthalEqualAreaProjection.h" |
| 13 |
|
| 14 |
#include <cmath> |
| 15 |
|
| 16 |
#include "eckit/config/Parametrisation.h" |
| 17 |
#include "eckit/types/FloatCompare.h" |
| 18 |
#include "eckit/utils/Hash.h" |
| 19 |
|
| 20 |
#include "atlas/projection/detail/ProjectionFactory.h" |
| 21 |
#include "atlas/runtime/Exception.h" |
| 22 |
#include "atlas/util/Config.h" |
| 23 |
#include "atlas/util/Constants.h" |
| 24 |
#include "atlas/util/CoordinateEnums.h" |
| 25 |
#include "atlas/util/Earth.h" |
| 26 |
|
| 27 |
namespace atlas { |
| 28 |
namespace projection { |
| 29 |
namespace detail { |
| 30 |
|
| 31 |
|
| 32 |
LambertAzimuthalEqualAreaProjection::LambertAzimuthalEqualAreaProjection(const eckit::Parametrisation& params): |
| 33 |
radius_(util::Earth::radius()) { |
| 34 |
ATLAS_ASSERT(params.get("central_longitude", reference_[LON])); |
| 35 |
ATLAS_ASSERT(params.get("standard_parallel", reference_[LAT])); |
| 36 |
params.get("radius", radius_ = util::Earth::radius()); |
| 37 |
params.get("false_northing", false_northing_); |
| 38 |
params.get("false_easting", false_easting_); |
| 39 |
|
| 40 |
|
| 41 |
lambda0_ = util::Constants::degreesToRadians() * reference_[LON]; |
| 42 |
phi1_ = util::Constants::degreesToRadians() * reference_[LAT]; |
| 43 |
sin_phi1_ = std::sin(phi1_); |
| 44 |
cos_phi1_ = std::cos(phi1_); |
| 45 |
} |
| 46 |
|
| 47 |
|
| 48 |
void LambertAzimuthalEqualAreaProjection::lonlat2xy(double crd[]) const { |
| 49 |
double dlambda = util::Constants::degreesToRadians() * (crd[LON] - reference_.lon()); |
| 50 |
double cos_dlambda = std::cos(dlambda); |
| 51 |
double sin_dlambda = std::sin(dlambda); |
| 52 |
|
| 53 |
double phi = util::Constants::degreesToRadians() * crd[LAT]; |
| 54 |
double sin_phi = std::sin(phi); |
| 55 |
double cos_phi = std::cos(phi); |
| 56 |
|
| 57 |
double kp = radius_ * std::sqrt(2. / (1. + sin_phi1_ * sin_phi + cos_phi1_ * cos_phi * cos_dlambda)); |
| 58 |
|
| 59 |
crd[XX] = kp * cos_phi * sin_dlambda; |
| 60 |
crd[YY] = kp * (cos_phi1_ * sin_phi - sin_phi1_ * cos_phi * cos_dlambda); |
| 61 |
crd[XX] += false_easting_; |
| 62 |
crd[YY] += false_northing_; |
| 63 |
} |
| 64 |
|
| 65 |
|
| 66 |
void LambertAzimuthalEqualAreaProjection::xy2lonlat(double crd[]) const { |
| 67 |
const double x = crd[XX] - false_easting_; |
| 68 |
const double y = crd[YY] - false_northing_; |
| 69 |
|
| 70 |
const double rho = std::sqrt(x * x + y * y); |
| 71 |
if (std::abs(rho) < 1.e-12) { |
| 72 |
crd[LON] = reference_[LON]; |
| 73 |
crd[LAT] = reference_[LAT]; |
| 74 |
return; |
| 75 |
} |
| 76 |
|
| 77 |
double c = 2. * std::asin(rho / (2. * radius_)); |
| 78 |
double cos_c = std::cos(c); |
| 79 |
double sin_c = std::sin(c); |
| 80 |
|
| 81 |
double lon_r = lambda0_ + std::atan2(x * sin_c, rho * cos_phi1_ * cos_c - y * sin_phi1_ * sin_c); |
| 82 |
double sin_lat_r = cos_c * sin_phi1_ + y * sin_c * cos_phi1_ / rho; |
| 83 |
|
| 84 |
crd[LON] = lon_r * util::Constants::radiansToDegrees(); |
| 85 |
crd[LAT] = sin_lat_r > 1 ? 90 : sin_lat_r < -1 ? -90 : util::Constants::radiansToDegrees() * std::asin(sin_lat_r); |
| 86 |
} |
| 87 |
|
| 88 |
|
| 89 |
ProjectionImpl::Jacobian LambertAzimuthalEqualAreaProjection::jacobian(const PointLonLat&) const { |
| 90 |
throw_NotImplemented("LambertAzimuthalEqualAreaProjection::jacobian", Here()); |
| 91 |
} |
| 92 |
|
| 93 |
LambertAzimuthalEqualAreaProjection::Spec LambertAzimuthalEqualAreaProjection::spec() const { |
| 94 |
Spec proj; |
| 95 |
proj.set("type", static_type()); |
| 96 |
proj.set("central_longitude", reference_[LON]); |
| 97 |
proj.set("standard_parallel", reference_[LAT]); |
| 98 |
proj.set("radius", radius_); |
| 99 |
proj.set("false_easting", false_easting_); |
| 100 |
proj.set("false_northing", false_northing_); |
| 101 |
|
| 102 |
return proj; |
| 103 |
} |
| 104 |
|
| 105 |
|
| 106 |
void LambertAzimuthalEqualAreaProjection::hash(eckit::Hash& h) const { |
| 107 |
h.add(static_type()); |
| 108 |
h.add(radius_); |
| 109 |
h.add(reference_[LON]); |
| 110 |
h.add(reference_[LAT]); |
| 111 |
} |
| 112 |
|
| 113 |
|
| 114 |
namespace { |
| 115 |
static ProjectionBuilder<LambertAzimuthalEqualAreaProjection> register_1( |
| 116 |
LambertAzimuthalEqualAreaProjection::static_type()); |
| 117 |
} |
| 118 |
|
| 119 |
|
| 120 |
} // namespace detail |
| 121 |
} // namespace projection |
| 122 |
} // namespace atlas |