@@ -113,6 +113,16 @@ static void store_properties(properties_t *properties, options_t const &options)
113113 properties->set_bool (" updatable" , options.slim && !options.droptemp );
114114 properties->set_string (" version" , get_osm2pgsql_short_version ());
115115 properties->set_int (" db_format" , options.middle_database_format );
116+ properties->set_string (" output" , options.output_backend );
117+
118+ if (options.style .empty ()) {
119+ properties->set_string (" style" , " " );
120+ } else {
121+ properties->set_string (
122+ " style" ,
123+ boost::filesystem::absolute (boost::filesystem::path{options.style })
124+ .string ());
125+ }
116126
117127 properties->store ();
118128}
@@ -241,6 +251,57 @@ static void check_db_format(properties_t const &properties, options_t *options)
241251 options->middle_database_format = format;
242252}
243253
254+ static void check_output (properties_t const &properties, options_t *options)
255+ {
256+ auto const output = properties.get_string (" output" , " pgsql" );
257+
258+ if (!options->output_backend_set ) {
259+ options->output_backend = output;
260+ log_info (" Using output '{}' (same as on import)." , output);
261+ return ;
262+ }
263+
264+ if (options->output_backend == output) {
265+ return ;
266+ }
267+
268+ throw fmt_error (" Different output specified on command line ('{}')"
269+ " then used on import ('{}')." ,
270+ options->output_backend , output);
271+ }
272+
273+ static void check_and_update_style_file (properties_t *properties,
274+ options_t *options)
275+ {
276+ auto const style_file_from_import = properties->get_string (" style" , " " );
277+
278+ if (options->style .empty ()) {
279+ log_info (" Using style file '{}' (same as on import)." ,
280+ style_file_from_import);
281+ options->style = style_file_from_import;
282+ return ;
283+ }
284+
285+ if (style_file_from_import.empty ()) {
286+ throw std::runtime_error{" Style file from import is empty!?" };
287+ }
288+
289+ const auto absolute_path =
290+ boost::filesystem::absolute (boost::filesystem::path{options->style })
291+ .string ();
292+
293+ if (absolute_path == style_file_from_import) {
294+ log_info (" Using style file '{}' (same as on import)." ,
295+ style_file_from_import);
296+ return ;
297+ }
298+
299+ log_info (" Using the style file you specified on the command line"
300+ " ('{}') instead of the one used on import ('{}')." ,
301+ absolute_path, style_file_from_import);
302+ properties->set_string (" style" , absolute_path, true );
303+ }
304+
244305// This is called in "append" mode to check that the command line options are
245306// compatible with the properties stored in the database.
246307static void check_and_update_properties (properties_t *properties,
@@ -251,6 +312,8 @@ static void check_and_update_properties(properties_t *properties,
251312 check_and_update_flat_node_file (properties, options);
252313 check_prefix (*properties, options);
253314 check_db_format (*properties, options);
315+ check_output (*properties, options);
316+ check_and_update_style_file (properties, options);
254317}
255318
256319// If we are in append mode and the middle nodes table isn't there, it probably
@@ -270,6 +333,20 @@ static void check_for_nodes_table(options_t const &options)
270333 }
271334}
272335
336+ static void check_and_set_style (options_t *options)
337+ {
338+ if (!options->style_set ) {
339+ if (options->output_backend == " flex" ||
340+ options->output_backend == " gazetteer" ) {
341+ throw std::runtime_error{" You have to set the config file "
342+ " with the -S|--style option." };
343+ }
344+ if (options->output_backend == " pgsql" ) {
345+ options->style = DEFAULT_STYLE;
346+ }
347+ }
348+ }
349+
273350int main (int argc, char *argv[])
274351{
275352 try {
@@ -296,6 +373,7 @@ int main(int argc, char *argv[])
296373 if (properties.load ()) {
297374 check_and_update_properties (&properties, &options);
298375 } else {
376+ check_and_set_style (&options);
299377 check_for_nodes_table (options);
300378 }
301379
@@ -313,6 +391,7 @@ int main(int argc, char *argv[])
313391 }
314392 }
315393 } else {
394+ check_and_set_style (&options);
316395 store_properties (&properties, options);
317396 auto const finfo = run (options);
318397 store_data_properties (&properties, finfo);
0 commit comments