@@ -52,6 +52,9 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
5252bool CommandDiff::setup (const std::vector<std::string>& arguments) {
5353 po::options_description opts_cmd{" COMMAND OPTIONS" };
5454 opts_cmd.add_options ()
55+ (" ignore-changeset" , " Ignore changeset id when comparing objects" )
56+ (" ignore-uid" , " Ignore user id when comparing objects" )
57+ (" ignore-user" , " Ignore user name when comparing objects" )
5558 (" object-type,t" , po::value<std::vector<std::string>>(), " Read only objects of given type (node, way, relation)" )
5659 (" output,o" , po::value<std::string>(), " Output file" )
5760 (" output-format,f" , po::value<std::string>(), " Format of output file" )
@@ -93,6 +96,18 @@ bool CommandDiff::setup(const std::vector<std::string>& arguments) {
9396 throw argument_error (" You need exactly two input files for this command." );
9497 }
9598
99+ if (vm.count (" ignore-changeset" )) {
100+ m_ignore_attrs_changeset = true ;
101+ }
102+
103+ if (vm.count (" ignore-uid" )) {
104+ m_ignore_attrs_uid = true ;
105+ }
106+
107+ if (vm.count (" ignore-user" )) {
108+ m_ignore_attrs_user = true ;
109+ }
110+
96111 if (vm.count (" output" )) {
97112 m_output_filename = vm[" output" ].as <std::string>();
98113 }
@@ -130,6 +145,18 @@ bool CommandDiff::setup(const std::vector<std::string>& arguments) {
130145 m_output_file = osmium::io::File{m_output_filename, m_output_format};
131146 m_output_file.check ();
132147
148+ std::string metadata{" version+timestamp" };
149+ if (!m_ignore_attrs_changeset) {
150+ metadata += " +changeset" ;
151+ }
152+ if (!m_ignore_attrs_uid) {
153+ metadata += " +uid" ;
154+ }
155+ if (!m_ignore_attrs_changeset) {
156+ metadata += " +user" ;
157+ }
158+ m_output_file.set (" add_metadata" , metadata);
159+
133160 auto f = m_output_file.format ();
134161 if (f != osmium::io::file_format::opl && f != osmium::io::file_format::debug) {
135162 throw argument_error (" File format does not support diff output. Use 'compact', 'opl' or 'debug' format." );
@@ -248,6 +275,21 @@ class OutputActionOSM : public OutputAction {
248275
249276}; // class OutputActionOSM
250277
278+ void CommandDiff::update_object_crc (osmium::CRC<osmium::CRC_zlib>* crc, const osmium::OSMObject &object) {
279+ crc->update_bool (object.visible ());
280+ crc->update (object.timestamp ());
281+ crc->update (object.tags ());
282+ if (!m_ignore_attrs_changeset) {
283+ crc->update_int32 (object.changeset ());
284+ }
285+ if (!m_ignore_attrs_uid) {
286+ crc->update_int32 (object.uid ());
287+ }
288+ if (!m_ignore_attrs_user) {
289+ crc->update_string (object.user ());
290+ }
291+ }
292+
251293bool CommandDiff::run () {
252294 osmium::io::Reader reader1{m_input_files[0 ], osm_entity_bits ()};
253295 osmium::io::ReaderWithProgressBar reader2{display_progress (), m_input_files[1 ], osm_entity_bits ()};
@@ -298,18 +340,20 @@ bool CommandDiff::run() {
298340 } else { /* *it1 == *it2 */
299341 osmium::CRC<osmium::CRC_zlib> crc1;
300342 osmium::CRC<osmium::CRC_zlib> crc2;
343+ update_object_crc (&crc1, *it1);
344+ update_object_crc (&crc2, *it2);
301345 switch (it1->type ()) {
302346 case osmium::item_type::node:
303- crc1.update (static_cast <const osmium::Node&>(*it1));
304- crc2.update (static_cast <const osmium::Node&>(*it2));
347+ crc1.update (static_cast <const osmium::Node&>(*it1). location () );
348+ crc2.update (static_cast <const osmium::Node&>(*it2). location () );
305349 break ;
306350 case osmium::item_type::way:
307- crc1.update (static_cast <const osmium::Way&>(*it1));
308- crc2.update (static_cast <const osmium::Way&>(*it2));
351+ crc1.update (static_cast <const osmium::Way&>(*it1). nodes () );
352+ crc2.update (static_cast <const osmium::Way&>(*it2). nodes () );
309353 break ;
310354 case osmium::item_type::relation:
311- crc1.update (static_cast <const osmium::Relation&>(*it1));
312- crc2.update (static_cast <const osmium::Relation&>(*it2));
355+ crc1.update (static_cast <const osmium::Relation&>(*it1). members () );
356+ crc2.update (static_cast <const osmium::Relation&>(*it2). members () );
313357 break ;
314358 default :
315359 break ;
0 commit comments