Skip to content

Commit

Permalink
sort osm objects by id and type
Browse files Browse the repository at this point in the history
  • Loading branch information
Sven Jäger authored and Venator2013 committed Aug 20, 2024
1 parent 0b45fca commit 39f91c7
Showing 1 changed file with 19 additions and 5 deletions.
24 changes: 19 additions & 5 deletions plugins/navteq/navteq_plugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@
#include <ogr_api.h>
#include <osmium/io/any_input.hpp>
#include <osmium/io/any_output.hpp>
#include <osmium/io/output_iterator.hpp>
#include <osmium/object_pointer_collection.hpp>
#include <osmium/osm/object_comparisons.hpp>
#include <ranges>

#include "converter/AdminBoundariesConverter.hpp"
Expand Down Expand Up @@ -253,9 +256,11 @@ void navteq_plugin::sortPBF() {
osmium::io::File tmpfile(
output_path.parent_path().append("tmp.pbf").string());

copyType(writer, tmpfile, osmium::osm_entity_bits::node);
copyType(writer, tmpfile, osmium::osm_entity_bits::way);
copyType(writer, tmpfile, osmium::osm_entity_bits::relation);
for (const auto entity :
{osmium::osm_entity_bits::node, osmium::osm_entity_bits::way,
osmium::osm_entity_bits::relation}) {
copyType(writer, tmpfile, entity);
}

writer.close();

Expand All @@ -264,11 +269,20 @@ void navteq_plugin::sortPBF() {

void navteq_plugin::copyType(osmium::io::Writer &writer, osmium::io::File &file,
osmium::osm_entity_bits::type bits) {
osmium::io::Reader reader(file, bits);
std::vector<osmium::memory::Buffer> data;
osmium::ObjectPointerCollection objects;

osmium::io::Reader reader{file, bits};
while (osmium::memory::Buffer buffer = reader.read()) {
writer(std::move(buffer));
osmium::apply(buffer, objects);
data.push_back(std::move(buffer));
}
reader.close();

objects.sort(osmium::object_order_type_id_version());

auto out = osmium::io::make_output_iterator(writer);
std::copy(objects.begin(), objects.end(), out);
}

void navteq_plugin::setBoundingBox(double minX, double minY, double maxX,
Expand Down

0 comments on commit 39f91c7

Please sign in to comment.