Fast map matching  0.1.0
result_config.cpp
1 #include "config/result_config.hpp"
2 #include "util/util.hpp"
3 #include "util/debug.hpp"
4 #include <set>
5 
7  std::stringstream ss;
9  ss << "opath ";
11  ss << "pgeom ";
13  ss << "offset ";
15  ss << "error ";
17  ss << "spdist ";
19  ss << "cpath ";
21  ss << "tpath ";
23  ss << "mgeom ";
25  ss << "ep ";
27  ss << "tp ";
29  ss << "length ";
30  SPDLOG_INFO("ResultConfig");
31  SPDLOG_INFO("File: {}",file);
32  SPDLOG_INFO("Fields: {}",ss.str());
33 };
34 
36  const boost::property_tree::ptree &xml_data) {
37  ResultConfig config;
38  config.file = xml_data.get<std::string>("config.output.file");
39  if (xml_data.get_child_optional("config.output.fields")) {
40  // Fields specified
41  // close the default output fields (cpath,mgeom are true by default)
42  config.output_config.write_cpath = false;
43  config.output_config.write_mgeom = false;
44  if (xml_data.get_child_optional("config.output.fields.opath")) {
45  config.output_config.write_opath = true;
46  }
47  if (xml_data.get_child_optional("config.output.fields.cpath")) {
48  config.output_config.write_cpath = true;
49  }
50  if (xml_data.get_child_optional("config.output.fields.tpath")) {
51  config.output_config.write_tpath = true;
52  }
53  if (xml_data.get_child_optional("config.output.fields.mgeom")) {
54  config.output_config.write_mgeom = true;
55  }
56  if (xml_data.get_child_optional("config.output.fields.pgeom")) {
57  config.output_config.write_pgeom = true;
58  }
59  if (xml_data.get_child_optional("config.output.fields.offset")) {
60  config.output_config.write_offset = true;
61  }
62  if (xml_data.get_child_optional("config.output.fields.error")) {
63  config.output_config.write_error = true;
64  }
65  if (xml_data.get_child_optional("config.output.fields.spdist")) {
66  config.output_config.write_spdist = true;
67  }
68  if (xml_data.get_child_optional("config.output.fields.ep")) {
69  config.output_config.write_ep = true;
70  }
71  if (xml_data.get_child_optional("config.output.fields.tp")) {
72  config.output_config.write_tp = true;
73  }
74  if (xml_data.get_child_optional("config.output.fields.length")) {
75  config.output_config.write_length = true;
76  }
77  if (xml_data.get_child_optional("config.output.fields.all")) {
78  config.output_config.write_opath = true;
79  config.output_config.write_pgeom = true;
80  config.output_config.write_offset = true;
81  config.output_config.write_error = true;
82  config.output_config.write_spdist = true;
83  config.output_config.write_cpath = true;
84  config.output_config.write_mgeom = true;
85  config.output_config.write_tpath = true;
86  config.output_config.write_ep = true;
87  config.output_config.write_tp = true;
88  config.output_config.write_length = true;
89  }
90  }
91  return config;
92 };
93 
95  const cxxopts::ParseResult &arg_data) {
97  config.file = arg_data["output"].as<std::string>();
98  if (arg_data.count("output_fields") > 0) {
99  config.output_config.write_cpath = false;
100  config.output_config.write_mgeom = false;
101  std::string fields = arg_data["output_fields"].as<std::string>();
102  std::set<std::string> dict = string2set(fields);
103  if (dict.find("opath") != dict.end()) {
104  config.output_config.write_opath = true;
105  }
106  if (dict.find("cpath") != dict.end()) {
107  config.output_config.write_cpath = true;
108  }
109  if (dict.find("mgeom") != dict.end()) {
110  config.output_config.write_mgeom = true;
111  }
112  if (dict.find("tpath") != dict.end()) {
113  config.output_config.write_tpath = true;
114  }
115  if (dict.find("pgeom") != dict.end()) {
116  config.output_config.write_pgeom = true;
117  }
118  if (dict.find("offset") != dict.end()) {
119  config.output_config.write_offset = true;
120  }
121  if (dict.find("error") != dict.end()) {
122  config.output_config.write_error = true;
123  }
124  if (dict.find("spdist") != dict.end()) {
125  config.output_config.write_spdist = true;
126  }
127  if (dict.find("ep") != dict.end()) {
128  config.output_config.write_ep = true;
129  }
130  if (dict.find("tp") != dict.end()) {
131  config.output_config.write_tp = true;
132  }
133  if (dict.find("length") != dict.end()) {
134  config.output_config.write_length = true;
135  }
136  if (dict.find("all") != dict.end()) {
137  config.output_config.write_opath = true;
138  config.output_config.write_pgeom = true;
139  config.output_config.write_offset = true;
140  config.output_config.write_error = true;
141  config.output_config.write_spdist = true;
142  config.output_config.write_cpath = true;
143  config.output_config.write_mgeom = true;
144  config.output_config.write_tpath = true;
145  config.output_config.write_ep = true;
146  config.output_config.write_tp = true;
147  config.output_config.write_length = true;
148  }
149  }
150  return config;
151 };
152 
154  const std::string &s) {
155  char delim = ',';
156  std::set<std::string> result;
157  std::stringstream ss(s);
158  std::string intermediate;
159  while (getline(ss, intermediate, delim)) {
160  result.insert(intermediate);
161  }
162  return result;
163 }
165  if (UTIL::file_exists(file))
166  {
167  SPDLOG_WARN("Overwrite existing result file {}",file);
168  };
169  std::string output_folder = UTIL::get_file_directory(file);
170  if (!UTIL::folder_exist(output_folder)) {
171  SPDLOG_CRITICAL("Output folder {} not exists",output_folder);
172  return false;
173  }
174  return true;
175 };
FMM::CONFIG::ResultConfig::load_from_xml
static ResultConfig load_from_xml(const boost::property_tree::ptree &xml_data)
Load result configuration data from xml file.
Definition: result_config.cpp:35
FMM::CONFIG::OutputConfig::write_tpath
bool write_tpath
if true, tpath (the path traversed between each two consecutive observations) will be exported
Definition: result_config.hpp:34
FMM::CONFIG::OutputConfig::write_ep
bool write_ep
if true, ep (emission proability of each point) will be exported
Definition: result_config.hpp:44
FMM::CONFIG::ResultConfig::validate
bool validate() const
Check the validation of the configuration.
Definition: result_config.cpp:164
FMM::CONFIG::OutputConfig::write_spdist
bool write_spdist
if true, spdist (the distance traversed between each two consecutive points) will be exported
Definition: result_config.hpp:39
FMM::CONFIG::OutputConfig::write_tp
bool write_tp
if true, tp (transition probability) will be exported
Definition: result_config.hpp:46
FMM::CONFIG::ResultConfig::output_config
OutputConfig output_config
Output fields to export.
Definition: result_config.hpp:57
FMM::CONFIG::OutputConfig::write_length
bool write_length
if true, length (length of each matched edge) will be exported
Definition: result_config.hpp:48
FMM::CONFIG::ResultConfig::file
std::string file
Output file to write the result.
Definition: result_config.hpp:56
FMM::UTIL::folder_exist
bool folder_exist(const std::string &folder_name)
Check if folder exists or not.
Definition: util.cpp:120
FMM::CONFIG::OutputConfig::write_mgeom
bool write_mgeom
if true, mgeom (the geometry of the matched path) will be exported
Definition: result_config.hpp:37
FMM::CONFIG::ResultConfig::string2set
static std::set< std::string > string2set(const std::string &s)
Parse a string separated by , into a set of strings.
Definition: result_config.cpp:153
FMM::UTIL::get_file_directory
std::string get_file_directory(const std::string &fn)
Get folder path from file path.
Definition: util.cpp:129
FMM::CONFIG::OutputConfig::write_cpath
bool write_cpath
if true, cpath (a list of edge ID representing the matched path) will be exported
Definition: result_config.hpp:32
FMM::CONFIG::OutputConfig::write_opath
bool write_opath
if true, opath (edge id matched for each point) will be exported
Definition: result_config.hpp:26
FMM::CONFIG::ResultConfig
Result Configuration class, defining output file and output fields.
Definition: result_config.hpp:55
FMM::CONFIG::OutputConfig::write_error
bool write_error
if true, gps error (distance from GPS point to the matched point) will be exported
Definition: result_config.hpp:30
FMM::CONFIG::ResultConfig::print
void print() const
Print the configuration information.
Definition: result_config.cpp:6
FMM::CONFIG::ResultConfig::load_from_arg
static ResultConfig load_from_arg(const cxxopts::ParseResult &arg_data)
Load result configuration from argument data.
Definition: result_config.cpp:94
FMM::CONFIG::OutputConfig::write_pgeom
bool write_pgeom
if true, pgeom (a linestring connecting the matched point) will be exported
Definition: result_config.hpp:42
FMM::UTIL::file_exists
bool file_exists(const char *filename)
Check if file exist or not.
Definition: util.cpp:61
FMM::CONFIG::OutputConfig::write_offset
bool write_offset
if true, offset (distance to the start point of a matched edge) will be exported
Definition: result_config.hpp:28