Skip to content

Commit

Permalink
refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
Sven Jäger committed Jul 15, 2024
1 parent 360b666 commit 1c08a0e
Show file tree
Hide file tree
Showing 4 changed files with 104 additions and 82 deletions.
87 changes: 86 additions & 1 deletion plugins/navteq/converter/StreetConverter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ void StreetConverter::init_g_cnd_mod_map(const boost::filesystem::path &dir) {
const boost::filesystem::path CND_MOD_DBF = "CndMod.dbf";
DBFHandle cnd_mod_handle = read_dbf_file(dir / CND_MOD_DBF);
for (int i = 0; i < DBFGetRecordCount(cnd_mod_handle); i++) {
uint64_t cond_id = dbf_get_uint_by_field(cnd_mod_handle, i, COND_ID);
uint64_t cond_id = dbf_get_uint_by_field(cnd_mod_handle, i, COND_ID.data());
std::string lang_code =
dbf_get_string_by_field(cnd_mod_handle, i, LANG_CODE.data());
uint64_t mod_type =
Expand Down Expand Up @@ -375,6 +375,91 @@ void StreetConverter::parse_ramp_names(
}
}

void StreetConverter::process_way(
const std::vector<boost::filesystem::path> &dirs,
const std::map<uint64_t, std::vector<z_lvl_index_type_t>> &z_level_map,
osmium::io::Writer &writer) {
for (auto &dir : dirs) {
// parse highway names and refs
auto hwys_ref_map = init_highway_names(dir);

// parse conditionals
init_under_construction(dir);

auto path = dir / STREETS_SHP;
auto ds = open_shape_file(path);

auto layer = ds->GetLayer(0);
if (layer == nullptr)
throw(shp_empty_error(path.string()));

osmium::memory::Buffer node_buffer(BUFFER_SIZE);
osmium::memory::Buffer way_buffer(BUFFER_SIZE);
for (auto &feat : *layer) {
process_way(feat, z_level_map, node_buffer, way_buffer);
}

node_buffer.commit();
way_buffer.commit();
writer(std::move(node_buffer));
writer(std::move(way_buffer));

g_hwys_ref_map.clear();
}
}

std::map<uint64_t, std::map<uint, std::string>>
StreetConverter::init_highway_names(const boost::filesystem::path &dir) {
std::map<uint64_t, std::map<uint, std::string>> hwys_ref_map;
if (dbf_file_exists(dir / MAJ_HWYS_DBF))
parse_highway_names(dir / MAJ_HWYS_DBF, hwys_ref_map, false);
if (dbf_file_exists(dir / SEC_HWYS_DBF))
parse_highway_names(dir / SEC_HWYS_DBF, hwys_ref_map, false);
if (dbf_file_exists(dir / ALT_STREETS_DBF))
parse_highway_names(dir / ALT_STREETS_DBF, hwys_ref_map, true);
if (dbf_file_exists(dir / STREETS_DBF))
parse_highway_names(dir / STREETS_DBF, hwys_ref_map, true);

return hwys_ref_map;
}

void StreetConverter::parse_highway_names(
const boost::filesystem::path &dbf_file,
std::map<uint64_t, std::map<uint, std::string>> &hwys_ref_map,
bool isStreetLayer) {
DBFHandle hwys_handle = read_dbf_file(dbf_file);
for (int i = 0; i < DBFGetRecordCount(hwys_handle); i++) {

uint64_t link_id = dbf_get_uint_by_field(hwys_handle, i, LINK_ID.data());
std::string hwy_name;
if (isStreetLayer)
hwy_name = dbf_get_string_by_field(hwys_handle, i, ST_NAME.data());
else
hwy_name = dbf_get_string_by_field(hwys_handle, i, HIGHWAY_NM.data());

uint routeType = dbf_get_uint_by_field(hwys_handle, i, ROUTE.data());

hwys_ref_map[link_id].emplace(routeType, hwy_name);
}
DBFClose(hwys_handle);
}

void StreetConverter::init_under_construction(
const boost::filesystem::path &dir) {
if (!dbf_file_exists(dir / CDMS_DBF))
return;

DBFHandle cond = read_dbf_file(dir / CDMS_DBF);
for (int i = 0; i < DBFGetRecordCount(cond); i++) {
uint64_t link_id = dbf_get_uint_by_field(cond, i, LINK_ID);
uint condType = dbf_get_uint_by_field(cond, i, COND_TYPE);

if (condType == 3)
g_construction_set.emplace(link_id);
}
DBFClose(cond);
}

void StreetConverter::process_way(
OGRFeatureUniquePtr &feat,
const std::map<uint64_t, std::vector<z_lvl_index_type_t>> &z_level_map,
Expand Down
17 changes: 17 additions & 0 deletions plugins/navteq/converter/StreetConverter.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,10 @@ class StreetConverter : public Converter {
std::map<osmium::Location, std::map<uint, std::string>> &ramps_ref_map,
const std::map<uint64_t, std::string> &junctionNames);

void process_way(
const std::vector<boost::filesystem::path> &dirs,
const std::map<uint64_t, std::vector<z_lvl_index_type_t>> &z_level_map,
osmium::io::Writer &writer);
void process_way(
OGRFeatureUniquePtr &feat,
const std::map<uint64_t, std::vector<z_lvl_index_type_t>> &z_level_map,
Expand Down Expand Up @@ -150,6 +154,13 @@ class StreetConverter : public Converter {
const std::map<uint64_t, std::map<uint, std::string>> &names_map,
const std::set<uint64_t> &construction_set, bool debugMode);

std::map<uint64_t, std::map<uint, std::string>>
init_highway_names(const boost::filesystem::path &dir);

void parse_highway_names(
const boost::filesystem::path &dbf_file,
std::map<uint64_t, std::map<uint, std::string>> &hwys_ref_map,
bool isStreetLayer);
void add_additional_restrictions(
osmium::builder::TagListBuilder &builder, uint64_t link_id,
uint64_t l_area_id, uint64_t r_area_id,
Expand Down Expand Up @@ -242,6 +253,8 @@ class StreetConverter : public Converter {

bool only_pedestrians(const OGRFeatureUniquePtr &f);

void init_under_construction(const boost::filesystem::path &dir);

// CndMod types (CM)
static constexpr std::string_view CM_MOD_TYPE = "MOD_TYPE";
static constexpr std::string_view CM_MOD_VAL = "MOD_VAL";
Expand Down Expand Up @@ -325,6 +338,10 @@ class StreetConverter : public Converter {
static constexpr std::string_view HIGHWAY = "highway";
static constexpr std::string_view CONSTRUCTION = "construction";

static constexpr std::string_view HIGHWAY_NM = "HIGHWAY_NM";
static constexpr std::string_view ST_NAME = "ST_NAME";
static constexpr std::string_view COND_TYPE = "COND_TYPE";

// higway classification
const std::vector<std::string_view> DEFAULT_HWY_FUNC_TYPE = {
"", PRIMARY, SECONDARY, SECONDARY, TERTIARY, UNCLASSIFIED, RESIDENTIAL};
Expand Down
78 changes: 0 additions & 78 deletions plugins/navteq/navteq.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -226,84 +226,6 @@ void init_cdms_map(
}
}

void init_under_construction(const boost::filesystem::path &dir) {
if (!dbf_file_exists(dir / CDMS_DBF))
return;

DBFHandle cond = read_dbf_file(dir / CDMS_DBF);
for (int i = 0; i < DBFGetRecordCount(cond); i++) {
link_id_type link_id = dbf_get_uint_by_field(cond, i, LINK_ID);
uint condType = dbf_get_uint_by_field(cond, i, COND_TYPE);

if (condType == 3)
g_construction_set.emplace(link_id);
}
DBFClose(cond);
}

void parse_highway_names(const boost::filesystem::path &dbf_file,
bool isStreetLayer) {
DBFHandle hwys_handle = read_dbf_file(dbf_file);
for (int i = 0; i < DBFGetRecordCount(hwys_handle); i++) {

link_id_type link_id = dbf_get_uint_by_field(hwys_handle, i, LINK_ID);
std::string hwy_name;
if (isStreetLayer)
hwy_name = dbf_get_string_by_field(hwys_handle, i, ST_NAME);
else
hwy_name = dbf_get_string_by_field(hwys_handle, i, HIGHWAY_NM);

uint routeType = dbf_get_uint_by_field(hwys_handle, i, ROUTE);

g_hwys_ref_map[link_id].emplace(routeType, hwy_name);
}
DBFClose(hwys_handle);
}

void init_highway_names(const boost::filesystem::path &dir) {
if (dbf_file_exists(dir / MAJ_HWYS_DBF))
parse_highway_names(dir / MAJ_HWYS_DBF, false);
if (dbf_file_exists(dir / SEC_HWYS_DBF))
parse_highway_names(dir / SEC_HWYS_DBF, false);
if (dbf_file_exists(dir / ALT_STREETS_DBF))
parse_highway_names(dir / ALT_STREETS_DBF, true);
if (dbf_file_exists(dir / STREETS_DBF))
parse_highway_names(dir / STREETS_DBF, true);
}

void process_way(const std::vector<boost::filesystem::path> &dirs,
z_lvl_map &z_level_map, osmium::io::Writer &writer) {
for (auto &dir : dirs) {
// parse highway names and refs
init_highway_names(dir);

// parse conditionals
init_under_construction(dir);

auto path = dir / STREETS_SHP;
auto ds = open_shape_file(path);

auto layer = ds->GetLayer(0);
if (layer == nullptr)
throw(shp_empty_error(path.string()));
boost::timer::progress_display progress(layer->GetFeatureCount());

osmium::memory::Buffer node_buffer(buffer_size);
osmium::memory::Buffer way_buffer(buffer_size);
for (auto &feat : *layer) {
process_way(feat, &z_level_map, node_buffer, way_buffer);
++progress;
}

node_buffer.commit();
way_buffer.commit();
writer(std::move(node_buffer));
writer(std::move(way_buffer));

g_hwys_ref_map.clear();
}
}

auto createPointAddressMapList(const boost::filesystem::path dir) {

auto pointAddressMap =
Expand Down
4 changes: 1 addition & 3 deletions plugins/navteq/navteq_mappings.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ static const boost::filesystem::path STREETS_DBF = "Streets.dbf";

// STREETS columns
const char *LINK_ID = "LINK_ID";
const char *ST_NAME = "ST_NAME";

const char *ADDR_TYPE = "ADDR_TYPE";
const char *L_REFADDR = "L_REFADDR";
Expand All @@ -53,15 +52,14 @@ const char *R_ADDRSCH = "R_ADDRSCH";
const char *COND_ID = "COND_ID";

// CDMS_DBF columns
const char *COND_TYPE = "COND_TYPE";

// const char *COND_VAL1 = "COND_VAL1";
// const char *COND_VAL2 = "COND_VAL2";
// const char *COND_VAL3 = "COND_VAL3";
// const char *COND_VAL4 = "COND_VAL4";

// MAJ_HWYS columns
// const char* LINK_ID = "LINK_ID";
const char *HIGHWAY_NM = "HIGHWAY_NM";

// condition types (CT)
#define CT_RESTRICTED_DRIVING_MANOEUVRE 7
Expand Down

0 comments on commit 1c08a0e

Please sign in to comment.