OGS
Station.cpp
Go to the documentation of this file.
1 
15 #include "Station.h"
16 
17 #include <cstdlib>
18 #include <utility>
19 
20 #include "BaseLib/Logging.h"
21 #include "BaseLib/StringTools.h"
22 
23 namespace GeoLib
24 {
25 Station::Station(double x, double y, double z, std::string name)
26  : Point(x, y, z), _name(std::move(name))
27 {
28 }
29 
30 Station::Station(Point* coords, std::string name)
31  : Point(*coords), _name(std::move(name))
32 {
33 }
34 
36  : Point(src),
37  _name(src._name),
38  _station_value(src._station_value),
39  _sensor_data(src._sensor_data.get() != nullptr
40  ? new SensorData(*(src._sensor_data.get()))
41  : nullptr)
42 {
43 }
44 
45 Station* Station::createStation(const std::string& line)
46 {
47  std::list<std::string> fields = BaseLib::splitString(line, '\t');
48 
49  if (fields.size() < 3)
50  {
51  INFO("Station::createStation() - Unexpected file format.");
52  return nullptr;
53  }
54 
55  auto it = fields.begin();
56  std::string name = *it;
57  auto const x = std::strtod(
58  (BaseLib::replaceString(",", ".", *(++it))).c_str(), nullptr);
59  auto const y = std::strtod(
60  (BaseLib::replaceString(",", ".", *(++it))).c_str(), nullptr);
61  auto z = 0.0;
62  if (++it != fields.end())
63  {
64  z = std::strtod((BaseLib::replaceString(",", ".", *it)).c_str(),
65  nullptr);
66  }
67  return new Station(x, y, z, name);
68 }
69 
70 Station* Station::createStation(const std::string& name, double x, double y,
71  double z)
72 {
73  return new Station(x, y, z, name);
74 }
75 
76 bool isStation(GeoLib::Point const* pnt)
77 {
78  auto const* bh(dynamic_cast<GeoLib::Station const*>(pnt));
79  return bh != nullptr;
80 }
81 
82 } // namespace GeoLib
void INFO(char const *fmt, Args const &... args)
Definition: Logging.h:32
Definition of the Station class.
Definition of string helper functions.
A Station (observation site) is basically a Point with some additional information.
Definition: Station.h:37
Station(double x=0.0, double y=0.0, double z=0.0, std::string name="")
Constructor.
Definition: Station.cpp:25
static Station * createStation(const std::string &line)
Creates a Station-object from information contained in a string (assuming the string has the right fo...
Definition: Station.cpp:45
A container for sensor data at an observation site. The class stores a number of time series and has ...
Definition: SensorData.h:62
std::string replaceString(const std::string &searchString, const std::string &replaceString, std::string stringToReplace)
Definition: StringTools.cpp:50
std::vector< std::string > splitString(std::string const &str)
Definition: StringTools.cpp:28
bool isStation(GeoLib::Point const *pnt)
Definition: Station.cpp:76