3#ifndef BOAT_GEOMETRY_TRANSFORM_HPP
4#define BOAT_GEOMETRY_TRANSFORM_HPP
6#include <boat/detail/numbers.hpp>
8#include <boost/geometry/algorithms/transform.hpp>
9#include <boost/geometry/srs/epsg.hpp>
10#include <boost/geometry/srs/transformation.hpp>
11#include <boost/geometry/strategies/transform/matrix_transformers.hpp>
12#include <boost/geometry/strategies/transform/srs_transformer.hpp>
18namespace srs = boost::geometry::srs;
23constexpr bool is_srs_spec = std::is_constructible_v<srs::projection<>, T>;
33 specialized<T, srs::projection> || specialized<T, srs::transformation>;
35static auto const lonlat = srs::proj4{
" +proj=lonlat +datum=WGS84 +no_defs"};
39 return srs::proj4{std::format(
40 " +proj=ortho +x_0=0 +y_0=0 +units=m +no_defs"
41 " +a={} +b={} +lat_0={} +lon_0={}",
42 numbers::earth::equatorial_radius,
43 numbers::earth::polar_radius,
50 if constexpr (specialized<
decltype(a), std::variant>)
51 return std::visit([&](
auto&& a) {
return transformation(a, b); }, a);
52 else if constexpr (specialized<
decltype(b), std::variant>)
53 return std::visit([&](
auto&& b) {
return transformation(a, b); }, b);
55 return srs::transformation<>(a, b);
66 return boost::geometry::strategy::transform::
67 matrix_transformer<double, 2, 2>{v};
70template <projection_or_transformation T>
73 return boost::geometry::strategy::transform::srs_forward_transformer<T>{v};
81template <projection_or_transformation T>
84 return boost::geometry::strategy::transform::srs_inverse_transformer<T>{v};
88template <tagged T1, same_tag<T1> T2,
class Strategy>
89bool transform(T1
const& geom1, T2& geom2, Strategy
const& strategy)
93 return boost::geometry::transform(a, b = {}, strategy);
95 [](
this auto&& self,
multi auto const& a,
multi auto& b) ->
bool {
97 for (
auto const& v : a)
98 if (!self(v, b.emplace_back()))
102 [](
this auto&& self,
dynamic auto const& a,
dynamic auto& b) ->
bool {
103 auto vis = [&]<
class T>(T const& v) {
106 return std::visit(vis, a);
113 return [=]<
tagged T>(T a) {
115 return (... && (b = std::move(a),
transform(b, a, strategies)))
116 ? std::optional{std::move(a)}
125 return srs::epsg{epsg};
127 return srs::proj4{proj4};
128 throw std::runtime_error(
"no SRS");
Definition vocabulary.hpp:34
Definition vocabulary.hpp:40
Definition vocabulary.hpp:58
Definition transform.hpp:29
Definition vocabulary.hpp:28
Definition algorithm.hpp:10
constexpr bool is_srs_spec
Definition transform.hpp:23
bool transform(T1 const &geom1, T2 &geom2, Strategy const &strategy)
Collections succeed if any element succeeds; failed elements are omitted.
Definition transform.hpp:89
std::variant< srs::epsg, srs::proj4 > srs_variant
Definition transform.hpp:20
auto forward(matrix const &v)
Definition transform.hpp:64
constexpr auto variant_index_v
Definition vocabulary.hpp:118
auto ortho(geographic::point const &v)
Definition transform.hpp:37
srs_variant make_srs_variant(int epsg, std::string const &proj4)
Prefers positive EPSG to PROJ.4; throws if neither is available.
Definition transform.hpp:122
auto backward(matrix const &v)
Definition transform.hpp:76
auto transformation(srs_spec auto const &a, srs_spec auto const &b)
Definition transform.hpp:48
boost::qvm::mat< double, 3, 3 > matrix
Definition vocabulary.hpp:104
model::d2::point_xy< double, cs::geographic< boost::geometry::degree > > point
Definition vocabulary.hpp:65