41 explicit epsg_code(std::string
const& str) : str_(str)
43 std::transform(str_.begin(), str_.end(), str_.begin(), ::toupper);
44 CUPROJ_EXPECTS(valid_prefix(),
"EPSG code must start with 'EPSG:'");
47 epsg_ = std::stoi(str_.substr(str_.find_first_not_of(
"EPSG:")));
48 }
catch (std::invalid_argument
const&) {
54 explicit epsg_code(
int code) : str_(
"EPSG:" + std::to_string(code)), epsg_(code) {}
56 explicit operator std::string()
const {
return str_; }
57 explicit operator int()
const {
return epsg_; }
60 inline bool is_wgs_84()
const {
return epsg_ == 4326; }
65 if (epsg_ >= 32601 && epsg_ <= 32660) {
66 return std::make_pair(epsg_ - 32600, hemisphere::NORTH);
67 }
else if (epsg_ >= 32701 && epsg_ <= 32760) {
68 return std::make_pair(epsg_ - 32700, hemisphere::SOUTH);
70 CUPROJ_FAIL(
"Unsupported UTM EPSG code. Must be in range [32601, 32760] or [32701, 32760]]");
79 inline bool valid_prefix()
const {
return str_.find(
"EPSG:") == 0; }
95template <
typename Coordinate,
typename T =
typename Coordinate::value_type>
103 std::vector<cuproj::operation_type> h_utm_pipeline{
104 operation_type::AXIS_SWAP,
105 operation_type::DEGREES_TO_RADIANS,
106 operation_type::CLAMP_ANGULAR_COORDINATES,
107 operation_type::TRANSVERSE_MERCATOR,
108 operation_type::OFFSET_SCALE_CARTESIAN_COORDINATES};
127template <
typename Coordinate>
135 if (src_code.is_wgs_84()) {
136 return direction::FORWARD;
138 std::swap(src_code, dst_code);
139 CUPROJ_EXPECTS(src_code.is_wgs_84(),
"Unsupported CRS combination.");
140 return direction::INVERSE;
144 auto [dst_zone, dst_hemisphere] = dst_code.to_utm_zone();
164template <
typename Coordinate>
166 std::string
const& dst_epsg)
188template <
typename Coordinate>
auto to_utm_zone()
Return a [zone, hemisphere] pair for the UTM zone corresponding to the EPSG code.
epsg_code(std::string const &str)
Construct an epsg_code from a string.
epsg_code(int code)
Construct an epsg_code from an integer.
A projection transforms coordinates between coordinate reference systems.
#define CUPROJ_EXPECTS(cond, reason)
Macro for checking (pre-)conditions that throws an exception when a condition is violated.
#define CUPROJ_FAIL(reason)
Indicates that an erroneous code path has been taken.
constexpr ellipsoid< T > make_ellipsoid_wgs84()
Create the WGS84 ellipsoid.
direction
Enumerates the direction of a transform operation.
projection< Coordinate > * make_utm_projection(int zone, hemisphere hemisphere, direction dir=direction::FORWARD)
Create a WGS84<-->UTM projection for the given UTM zone and hemisphere.
cuproj::projection< Coordinate > * make_projection(detail::epsg_code const &src_epsg, detail::epsg_code const &dst_epsg)
Create a projection object from EPSG codes.
hemisphere
Hemisphere identifier for projections.