diff --git a/CHANGELOG.md b/CHANGELOG.md index 20ddd77..116425c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -14,10 +14,11 @@ This project adheres to [Semantic Versioning](https://semver.org/). ### Changed +- Needs at least libosmium version 2.20.0. - Switch from RapidJSON to NLohman JSON. RapidJSON hasn't seen an update in a long time, so we are using a different JSON library. - Removed "spaten" output format. -- Open writer in getid command earlier, so see potential errors earlier. +- Open writer in some commands earlier, so we see potential errors earlier. - Lots of small code cleanups. ### Fixed diff --git a/CMakeLists.txt b/CMakeLists.txt index cf928eb..e29f311 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -48,7 +48,7 @@ option(RUN_TESTS_WITH_BINARY_COMPARE "Run tests that do binary comparisons" ON) find_package(Boost 1.55.0 REQUIRED COMPONENTS program_options) include_directories(SYSTEM ${Boost_INCLUDE_DIRS}) -find_package(Osmium 2.17.0 REQUIRED COMPONENTS io) +find_package(Osmium 2.20.0 REQUIRED COMPONENTS io) include_directories(SYSTEM ${OSMIUM_INCLUDE_DIRS}) find_package(nlohmann_json) diff --git a/src/command_add_locations_to_ways.cpp b/src/command_add_locations_to_ways.cpp index b236e34..871b993 100644 --- a/src/command_add_locations_to_ways.cpp +++ b/src/command_add_locations_to_ways.cpp @@ -176,6 +176,9 @@ void CommandAddLocationsToWays::find_member_nodes() { } bool CommandAddLocationsToWays::run() { + m_output_file.set("locations_on_ways"); + osmium::io::Writer writer{m_output_file, m_output_overwrite, m_fsync}; + if (m_keep_member_nodes) { m_vout << "Getting all nodes referenced from relations...\n"; find_member_nodes(); @@ -191,14 +194,12 @@ bool CommandAddLocationsToWays::run() { location_handler.ignore_errors(); } - m_output_file.set("locations_on_ways"); - if (m_input_files.size() == 1) { // single input file m_vout << "Copying input file '" << m_input_files[0].filename() << "'...\n"; osmium::io::Reader reader{m_input_files[0]}; osmium::io::Header header{reader.header()}; setup_header(header); - osmium::io::Writer writer{m_output_file, header, m_output_overwrite, m_fsync}; + writer.set_header(header); osmium::ProgressBar progress_bar{reader.file_size(), display_progress()}; copy_data(progress_bar, reader, writer, location_handler); @@ -209,7 +210,7 @@ bool CommandAddLocationsToWays::run() { } else { // multiple input files osmium::io::Header header; setup_header(header); - osmium::io::Writer writer{m_output_file, header, m_output_overwrite, m_fsync}; + writer.set_header(header); osmium::ProgressBar progress_bar{file_size_sum(m_input_files), display_progress()}; for (const auto& input_file : m_input_files) { diff --git a/src/command_apply_changes.cpp b/src/command_apply_changes.cpp index 125d9c8..22d712d 100644 --- a/src/command_apply_changes.cpp +++ b/src/command_apply_changes.cpp @@ -275,6 +275,13 @@ void CommandApplyChanges::apply_changes_and_write(osmium::ObjectPointerCollectio } bool CommandApplyChanges::run() { + if (m_locations_on_ways) { + m_output_file.set("locations_on_ways"); + } + + m_vout << "Opening output file...\n"; + osmium::io::Writer writer{m_output_file, m_output_overwrite, m_fsync}; + std::vector changes; osmium::ObjectPointerCollection objects; @@ -302,13 +309,7 @@ bool CommandApplyChanges::run() { if (m_with_history) { header.set_has_multiple_object_versions(true); } - - if (m_locations_on_ways) { - m_output_file.set("locations_on_ways"); - } - - m_vout << "Opening output file...\n"; - osmium::io::Writer writer{m_output_file, header, m_output_overwrite, m_fsync}; + writer.set_header(header); if (m_with_history) { // For history files this is a straightforward sort of the change diff --git a/src/command_derive_changes.cpp b/src/command_derive_changes.cpp index ae2f6fd..4f92c75 100644 --- a/src/command_derive_changes.cpp +++ b/src/command_derive_changes.cpp @@ -151,6 +151,12 @@ void CommandDeriveChanges::write_deleted(osmium::io::Writer& writer, osmium::OSM } bool CommandDeriveChanges::run() { + m_vout << "Opening output file...\n"; + if (m_output_file.format() != osmium::io::file_format::xml || !m_output_file.is_true("xml_change_format")) { + warning("Output format chosen is not the XML change format. Use .osc(.gz|bz2) as suffix or -f option.\n"); + } + osmium::io::Writer writer{m_output_file, m_output_overwrite, m_fsync}; + m_vout << "Opening input files...\n"; osmium::io::Reader reader1{m_input_files[0], osmium::osm_entity_bits::object}; osmium::io::ReaderWithProgressBar reader2{display_progress(), m_input_files[1], osmium::osm_entity_bits::object}; @@ -161,16 +167,9 @@ bool CommandDeriveChanges::run() { auto end1 = in1.end(); auto end2 = in2.end(); - reader2.progress_bar().remove(); - m_vout << "Opening output file...\n"; - if (m_output_file.format() != osmium::io::file_format::xml || !m_output_file.is_true("xml_change_format")) { - warning("Output format chosen is not the XML change format. Use .osc(.gz|bz2) as suffix or -f option.\n"); - } - osmium::io::Header header; setup_header(header); - - osmium::io::Writer writer{m_output_file, header, m_output_overwrite, m_fsync}; + writer.set_header(header); reader2.progress_bar().remove(); m_vout << "Deriving changes...\n"; diff --git a/src/command_getid.cpp b/src/command_getid.cpp index e651bb7..2faec61 100644 --- a/src/command_getid.cpp +++ b/src/command_getid.cpp @@ -333,6 +333,9 @@ void CommandGetId::find_referenced_objects() { } bool CommandGetId::run() { + m_vout << "Opening output file...\n"; + osmium::io::Writer writer{m_output_file, m_output_overwrite, m_fsync}; + if (m_add_referenced_objects) { find_referenced_objects(); } @@ -340,11 +343,9 @@ bool CommandGetId::run() { m_vout << "Opening input file...\n"; osmium::io::Reader reader{m_input_file, get_needed_types()}; - m_vout << "Opening output file...\n"; osmium::io::Header header{reader.header()}; setup_header(header); - - osmium::io::Writer writer{m_output_file, header, m_output_overwrite, m_fsync}; + writer.set_header(header); m_vout << "Copying matching objects to output file...\n"; osmium::ProgressBar progress_bar{reader.file_size(), display_progress()}; diff --git a/src/command_sort.cpp b/src/command_sort.cpp index e2ac84d..8ff3dc4 100644 --- a/src/command_sort.cpp +++ b/src/command_sort.cpp @@ -104,6 +104,8 @@ void CommandSort::show_arguments() { } bool CommandSort::run_single_pass() { + osmium::io::Writer writer{m_output_file, m_output_overwrite, m_fsync}; + std::vector data; osmium::ObjectPointerCollection objects; @@ -149,8 +151,7 @@ bool CommandSort::run_single_pass() { if (bounding_box) { header.add_box(bounding_box); } - - osmium::io::Writer writer{m_output_file, header, m_output_overwrite, m_fsync}; + writer.set_header(header); m_vout << "Sorting data...\n"; objects.sort(osmium::object_order_type_id_version()); @@ -169,6 +170,8 @@ bool CommandSort::run_single_pass() { } bool CommandSort::run_multi_pass() { + osmium::io::Writer writer{m_output_file, m_output_overwrite, m_fsync}; + osmium::Box bounding_box; m_vout << "Reading input file headers...\n"; @@ -185,8 +188,7 @@ bool CommandSort::run_multi_pass() { if (bounding_box) { header.add_box(bounding_box); } - - osmium::io::Writer writer{m_output_file, header, m_output_overwrite, m_fsync}; + writer.set_header(header); osmium::ProgressBar progress_bar{file_size_sum(m_input_files) * 3, display_progress()}; diff --git a/src/command_tags_filter.cpp b/src/command_tags_filter.cpp index 3d6368b..27b7311 100644 --- a/src/command_tags_filter.cpp +++ b/src/command_tags_filter.cpp @@ -363,44 +363,29 @@ void CommandTagsFilter::copy_matching_objects(osmium::io::Reader& reader, osmium } } progress_bar.done(); - - m_vout << "Closing output file...\n"; - writer.close(); - - m_vout << "Closing input file...\n"; - reader.close(); } bool CommandTagsFilter::run() { - if (m_add_referenced_objects) { - m_vout << "Opening input file to get header...\n"; - osmium::io::Reader reader_only_for_header{m_input_file, osmium::osm_entity_bits::nothing}; - - m_vout << "Opening output file...\n"; - osmium::io::Header header{reader_only_for_header.header()}; - setup_header(header); - reader_only_for_header.close(); - - osmium::io::Writer writer{m_output_file, header, m_output_overwrite, m_fsync}; + m_vout << "Opening output file...\n"; + osmium::io::Writer writer{m_output_file, m_output_overwrite, m_fsync}; + if (m_add_referenced_objects) { find_referenced_objects(); + } - m_vout << "Opening input file...\n"; - osmium::io::Reader reader{m_input_file, get_needed_types()}; - - copy_matching_objects(reader, writer); - } else { - m_vout << "Opening input file...\n"; - osmium::io::Reader reader{m_input_file, get_needed_types()}; + m_vout << "Opening input file...\n"; + osmium::io::Reader reader{m_input_file, get_needed_types()}; + osmium::io::Header header{reader.header()}; + setup_header(header); + writer.set_header(header); - m_vout << "Opening output file...\n"; - osmium::io::Header header{reader.header()}; - setup_header(header); + copy_matching_objects(reader, writer); - osmium::io::Writer writer{m_output_file, header, m_output_overwrite, m_fsync}; + m_vout << "Closing output file...\n"; + writer.close(); - copy_matching_objects(reader, writer); - } + m_vout << "Closing input file...\n"; + reader.close(); show_memory_used();