CYCLUS
Loading...
Searching...
No Matches
position.h
Go to the documentation of this file.
1#ifndef CYCLUS_SRC_TOOLKIT_POSITION_H_
2#define CYCLUS_SRC_TOOLKIT_POSITION_H_
3#define CYCLUS_DECIMAL_SECOND_MULTIPLIER 3600
4
5#include <string>
6
7#include "cyclus.h"
8
9namespace cyclus {
10namespace toolkit {
11/// @class Position
12/// The Position class is a basic class that stores the geographic location of
13/// each
14/// agent in latitude and longitude and follows the ISO
15/// 6709 standard. Allows string expression of Position objects as specified in
16/// ANNEX H of ISO 6709 found here: 'https://www.iso.org/standard/39242.html'
17/// or a quick simplified version found here
18/// 'https://en.wikipedia.org/wiki/ISO_6709'
19///
20/// Brief Description of ISO 6709:
21/// 1. Latitude comes before Longitude
22/// 2. North latitude is positive
23/// 3. East longitude is positive
24/// 4. Fraction of degrees (decimal values) is prefered in digital data
25/// exchange.
26///
27/// The class is adapted from 'https://github.com/jaime-olivares/coordinate'
28/// under the MIT License.
29///
30/// Copyright (c) 2015 Jaime Olivares
31///
32/// Permission is hereby granted, free of charge, to any person obtaining a
33/// copy of this software and associated documentation files (the "Software")
34/// , to deal in the Software without restriction, including without
35/// limitation the rights to use, copy, modify, merge, publish, distribute,
36/// sublicense, and/or sell copies of the Software, and to permit persons to
37/// whom the Software is furnished to do so, subject to the following
38/// conditions:
39///
40/// The above copyright notice and this permission notice shall be included
41/// in all copies or substantial portions of the Software.
42///
43/// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
44/// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
45/// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
46/// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
47/// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
48/// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
49/// USE OR OTHER DEALINGS IN THE SOFTWARE.
50///
51/// Longitude and Latitude is stored as seconds of degrees. This was also
52/// adapted from 'https://github.com/jaime-olivares/coordinate'. This, according
53/// to the jaime-olivares, allows the coordinate elements such as degrees,
54/// minutes, and seconds to "remain on the integral portion of values, with the
55/// exception of decimal of seconds, avoiding loss of precision." This is
56/// calculated by multiplying decimal degrees by 3600.
57/// example: 05.2169 -> 18780.84
58
59class Position {
60 public:
66
67 /// The default constructor for Position. This will creat an object with
68 /// lat=0, and long=0.
69 Position();
70
71 /// Position constructor with latitude and longditude as degrees as a double
72 /// point precision floating point.
73 /// @param deciaml_lat latitude expressed in degrees as a double.
74 /// @param decimal_lon longditude expressed in degrees as a double.
75 Position(double decimal_lat, double decimal_lon);
76
77 /// The default destructor for Position
78 ~Position();
79
80 /// Returns the current latitude.
81 /// @return decimal representation of latitude.
82 double latitude() const;
83
84 /// Returns the current longitude.
85 /// @return decimal representation of longitude.
86 double longitude() const;
87
88 /// Sets a new latitude
89 /// @param lat latitude expressed in decimal degrees.
90 void latitude(double lat);
91
92 /// Sets a new longitude
93 /// @param lon longitude expressed in decimal degrees.
94 void longitude(double lon);
95
96 /// Sets a new latitude and longitude
97 /// @param lat latitude, and lon longitude expressed in decimal degrees.
98 void set_position(double lat, double lon);
99
100 /// Returns the distance (in km) between this Position object and the target
101 /// Position object.
102 /// @param target the Position object some distnace away from the current one
103 /// @return distance between this and target in kilometers
104 double Distance(Position target) const;
105
106 /// Converts Position location into a string expression that follows ISO 6709
107 /// Annex
108 /// H. Function can be passed without any parameters for degrees format.
109 /// @param return_format_
110 /// @parblock_
111 /// The format of output. Options are 'Position::StringFormat::DEGREES',
112 /// 'Position::StringFormat::DEGREES_
113 /// MINUTES_',
114 /// 'Position::StringFormat::DEGREES_
115 /// MINUTES_
116 /// _ SECONDS':
117 ///
118 /// Position::StringFormat::DEGREES :return in degrees
119 /// format
120 /// Position::StringFormat::DEGREES_MINUTES :return in degrees
121 /// and minutes format
122 /// Position::StringFormat::DEGREES_MINUTES_SECONDS:return in degrees
123 /// minutes seconds
124 /// format
125 /// @endparblock
126 /// @return String representation of the Position object that complies with
127 /// ISO6709 Annex H
128 std::string ToString(
130
131 private:
132 /// Latitude is stored as seconds of degree. Explanation and example is
133 /// available above in class documentation
134 double latitude_;
135
136 /// Longitude is stored as seconds of degree.
137 double longitude_;
138
139 /// Checks if the decimal degree of longitude is within acceptable range.
140 /// The acceptable range is between -180 and 180 (inclusive).
141 /// @param lat latitude expressed in decimal degrees.
142 void LonCheck(double lon);
143
144 /// Checks if the decimal degree of latitude is within acceptable range.
145 /// The acceptable range is between -90 and 90 (inclusive).
146 /// @param lat latitude expressed in decimal degrees.
147 void LatCheck(double lat);
148
149 /// Sets the precision for double values.
150 /// @param value that requires change of precision
151 /// @param precision the number decimal places wanted
152 /// @return value with the number of decimal places (precision) as defined
153 double SetPrecision(double value, double precision) const;
154
155 /// Formats longitude for toString function
156 /// @param mode
157 /// @parblock
158 /// The format of output. Options are '1', '2' or '3' :
159 ///
160 /// 1: return in degrees format
161 /// 2: return in degrees and minutes format
162 /// 3: return in degrees minutes seconds format
163 /// @endparblock
164 /// @param lon longitude of the object
165 /// @return partially formatted string
166 std::string ToStringHelperLon(int mode, double lon) const;
167
168 /// Formats latitude for toString function
169 /// @param mode
170 /// @parblock
171 /// The format of output. Options are '1', '2' or '3' :
172 ///
173 /// 1: return in degrees format
174 /// 2: return in degrees and minutes format
175 /// 3: return in degrees minutes seconds format
176 /// @endparblock
177 /// @param lat latitude of the object
178 /// @return partially formatted string
179 std::string ToStringHelperLat(int mode, double lat) const;
180
181 /// Adds "+" or "-" sign for the ToStringHelperLon/Lat function
182 /// @param value longitude or latitude of the object
183 /// @returns "+" or "-" for the ToString function
184 std::string ToStringHelper(double value) const;
185
186 /// Formats longitude and latitude in degrees and minutes for the
187 /// ToStringHelperLon/Lat function
188 /// @param value longitude or latitude of the object
189 /// @return formatted string representation of longiiiitude or latitude
190 std::string ToStringHelperDM(double value) const;
191
192 /// Formats longitude and latitude in degrees minutes and seconds for the
193 /// ToStringHelperLon/Lat function
194 /// @param value longitude or latitude of the object
195 /// @return formatted string representation of longiiiitude or latitude
196 std::string ToStringHelperDMS(double value) const;
197};
198
199} // namespace toolkit
200} // namespace cyclus
201
202#endif // CYCLUS_SRC_TOOLKIT_POSITION_H_
The Position class is a basic class that stores the geographic location of each agent in latitude and...
Definition position.h:59
double Distance(Position target) const
Returns the distance (in km) between this Position object and the target Position object.
Definition position.cc:66
double longitude() const
Returns the current longitude.
Definition position.cc:25
~Position()
The default destructor for Position.
Definition position.cc:19
Position()
The default constructor for Position.
Definition position.cc:10
void set_position(double lat, double lon)
Sets a new latitude and longitude.
Definition position.cc:39
std::string ToString(Position::StringFormat format=StringFormat::DEGREES) const
Converts Position location into a string expression that follows ISO 6709 Annex H.
Definition position.cc:84
double latitude() const
Returns the current latitude.
Definition position.cc:21
taken directly from OsiSolverInterface.cpp on 2/17/14 from https://projects.coin-or....
Definition agent.cc:14
T OptionalQuery(InfileTree *tree, std::string query, T default_val)
a query method for optional parameters