Skip to content

Commit

Permalink
add rest areas
Browse files Browse the repository at this point in the history
  • Loading branch information
Sven Jäger committed Jul 12, 2024
1 parent 02f243d commit 58cc1fd
Show file tree
Hide file tree
Showing 7 changed files with 138 additions and 76 deletions.
4 changes: 4 additions & 0 deletions plugins/navteq/converter/Converter.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,10 @@ class Converter {

static constexpr std::string_view FEAT_COD = "FEAT_COD";
static constexpr std::string_view POLYGON_NM = "POLYGON_NM";

static constexpr std::string_view FAC_TYPE = "FAC_TYPE";
static constexpr std::string_view POI_NMTYPE = "POI_NMTYPE";
static constexpr std::string_view POI_NAME = "POI_NAME";
};

#endif // CONVERTER_HPP
89 changes: 89 additions & 0 deletions plugins/navteq/converter/RestAreaConverter.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
/*
* This file is part of the Morituri project.
* Morituri is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Morituri is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Morituri. If not, see <https://www.gnu.org/licenses/>.
*/

#include "RestAreaConverter.hpp"

void RestAreaConverter::convert(
const std::vector<boost::filesystem::path> &dirs,
osmium::io::Writer &writer) {

const boost::filesystem::path TRAVDEST_SHP = "TravDest.shp";
for (auto dir : dirs) {
add_rest_area(dir / TRAVDEST_SHP, writer);
}
}

void RestAreaConverter::add_rest_area(boost::filesystem::path rest_area_file,
osmium::io::Writer &writer) {

auto ds = GDALDatasetUniquePtr(GDALDataset::Open(rest_area_file.c_str()));
if (!ds) {
BOOST_LOG_TRIVIAL(debug) << "No rest area shp found in " << rest_area_file;
return;
}
auto layer = ds->GetLayer(0);
if (!layer) {
throw(shp_empty_error(rest_area_file.string()));
}

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

int facTypeField = layer->FindFieldIndex(FAC_TYPE.data(), true);
int poiNmTypeField = layer->FindFieldIndex(POI_NMTYPE.data(), true);

for (auto &feat : *layer) {
uint fac_type = feat->GetFieldAsInteger(facTypeField);
if (fac_type != 7897) {
continue;
}

std::string name_type = feat->GetFieldAsString(poiNmTypeField);
if (name_type != "B") {
// Skip this entry as it's just a translated namePlc of former one
continue;
}
process_rest_area(feat, node_buffer);
}
writer(std::move(node_buffer));
}

void RestAreaConverter::process_rest_area(const OGRFeatureUniquePtr &feat,
osmium::memory::Buffer &node_buffer) {

auto geom = feat->GetGeometryRef();
auto geom_type = geom->getGeometryType();

if (geom_type != wkbPoint) {
throw(std::runtime_error(
"Rest area item with geometry=" + std::string(geom->getGeometryName()) +
" is not yet supported."));
}

auto point = static_cast<OGRPoint *>(geom);
osmium::Location location(point->getX(), point->getY());
{
// scope node_builder
// Add new node
osmium::builder::NodeBuilder node_builder(node_buffer);
build_node(location, &node_builder);
osmium::builder::TagListBuilder tl_builder(node_builder);

std::string name = feat->GetFieldAsString(POI_NAME.data());
tl_builder.add_tag("name", to_camel_case_with_spaces(name));
tl_builder.add_tag("highway", "rest_area");
}
node_buffer.commit();
}
41 changes: 41 additions & 0 deletions plugins/navteq/converter/RestAreaConverter.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
/*
* This file is part of the Morituri project.
* Morituri is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Morituri is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Morituri. If not, see <https://www.gnu.org/licenses/>.
*/

#ifndef RESTAREACONVERTER_HPP
#define RESTAREACONVERTER_HPP

#include "Converter.hpp"

#include <ogrsf_frmts.h>

class RestAreaConverter : public Converter {

public:
RestAreaConverter();
virtual ~RestAreaConverter();

virtual void convert(const std::vector<boost::filesystem::path> &dirs,
osmium::io::Writer &writer);

private:
void add_rest_area(boost::filesystem::path rest_area_file,
osmium::io::Writer &writer);

void process_rest_area(const OGRFeatureUniquePtr &feat,
osmium::memory::Buffer &node_buffer);
};

#endif // RESTAREACONVERTER_HPP
64 changes: 0 additions & 64 deletions plugins/navteq/navteq.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -1239,34 +1239,6 @@ void process_hamlets(const OGRFeatureUniquePtr &feat,
node_buffer.commit();
}

void process_rest_area(const OGRFeatureUniquePtr &feat,
osmium::memory::Buffer &node_buffer) {

auto geom = feat->GetGeometryRef();
auto geom_type = geom->getGeometryType();

if (geom_type != wkbPoint) {
throw(std::runtime_error(
"Rest area item with geometry=" + std::string(geom->getGeometryName()) +
" is not yet supported."));
}

auto point = static_cast<OGRPoint *>(geom);
osmium::Location location(point->getX(), point->getY());
{
// scope node_builder
// Add new node
osmium::builder::NodeBuilder node_builder(node_buffer);
build_node(location, &node_builder);
osmium::builder::TagListBuilder tl_builder(node_builder);

std::string name = feat->GetFieldAsString(POI_NAME);
tl_builder.add_tag("name", to_camel_case_with_spaces(name));
tl_builder.add_tag("highway", "rest_area");
}
node_buffer.commit();
}

