Fast map matching  0.1.0
gps_config.cpp
1 #include "config/gps_config.hpp"
2 #include "util/util.hpp"
3 #include "util/debug.hpp"
4 
6  int format = get_gps_format();
7  if (format==0) {
8  SPDLOG_INFO("GPS format: GDAL trajectory");
9  SPDLOG_INFO("File name: {} ",file);
10  SPDLOG_INFO("ID name: {} ",id);
11  SPDLOG_INFO("Timestamp name: {} ",timestamp);
12  } else if (format==1) {
13  SPDLOG_INFO("GPS format: CSV trajectory");
14  SPDLOG_INFO("File name: {} ",file);
15  SPDLOG_INFO("ID name: {} ",id);
16  SPDLOG_INFO("Geom name: {} ",geom);
17  SPDLOG_INFO("Timestamp name: {} ",timestamp);
18  } else {
19  SPDLOG_INFO("GPS format: CSV point");
20  SPDLOG_INFO("File name: {} ",file);
21  SPDLOG_INFO("ID name: {} ",id);
22  SPDLOG_INFO("x name: {} ",x);
23  SPDLOG_INFO("y name: {} ",y);
24  SPDLOG_INFO("Timestamp name: {} ",timestamp);
25  }
26 };
27 
29  const boost::property_tree::ptree &xml_data){
30  GPSConfig config;
31  config.file = xml_data.get<std::string>("config.input.gps.file");
32  config.id = xml_data.get("config.input.gps.id", "id");
33  config.geom = xml_data.get("config.input.gps.geom", "geom");
34  config.timestamp = xml_data.get("config.input.gps.timestamp",
35  "timestamp");
36  config.x = xml_data.get("config.input.gps.x", "x");
37  config.y = xml_data.get("config.input.gps.y", "y");
38  config.gps_point = !(!xml_data.get_child_optional(
39  "config.input.gps.gps_point"));
40  return config;
41 };
42 
44  const cxxopts::ParseResult &arg_data){
45  GPSConfig config;
46  config.file = arg_data["gps"].as<std::string>();
47  config.id = arg_data["gps_id"].as<std::string>();
48  config.geom = arg_data["gps_geom"].as<std::string>();
49  config.timestamp = arg_data["gps_timestamp"].as<std::string>();
50  config.x = arg_data["gps_x"].as<std::string>();
51  config.y = arg_data["gps_y"].as<std::string>();
52  if (arg_data.count("gps_point")>0)
53  config.gps_point = true;
54  return config;
55 };
56 
58  std::string fn_extension = file.substr(
59  file.find_last_of(".") + 1);
60  if (fn_extension == "csv" || fn_extension == "txt") {
61  if (gps_point) {
62  return 2;
63  } else {
64  return 1;
65  }
66  } else if (fn_extension == "gpkg" || fn_extension == "shp") {
67  return 0;
68  } else {
69  SPDLOG_CRITICAL("GPS file extension {} unknown",fn_extension);
70  return -1;
71  }
72 };
73 
75  if (!UTIL::file_exists(file))
76  {
77  SPDLOG_CRITICAL("GPS file {} not found",file);
78  return false;
79  };
80  if (get_gps_format()<0) {
81  SPDLOG_CRITICAL("Unknown GPS format");
82  return false;
83  }
84  return true;
85 }
FMM::CONFIG::GPSConfig::x
std::string x
x field/column name
Definition: gps_config.hpp:30
FMM::CONFIG::GPSConfig::y
std::string y
y field/column name
Definition: gps_config.hpp:31
FMM::CONFIG::GPSConfig::validate
bool validate() const
Validate the GPS configuration for file existence, parameter validation.
Definition: gps_config.cpp:74
FMM::CONFIG::GPSConfig::id
std::string id
id field/column name
Definition: gps_config.hpp:28
FMM::CONFIG::GPSConfig::gps_point
bool gps_point
gps point stored or not
Definition: gps_config.hpp:33
FMM::CONFIG::GPSConfig::file
std::string file
filename
Definition: gps_config.hpp:27
FMM::CONFIG::GPSConfig::geom
std::string geom
geometry field/column name
Definition: gps_config.hpp:29
FMM::CONFIG::GPSConfig
GPS configuration class for reading data from a file.
Definition: gps_config.hpp:26
FMM::CONFIG::GPSConfig::print
void print() const
Print members of the GPS configuration.
Definition: gps_config.cpp:5
FMM::CONFIG::GPSConfig::timestamp
std::string timestamp
timestamp field/column name
Definition: gps_config.hpp:32
FMM::UTIL::file_exists
bool file_exists(const char *filename)
Check if file exist or not.
Definition: util.cpp:61
FMM::CONFIG::GPSConfig::get_gps_format
int get_gps_format() const
Find the GPS format.
Definition: gps_config.cpp:57
FMM::CONFIG::GPSConfig::load_from_xml
static GPSConfig load_from_xml(const boost::property_tree::ptree &xml_data)
Load GPSConfig from XML data.
Definition: gps_config.cpp:28
FMM::CONFIG::GPSConfig::load_from_arg
static GPSConfig load_from_arg(const cxxopts::ParseResult &arg_data)
Load GPSConfig from argument parsed data.
Definition: gps_config.cpp:43