OSM IDs are only unique within the same object type, but
MergeInputReader.apply_to_reader() appears to treat them as globally unique
when applying changes.
Example:
<osm version="0.6">
<node id="1" version="1" lon="-90" lat="45"/>
<node id="2" version="1" lon="90" lat="45"/>
<way id="1" version="1">
<nd ref="1"/>
<nd ref="2"/>
</way>
<relation id="1" version="1">
<member type="way" ref="1"/>
</relation>
</osm>
<osmChange version="0.6">
<modify>
<relation id="1" version="2">
<member type="way" ref="1" role=""/>
<tag k="hello" v="world"/>
</relation>
</modify>
</osmChange>
Produces:
<?xml version='1.0' encoding='UTF-8'?>
<osm version="0.6" generator="libosmium/2.23.1">
<node id="1" version="1" lat="45" lon="-90"/>
<node id="2" version="1" lat="45" lon="90"/>
<way id="1" version="1">
<nd ref="1"/>
<nd ref="2"/>
</way>
</osm>
The updated file should include relation/1.
If I change the relation's ID to 10 (so it doesn't collide with way/1 -- or node/1), it works as expected:
<?xml version='1.0' encoding='UTF-8'?>
<osm version="0.6" generator="libosmium/2.23.1">
<node id="1" version="1" lat="45" lon="-90"/>
<node id="2" version="1" lat="45" lon="90"/>
<way id="1" version="1">
<nd ref="1"/>
<nd ref="2"/>
</way>
<relation id="10" version="2">
<member type="way" ref="1" role=""/>
<tag k="hello" v="world"/>
</relation>
</osm>
I discovered this in PyOsmium 4.3.1 using:
def apply_changes(source, changes_file, target):
changes = osmium.MergeInputReader()
changes.add_file(str(changes_file))
reader = osmium.io.Reader(source)
writer = osmium.io.Writer(str(target), reader.header())
try:
changes.apply_to_reader(reader, writer)
finally:
reader.close()
writer.close()
The problematic code appearas to be in lib/merge_input_reader.cc:
class copy_first_with_id {
osmium::io::Writer* writer;
osmium::object_id_type id = 0;
public:
// ...
void push_back(const osmium::OSMObject& obj) {
if (obj.id() != id) {
if (obj.visible()) {
(*writer)(obj);
}
id = obj.id();
}
}
};
osmium-tool appears to use similar code (though I haven't verified its output yet), so it may be affected by the same bug.
OSM IDs are only unique within the same object type, but
MergeInputReader.apply_to_reader()appears to treat them as globally uniquewhen applying changes.
Example:
Produces:
The updated file should include
relation/1.If I change the relation's ID to
10(so it doesn't collide withway/1-- ornode/1), it works as expected:I discovered this in PyOsmium 4.3.1 using:
The problematic code appearas to be in
lib/merge_input_reader.cc:osmium-toolappears to use similar code (though I haven't verified its output yet), so it may be affected by the same bug.