Skip to content

Commit

Permalink
Merge pull request #44 from GIScience/feat/improve_processing_logs
Browse files Browse the repository at this point in the history
Feat: print country stats for processed nodes
  • Loading branch information
aoles committed Mar 25, 2024
2 parents ea8716b + 996c973 commit 4431bff
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 11 deletions.
3 changes: 1 addition & 2 deletions src/location_area_service.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,6 @@ void LocationAreaService::load(const std::string &path) {

area_id_t index = 0;
area_id_t valid_rows = 0;
mapping_id_[index] = "";
if (!file_has_header_) {
index++;
}
Expand Down Expand Up @@ -173,7 +172,7 @@ void LocationAreaService::output_mapping() {
// std::cout << "area[" << k << "] = (" << a.id << ", " << a.geo << ") " << std::endl;
split_geos_count++;
}
std::cout << "Areas: " << mapping_id_.size() << ", Split geometries: " << split_geos_count << ", Grid: [ NO AREA: " << no_area_count << " SINGLE: " << single_area_count << " MULTIPLE: " << multiple_area_count << " ] " << std::endl;
std::cout << "Areas: " << mapping_id_.size() << ", Split geometries: " << split_geos_count << ", Grid: [ empty: " << no_area_count << ", single: " << single_area_count << ", multiple: " << multiple_area_count << " ] " << std::endl;
}

void LocationAreaService::add_area_to_mapping_index(area_id_t id, const std::string &geometry) {
Expand Down
11 changes: 3 additions & 8 deletions src/osm-transform.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@

#include <boost/regex.hpp>

#include <osmium/io/any_input.hpp>
#include <osmium/io/any_output.hpp>
#include <osmium/util/file.hpp>
#include <osmium/util/progress_bar.hpp>
Expand Down Expand Up @@ -74,7 +73,6 @@ void first_pass(Config &config, boost::regex &remove_tag_regex,
printf("Processed in %.3f s\n\n", chrono::duration_cast<chrono::milliseconds>(chrono::steady_clock::now() - start).count() / 1000.0);
}


void copy(const std::string& input, osmium::io::Writer& writer) {
osmium::io::Reader reader{input};
osmium::ProgressBar progress{reader.file_size(), osmium::isatty(2)};
Expand Down Expand Up @@ -120,7 +118,6 @@ void second_pass(Config &config, boost::regex &remove_tag_regex,
RewriteHandler handler(1000000000, location_index, location_elevation_service, location_area_service, remove_tag_regex, valid_ids, no_elevation, config.interpolate, config.interpolate_threshold);
handler.add_elevation_ = config.add_elevation;


if (config.interpolate) {
auto wr_output = remove_extension(std::filesystem::path(config.filename.c_str()).stem()) + ".ors.wr.pbf";
osmium::io::Writer wr_writer{wr_output, header, osmium::io::overwrite::allow};
Expand All @@ -144,9 +141,7 @@ void second_pass(Config &config, boost::regex &remove_tag_regex,
progress.done();
reader.close();


osmium::io::Writer writer{output, header, osmium::io::overwrite::allow};
auto total_size = std::filesystem::file_size(n_output) + std::filesystem::file_size(wr_output);
copy(n_output, writer);
std::remove(n_output.c_str());
copy(wr_output, writer);
Expand Down Expand Up @@ -175,6 +170,8 @@ void second_pass(Config &config, boost::regex &remove_tag_regex,
std::cout << "About " << mem << " KBytes used for node location index (in main memory or on disk).\n";
}

handler.printCountryStats();

const auto end = chrono::steady_clock::now();
printf("Processed in %.3f s\n", chrono::duration_cast<chrono::milliseconds>(end - start).count() / 1000.0);

Expand All @@ -185,7 +182,7 @@ void second_pass(Config &config, boost::regex &remove_tag_regex,
reduction, static_cast<float>(reduction) / static_cast<float>(insize) * 100);
if (config.add_elevation) {
auto valid_nodes = valid_ids.nodes().size();
printf("All Nodes: %19lu Nodes\n",valid_nodes);
printf("All Nodes: %19llu Nodes\n", valid_nodes);
if (config.interpolate) {
printf("Added Nodes: %17llu Nodes\n",handler.nodes_added_by_interpolation_);
}
Expand All @@ -211,5 +208,3 @@ void second_pass(Config &config, boost::regex &remove_tag_regex,
}
cout << endl;
}


10 changes: 10 additions & 0 deletions src/rewrite_handler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,16 @@ void RewriteHandler::node(const osmium::Node &node) {
}
}
auto countries = location_area_.get_area(node.location());
switch (countries.size()) {
case 0:
nodes_with_no_country_++;
break;
case 1:
nodes_with_single_country_++;
break;
default:
nodes_with_multiple_countries_++;
}
copy_tags(builder, node.tags(), ele, countries);
if (interpolate_) {
location_index_->set(static_cast<osmium::unsigned_object_id_type>(node.id()), node.location());
Expand Down
11 changes: 10 additions & 1 deletion src/rewrite_handler.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ class RewriteHandler : public osmium::handler::Handler {
void copy_tags(osmium::builder::Builder &parent, const osmium::TagList &tags, double ele, const std::vector<std::string>& countries);
void copy_tags(osmium::builder::Builder &parent, const osmium::TagList &tags);


auto get_node_location(const osmium::object_id_type id) -> osmium::Location {
return location_index_->get_noexcept(static_cast<osmium::unsigned_object_id_type>(id));
}
Expand All @@ -57,6 +56,9 @@ class RewriteHandler : public osmium::handler::Handler {
unsigned long long nodes_with_elevation_ = 0;
unsigned long long nodes_with_elevation_not_found_ = 0;
unsigned long long nodes_added_by_interpolation_ = 0;
unsigned long long nodes_with_single_country_ = 0;
unsigned long long nodes_with_multiple_countries_ = 0;
unsigned long long nodes_with_no_country_ = 0;

explicit RewriteHandler(const osmium::object_id_type next_node_id,
std::unique_ptr<osmium::index::map::Map<osmium::unsigned_object_id_type, osmium::Location>> &location_index,
Expand Down Expand Up @@ -91,6 +93,13 @@ class RewriteHandler : public osmium::handler::Handler {
void way(const osmium::Way &way);

void relation(const osmium::Relation &relation);

void printCountryStats() {
std::cout << "Nodes with no country: " << nodes_with_no_country_ << ", "
<< "single country: " << nodes_with_single_country_ << ", "
<< "multiple countries: " << nodes_with_multiple_countries_
<< std::endl;
};
};


Expand Down

0 comments on commit 4431bff

Please sign in to comment.