Debian Codegraph @

include/boost_1_77_0/patches/boost/geometry/srs/projections/dpar.hpp

raw
1 // Boost.Geometry
2
3 // Copyright (c) 2017, 2026, Oracle and/or its affiliates.
4 // Contributed and/or modified by Vissarion Fysikopoulos, on behalf of Oracle
5 // Contributed and/or modified by Adam Wulkiewicz, on behalf of Oracle
6
7 // Use, modification and distribution is subject to the Boost Software License,
8 // Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
9 // http://www.boost.org/LICENSE_1_0.txt)
10
11 #ifndef BOOST_GEOMETRY_SRS_PROJECTIONS_DPAR_HPP
12 #define BOOST_GEOMETRY_SRS_PROJECTIONS_DPAR_HPP
13
14
15 #include <string>
16 #include <type_traits>
17 #include <vector>
18
19 #include <boost/geometry/core/radius.hpp>
20 #include <boost/geometry/core/tag.hpp>
21 #include <boost/geometry/core/tags.hpp>
22
23 #include <boost/geometry/srs/projections/exception.hpp>
24 #include <boost/geometry/srs/projections/par_data.hpp>
25 #include <boost/geometry/srs/sphere.hpp>
26 #include <boost/geometry/srs/spheroid.hpp>
27
28 #include <boost/geometry/util/range.hpp>
29
30 #include <boost/range/begin.hpp>
31 #include <boost/range/end.hpp>
32 #include <boost/range/size.hpp>
33 #include <boost/range/value_type.hpp>
34 #include <boost/tuple/tuple.hpp>
35 #include <boost/variant/variant.hpp>
36
37
38 namespace boost { namespace geometry { namespace srs
39 {
40
41 namespace detail
42 {
43
44 template <typename T, int I, typename ...>
45 struct find_type_index_impl
46 : std::integral_constant<int, I>
47 {};
48
49 template
50 <
51 typename T,
52 int I,
53 typename Type,
54 typename ...Types
55 >
56 struct find_type_index_impl<T, I, Type, Types...>
57 : std::conditional_t
58 <
59 std::is_same<T, Type>::value,
60 std::integral_constant<int, I>,
61 typename find_type_index_impl<T, I + 1, Types...>::type
62 >
63 {};
64
65 template <typename Variant, typename T>
66 struct find_type_index
67 {};
68
69 template <BOOST_VARIANT_ENUM_PARAMS(typename T), typename T>
70 struct find_type_index<boost::variant<BOOST_VARIANT_ENUM_PARAMS(T)>, T>
71 : find_type_index_impl<T, 0, BOOST_VARIANT_ENUM_PARAMS(T)>
72 {};
73
74
75 template
76 <
77 typename Range,
78 typename ToValue,
79 bool IsRange = range::detail::is_range<Range>::value
80 >
81 struct is_convertible_range
82 : std::is_convertible
83 <
84 typename boost::range_value<Range>::type,
85 ToValue
86 >
87 {};
88
89 template
90 <
91 typename Range,
92 typename ToValue
93 >
94 struct is_convertible_range<Range, ToValue, false>
95 : std::false_type
96 {};
97
98 } // namespace detail
99
100
101 namespace dpar
102 {
103
104 enum value_datum
105 {
106 datum_wgs84 = 0,
107 datum_ggrs87,
108 datum_nad83,
109 datum_nad27,
110 datum_potsdam,
111 datum_carthage,
112 datum_hermannskogel,
113 datum_ire65,
114 datum_nzgd49,
115 datum_osgb36,
116 };
117
118 enum value_ellps
119 {
120 ellps_merit = 0,
121 ellps_sgs85,
122 ellps_grs80,
123 ellps_iau76,
124 ellps_airy,
125 ellps_apl4_9,
126 ellps_nwl9d,
127 ellps_mod_airy,
128 ellps_andrae,
129 ellps_aust_sa,
130 ellps_grs67,
131 ellps_bessel,
132 ellps_bess_nam,
133 ellps_clrk66,
134 ellps_clrk80,
135 ellps_clrk80ign,
136 ellps_cpm,
137 ellps_delmbr,
138 ellps_engelis,
139 ellps_evrst30,
140 ellps_evrst48,
141 ellps_evrst56,
142 ellps_evrst69,
143 ellps_evrstss,
144 ellps_fschr60,
145 ellps_fschr60m,
146 ellps_fschr68,
147 ellps_helmert,
148 ellps_hough,
149 ellps_intl,
150 ellps_krass,
151 ellps_kaula,
152 ellps_lerch,
153 ellps_mprts,
154 ellps_new_intl,
155 ellps_plessis,
156 ellps_seasia,
157 ellps_walbeck,
158 ellps_wgs60,
159 ellps_wgs66,
160 ellps_wgs72,
161 ellps_wgs84,
162 ellps_sphere
163 };
164
165 enum value_mode
166 {
167 mode_plane = 0,
168 mode_di,
169 mode_dd,
170 mode_hex
171 };
172
173 enum value_orient
174 {
175 orient_isea = 0,
176 orient_pole,
177 };
178
179 enum value_pm
180 {
181 pm_greenwich = 0,
182 pm_lisbon,
183 pm_paris,
184 pm_bogota,
185 pm_madrid,
186 pm_rome,
187 pm_bern,
188 pm_jakarta,
189 pm_ferro,
190 pm_brussels,
191 pm_stockholm,
192 pm_athens,
193 pm_oslo
194 };
195
196 enum value_proj
197 {
198 proj_unknown = 0,
199 proj_aea, proj_leac,
200 proj_aeqd,
201 proj_airy,
202 proj_aitoff, proj_wintri,
203 proj_august,
204 proj_apian, proj_ortel, proj_bacon,
205 proj_bipc,
206 proj_boggs,
207 proj_bonne,
208 proj_cass,
209 proj_cc,
210 proj_cea,
211 proj_chamb,
212 proj_col_urban,
213 proj_collg,
214 proj_crast,
215 proj_denoy,
216 proj_eck1,
217 proj_eck2,
218 proj_eck3, proj_putp1, proj_wag6, proj_kav7,
219 proj_eck4,
220 proj_eck5,
221 proj_eqc,
222 proj_eqdc,
223 proj_etmerc, proj_utm,
224 proj_fahey,
225 proj_fouc_s,
226 proj_gall,
227 proj_geocent,
228 proj_geos,
229 proj_gins8,
230 proj_gn_sinu, proj_sinu, proj_eck6, proj_mbtfps,
231 proj_gnom,
232 proj_goode,
233 proj_gstmerc,
234 proj_hammer,
235 proj_hatano,
236 proj_healpix,
237 proj_rhealpix,
238 proj_igh,
239 proj_imw_p,
240 proj_isea,
241 proj_krovak,
242 proj_labrd,
243 proj_laea,
244 proj_lagrng,
245 proj_larr,
246 proj_lask,
247 proj_lonlat, proj_latlon, proj_latlong, proj_longlat,
248 proj_lcc,
249 proj_lcca,
250 proj_loxim,
251 proj_lsat,
252 proj_mbt_fps,
253 proj_mbtfpp,
254 proj_mbtfpq,
255 proj_merc,
256 proj_mill,
257 proj_mil_os, proj_lee_os, proj_gs48, proj_alsk, proj_gs50,
258 proj_moll, proj_wag4, proj_wag5,
259 proj_natearth,
260 proj_nell,
261 proj_nell_h,
262 proj_nicol,
263 proj_nsper, proj_tpers,
264 proj_nzmg,
265 proj_ob_tran,
266 proj_ocea,
267 proj_oea,
268 proj_omerc,
269 proj_ortho,
270 proj_poly,
271 proj_putp2,
272 proj_putp3, proj_putp3p,
273 proj_putp4p, proj_weren,
274 proj_putp5, proj_putp5p,
275 proj_putp6, proj_putp6p,
276 proj_qsc,
277 proj_robin,
278 proj_rouss,
279 proj_rpoly,
280 proj_euler, proj_murd1, proj_murd2, proj_murd3, proj_pconic, proj_tissot, proj_vitk1,
281 proj_somerc,
282 proj_stere, proj_ups,
283 proj_sterea,
284 proj_kav5, proj_qua_aut, proj_fouc, proj_mbt_s,
285 proj_tcc,
286 proj_tcea,
287 proj_tmerc,
288 proj_tpeqd,
289 proj_urm5,
290 proj_urmfps, proj_wag1,
291 proj_vandg,
292 proj_vandg2, proj_vandg3,
293 proj_vandg4,
294 proj_wag2,
295 proj_wag3,
296 proj_wag7,
297 proj_webmerc,
298 proj_wink1,
299 proj_wink2
300 };
301
302 enum value_sweep
303 {
304 sweep_x = 0, sweep_y
305 };
306
307 enum value_units
308 {
309 units_km = 0,
310 units_m,
311 units_dm,
312 units_cm,
313 units_mm,
314 units_kmi,
315 units_in,
316 units_ft,
317 units_yd,
318 units_mi,
319 units_fath,
320 units_ch,
321 units_link,
322 units_us_in,
323 units_us_ft,
324 units_us_yd,
325 units_us_ch,
326 units_us_mi,
327 units_ind_yd,
328 units_ind_ft,
329 units_ind_ch
330 };
331
332 enum name_f
333 {
334 a = 0,
335 b,
336 e,
337 es,
338 f,
339 h,
340 h_0,
341 k = 7,
342 k_0,
343 m, // also used for M
344 n,
345 //phdg_0, // currently not used
346 //plat_0, // currently not used
347 //plon_0, // currently not used
348 q = 14,
349 r, // originally R
350 rf,
351 to_meter,
352 vto_meter,
353 w, // originally W
354 x_0,
355 y_0
356 };
357
358 enum name_r
359 {
360 alpha = 22,
361 azi,
362 gamma,
363 lat_0,
364 lat_1,
365 lat_2,
366 lat_3,
367 lat_b,
368 lat_ts, // 30
369 lon_0,
370 lon_1,
371 lon_2,
372 lon_3,
373 lon_wrap,
374 lonc,
375 o_alpha,
376 o_lat_1,
377 o_lat_2,
378 o_lat_c, // 40
379 o_lat_p,
380 o_lon_1,
381 o_lon_2,
382 o_lon_c,
383 o_lon_p,
384 r_lat_a, // originally R_lat_a
385 r_lat_g, // originally R_lat_g
386 theta,
387 tilt
388 };
389
390 enum name_i
391 {
392 aperture = 50,
393 lsat,
394 north_square,
395 path,
396 resolution,
397 south_square,
398 zone
399 };
400
401 enum name_be
402 {
403 czech = 57,
404 geoc,
405 guam,
406 no_cut, // 60
407 no_defs,
408 no_rot,
409 ns,
410 over,
411 r_au, // originally R_A
412 r_a, // originally R_a
413 r_g, // originally R_g
414 r_h, // originally R_h
415 r_v, // originally R_V
416 rescale, // 70
417 south,
418 variant_c, // BG specific
419 no_off,
420 hyperbolic
421 };
422
423 /*enum name_catalog
424 {
425 catalog = 72 // currently not used
426 };
427
428 enum name_date
429 {
430 date = 73 // currently not used
431 };*/
432
433 enum name_datum
434 {
435 datum = 74
436 };
437
438 enum name_ellps
439 {
440 ellps = 75 // id, sphere or spheroid
441 };
442
443 /*enum name_geoidgrids
444 {
445 geoidgrids = 76 // currently not used
446 };*/
447
448 enum name_mode
449 {
450 mode = 77
451 };
452
453 enum name_nadgrids
454 {
455 nadgrids = 78 // arbitrary-length list of strings
456 };
457
458 enum name_orient
459 {
460 orient = 79
461 };
462
463 enum name_pm
464 {
465 pm = 80 // id or angle
466 };
467
468 enum name_proj
469 {
470 o_proj = 81,
471 proj
472 };
473
474 enum name_sweep
475 {
476 sweep = 83
477 };
478
479 enum name_towgs84
480 {
481 towgs84 = 84 // 3 or 7 element list of numbers
482 };
483
484 enum name_units
485 {
486 units = 85,
487 vunits
488 };
489
490 enum name_axis
491 {
492 axis = 86 // 3 element list of numbers
493 };
494
495 template <typename T>
496 struct parameter
497 {
498 parameter()
499 : m_id(-1), m_value(false)
500 {}
501
502 parameter(name_f id, T const& v)
503 : m_id(id), m_value(v)
504 {}
505
506 // TODO various angle units
507 parameter(name_r id, T const& v)
508 : m_id(id), m_value(v)
509 {}
510
511 parameter(name_i id, int v)
512 : m_id(id), m_value(v)
513 {}
514
515 parameter(name_be id)
516 : m_id(id), m_value(true)
517 {}
518
519 parameter(name_be id, bool v)
520 : m_id(id), m_value(v)
521 {}
522
523 parameter(name_datum id, value_datum v)
524 : m_id(id), m_value(int(v))
525 {}
526
527 parameter(value_datum v)
528 : m_id(datum), m_value(int(v))
529 {}
530
531 // TODO: store model at this point?
532 parameter(name_ellps id, value_ellps v)
533 : m_id(id), m_value(int(v))
534 {}
535 // TODO: store model at this point?
536 parameter(value_ellps v)
537 : m_id(ellps), m_value(int(v))
538 {}
539
540 template
541 <
542 typename Sphere,
543 std::enable_if_t
544 <
545 std::is_same<typename geometry::tag<Sphere>::type, srs_sphere_tag>::value,
546 int
547 > = 0
548 >
549 parameter(name_ellps id, Sphere const& v)
550 : m_id(id)
551 , m_value(T(get_radius<0>(v)))
552 {}
553
554 template
555 <
556 typename Spheroid,
557 std::enable_if_t
558 <
559 std::is_same<typename geometry::tag<Spheroid>::type, srs_spheroid_tag>::value,
560 int
561 > = 0
562 >
563 parameter(name_ellps id, Spheroid const& v)
564 : m_id(id)
565 , m_value(srs::spheroid<T>(get_radius<0>(v), get_radius<2>(v)))
566 {}
567
568 parameter(name_mode id, value_mode v)
569 : m_id(id), m_value(int(v))
570 {}
571
572 parameter(value_mode v)
573 : m_id(mode), m_value(int(v))
574 {}
575
576 template
577 <
578 typename Range,
579 std::enable_if_t
580 <
581 detail::is_convertible_range<Range const, std::string>::value,
582 int
583 > = 0
584 >
585 parameter(name_nadgrids id, Range const& v)
586 : m_id(id)
587 , m_value(srs::detail::nadgrids(boost::begin(v), boost::end(v)))
588 {}
589
590 #ifndef BOOST_NO_CXX11_HDR_INITIALIZER_LIST
591 parameter(name_nadgrids id, std::initializer_list<std::string> v)
592 : m_id(id)
593 , m_value(srs::detail::nadgrids(v))
594 {}
595 #endif
596
597 parameter(name_orient id, value_orient v)
598 : m_id(id), m_value(int(v))
599 {}
600
601 parameter(value_orient v)
602 : m_id(orient), m_value(int(v))
603 {}
604
605 // TODO: store to_meters at this point?
606 parameter(name_pm id, value_pm v)
607 : m_id(id), m_value(int(v))
608 {}
609 // TODO: store to_meters at this point?
610 parameter(value_pm v)
611 : m_id(pm), m_value(int(v))
612 {}
613
614 // TODO angle units
615 parameter(name_pm id, T const& v)
616 : m_id(id), m_value(v)
617 {}
618
619 parameter(name_proj id, value_proj v)
620 : m_id(id), m_value(int(v))
621 {}
622
623 parameter(value_proj v)
624 : m_id(proj), m_value(int(v))
625 {}
626
627 parameter(name_sweep id, value_sweep v)
628 : m_id(id), m_value(int(v))
629 {}
630
631 parameter(value_sweep v)
632 : m_id(sweep), m_value(int(v))
633 {}
634
635 template
636 <
637 typename Range,
638 std::enable_if_t
639 <
640 detail::is_convertible_range<Range const, T>::value,
641 int
642 > = 0
643 >
644 parameter(name_towgs84 id, Range const& v)
645 : m_id(id)
646 , m_value(srs::detail::towgs84<T>(boost::begin(v), boost::end(v)))
647 {
648 std::size_t n = boost::size(v);
649 if (n != 3 && n != 7)
650 {
651 BOOST_THROW_EXCEPTION( projection_exception("Invalid number of towgs84 elements. Should be 3 or 7.") );
652 }
653 }
654
655 #ifndef BOOST_NO_CXX11_HDR_INITIALIZER_LIST
656 parameter(name_towgs84 id, std::initializer_list<T> v)
657 : m_id(id)
658 , m_value(srs::detail::towgs84<T>(v))
659 {
660 std::size_t n = v.size();
661 if (n != 3 && n != 7)
662 {
663 BOOST_THROW_EXCEPTION( projection_exception("Invalid number of towgs84 elements. Should be 3 or 7.") );
664 }
665 }
666 #endif
667
668 parameter(name_axis id, std::initializer_list<int> v)
669 : m_id(id)
670 , m_value(srs::detail::axis(v))
671 {
672 std::size_t n = v.size();
673 if (n != 3)
674 {
675 BOOST_THROW_EXCEPTION( projection_exception("Invalid number of axis elements. Should be 3.") );
676 }
677 }
678
679 parameter(name_units id, value_units v)
680 : m_id(id), m_value(int(v))
681 {}
682
683 parameter(value_units v)
684 : m_id(units), m_value(int(v))
685 {}
686
687 private:
688 typedef boost::variant
689 <
690 bool,
691 int,
692 T,
693 srs::spheroid<T>,
694 srs::detail::nadgrids,
695 srs::detail::towgs84<T>
696 > variant_type;
697
698 public:
699 bool is_id_equal(name_f const& id) const { return m_id == int(id); }
700 bool is_id_equal(name_r const& id) const { return m_id == int(id); }
701 bool is_id_equal(name_i const& id) const { return m_id == int(id); }
702 bool is_id_equal(name_be const& id) const { return m_id == int(id); }
703 bool is_id_equal(name_datum const& id) const { return m_id == int(id); }
704 bool is_id_equal(name_ellps const& id) const { return m_id == int(id); }
705 bool is_id_equal(name_mode const& id) const { return m_id == int(id); }
706 bool is_id_equal(name_nadgrids const& id) const { return m_id == int(id); }
707 bool is_id_equal(name_orient const& id) const { return m_id == int(id); }
708 bool is_id_equal(name_pm const& id) const { return m_id == int(id); }
709 bool is_id_equal(name_proj const& id) const { return m_id == int(id); }
710 bool is_id_equal(name_sweep const& id) const { return m_id == int(id); }
711 bool is_id_equal(name_towgs84 const& id) const { return m_id == int(id); }
712 bool is_id_equal(name_units const& id) const { return m_id == int(id); }
713 bool is_id_equal(name_axis const& id) const { return m_id == int(id); }
714
715 template <typename V>
716 V const& get_value() const
717 {
718 return boost::get<V>(m_value);
719 }
720
721 template <typename V>
722 bool is_value_set() const
723 {
724 return m_value.which() == srs::detail::find_type_index<variant_type, V>::value;
725 }
726
727 private:
728 int m_id;
729 variant_type m_value;
730 };
731
732 template <typename T = double>
733 class parameters
734 {
735 typedef std::vector<parameter<T> > container_type;
736
737 public:
738 typedef typename container_type::value_type value_type;
739 typedef typename container_type::const_iterator const_iterator;
740 typedef typename container_type::const_reference const_reference;
741 typedef typename container_type::size_type size_type;
742
743 BOOST_DEFAULTED_FUNCTION(parameters(), {})
744
745 #if defined(BOOST_NO_CXX11_RVALUE_REFERENCES) || defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES)
746 template <typename Id>
747 explicit parameters(Id id)
748 {
749 add(id);
750 }
751
752 template <typename Id>
753 parameters & add(Id id)
754 {
755 m_params.push_back(parameter<T>(id));
756 return *this;
757 }
758
759 template <typename Id>
760 parameters & operator()(Id id)
761 {
762 return add(id);
763 }
764
765 template <typename Id, typename V>
766 parameters(Id id, V const& value)
767 {
768 add(id, value);
769 }
770
771 template <typename Id, typename V>
772 parameters & add(Id id, V const& value)
773 {
774 m_params.push_back(parameter<T>(id, value));
775 return *this;
776 }
777
778 template <typename Id, typename V>
779 parameters & operator()(Id id, V const& value)
780 {
781 return add(id, value);
782 }
783
784 #ifndef BOOST_NO_CXX11_HDR_INITIALIZER_LIST
785 template <typename Id, typename V>
786 parameters(Id id, std::initializer_list<V> value)
787 {
788 add(id, value);
789 }
790
791 template <typename Id, typename V>
792 parameters & add(Id id, std::initializer_list<V> value)
793 {
794 m_params.push_back(parameter<T>(id, value));
795 return *this;
796 }
797
798 template <typename Id, typename V>
799 parameters & operator()(Id id, std::initializer_list<V> value)
800 {
801 return add(id, value);
802 }
803 #endif // BOOST_NO_CXX11_HDR_INITIALIZER_LIST
804 #else // BOOST_NO_CXX11_RVALUE_REFERENCES || BOOST_NO_CXX11_RVALUE_REFERENCES
805 template <typename Id>
806 explicit parameters(Id id)
807 {
808 add(id);
809 }
810
811 template <typename Id>
812 parameters & add(Id id)
813 {
814 m_params.emplace_back(id);
815 return *this;
816 }
817
818 template <typename Id>
819 parameters & operator()(Id id)
820 {
821 return add(id);
822 }
823
824 template <typename Id, typename V>
825 parameters(Id id, V && value)
826 {
827 add(id, std::forward<V>(value));
828 }
829
830 template <typename Id, typename V>
831 parameters & add(Id id, V && value)
832 {
833 m_params.emplace_back(id, std::forward<V>(value));
834 return *this;
835 }
836
837 template <typename Id, typename V>
838 parameters & operator()(Id id, V && value)
839 {
840 return add(id, std::forward<V>(value));
841 }
842
843 #ifndef BOOST_NO_CXX11_HDR_INITIALIZER_LIST
844 template <typename Id, typename V>
845 parameters(Id id, std::initializer_list<V> value)
846 {
847 add(id, value);
848 }
849
850 template <typename Id, typename V>
851 parameters & add(Id id, std::initializer_list<V> value)
852 {
853 m_params.emplace_back(id, value);
854 return *this;
855 }
856
857 template <typename Id, typename V>
858 parameters & operator()(Id id, std::initializer_list<V> value)
859 {
860 return add(id, value);
861 }
862 #endif // BOOST_NO_CXX11_HDR_INITIALIZER_LIST
863 #endif // BOOST_NO_CXX11_RVALUE_REFERENCES || BOOST_NO_CXX11_RVALUE_REFERENCES
864
865 const_iterator begin() const { return m_params.begin(); }
866 const_iterator end() const { return m_params.end(); }
867 const_reference operator[](size_type i) const { return m_params[i]; }
868 size_type size() { return m_params.size(); }
869 bool empty() { return m_params.empty(); }
870
871 private:
872 container_type m_params;
873 };
874
875
876 } // namespace dpar
877
878
879 }}} // namespace boost::geometry::srs
880
881
882 #endif // BOOST_GEOMETRY_SRS_PROJECTIONS_DPAR_HPP