/**
* \brief adds tags from administrative boundaries to mtd_area_map.
* adds tags from administrative boundaries to mtd_area_map
Expand Down Expand Up @@ -1435,42 +1407,6 @@ void add_hamlet_nodes(const std::vector<boost::filesystem::path> &dirs,
}
}

void add_rest_area_nodes(const std::vector<boost::filesystem::path> &dirs,
osmium::io::Writer &writer) {

for (auto dir : dirs) {

// hamlets are optional
if (!shp_file_exists(dir / TRAVDEST_SHP))
continue;

auto ds = open_shape_file(dir / TRAVDEST_SHP);
auto layer = ds->GetLayer(0);
if (layer == nullptr)
throw(shp_empty_error(dir.string()));

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

int facTypeField = layer->FindFieldIndex(FAC_TYPE, true);
int poiNmTypeField = layer->FindFieldIndex(POI_NMTYPE, true);

for (auto &feat : *layer) {
uint fac_type = feat->GetFieldAsInteger(facTypeField);
if (fac_type != 7897) {
continue;
}

std::string name_type = feat->GetFieldAsString(poiNmTypeField);
if (name_type != "B") {
// Skip this entry as it's just a translated namePlc of former one
continue;
}
process_rest_area(feat, node_buffer);
}
writer(std::move(node_buffer));
}
}

void init_g_cnd_mod_map(const boost::filesystem::path &dir) {
DBFHandle cnd_mod_handle = read_dbf_file(dir / CND_MOD_DBF);
for (int i = 0; i < DBFGetRecordCount(cnd_mod_handle); i++) {
Expand Down
3 changes: 0 additions & 3 deletions plugins/navteq/navteq_mappings.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,11 @@ static const boost::filesystem::path ADMINBNDY_3_SHP = "Adminbndy3.shp";
static const boost::filesystem::path ADMINBNDY_4_SHP = "Adminbndy4.shp";
static const boost::filesystem::path ADMINBNDY_5_SHP = "Adminbndy5.shp";

static const boost::filesystem::path RAILWAYS_POLY_SHP = "RailRds.shp";
static const boost::filesystem::path LAND_USE_A_SHP = "LandUseA.shp";
static const boost::filesystem::path LAND_USE_B_SHP = "LandUseB.shp";
static const boost::filesystem::path NAMED_PLC_SHP = "NamedPlc.shp";
static const boost::filesystem::path HAMLET_SHP = "Hamlet.shp";
static const boost::filesystem::path POINT_ADDRESS_SHP = "PointAddress.shp";
static const boost::filesystem::path LANDMARK_SHP = "Landmark.shp";
static const boost::filesystem::path TRAVDEST_SHP = "TravDest.shp";

static const boost::filesystem::path MTD_CNTRY_REF_DBF = "MtdCntryRef.dbf";
static const boost::filesystem::path MTD_AREA_DBF = "MtdArea.dbf";
Expand Down
10 changes: 4 additions & 6 deletions plugins/navteq/navteq_plugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@
#include <osmium/io/any_input.hpp>
#include <osmium/io/any_output.hpp>

#include "converter/BuildingConverter.hpp"
#include "converter/RailwayConverter.hpp"
#include "converter/RestAreaConverter.hpp"
#include "converter/WaterConverter.hpp"

#include "navteq.hpp"
Expand All @@ -34,6 +36,8 @@ navteq_plugin::navteq_plugin(const boost::filesystem::path &executable_path)
// setting executable_path in navteq2osm_tag_parser.hpp for reading ISO-file
g_executable_path = this->executable_path;

converter.emplace_back(new BuildingConverter());
converter.emplace_back(new RestAreaConverter());
converter.emplace_back(new RailwayConverter());
converter.emplace_back(new WaterConverter());
}
Expand Down Expand Up @@ -246,12 +250,6 @@ void navteq_plugin::execute() {
BOOST_LOG_TRIVIAL(info) << "Add hamlet nodes";
add_hamlet_nodes(dataDirs, writer);

BOOST_LOG_TRIVIAL(info) << "Add buildings";
add_buildings(dataDirs, writer);

BOOST_LOG_TRIVIAL(info) << "Add rest areas";
add_rest_area_nodes(dataDirs, writer);

// run converters
for (auto &c : converter)
c->convert(dataDirs, writer);
Expand Down
3 changes: 0 additions & 3 deletions plugins/navteq/navteq_plugin.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,6 @@ class navteq_plugin : public base_plugin {
void add_landuse(const std::vector<boost::filesystem::path> &dirs,
osmium::io::Writer &writer);

void add_buildings(const std::vector<boost::filesystem::path> &dirs,
osmium::io::Writer &writer);

void sortPBF();
void copyType(osmium::io::Writer &writer, osmium::io::File &file,
osmium::osm_entity_bits::type bits);
Expand Down

0 comments on commit 58cc1fd

Please sign in to comment.