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 std::string dbf_file = oc.
getString(
"shapefile-prefix") +
".dbf";
79 std::string shp_file = oc.
getString(
"shapefile-prefix") +
".shp";
80 std::string shx_file = oc.
getString(
"shapefile-prefix") +
".shx";
97 dbf_file, shp_file, oc.
getBool(
"speed-in-kmh"));
110 const std::string& dbf_name,
111 const std::string& shp_name,
113 : myOptions(oc), mySHPName(shp_name),
115 myNodeCont(nc), myEdgeCont(ec), myTypeCont(tc),
116 mySpeedInKMH(speedInKMH),
130 #if GDAL_VERSION_MAJOR < 2
132 OGRDataSource* poDS = OGRSFDriverRegistrar::Open(
mySHPName.c_str(), FALSE);
135 GDALDataset* poDS = (GDALDataset*)GDALOpenEx(
mySHPName.c_str(), GDAL_OF_VECTOR | GA_ReadOnly, NULL, NULL, NULL);
143 OGRLayer* poLayer = poDS->GetLayer(0);
144 poLayer->ResetReading();
147 OGRSpatialReference* origTransf = poLayer->GetSpatialRef();
148 OGRSpatialReference destTransf;
150 destTransf.SetWellKnownGeogCS(
"WGS84");
151 #if GDAL_VERSION_MAJOR > 2
152 if (
myOptions.
getBool(
"shapefile.traditional-axis-mapping") || origTransf !=
nullptr) {
153 destTransf.SetAxisMappingStrategy(OAMS_TRADITIONAL_GIS_ORDER);
156 OGRCoordinateTransformation* poCT = origTransf ==
nullptr ? nullptr : OGRCreateCoordinateTransformation(origTransf, &destTransf);
157 if (poCT ==
nullptr) {
159 OGRSpatialReference origTransf2;
160 origTransf2.SetWellKnownGeogCS(
"WGS84");
161 poCT = OGRCreateCoordinateTransformation(&origTransf2, &destTransf);
166 OGRFeature* poFeature;
167 poLayer->ResetReading();
172 int featureIndex = 0;
173 bool warnNotUnique =
true;
174 bool warnMissingProjection =
true;
175 std::string idPrefix =
"";
176 std::map<std::string, int> idIndex;
177 while ((poFeature = poLayer->GetNextFeature()) != NULL) {
179 if (featureIndex == 0) {
184 std::string from_node;
186 if (!getStringEntry(poFeature,
"shapefile.street-id",
"LINK_ID",
true,
id)) {
194 getStringEntry(poFeature,
"shapefile.name",
"ST_NAME",
true, name);
197 if (!getStringEntry(poFeature,
"shapefile.from-id",
"REF_IN_ID",
true, from_node)) {
198 WRITE_ERRORF(
TL(
"Needed field '%' (from node id) is missing."), from_node);
201 if (!getStringEntry(poFeature,
"shapefile.to-id",
"NREF_IN_ID",
true, to_node)) {
202 WRITE_ERRORF(
TL(
"Needed field '%' (to node id) is missing."), to_node);
206 if (from_node ==
"" || to_node ==
"") {
214 }
else if (poFeature->GetFieldIndex(
"ST_TYP_AFT") >= 0) {
215 type = poFeature->GetFieldAsString(
"ST_TYP_AFT");
221 double speed = getSpeed(*poFeature,
id);
222 int nolanes = getLaneNo(*poFeature,
id, speed);
223 int priority = getPriority(*poFeature,
id);
224 double width = getLaneWidth(*poFeature,
id, nolanes);
225 double length = getLength(*poFeature,
id);
226 if (nolanes <= 0 || speed <= 0) {
233 WRITE_ERRORF(
TL(
"Required field '%' or '%' is missing (add fields or set option --shapefile.use-defaults-on-failure)."), lanesField, speedField);
235 OGRFeature::DestroyFeature(poFeature);
245 OGRGeometry* poGeometry = poFeature->GetGeometryRef();
246 OGRwkbGeometryType gtype = poGeometry->getGeometryType();
247 if (gtype != wkbLineString && gtype != wkbLineString25D) {
248 OGRFeature::DestroyFeature(poFeature);
249 WRITE_ERRORF(
TL(
"Road geometry must be of type 'linestring' or 'linestring25D' (found '%')"),
toString(gtype));
252 OGRLineString* cgeom = (OGRLineString*) poGeometry;
253 if (poCT ==
nullptr && warnMissingProjection) {
255 for (
int j = 0; j < cgeom->getNumPoints(); j++) {
256 if (fabs(cgeom->getX(j)) > 180 || fabs(cgeom->getY(j)) > 90) {
260 if (2 * outOfRange > cgeom->getNumPoints()) {
261 WRITE_WARNING(
TL(
"No coordinate system found and coordinates look already projected."));
264 WRITE_WARNING(
TL(
"Could not find geo coordinate system, assuming WGS84."));
266 warnMissingProjection =
false;
268 if (poCT !=
nullptr) {
270 cgeom->transform(poCT);
274 for (
int j = 0; j < cgeom->getNumPoints(); j++) {
275 Position pos(cgeom->getX(j), cgeom->getY(j), cgeom->getZ(j));
284 if (from ==
nullptr) {
287 if (from ==
nullptr) {
288 from =
new NBNode(from_node, from_pos);
302 to =
new NBNode(to_node, to_pos);
318 int index = poFeature->GetDefnRef()->GetFieldIndex(
"DIR_TRAVEL");
319 if (index >= 0 && poFeature->IsFieldSet(index)) {
320 dir = poFeature->GetFieldAsString(index);
322 const std::string origID = saveOrigIDs ? id :
"";
326 if (existing !=
nullptr || existingReverse !=
nullptr) {
327 if ((existing !=
nullptr && existing->
getGeometry() == shape)
328 || (existingReverse !=
nullptr && existingReverse->
getGeometry() == shape.
reverse())) {
329 WRITE_ERRORF(
TL(
"Edge '%' is not unique."), (existing !=
nullptr ?
id : existingReverse->
getID()));
331 if (idIndex.count(
id) == 0) {
338 WRITE_WARNINGF(
TL(
"Edge '%' is not unique. Renaming subsequent edge to '%'."), idPrefix,
id);
339 warnNotUnique =
false;
344 if (dir ==
"B" || dir ==
"F" || dir ==
"" ||
myOptions.
getBool(
"shapefile.all-bidirectional")) {
350 NBEdge* edge =
new NBEdge(
id, from, to, type, speed,
NBEdge::UNSPECIFIED_FRICTION, nolanes, priority, width,
NBEdge::UNSPECIFIED_OFFSET, shape, spread, name, origID);
355 addParams(edge, poFeature, params);
357 WRITE_ERRORF(
TL(
"Could not create edge '%'. An edge with the same id already exists."),
id);
361 if ((dir ==
"B" || dir ==
"T" ||
myOptions.
getBool(
"shapefile.all-bidirectional")) && !oneway) {
367 NBEdge* edge =
new NBEdge(
"-" +
id, to, from, type, speed,
NBEdge::UNSPECIFIED_FRICTION, nolanes, priority, width,
NBEdge::UNSPECIFIED_OFFSET, shape.
reverse(), spread, name, origID);
372 addParams(edge, poFeature, params);
374 WRITE_ERRORF(
TL(
"Could not create edge '-%'. An edge with the same id already exists."),
id);
378 OGRFeature::DestroyFeature(poFeature);
381 #if GDAL_VERSION_MAJOR < 2
382 OGRDataSource::DestroyDataSource(poDS);
394 NIImporter_ArcView::getSpeed(OGRFeature& poFeature,
const std::string& edgeid) {
396 int index = poFeature.GetDefnRef()->GetFieldIndex(
myOptions.
getString(
"shapefile.speed").c_str());
397 if (index >= 0 && poFeature.IsFieldSet(index)) {
398 const double speed = poFeature.GetFieldAsDouble(index);
402 +
"': '" + std::string(poFeature.GetFieldAsString(index)) +
"'");
413 int index = poFeature.GetDefnRef()->GetFieldIndex(
"speed");
414 if (index >= 0 && poFeature.IsFieldSet(index)) {
415 return (
double) poFeature.GetFieldAsDouble(index);
417 index = poFeature.GetDefnRef()->GetFieldIndex(
"SPEED");
418 if (index >= 0 && poFeature.IsFieldSet(index)) {
419 return (
double) poFeature.GetFieldAsDouble(index);
422 index = poFeature.GetDefnRef()->GetFieldIndex(
"SPEED_CAT");
423 if (index >= 0 && poFeature.IsFieldSet(index)) {
424 std::string def = poFeature.GetFieldAsString(index);
432 NIImporter_ArcView::getLaneWidth(OGRFeature& poFeature,
const std::string& edgeid,
int laneNumber) {
434 int index = poFeature.GetDefnRef()->GetFieldIndex(
myOptions.
getString(
"shapefile.width").c_str());
435 if (index >= 0 && poFeature.IsFieldSet(index)) {
436 const double width = poFeature.GetFieldAsDouble(index);
440 +
"' of edge '" + edgeid
441 +
"': '" + std::string(poFeature.GetFieldAsString(index)) +
"'");
443 return width / laneNumber;
456 NIImporter_ArcView::getLength(OGRFeature& poFeature,
const std::string& edgeid) {
458 int index = poFeature.GetDefnRef()->GetFieldIndex(
myOptions.
getString(
"shapefile.length").c_str());
459 if (index >= 0 && poFeature.IsFieldSet(index)) {
460 const double length = poFeature.GetFieldAsDouble(index);
464 +
"' of edge '" + edgeid
465 +
"': '" + std::string(poFeature.GetFieldAsString(index)) +
"'");
476 NIImporter_ArcView::getLaneNo(OGRFeature& poFeature,
const std::string& edgeid,
479 int index = poFeature.GetDefnRef()->GetFieldIndex(
myOptions.
getString(
"shapefile.laneNumber").c_str());
480 if (index >= 0 && poFeature.IsFieldSet(index)) {
481 const int laneNumber = poFeature.GetFieldAsInteger(index);
482 if (laneNumber <= 0) {
485 +
"': '" + std::string(poFeature.GetFieldAsString(index)) +
"'");
496 int index = poFeature.GetDefnRef()->GetFieldIndex(
"nolanes");
497 if (index >= 0 && poFeature.IsFieldSet(index)) {
498 return (
int) poFeature.GetFieldAsInteger(index);
500 index = poFeature.GetDefnRef()->GetFieldIndex(
"NOLANES");
501 if (index >= 0 && poFeature.IsFieldSet(index)) {
502 return (
int) poFeature.GetFieldAsInteger(index);
504 index = poFeature.GetDefnRef()->GetFieldIndex(
"rnol");
505 if (index >= 0 && poFeature.IsFieldSet(index)) {
506 return (
int) poFeature.GetFieldAsInteger(index);
508 index = poFeature.GetDefnRef()->GetFieldIndex(
"LANE_CAT");
509 if (index >= 0 && poFeature.IsFieldSet(index)) {
510 std::string def = poFeature.GetFieldAsString(index);
518 NIImporter_ArcView::getPriority(OGRFeature& poFeature,
const std::string& ) {
524 int index = poFeature.GetDefnRef()->GetFieldIndex(
"priority");
525 if (index >= 0 && poFeature.IsFieldSet(index)) {
526 return poFeature.GetFieldAsInteger(index);
528 index = poFeature.GetDefnRef()->GetFieldIndex(
"PRIORITY");
529 if (index >= 0 && poFeature.IsFieldSet(index)) {
530 return poFeature.GetFieldAsInteger(index);
533 index = poFeature.GetDefnRef()->GetFieldIndex(
"FUNC_CLASS");
534 if (index >= 0 && poFeature.IsFieldSet(index)) {
535 return poFeature.GetFieldAsInteger(index);
541 NIImporter_ArcView::checkSpread(
NBEdge* e) {
550 NIImporter_ArcView::getStringEntry(OGRFeature* poFeature,
const std::string& optionName,
const char* defaultName,
bool prune, std::string& into) {
551 std::string v(defaultName);
555 if (poFeature->GetFieldIndex(v.c_str()) < 0) {
563 into = poFeature->GetFieldAsString((
char*)v.c_str());
570 std::vector<std::string>
571 NIImporter_ArcView::getFieldNames(OGRFeature* poFeature)
const {
572 std::vector<std::string> fields;
573 for (
int i = 0; i < poFeature->GetFieldCount(); i++) {
574 fields.push_back(poFeature->GetFieldDefnRef(i)->GetNameRef());
580 NIImporter_ArcView::addParams(
NBEdge* edge, OGRFeature* poFeature,
const std::vector<std::string>& params)
const {
581 for (
const std::string& p : params) {
582 int index = poFeature->GetDefnRef()->GetFieldIndex(p.c_str());
583 if (index >= 0 && poFeature->IsFieldSet(index)) {
584 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...
#define UNUSED_PARAMETER(x)
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
static const double UNSPECIFIED_FRICTION
unspecified lane friction
const std::string & getID() const
NBNode * getToNode() const
Returns the destination node of the edge.
static const double UNSPECIFIED_LOADED_LENGTH
no length override given
void setLaneSpreadFunction(LaneSpreadFunction spread)
(Re)sets how the lanes lateral offset shall be computed
const PositionVector & getGeometry() const
Returns the geometry 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
NBNode * getFromNode() const
Returns the origin node of the edge.
Instance responsible for building networks.
NBTypeCont & getTypeCont()
Returns a reference to the type container.
NBEdgeCont & getEdgeCont()
static bool transformCoordinate(Position &from, bool includeInBoundary=true, GeoConvHelper *from_srs=nullptr)
transforms loaded coordinates handles projections, offsets (using GeoConvHelper) and import of height...
NBNodeCont & getNodeCont()
Returns a reference to the node container.
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 &dbf_name, 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.