pj_strerrno.hpp 9.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219
  1. // Boost.Geometry
  2. // This file is manually converted from PROJ4
  3. // This file was modified by Oracle on 2017, 2018.
  4. // Modifications copyright (c) 2017-2018, Oracle and/or its affiliates.
  5. // Contributed and/or modified by Adam Wulkiewicz, on behalf of Oracle
  6. // Use, modification and distribution is subject to the Boost Software License,
  7. // Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
  8. // http://www.boost.org/LICENSE_1_0.txt)
  9. // This file is converted from PROJ4, http://trac.osgeo.org/proj
  10. // PROJ4 is originally written by Gerald Evenden (then of the USGS)
  11. // PROJ4 is maintained by Frank Warmerdam
  12. // This file was converted to Geometry Library by Adam Wulkiewicz
  13. // Original copyright notice:
  14. // None
  15. /* list of projection system pj_errno values */
  16. #ifndef BOOST_GEOMETRY_PROJECTIONS_IMPL_PJ_STRERRNO_HPP
  17. #define BOOST_GEOMETRY_PROJECTIONS_IMPL_PJ_STRERRNO_HPP
  18. #include <cerrno>
  19. #include <cstring>
  20. #include <sstream>
  21. #include <string>
  22. namespace boost { namespace geometry { namespace projections
  23. {
  24. namespace detail
  25. {
  26. // Originally defined in projects.hpp
  27. /* library errors */
  28. enum error_type
  29. {
  30. error_no_args = -1,
  31. error_no_option_in_init_file = -2,
  32. error_no_colon_in_init_string = -3,
  33. error_proj_not_named = -4,
  34. error_unknown_projection_id = -5,
  35. error_eccentricity_is_one = -6,
  36. error_unknow_unit_id = -7,
  37. error_invalid_boolean_param = -8,
  38. error_unknown_ellp_param = -9,
  39. error_rev_flattening_is_zero = -10,
  40. error_ref_rad_larger_than_90 = -11,
  41. error_es_less_than_zero = -12,
  42. error_major_axis_not_given = -13,
  43. error_lat_or_lon_exceed_limit = -14,
  44. error_invalid_x_or_y = -15,
  45. error_wrong_format_dms_value = -16,
  46. error_non_conv_inv_meri_dist = -17,
  47. error_non_con_inv_phi2 = -18,
  48. error_acos_asin_arg_too_large = -19,
  49. error_tolerance_condition = -20,
  50. error_conic_lat_equal = -21,
  51. error_lat_larger_than_90 = -22,
  52. error_lat1_is_zero = -23,
  53. error_lat_ts_larger_than_90 = -24,
  54. error_control_point_no_dist = -25,
  55. error_no_rotation_proj = -26,
  56. error_w_or_m_zero_or_less = -27,
  57. error_lsat_not_in_range = -28,
  58. error_path_not_in_range = -29,
  59. error_h_less_than_zero = -30,
  60. error_k_less_than_zero = -31,
  61. error_lat_1_or_2_zero_or_90 = -32,
  62. error_lat_0_or_alpha_eq_90 = -33,
  63. error_ellipsoid_use_required = -34,
  64. error_invalid_utm_zone = -35,
  65. error_tcheby_val_out_of_range = -36,
  66. error_failed_to_find_proj = -37,
  67. error_failed_to_load_grid = -38,
  68. error_invalid_m_or_n = -39,
  69. error_n_out_of_range = -40,
  70. error_lat_1_2_unspecified = -41,
  71. error_abs_lat1_eq_abs_lat2 = -42,
  72. error_lat_0_half_pi_from_mean = -43,
  73. error_unparseable_cs_def = -44,
  74. error_geocentric = -45,
  75. error_unknown_prime_meridian = -46,
  76. error_axis = -47,
  77. error_grid_area = -48,
  78. error_invalid_sweep_axis = -49,
  79. error_malformed_pipeline = -50,
  80. error_unit_factor_less_than_0 = -51,
  81. error_invalid_scale = -52,
  82. error_non_convergent = -53,
  83. error_missing_args = -54,
  84. error_lat_0_is_zero = -55,
  85. error_ellipsoidal_unsupported = -56,
  86. error_too_many_inits = -57,
  87. error_invalid_arg = -58
  88. };
  89. static const char *
  90. pj_err_list[] = {
  91. "no arguments in initialization list", /* -1 */
  92. "no options found in 'init' file", /* -2 */
  93. "no colon in init= string", /* -3 */
  94. "projection not named", /* -4 */
  95. "unknown projection id", /* -5 */
  96. "effective eccentricity = 1.", /* -6 */
  97. "unknown unit conversion id", /* -7 */
  98. "invalid boolean param argument", /* -8 */
  99. "unknown elliptical parameter name", /* -9 */
  100. "reciprocal flattening (1/f) = 0", /* -10 */
  101. "|radius reference latitude| > 90", /* -11 */
  102. "squared eccentricity < 0", /* -12 */
  103. "major axis or radius = 0 or not given", /* -13 */
  104. "latitude or longitude exceeded limits", /* -14 */
  105. "invalid x or y", /* -15 */
  106. "improperly formed DMS value", /* -16 */
  107. "non-convergent inverse meridional dist", /* -17 */
  108. "non-convergent inverse phi2", /* -18 */
  109. "acos/asin: |arg| >1.+1e-14", /* -19 */
  110. "tolerance condition error", /* -20 */
  111. "conic lat_1 = -lat_2", /* -21 */
  112. "lat_1 >= 90", /* -22 */
  113. "lat_1 = 0", /* -23 */
  114. "lat_ts >= 90", /* -24 */
  115. "no distance between control points", /* -25 */
  116. "projection not selected to be rotated", /* -26 */
  117. "W <= 0 or M <= 0", /* -27 */
  118. "lsat not in 1-5 range", /* -28 */
  119. "path not in range", /* -29 */
  120. "h <= 0", /* -30 */
  121. "k <= 0", /* -31 */
  122. "lat_0 = 0 or 90 or alpha = 90", /* -32 */
  123. "lat_1=lat_2 or lat_1=0 or lat_2=90", /* -33 */
  124. "elliptical usage required", /* -34 */
  125. "invalid UTM zone number", /* -35 */
  126. "arg(s) out of range for Tcheby eval", /* -36 */
  127. "failed to find projection to be rotated", /* -37 */
  128. "failed to load datum shift file", /* -38 */
  129. "both n & m must be spec'd and > 0", /* -39 */
  130. "n <= 0, n > 1 or not specified", /* -40 */
  131. "lat_1 or lat_2 not specified", /* -41 */
  132. "|lat_1| == |lat_2|", /* -42 */
  133. "lat_0 is pi/2 from mean lat", /* -43 */
  134. "unparseable coordinate system definition", /* -44 */
  135. "geocentric transformation missing z or ellps", /* -45 */
  136. "unknown prime meridian conversion id", /* -46 */
  137. "illegal axis orientation combination", /* -47 */
  138. "point not within available datum shift grids", /* -48 */
  139. "invalid sweep axis, choose x or y", /* -49 */
  140. "malformed pipeline", /* -50 */
  141. "unit conversion factor must be > 0", /* -51 */
  142. "invalid scale", /* -52 */
  143. "non-convergent computation", /* -53 */
  144. "missing required arguments", /* -54 */
  145. "lat_0 = 0", /* -55 */
  146. "ellipsoidal usage unsupported", /* -56 */
  147. "only one +init allowed for non-pipeline operations", /* -57 */
  148. "argument not numerical or out of range", /* -58 */
  149. /* When adding error messages, remember to update ID defines in
  150. projects.h, and transient_error array in pj_transform */
  151. };
  152. inline std::string pj_generic_strerrno(std::string const& msg, int err)
  153. {
  154. std::stringstream ss;
  155. ss << msg << " (" << err << ")";
  156. return ss.str();
  157. }
  158. inline std::string pj_strerrno(int err) {
  159. if (0==err)
  160. {
  161. return "";
  162. }
  163. else if (err > 0)
  164. {
  165. // std::strerror function may be not thread-safe
  166. //return std::strerror(err);
  167. switch(err)
  168. {
  169. #ifdef EINVAL
  170. case EINVAL:
  171. return "Invalid argument";
  172. #endif
  173. #ifdef EDOM
  174. case EDOM:
  175. return "Math argument out of domain of func";
  176. #endif
  177. #ifdef ERANGE
  178. case ERANGE:
  179. return "Math result not representable";
  180. #endif
  181. default:
  182. return pj_generic_strerrno("system error", err);
  183. }
  184. }
  185. else /*if (err < 0)*/
  186. {
  187. size_t adjusted_err = - err - 1;
  188. if (adjusted_err < (sizeof(pj_err_list) / sizeof(char *)))
  189. {
  190. return(pj_err_list[adjusted_err]);
  191. }
  192. else
  193. {
  194. return pj_generic_strerrno("invalid projection system error", err);
  195. }
  196. }
  197. }
  198. } // namespace detail
  199. }}} // namespace boost::geometry::projections
  200. #endif // BOOST_GEOMETRY_PROJECTIONS_IMPL_PJ_STRERRNO_HPP