diff --git a/plugins/navteq/converter/StreetConverter.cpp b/plugins/navteq/converter/StreetConverter.cpp index ef078a1..c1b3e4b 100644 --- a/plugins/navteq/converter/StreetConverter.cpp +++ b/plugins/navteq/converter/StreetConverter.cpp @@ -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 = @@ -375,6 +375,91 @@ void StreetConverter::parse_ramp_names( } } +void StreetConverter::process_way( + const std::vector &dirs, + const std::map> &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> +StreetConverter::init_highway_names(const boost::filesystem::path &dir) { + std::map> 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> &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> &z_level_map, diff --git a/plugins/navteq/converter/StreetConverter.hpp b/plugins/navteq/converter/StreetConverter.hpp index f6c12dc..7370aac 100644 --- a/plugins/navteq/converter/StreetConverter.hpp +++ b/plugins/navteq/converter/StreetConverter.hpp @@ -118,6 +118,10 @@ class StreetConverter : public Converter { std::map> &ramps_ref_map, const std::map &junctionNames); + void process_way( + const std::vector &dirs, + const std::map> &z_level_map, + osmium::io::Writer &writer); void process_way( OGRFeatureUniquePtr &feat, const std::map> &z_level_map, @@ -150,6 +154,13 @@ class StreetConverter : public Converter { const std::map> &names_map, const std::set &construction_set, bool debugMode); + std::map> + init_highway_names(const boost::filesystem::path &dir); + + void parse_highway_names( + const boost::filesystem::path &dbf_file, + std::map> &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, @@ -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"; @@ -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 DEFAULT_HWY_FUNC_TYPE = { "", PRIMARY, SECONDARY, SECONDARY, TERTIARY, UNCLASSIFIED, RESIDENTIAL}; diff --git a/plugins/navteq/navteq.hpp b/plugins/navteq/navteq.hpp index 19673f2..8f57a81 100644 --- a/plugins/navteq/navteq.hpp +++ b/plugins/navteq/navteq.hpp @@ -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 &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 = diff --git a/plugins/navteq/navteq_mappings.hpp b/plugins/navteq/navteq_mappings.hpp index df6405c..53c3dd9 100644 --- a/plugins/navteq/navteq_mappings.hpp +++ b/plugins/navteq/navteq_mappings.hpp @@ -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"; @@ -53,7 +52,7 @@ 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"; @@ -61,7 +60,6 @@ const char *COND_TYPE = "COND_TYPE"; // MAJ_HWYS columns // const char* LINK_ID = "LINK_ID"; -const char *HIGHWAY_NM = "HIGHWAY_NM"; // condition types (CT) #define CT_RESTRICTED_DRIVING_MANOEUVRE 7