alaCarte Maps
Renderer for OpenStreetMap tiles
alacarte_importer.cpp
Go to the documentation of this file.
1 
22 #include "config.hpp"
23 #include "settings.hpp"
24 
25 #include "utils/application.hpp"
26 
28 #include "general/geodata.hpp"
29 
30 #include "importer/importer.hpp"
31 
32 
33 
34 
40  : public Application
41 {
42 public:
48  {
49 #define OPT(_name, _shortcut) (string(_name).append(",").append(_shortcut)).c_str()
50  using namespace boost::program_options;
51 
52 
53  // only in cmd
54  cmd_desc.add_options()
55  (OPT(opt::help, "h"), "produce help message")
56  (OPT(opt::config, "c"), value<string>()->default_value(DEFAULT_CONFIG_NAME),
57  "specifies a config file which will be loaded at program start. Absolute and relative paths are possible. Additionally we search in " SYSCONFDIR ".")
58  ;
59 
60  // in cmd and config
61  config_desc.add_options()
62  (OPT(opt::logfile, "l"), value<string>()->default_value("alacarte_%N.log")/*->value_name("path")*/, "specifies the logfile")
63  (OPT(opt::importer::path_to_osmdata, "i"), value<string>()->required()/*->value_name("path")*/, "path to a xml file containing osm data")
64  (OPT(opt::importer::path_to_geodata, "g"), value<string>()->required()->default_value("ala.carte")/*->value_name("path")*/, "path, where preprocessed data will be saved")
65  (OPT(opt::importer::check_xml_entities, "x"), value<bool>()->required()->default_value(true)/*->value_name("path")*/,
66  "Specifies weather the parser should not ignore unknown entities.")
67  (opt::importer::min_lat, value<double>(), "minimum node latitude")
68  (opt::importer::min_lon, value<double>(), "minimum node longitude")
69  (opt::importer::max_lat, value<double>(), "maximum node latitude")
70  (opt::importer::max_lon, value<double>(), "maximum node longitude")
71  ;
72 
73 
74  cmd_desc.add(config_desc);
75 
77  }
78 
79 protected:
80  virtual bool startupDiagnostic(const shared_ptr<Configuration>& config)
81  {
83  }
84 
90  virtual void onRun( const shared_ptr<Configuration>& config )
91  {
92  shared_ptr<Importer> importer = boost::make_shared<Importer>(config);
93 
94  shared_ptr<Geodata> geodata;
95 
96  try {
97  geodata = importer->importXML();
98 
99  } catch(excp::InputFormatException& e)
100  {
101  LOG_SEV(importer_log, error) << "Failed to parse \"" << excp::ErrorOut<excp::InfoFileName>(e) << "\"!";
102  LOG_SEV(importer_log, error) << "Error:";
103  LOG_SEV(importer_log, error) << excp::ErrorOut<excp::InfoWhat>(e);
104 
105  return;
106  }
107 
108  geodata->save(config->get<string>(opt::importer::path_to_geodata));
109  }
110 
111 };
112 
113 
114 
115 
117 int main(int argc, char** argv)
118 {
120 
121  return app.start(argc, argv);
122 }
boost::program_options::positional_options_description pos_desc
Definition: application.hpp:53
static const char * path_to_geodata
Option to get the filename to save geodata (type: string)
static const char * check_xml_entities
Check all xml entities.
#define OPT(_name, _shortcut)
static const char * max_lat
maximum node latitude to include into imported data
Thrown if input was not in the right format.
Definition: exceptions.hpp:77
static const char * min_lat
minimum node latitude to include into imported data
static const char * path_to_osmdata
Option to get the path to osm xml file (type: string)
virtual bool startupDiagnostic(const shared_ptr< Configuration > &config)
#define LOG_SEV(log, lvl)
Definition: settings.hpp:78
bool diagnosticCheckFile(const shared_ptr< Configuration > &config, const string &key)
boost::program_options::options_description config_desc
Definition: application.hpp:52
static const char * min_lon
minimum node longitude to include into imported data
This file is part of alaCarte.
#define DEFAULT_CONFIG_NAME
Definition: settings.hpp:127
boost::program_options::options_description cmd_desc
Definition: application.hpp:51
static const char * config
Option to get the configuration filename (type: string)
static const char * max_lon
maximum node longitude to include into imported data
static const char * help
Use Configuration::has to check weather the user wanted help.
virtual void onRun(const shared_ptr< Configuration > &config)
Contains the main functionality for the importer.
AlacarteImporterApp()
Inits the Configuration descriptions.
int start(int argc, char **argv)
Starts the aplication with or without Exceptionhandling.
static const char * logfile
Option to get the filename of the log (type: string)