Skip to content

Commit 4e5658c

Browse files
committed
Move warning from cmds to io.cpp
1 parent f01c2ac commit 4e5658c

File tree

4 files changed

+35
-27
lines changed

4 files changed

+35
-27
lines changed

src/command_add_locations_to_ways.cpp

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,7 @@ bool CommandAddLocationsToWays::run() {
198198
m_vout << "Copying input file '" << m_input_files[0].filename() << "'...\n";
199199
osmium::io::Reader reader{m_input_files[0]};
200200
osmium::io::Header header{reader.header()};
201-
setup_header(header, reader.header());
201+
setup_header(header);
202202
writer.set_header(header);
203203

204204
osmium::ProgressBar progress_bar{reader.file_size(), display_progress()};
@@ -208,22 +208,15 @@ bool CommandAddLocationsToWays::run() {
208208
writer.close();
209209
reader.close();
210210
} else { // multiple input files
211-
osmium::io::Header first_input_header;
212-
bool first_file = true;
213-
211+
osmium::io::Header header;
212+
setup_header(header);
213+
writer.set_header(header);
214+
214215
osmium::ProgressBar progress_bar{file_size_sum(m_input_files), display_progress()};
215216
for (const auto& input_file : m_input_files) {
216217
progress_bar.remove();
217218
m_vout << "Copying input file '" << input_file.filename() << "'...\n";
218219
osmium::io::Reader reader{input_file};
219-
220-
if (first_file) {
221-
first_input_header = reader.header();
222-
osmium::io::Header header;
223-
setup_header(header, first_input_header);
224-
writer.set_header(header);
225-
first_file = false;
226-
}
227220

228221
copy_data(progress_bar, reader, writer, location_handler);
229222

src/command_cat.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,7 @@ bool CommandCat::run() {
162162

163163
report_filename(&m_vout, m_input_files[0], reader);
164164

165-
setup_header(header, reader.header());
165+
setup_header(header);
166166
osmium::io::Writer writer{m_output_file, header, m_output_overwrite, m_fsync};
167167

168168
if (m_buffer_data) {

src/command_sort.cpp

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -110,8 +110,7 @@ bool CommandSort::run_single_pass() {
110110
osmium::ObjectPointerCollection objects;
111111

112112
osmium::Box bounding_box;
113-
osmium::io::Header first_input_header;
114-
bool first_file = true;
113+
osmium::io::Header merged_input_header;
115114

116115
uint64_t buffers_count = 0;
117116
uint64_t buffers_size = 0;
@@ -122,11 +121,12 @@ bool CommandSort::run_single_pass() {
122121
for (const auto& file : m_input_files) {
123122
osmium::io::Reader reader{file, osmium::osm_entity_bits::object};
124123
const osmium::io::Header header{reader.header()};
125-
if (first_file) {
126-
first_input_header = header;
127-
first_file = false;
128-
}
129124
bounding_box.extend(header.joined_boxes());
125+
126+
// Merge input header info for warning detection
127+
for (const auto& option : header) {
128+
merged_input_header.set(option.first, option.second);
129+
}
130130
while (osmium::memory::Buffer buffer = reader.read()) {
131131
++buffers_count;
132132
buffers_size += buffer.committed();
@@ -152,7 +152,7 @@ bool CommandSort::run_single_pass() {
152152

153153
m_vout << "Opening output file...\n";
154154
osmium::io::Header header;
155-
setup_header(header, first_input_header);
155+
setup_header(header, merged_input_header);
156156
header.set("sorting", "Type_then_ID");
157157
if (bounding_box) {
158158
header.add_box(bounding_box);
@@ -179,24 +179,24 @@ bool CommandSort::run_multi_pass() {
179179
osmium::io::Writer writer{m_output_file, m_output_overwrite, m_fsync};
180180

181181
osmium::Box bounding_box;
182-
osmium::io::Header first_input_header;
183-
bool first_file = true;
182+
osmium::io::Header merged_input_header;
184183

185184
m_vout << "Reading input file headers...\n";
186185
for (const auto& file : m_input_files) {
187186
osmium::io::Reader reader{file, osmium::osm_entity_bits::nothing};
188187
const osmium::io::Header header{reader.header()};
189-
if (first_file) {
190-
first_input_header = header;
191-
first_file = false;
192-
}
193188
bounding_box.extend(header.joined_boxes());
189+
190+
// Merge input header info for warning detection
191+
for (const auto& option : header) {
192+
merged_input_header.set(option.first, option.second);
193+
}
194194
reader.close();
195195
}
196196

197197
m_vout << "Opening output file...\n";
198198
osmium::io::Header header;
199-
setup_header(header, first_input_header);
199+
setup_header(header, merged_input_header);
200200
if (bounding_box) {
201201
header.add_box(bounding_box);
202202
}

src/io.cpp

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -210,6 +210,21 @@ void with_osm_output::setup_header(osmium::io::Header& header) const {
210210
for (const auto& h : m_output_headers) {
211211
header.set(h);
212212
}
213+
214+
// Check if input PBF has locations_on_ways but output format won't preserve them
215+
bool has_locations_on_ways = false;
216+
for (const auto& option : header) {
217+
if (option.first.find("pbf_optional_feature") != std::string::npos &&
218+
option.second == "LocationsOnWays") {
219+
has_locations_on_ways = true;
220+
break;
221+
}
222+
}
223+
224+
if (has_locations_on_ways && m_output_format.find("locations_on_ways") == std::string::npos) {
225+
std::cerr << "Warning! Input file contains locations on ways that will be lost in output.\n";
226+
std::cerr << "Use --output-format with locations_on_ways option to preserve node locations on ways.\n";
227+
}
213228
}
214229

215230
void init_header(osmium::io::Header& header, const osmium::io::Header& input_header, const std::vector<std::string>& options) {

0 commit comments

Comments
 (0)