Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions lib/merge_input_reader.cc
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ namespace {
class copy_first_with_id {
osmium::io::Writer* writer;
osmium::object_id_type id = 0;
osmium::item_type type = osmium::item_type::undefined;

public:
using iterator_category = std::output_iterator_tag;
Expand All @@ -44,11 +45,12 @@ namespace {
}

void push_back(const osmium::OSMObject& obj) {
if (obj.id() != id) {
if (obj.id() != id || obj.type() != type) {
if (obj.visible()) {
(*writer)(obj);
}
id = obj.id();
type = obj.type();
}
}

Expand All @@ -67,7 +69,7 @@ class MergeInputReader
osmium::item_type prev_type = osmium::item_type::undefined;
osmium::object_id_type prev_id = 0;
for (auto &item: objects) {
if (item.type() != prev_type || item.id() != prev_id) {
if (item.id() != prev_id || item.type() != prev_type) {
prev_type = item.type();
prev_id = item.id();
pyosmium::apply_item(item, handler);
Expand Down
76 changes: 76 additions & 0 deletions test/test_merge_input_reader.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,3 +99,79 @@ def test_multibuffer_simplify(adder, tmp_path):
mir.apply(h, simplify=True)

assert h.data == ['N1/1', 'N2/1', 'W3/2']


def test_simplify_same_id_different_object(tmp_path):
mir = osmium.MergeInputReader()

opls = ["""\
n1 v1 x1 y1
n2 v1 x90 y45
w1 v1 Nn1,n2
r1 v1 Mw1@
""",
"""\
r1 v2 Mw1@ Thello=world
"""]

for opl in opls:
add_as_file(mir, opl, tmp_path)

h = ListHandler()
mir.apply(h, simplify=True)

assert h.data == ['N1/1', 'N2/1', 'W1/1', 'R1/2']


def test_apply_to_reader_nohistory(test_data, tmp_path):
fn = test_data("""\
n1 v1 x1 y1
n2 v1 x90 y45
w1 v1 Nn1,n2
r1 v1 Mw1@
""")

outfn = tmp_path / 'outfile_apply_to_reader_nohistory.opl'

reader = osmium.io.Reader(fn)
writer = osmium.io.Writer(outfn)

mir = osmium.MergeInputReader()
add_as_buffer(mir, "r1 v2 Mw1@ Thello=world", tmp_path)

mir.apply_to_reader(reader, writer, False)

reader.close()
writer.close()

h = ListHandler()
osmium.apply(outfn, h)

assert h.data == ['N1/1', 'N2/1', 'W1/1', 'R1/2']


def test_apply_to_reader_with_history(test_data, tmp_path):
fn = test_data("""\
n1 v1 x1 y1
n2 v1 x90 y45
w1 v1 Nn1,n2
r1 v1 Mw1@
""")

outfn = tmp_path / 'outfile_apply_to_reader_nohistory.opl'

reader = osmium.io.Reader(fn)
writer = osmium.io.Writer(outfn)

mir = osmium.MergeInputReader()
add_as_buffer(mir, "r1 v2 Mw1@ Thello=world", tmp_path)

mir.apply_to_reader(reader, writer, True)

reader.close()
writer.close()

h = ListHandler()
osmium.apply(outfn, h)

assert h.data == ['N1/1', 'N2/1', 'W1/1', 'R1/1', 'R1/2']
Loading