1 // Boost.Geometry 2 3 // Copyright (c) 2008-2012 Barend Gehrels, Amsterdam, the Netherlands. 4 5 // Copyright (c) 2017-2018, Oracle and/or its affiliates. 6 // Contributed and/or modified by Adam Wulkiewicz, on behalf of Oracle 7 8 // Use, modification and distribution is subject to the Boost Software License, 9 // Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at 10 // http://www.boost.org/LICENSE_1_0.txt) 11 12 #ifndef BOOST_GEOMETRY_SRS_PROJECTIONS_PROJ4_HPP 13 #define BOOST_GEOMETRY_SRS_PROJECTIONS_PROJ4_HPP 14 15 16 #include <string> 17 #include <vector> 18 19 #include <boost/algorithm/string/trim.hpp> 20 21 22 namespace boost { namespace geometry 23 { 24 25 namespace srs 26 { 27 28 29 struct dynamic {}; 30 31 32 struct proj4 33 { proj4boost::geometry::srs::proj434 explicit proj4(const char* s) 35 : m_str(s) 36 {} 37 proj4boost::geometry::srs::proj438 explicit proj4(std::string const& s) 39 : m_str(s) 40 {} 41 strboost::geometry::srs::proj442 std::string const& str() const 43 { 44 return m_str; 45 } 46 47 private: 48 std::string m_str; 49 }; 50 51 52 namespace detail 53 { 54 55 struct proj4_parameter 56 { proj4_parameterboost::geometry::srs::detail::proj4_parameter57 proj4_parameter() {} proj4_parameterboost::geometry::srs::detail::proj4_parameter58 proj4_parameter(std::string const& n, std::string const& v) : name(n), value(v) {} 59 std::string name; 60 std::string value; 61 }; 62 63 struct proj4_parameters 64 : std::vector<proj4_parameter> 65 { 66 // Initially implemented as part of pj_init_plus() and pj_init() proj4_parametersboost::geometry::srs::detail::proj4_parameters67 proj4_parameters(std::string const& proj4_str) 68 { 69 const char* sep = " +"; 70 71 /* split into arguments based on '+' and trim white space */ 72 73 // boost::split splits on one character, here it should be on " +", so implementation below 74 // todo: put in different routine or sort out 75 std::string def = boost::trim_copy(proj4_str); 76 boost::trim_left_if(def, boost::is_any_of(sep)); 77 78 std::string::size_type loc = def.find(sep); 79 while (loc != std::string::npos) 80 { 81 std::string par = def.substr(0, loc); 82 boost::trim(par); 83 if (! par.empty()) 84 { 85 this->add(par); 86 } 87 88 def.erase(0, loc); 89 boost::trim_left_if(def, boost::is_any_of(sep)); 90 loc = def.find(sep); 91 } 92 93 if (! def.empty()) 94 { 95 this->add(def); 96 } 97 } 98 addboost::geometry::srs::detail::proj4_parameters99 void add(std::string const& str) 100 { 101 std::string name = str; 102 std::string value; 103 boost::trim_left_if(name, boost::is_any_of("+")); 104 std::string::size_type loc = name.find("="); 105 if (loc != std::string::npos) 106 { 107 value = name.substr(loc + 1); 108 name.erase(loc); 109 } 110 111 this->add(name, value); 112 } 113 addboost::geometry::srs::detail::proj4_parameters114 void add(std::string const& name, std::string const& value) 115 { 116 this->push_back(proj4_parameter(name, value)); 117 } 118 }; 119 120 } 121 122 123 } // namespace srs 124 125 126 }} // namespace boost::geometry 127 128 129 #endif // BOOST_GEOMETRY_SRS_PROJECTIONS_PROJ4_HPP 130