49#pragma warning(disable: 4435 5219 5220)
52#pragma GCC diagnostic push
53#pragma GCC diagnostic ignored "-Wpedantic"
55#include <ogrsf_frmts.h>
57#pragma GCC diagnostic pop
73 if (!oc.
isSet(
"shapefile-prefix")) {
78 const std::string dbf_file = oc.
getString(
"shapefile-prefix") +
".dbf";
79 const std::string shp_file = oc.
getString(
"shapefile-prefix") +
".shp";
80 const std::string shx_file = oc.
getString(
"shapefile-prefix") +
".shx";
98 shp_file, oc.
getBool(
"speed-in-kmh"));
111 const std::string& shp_name,
113 : myOptions(oc), mySHPName(shp_name),
115 myNodeCont(nc), myEdgeCont(ec), myTypeCont(tc),
116 mySpeedInKMH(speedInKMH),
129#if GDAL_VERSION_MAJOR < 2
131 OGRDataSource* poDS = OGRSFDriverRegistrar::Open(
mySHPName.c_str(), FALSE);
134 GDALDataset* poDS = (GDALDataset*)GDALOpenEx(
mySHPName.c_str(), GDAL_OF_VECTOR | GA_ReadOnly, NULL, NULL, NULL);
142 OGRLayer* poLayer = poDS->GetLayer(0);
143 poLayer->ResetReading();
146 OGRSpatialReference* origTransf = poLayer->GetSpatialRef();
147 OGRSpatialReference destTransf;
149 destTransf.SetWellKnownGeogCS(
"WGS84");
150#if GDAL_VERSION_MAJOR > 2
151 if (
myOptions.
getBool(
"shapefile.traditional-axis-mapping") || origTransf !=
nullptr) {
152 destTransf.SetAxisMappingStrategy(OAMS_TRADITIONAL_GIS_ORDER);
155 OGRCoordinateTransformation* poCT = origTransf ==
nullptr ? nullptr : OGRCreateCoordinateTransformation(origTransf, &destTransf);
156 if (poCT ==
nullptr) {
158 OGRSpatialReference origTransf2;
159 origTransf2.SetWellKnownGeogCS(
"WGS84");
160 poCT = OGRCreateCoordinateTransformation(&origTransf2, &destTransf);
165 OGRFeature* poFeature;
166 poLayer->ResetReading();
171 int featureIndex = 0;
172 bool warnNotUnique =
true;
173 bool warnMissingProjection =
true;
174 std::string idPrefix =
"";
175 std::map<std::string, int> idIndex;
176 while ((poFeature = poLayer->GetNextFeature()) != NULL) {
178 if (featureIndex == 0) {
183 std::string from_node;
185 if (!getStringEntry(poFeature,
"shapefile.street-id",
"LINK_ID",
true,
id)) {
193 getStringEntry(poFeature,
"shapefile.name",
"ST_NAME",
true, name);
196 if (!getStringEntry(poFeature,
"shapefile.from-id",
"REF_IN_ID",
true, from_node)) {
197 WRITE_ERRORF(
TL(
"Needed field '%' (from node id) is missing."), from_node);
200 if (!getStringEntry(poFeature,
"shapefile.to-id",
"NREF_IN_ID",
true, to_node)) {
201 WRITE_ERRORF(
TL(
"Needed field '%' (to node id) is missing."), to_node);
205 if (from_node ==
"" || to_node ==
"") {
213 }
else if (poFeature->GetFieldIndex(
"ST_TYP_AFT") >= 0) {
214 type = poFeature->GetFieldAsString(
"ST_TYP_AFT");
220 double speed = getSpeed(*poFeature,
id);
221 int nolanes = getLaneNo(*poFeature,
id, speed);
222 int priority = getPriority(*poFeature,
id);
223 double width = getLaneWidth(*poFeature,
id, nolanes);
224 double length = getLength(*poFeature,
id);
225 if (nolanes <= 0 || speed <= 0) {
232 WRITE_ERRORF(
TL(
"Required field '%' or '%' is missing (add fields or set option --shapefile.use-defaults-on-failure)."), lanesField, speedField);
234 OGRFeature::DestroyFeature(poFeature);
244 OGRGeometry* poGeometry = poFeature->GetGeometryRef();
245 OGRwkbGeometryType gtype = poGeometry->getGeometryType();
246 if (gtype != wkbLineString && gtype != wkbLineString25D) {
247 OGRFeature::DestroyFeature(poFeature);
248 WRITE_ERRORF(
TL(
"Road geometry must be of type 'linestring' or 'linestring25D' (found '%')"),
toString(gtype));
251 OGRLineString* cgeom = (OGRLineString*) poGeometry;
252 if (poCT ==
nullptr && warnMissingProjection) {
254 for (
int j = 0; j < cgeom->getNumPoints(); j++) {
255 if (fabs(cgeom->getX(j)) > 180 || fabs(cgeom->getY(j)) > 90) {
259 if (2 * outOfRange > cgeom->getNumPoints()) {
260 WRITE_WARNING(
TL(
"No coordinate system found and coordinates look already projected."));
263 WRITE_WARNING(
TL(
"Could not find geo coordinate system, assuming WGS84."));
265 warnMissingProjection =
false;
267 if (poCT !=
nullptr) {
269 cgeom->transform(poCT);
273 for (
int j = 0; j < cgeom->getNumPoints(); j++) {
274 Position pos(cgeom->getX(j), cgeom->getY(j), cgeom->getZ(j));
283 if (from ==
nullptr) {
286 if (from ==
nullptr) {
287 from =
new NBNode(from_node, from_pos);
301 to =
new NBNode(to_node, to_pos);
317 int index = poFeature->GetDefnRef()->GetFieldIndex(
"DIR_TRAVEL");
318 if (index >= 0 && poFeature->IsFieldSet(index)) {
319 dir = poFeature->GetFieldAsString(index);
321 const std::string origID = saveOrigIDs ? id :
"";
325 if (existing !=
nullptr || existingReverse !=
nullptr) {
326 if ((existing !=
nullptr && existing->
getGeometry() == shape)
327 || (existingReverse !=
nullptr && existingReverse->
getGeometry() == shape.
reverse())) {
328 WRITE_ERRORF(
TL(
"Edge '%' is not unique."), (existing !=
nullptr ?
id : existingReverse->
getID()));
330 if (idIndex.count(
id) == 0) {
337 WRITE_WARNINGF(
TL(
"Edge '%' is not unique. Renaming subsequent edge to '%'."), idPrefix,
id);
338 warnNotUnique =
false;
343 if (dir ==
"B" || dir ==
"F" || dir ==
"" ||
myOptions.
getBool(
"shapefile.all-bidirectional")) {
349 NBEdge* edge =
new NBEdge(
id, from, to, type, speed,
NBEdge::UNSPECIFIED_FRICTION, nolanes, priority, width,
NBEdge::UNSPECIFIED_OFFSET, shape, spread, name, origID);
354 addParams(edge, poFeature, params);
356 WRITE_ERRORF(
TL(
"Could not create edge '%'. An edge with the same id already exists."),
id);
360 if ((dir ==
"B" || dir ==
"T" ||
myOptions.
getBool(
"shapefile.all-bidirectional")) && !oneway) {
366 NBEdge* edge =
new NBEdge(
"-" +
id, to, from, type, speed,
NBEdge::UNSPECIFIED_FRICTION, nolanes, priority, width,
NBEdge::UNSPECIFIED_OFFSET, shape.
reverse(), spread, name, origID);
371 addParams(edge, poFeature, params);
373 WRITE_ERRORF(
TL(
"Could not create edge '-%'. An edge with the same id already exists."),
id);
377 OGRFeature::DestroyFeature(poFeature);
380#if GDAL_VERSION_MAJOR < 2
381 OGRDataSource::DestroyDataSource(poDS);
393NIImporter_ArcView::getSpeed(OGRFeature& poFeature,
const std::string& edgeid) {
395 int index = poFeature.GetDefnRef()->GetFieldIndex(
myOptions.
getString(
"shapefile.speed").c_str());
396 if (index >= 0 && poFeature.IsFieldSet(index)) {
397 const double speed = poFeature.GetFieldAsDouble(index);
401 +
"': '" + std::string(poFeature.GetFieldAsString(index)) +
"'");
412 int index = poFeature.GetDefnRef()->GetFieldIndex(
"speed");
413 if (index >= 0 && poFeature.IsFieldSet(index)) {
414 return (
double) poFeature.GetFieldAsDouble(index);
416 index = poFeature.GetDefnRef()->GetFieldIndex(
"SPEED");
417 if (index >= 0 && poFeature.IsFieldSet(index)) {
418 return (
double) poFeature.GetFieldAsDouble(index);
421 index = poFeature.GetDefnRef()->GetFieldIndex(
"SPEED_CAT");
422 if (index >= 0 && poFeature.IsFieldSet(index)) {
423 std::string def = poFeature.GetFieldAsString(index);
431NIImporter_ArcView::getLaneWidth(OGRFeature& poFeature,
const std::string& edgeid,
int laneNumber) {
433 int index = poFeature.GetDefnRef()->GetFieldIndex(
myOptions.
getString(
"shapefile.width").c_str());
434 if (index >= 0 && poFeature.IsFieldSet(index)) {
435 const double width = poFeature.GetFieldAsDouble(index);
439 +
"' of edge '" + edgeid
440 +
"': '" + std::string(poFeature.GetFieldAsString(index)) +
"'");
442 return width / laneNumber;
455NIImporter_ArcView::getLength(OGRFeature& poFeature,
const std::string& edgeid) {
457 int index = poFeature.GetDefnRef()->GetFieldIndex(
myOptions.
getString(
"shapefile.length").c_str());
458 if (index >= 0 && poFeature.IsFieldSet(index)) {
459 const double length = poFeature.GetFieldAsDouble(index);
463 +
"' of edge '" + edgeid
464 +
"': '" + std::string(poFeature.GetFieldAsString(index)) +
"'");
475NIImporter_ArcView::getLaneNo(OGRFeature& poFeature,
const std::string& edgeid,
478 int index = poFeature.GetDefnRef()->GetFieldIndex(
myOptions.
getString(
"shapefile.laneNumber").c_str());
479 if (index >= 0 && poFeature.IsFieldSet(index)) {
480 const int laneNumber = poFeature.GetFieldAsInteger(index);
481 if (laneNumber <= 0) {
484 +
"': '" + std::string(poFeature.GetFieldAsString(index)) +
"'");
495 int index = poFeature.GetDefnRef()->GetFieldIndex(
"nolanes");
496 if (index >= 0 && poFeature.IsFieldSet(index)) {
497 return (
int) poFeature.GetFieldAsInteger(index);
499 index = poFeature.GetDefnRef()->GetFieldIndex(
"NOLANES");
500 if (index >= 0 && poFeature.IsFieldSet(index)) {
501 return (
int) poFeature.GetFieldAsInteger(index);
503 index = poFeature.GetDefnRef()->GetFieldIndex(
"rnol");
504 if (index >= 0 && poFeature.IsFieldSet(index)) {
505 return (
int) poFeature.GetFieldAsInteger(index);
507 index = poFeature.GetDefnRef()->GetFieldIndex(
"LANE_CAT");
508 if (index >= 0 && poFeature.IsFieldSet(index)) {
509 std::string def = poFeature.GetFieldAsString(index);
517NIImporter_ArcView::getPriority(OGRFeature& poFeature,
const std::string& ) {
523 int index = poFeature.GetDefnRef()->GetFieldIndex(
"priority");
524 if (index >= 0 && poFeature.IsFieldSet(index)) {
525 return poFeature.GetFieldAsInteger(index);
527 index = poFeature.GetDefnRef()->GetFieldIndex(
"PRIORITY");
528 if (index >= 0 && poFeature.IsFieldSet(index)) {
529 return poFeature.GetFieldAsInteger(index);
532 index = poFeature.GetDefnRef()->GetFieldIndex(
"FUNC_CLASS");
533 if (index >= 0 && poFeature.IsFieldSet(index)) {
534 return poFeature.GetFieldAsInteger(index);
540NIImporter_ArcView::checkSpread(
NBEdge* e) {
549NIImporter_ArcView::getStringEntry(OGRFeature* poFeature,
const std::string& optionName,
const char* defaultName,
bool prune, std::string& into) {
550 std::string v(defaultName);
554 if (poFeature->GetFieldIndex(v.c_str()) < 0) {
562 into = poFeature->GetFieldAsString((
char*)v.c_str());
569std::vector<std::string>
570NIImporter_ArcView::getFieldNames(OGRFeature* poFeature)
const {
571 std::vector<std::string> fields;
572 for (
int i = 0; i < poFeature->GetFieldCount(); i++) {
573 fields.push_back(poFeature->GetFieldDefnRef(i)->GetNameRef());
579NIImporter_ArcView::addParams(
NBEdge* edge, OGRFeature* poFeature,
const std::vector<std::string>& params)
const {
580 for (
const std::string& p : params) {
581 int index = poFeature->GetDefnRef()->GetFieldIndex(p.c_str());
582 if (index >= 0 && poFeature->IsFieldSet(index)) {
583 edge->
setParameter(p, poFeature->GetFieldAsString(index));
#define WRITE_WARNINGF(...)
#define WRITE_ERRORF(...)
#define WRITE_MESSAGE(msg)
#define WRITE_WARNING(msg)
#define PROGRESS_DONE_MESSAGE()
#define PROGRESS_BEGIN_MESSAGE(msg)
LaneSpreadFunction
Numbers representing special SUMO-XML-attribute values Information how the edge's lateral offset shal...
std::string toString(const T &t, std::streamsize accuracy=gPrecision)
static bool isReadable(std::string path)
Checks whether the given file is readable.
static GeoConvHelper & getProcessing()
the coordinate transformation to use for input conversion and processing
static bool init(OptionsCont &oc)
Initialises the processing and the final instance using the given options.
static MsgHandler * getErrorInstance()
Returns the instance to add errors to.
Storage for edges, including some functionality operating on multiple edges.
NBEdge * retrieve(const std::string &id, bool retrieveExtracted=false) const
Returns the edge that has the given id.
bool insert(NBEdge *edge, bool ignorePrunning=false)
Adds an edge to the dictionary.
The representation of a single edge during network building.
void setPermissions(SVCPermissions permissions, int lane=-1)
set allowed/disallowed classes for the given lane or for all lanes if -1 is given
NBNode * getToNode() const
Returns the destination node of the edge.
static const double UNSPECIFIED_FRICTION
unspecified lane friction
const PositionVector & getGeometry() const
Returns the geometry of the edge.
const std::string & getID() const
static const double UNSPECIFIED_LOADED_LENGTH
no length override given
void setLaneSpreadFunction(LaneSpreadFunction spread)
(Re)sets how the lanes lateral offset shall be computed
NBNode * getFromNode() const
Returns the origin node of the edge.
static const double UNSPECIFIED_WIDTH
unspecified lane width
static const double UNSPECIFIED_OFFSET
unspecified lane offset
void setLoadedLength(double val)
set loaded length
Instance responsible for building networks.
NBNodeCont & getNodeCont()
Returns a reference to the node container.
NBEdgeCont & getEdgeCont()
NBTypeCont & getTypeCont()
Returns a reference to the type container.
static bool transformCoordinate(Position &from, bool includeInBoundary=true, GeoConvHelper *from_srs=nullptr)
transforms loaded coordinates handles projections, offsets (using GeoConvHelper) and import of height...
Container for nodes during the netbuilding process.
bool insert(const std::string &id, const Position &position, NBDistrict *district=0)
Inserts a node into the map.
NBNode * retrieve(const std::string &id) const
Returns the node with the given name.
Represents a single node (junction) during network building.
NBEdge * getConnectionTo(NBNode *n) const
get connection to certain node
A storage for available edgeTypes of edges.
double getEdgeTypeSpeed(const std::string &edgeType) const
Returns the maximal velocity for the given edgeType [m/s].
int getEdgeTypePriority(const std::string &edgeType) const
Returns the priority for the given edgeType.
int getEdgeTypeNumLanes(const std::string &edgeType) const
Returns the number of lanes for the given edgeType.
double getEdgeTypeWidth(const std::string &edgeType) const
Returns the lane width for the given edgeType [m].
SVCPermissions getEdgeTypePermissions(const std::string &edgeType) const
Returns allowed vehicle classes for the given edgeType.
bool knows(const std::string &edgeType) const
Returns whether the named edgeType is in the container.
bool getEdgeTypeIsOneWay(const std::string &edgeType) const
Returns whether edges are one-way per default for the given edgeType.
Importer for networks stored in ArcView-shape format.
const OptionsCont & myOptions
The options to use.
void load()
Loads the shape files.
int myRunningEdgeID
A running number to assure unique ids (as fallback)
static void loadNetwork(const OptionsCont &oc, NBNetBuilder &nb)
Loads content of the optionally given ArcView Shape files.
std::string mySHPName
The name of the shape file.
NBTypeCont & myTypeCont
The container to get the types from.
NBNodeCont & myNodeCont
The container to add nodes to.
bool mySpeedInKMH
Whether the speed is given in km/h.
~NIImporter_ArcView()
Destructor.
NBEdgeCont & myEdgeCont
The container to add edges to.
NIImporter_ArcView(const OptionsCont &oc, NBNodeCont &nc, NBEdgeCont &ec, NBTypeCont &tc, const std::string &shp_name, bool speedInKMH)
Constructor.
static int getLaneNumber(const std::string &id, const std::string &laneNoS, double speed)
Returns the lane number evaluating the given Navteq-description.
static double getSpeed(const std::string &id, const std::string &speedClassS)
Returns the speed evaluating the given Navteq-description.
A storage for options typed value containers)
bool isSet(const std::string &name, bool failOnNonExistant=true) const
Returns the information whether the named option is set.
double getFloat(const std::string &name) const
Returns the double-value of the named option (only for Option_Float)
std::string getString(const std::string &name) const
Returns the string-value of the named option (only for Option_String)
bool getBool(const std::string &name) const
Returns the boolean-value of the named option (only for Option_Bool)
const StringVector & getStringVector(const std::string &name) const
Returns the list of string-value of the named option (only for Option_StringVector)
static OptionsCont & getOptions()
Retrieves the options.
virtual void setParameter(const std::string &key, const std::string &value)
Sets a parameter.
A point in 2D or 3D with translation and scaling methods.
void push_back_noDoublePos(const Position &p)
insert in back a non double position
PositionVector reverse() const
reverse position vector
static std::string replace(std::string str, const std::string &what, const std::string &by)
Replaces all occurrences of the second string by the third string within the first string.
static std::string prune(const std::string &str)
Removes trailing and leading whitechars.
static bool startsWith(const std::string &str, const std::string prefix)
Checks whether a given string starts with the prefix.