File indexing completed on 2025-01-18 09:36:40
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012 #ifndef BOOST_GEOMETRY_SRS_PROJECTIONS_PROJ4_HPP
0013 #define BOOST_GEOMETRY_SRS_PROJECTIONS_PROJ4_HPP
0014
0015
0016 #include <string>
0017 #include <vector>
0018
0019 #include <boost/algorithm/string/trim.hpp>
0020
0021
0022 namespace boost { namespace geometry
0023 {
0024
0025 namespace srs
0026 {
0027
0028
0029 struct dynamic {};
0030
0031
0032 struct proj4
0033 {
0034 explicit proj4(const char* s)
0035 : m_str(s)
0036 {}
0037
0038 explicit proj4(std::string const& s)
0039 : m_str(s)
0040 {}
0041
0042 std::string const& str() const
0043 {
0044 return m_str;
0045 }
0046
0047 private:
0048 std::string m_str;
0049 };
0050
0051
0052 namespace detail
0053 {
0054
0055 struct proj4_parameter
0056 {
0057 proj4_parameter() {}
0058 proj4_parameter(std::string const& n, std::string const& v) : name(n), value(v) {}
0059 std::string name;
0060 std::string value;
0061 };
0062
0063 struct proj4_parameters
0064 : std::vector<proj4_parameter>
0065 {
0066
0067 proj4_parameters(std::string const& proj4_str)
0068 {
0069 const char* sep = " +";
0070
0071
0072
0073
0074
0075 std::string def = boost::trim_copy(proj4_str);
0076 boost::trim_left_if(def, boost::is_any_of(sep));
0077
0078 std::string::size_type loc = def.find(sep);
0079 while (loc != std::string::npos)
0080 {
0081 std::string par = def.substr(0, loc);
0082 boost::trim(par);
0083 if (! par.empty())
0084 {
0085 this->add(par);
0086 }
0087
0088 def.erase(0, loc);
0089 boost::trim_left_if(def, boost::is_any_of(sep));
0090 loc = def.find(sep);
0091 }
0092
0093 if (! def.empty())
0094 {
0095 this->add(def);
0096 }
0097 }
0098
0099 void add(std::string const& str)
0100 {
0101 std::string name = str;
0102 std::string value;
0103 boost::trim_left_if(name, boost::is_any_of("+"));
0104 std::string::size_type loc = name.find("=");
0105 if (loc != std::string::npos)
0106 {
0107 value = name.substr(loc + 1);
0108 name.erase(loc);
0109 }
0110
0111 this->add(name, value);
0112 }
0113
0114 void add(std::string const& name, std::string const& value)
0115 {
0116 this->push_back(proj4_parameter(name, value));
0117 }
0118 };
0119
0120 }
0121
0122
0123 }
0124
0125
0126 }}
0127
0128
0129 #endif