MeteoIODoc  MeteoIODoc-2.6.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
PSQLIO.h
Go to the documentation of this file.
1 /***********************************************************************************/
2 /* Copyright 2012 Mountain-eering Srl, Trento/Bolzano, Italy */
3 /***********************************************************************************/
4 /* This file is part of MeteoIO.
5  MeteoIO is free software: you can redistribute it and/or modify
6  it under the terms of the GNU Lesser General Public License as published by
7  the Free Software Foundation, either version 3 of the License, or
8  (at your option) any later version.
9 
10  MeteoIO is distributed in the hope that it will be useful,
11  but WITHOUT ANY WARRANTY; without even the implied warranty of
12  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  GNU Lesser General Public License for more details.
14 
15  You should have received a copy of the GNU Lesser General Public License
16  along with MeteoIO. If not, see <http://www.gnu.org/licenses/>.
17 */
18 #ifndef PSQLIO_H
19 #define PSQLIO_H
20 
21 #include <meteoio/IOInterface.h>
22 
23 #include <libpq-fe.h>
24 #include <string>
25 #include <map>
26 
27 namespace mio {
28 
38 class PSQLIO : public IOInterface {
39  public:
40  PSQLIO(const std::string& configfile);
41  PSQLIO(const PSQLIO&);
42  PSQLIO(const Config& cfg);
43 
44  PSQLIO& operator=(const PSQLIO& in);
45 
46  virtual void readStationData(const Date& date, std::vector<StationData>& vecStation);
47  virtual void readMeteoData(const Date& dateStart, const Date& dateEnd,
48  std::vector< std::vector<MeteoData> >& vecMeteo);
49 
50  virtual void writeMeteoData(const std::vector< std::vector<MeteoData> >& vecMeteo,
51  const std::string& name="");
52 
53  private:
54  void getParameters(const Config& cfg);
55  void open_connection(const bool& input=true);
56  PGresult* sql_exec(const std::string& sqlcommand, const bool& input=true);
57  static bool replace(std::string& str, const std::string& from, const std::string& to);
58  void readData(const Date& dateStart, const Date& dateEnd, std::vector<MeteoData>& vecMeteo, const size_t& stationindex);
59  void readMetaData(const std::string& query, std::vector<StationData>& vecStation, const bool& input=true);
60  void add_meta_data(const unsigned int& index, const StationData& sd);
61  void map_parameters(PGresult* result, MeteoData& md, std::vector<size_t>& index);
62  void parse_row(PGresult* result, const int& row, const int& cols,
63  MeteoData& md, std::vector<size_t>& index, std::vector<mio::MeteoData>& vecMeteo);
64  void close_connection(PGconn *conn);
65  static bool checkConsistency(const std::vector<MeteoData>& vecMeteo, StationData& sd);
66  static size_t checkExistence(const std::vector<StationData>& vec_stations, const StationData& sd);
67  static void convertUnits(MeteoData& meteo);
68  static void convertUnitsBack(MeteoData& meteo);
69  static void checkForUsedParameters(const std::vector<MeteoData>& vecMeteo, std::vector<bool>& vecParamInUse, std::vector<std::string>& vecColumnName);
70  void add_sensors(const unsigned int& index, const std::vector<std::string>& vecColumnName, std::map<size_t, std::string>& map_sensor_id);
71  int get_sensor_index();
72  int get_measurement_index();
73  void get_sensors(const std::string& index, const std::vector<std::string>& vecColumnName, std::map<size_t, std::string>& map_sensor_id);
74 
75  std::string coordin, coordinparam, coordout, coordoutparam; //projection parameters
76  std::string in_endpoint, in_port, in_dbname, in_userid, in_passwd;
77  std::string out_endpoint, out_port, out_dbname, out_userid, out_passwd;
78  bool input_configured, output_configured;
79 
80  PGconn *psql;
81  double default_timezone;
82  std::vector<StationData> vecMeta;
83  std::vector<std::string> vecFixedStationID, vecMobileStationID;
84  std::string sql_meta, sql_data;
85 
86  static const double plugin_nodata; //plugin specific nodata value, e.g. -999
87 };
88 
89 } //namespace
90 #endif
PSQLIO & operator=(const PSQLIO &in)
Definition: PSQLIO.cc:110
virtual void readMeteoData(const Date &dateStart, const Date &dateEnd, std::vector< std::vector< MeteoData > > &vecMeteo)
Fill vecMeteo with a time series of objects corresponding to the interval indicated by dateStart and ...
Definition: PSQLIO.cc:255
PSQLIO(const std::string &configfile)
Definition: PSQLIO.cc:80
A class representing the IO Layer of the software Alpine3D. For each type of IO (File, DB, Webservice, etc) a derived class is to be created that holds the specific implementation of the appropriate virtual methods. The IOHandler class is a wrapper class that is able to deal with all above implementations of the IOInterface abstract base class.
Definition: IOInterface.h:43
virtual void writeMeteoData(const std::vector< std::vector< MeteoData > > &vecMeteo, const std::string &name="")
Write vecMeteo time series to a certain destination.
Definition: PSQLIO.cc:588
This plugin connects to a generic PostgreSQL server to retrieve its meteorological data...
Definition: PSQLIO.h:38
virtual void readStationData(const Date &date, std::vector< StationData > &vecStation)
Fill vecStation with StationData objects for a certain date of interest.
Definition: PSQLIO.cc:219
A class that reads a key/value file. These files (typically named *.ini) follow the INI file format s...
Definition: Config.h:58
A class to handle timestamps. This class handles conversion between different time display formats (I...
Definition: Date.h:79
A class to represent meteo stations with attributes like longitude, latitude, etc.
Definition: StationData.h:38
A class to represent a singular measurement received from one station at a certain time (represented ...
Definition: MeteoData.h:101