41 explicit epsg_code(std::string
const& str) : str_(str)
43 std::transform(str_.begin(), str_.end(), str_.begin(), ::toupper);
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(
"不支持的 UTM EPSG 代码。必须在范围 [32601, 32660] 或 [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);
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()
返回对应于 EPSG 代码的 UTM 分区 [分区号, 半球] 对。
epsg_code(std::string const &str)
从字符串构造 epsg_code。
epsg_code(int code)
从整数构造 epsg_code。
#define CUPROJ_EXPECTS(cond, reason)
用于检查(前置)条件的宏,当条件被违反时抛出异常。
#define CUPROJ_FAIL(reason)
表示已执行了错误的程序路径。
constexpr ellipsoid< T > make_ellipsoid_wgs84()
创建 WGS84 椭球体。
projection< Coordinate > * make_utm_projection(int zone, hemisphere hemisphere, direction dir=direction::FORWARD)
为给定的 UTM 分区和半球创建 WGS84<-->UTM 投影。
cuproj::projection< Coordinate > * make_projection(detail::epsg_code const &src_epsg, detail::epsg_code const &dst_epsg)
从 EPSG 代码创建投影对象。