OGS
Station.cpp
Go to the documentation of this file.
1// SPDX-FileCopyrightText: Copyright (c) OpenGeoSys Community (opengeosys.org)
2// SPDX-License-Identifier: BSD-3-Clause
3
4#include "Station.h"
5
6#include <cstdlib>
7#include <utility>
8
9#include "BaseLib/Logging.h"
10#include "BaseLib/StringTools.h"
11
12namespace GeoLib
13{
14Station::Station(double const x, double const y, double const z,
15 std::string name)
16 : Point(x, y, z), _name(std::move(name))
17{
18}
19
20Station::Station(Point const* const coords, std::string name)
21 : Point(*coords), _name(std::move(name))
22{
23}
24
26 : Point(src),
27 _name(src._name),
29 _sensor_data(src._sensor_data.get() != nullptr
30 ? new SensorData(*(src._sensor_data.get()))
31 : nullptr)
32{
33}
34
35Station* Station::createStation(const std::string& line)
36{
37 std::list<std::string> fields = BaseLib::splitString(line, '\t');
38
39 if (fields.size() < 3)
40 {
41 INFO("Station::createStation() - Unexpected file format.");
42 return nullptr;
43 }
44
45 auto it = fields.begin();
46 std::string name = *it;
47 auto const x = std::strtod(
48 (BaseLib::replaceString(",", ".", *(++it))).c_str(), nullptr);
49 auto const y = std::strtod(
50 (BaseLib::replaceString(",", ".", *(++it))).c_str(), nullptr);
51 auto z = 0.0;
52 if (++it != fields.end())
53 {
54 z = std::strtod((BaseLib::replaceString(",", ".", *it)).c_str(),
55 nullptr);
56 }
57 return new Station(x, y, z, name);
58}
59
60Station* Station::createStation(const std::string& name, double x, double y,
61 double z)
62{
63 return new Station(x, y, z, name);
64}
65
66bool isStation(GeoLib::Point const* pnt)
67{
68 auto const* bh(dynamic_cast<GeoLib::Station const*>(pnt));
69 return bh != nullptr;
70}
71
72} // namespace GeoLib
void INFO(fmt::format_string< Args... > fmt, Args &&... args)
Definition Logging.h:28
Point()=default
A Station (observation site) is basically a Point with some additional information.
Definition Station.h:26
double _station_value
Definition Station.h:82
Station(double x=0.0, double y=0.0, double z=0.0, std::string name="")
Constructor.
Definition Station.cpp:14
std::unique_ptr< SensorData > _sensor_data
Definition Station.h:83
std::string _name
Definition Station.h:81
static Station * createStation(const std::string &line)
Definition Station.cpp:35
A container for sensor data at an observation site. The class stores a number of time series and has ...
Definition SensorData.h:52
std::string replaceString(const std::string &searchString, const std::string &replaceString, std::string stringToReplace)
std::vector< std::string > splitString(std::string const &str)
bool isStation(GeoLib::Point const *pnt)
Definition Station.cpp:66