Skip to content

Commit

Permalink
prepare for concurrent conversion
Browse files Browse the repository at this point in the history
  • Loading branch information
Sven Jäger authored and Venator2013 committed Aug 12, 2024
1 parent 426e991 commit 37f83d4
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 16 deletions.
1 change: 1 addition & 0 deletions .devcontainer/vcpkg.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
"dependencies": [
"boost-log",
"boost-program-options",
"concurrencpp",
"icu",
"libosmium",
{
Expand Down
42 changes: 27 additions & 15 deletions plugins/navteq/converter/StreetConverter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,11 @@

#include "../../comm2osm_exceptions.hpp"

std::map<osmium::Location, osmium::unsigned_object_id_type>
StreetConverter::g_regionConnectingPoints;

std::mutex StreetConverter::g_regionConnectingPoints_mutex;

StreetConverter::StreetConverter(const std::filesystem::path &executable_path)
: Converter(executable_path) {}

Expand Down Expand Up @@ -327,8 +332,10 @@ StreetConverter::process_way_end_nodes(
&z_level_map,
osmium::io::Writer &writer) {

g_regionConnectingPoints_mutex.lock();
std::map<osmium::Location, osmium::unsigned_object_id_type>
way_end_points_map(regionConnectingPoints);
g_regionConnectingPoints_mutex.unlock();

auto path = dir / STREETS_SHP;
auto ds = openDataSource(path);
Expand Down Expand Up @@ -919,26 +926,31 @@ void StreetConverter::update_region_connecting_points(

osmium::memory::Buffer node_buffer(BUFFER_SIZE);

for (auto &feat : *layer) {
// lock the region connecting points
{
std::lock_guard<std::mutex> lock(g_regionConnectingPoints_mutex);

bool aligned = get_bool_from_feature(feat, ALIGNED);
if (!aligned)
continue;
for (auto &feat : *layer) {

auto geom = feat->GetGeometryRef();
auto geom_type = geom->getGeometryType();
bool aligned = get_bool_from_feature(feat, ALIGNED);
if (!aligned)
continue;

if (geom_type != wkbPoint) {
throw(std::runtime_error("Region connecting points with geometry=" +
std::string(geom->getGeometryName()) +
" is not yet supported."));
}
auto geom = feat->GetGeometryRef();
auto geom_type = geom->getGeometryType();

auto point = static_cast<OGRPoint *>(geom);
if (geom_type != wkbPoint) {
throw(std::runtime_error("Region connecting points with geometry=" +
std::string(geom->getGeometryName()) +
" is not yet supported."));
}

// process the region connecting points
process_way_end_node(osmium::Location(point->getX(), point->getY()), data,
regionConnectingPoints, node_buffer);
auto point = static_cast<OGRPoint *>(geom);

// process the region connecting points
process_way_end_node(osmium::Location(point->getX(), point->getY()), data,
regionConnectingPoints, node_buffer);
}
}

node_buffer.commit();
Expand Down
4 changes: 3 additions & 1 deletion plugins/navteq/converter/StreetConverter.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -427,8 +427,10 @@ class StreetConverter : public Converter {
const ushort CT_TRANSPORT_SPECIAL_SPEED_SITUATION = 25;

// should be global for connectivity between regions
std::map<osmium::Location, osmium::unsigned_object_id_type>
static std::map<osmium::Location, osmium::unsigned_object_id_type>
g_regionConnectingPoints;

static std::mutex g_regionConnectingPoints_mutex;
};

#endif // STREETCONVERTER_HPP

0 comments on commit 37f83d4

Please sign in to comment.