48 #pragma GCC diagnostic push
49 #pragma GCC diagnostic ignored "-Wpedantic"
51 #include <ogrsf_frmts.h>
53 #pragma GCC diagnostic pop
66 if (!oc.
isSet(
"shapefile-prefix")) {
71 std::string dbf_file = oc.
getString(
"shapefile-prefix") +
".dbf";
72 std::string shp_file = oc.
getString(
"shapefile-prefix") +
".shp";
73 std::string shx_file = oc.
getString(
"shapefile-prefix") +
".shx";
90 dbf_file, shp_file, oc.
getBool(
"speed-in-kmh"));
103 const std::string& dbf_name,
104 const std::string& shp_name,
106 : myOptions(oc), mySHPName(shp_name),
108 myNodeCont(nc), myEdgeCont(ec), myTypeCont(tc),
109 mySpeedInKMH(speedInKMH),
123 #if GDAL_VERSION_MAJOR < 2
125 OGRDataSource* poDS = OGRSFDriverRegistrar::Open(
mySHPName.c_str(), FALSE);
128 GDALDataset* poDS = (GDALDataset*)GDALOpenEx(
mySHPName.c_str(), GDAL_OF_VECTOR | GA_ReadOnly, NULL, NULL, NULL);
136 OGRLayer* poLayer = poDS->GetLayer(0);
137 poLayer->ResetReading();
140 OGRSpatialReference* origTransf = poLayer->GetSpatialRef();
141 OGRSpatialReference destTransf;
143 destTransf.SetWellKnownGeogCS(
"WGS84");
144 #if GDAL_VERSION_MAJOR > 2
146 destTransf.SetAxisMappingStrategy(OAMS_TRADITIONAL_GIS_ORDER);
149 OGRCoordinateTransformation* poCT = OGRCreateCoordinateTransformation(origTransf, &destTransf);
150 if (poCT ==
nullptr) {
152 OGRSpatialReference origTransf2;
153 origTransf2.SetWellKnownGeogCS(
"WGS84");
154 poCT = OGRCreateCoordinateTransformation(&origTransf2, &destTransf);
156 if (poCT ==
nullptr) {
157 WRITE_WARNING(
"Could not create geocoordinates converter; check whether proj.4 is installed.");
162 OGRFeature* poFeature;
163 poLayer->ResetReading();
168 int featureIndex = 0;
169 bool warnNotUnique =
true;
170 std::string idPrefix =
"";
171 std::map<std::string, int> idIndex;
172 while ((poFeature = poLayer->GetNextFeature()) != NULL) {
174 if (featureIndex == 0) {
179 std::string from_node;
181 if (!getStringEntry(poFeature,
"shapefile.street-id",
"LINK_ID",
true,
id)) {
182 WRITE_ERROR(
"Needed field '" +
id +
"' (street-id) is missing.");
189 getStringEntry(poFeature,
"shapefile.name",
"ST_NAME",
true, name);
192 if (!getStringEntry(poFeature,
"shapefile.from-id",
"REF_IN_ID",
true, from_node)) {
193 WRITE_ERROR(
"Needed field '" + from_node +
"' (from node id) is missing.");
196 if (!getStringEntry(poFeature,
"shapefile.to-id",
"NREF_IN_ID",
true, to_node)) {
197 WRITE_ERROR(
"Needed field '" + to_node +
"' (to node id) is missing.");
201 if (from_node ==
"" || to_node ==
"") {
209 }
else if (poFeature->GetFieldIndex(
"ST_TYP_AFT") >= 0) {
210 type = poFeature->GetFieldAsString(
"ST_TYP_AFT");
217 double speed = getSpeed(*poFeature,
id);
218 int nolanes = getLaneNo(*poFeature,
id, speed);
219 int priority = getPriority(*poFeature,
id);
220 if (nolanes <= 0 || speed <= 0) {
227 WRITE_ERROR(
"Required field '" + lanesField +
"' or '" + speedField +
"' is missing (add fields or set option --shapefile.use-defaults-on-failure).");
229 OGRFeature::DestroyFeature(poFeature);
234 speed = speed / (double) 3.6;
239 OGRGeometry* poGeometry = poFeature->GetGeometryRef();
240 OGRwkbGeometryType gtype = poGeometry->getGeometryType();
241 if (gtype != wkbLineString && gtype != wkbLineString25D) {
242 OGRFeature::DestroyFeature(poFeature);
243 WRITE_ERROR(
"Road geometry must be of type 'linestring' or 'linestring25D' (found '" +
toString(gtype) +
"')");
246 OGRLineString* cgeom = (OGRLineString*) poGeometry;
247 if (poCT !=
nullptr) {
249 cgeom->transform(poCT);
253 for (
int j = 0; j < cgeom->getNumPoints(); j++) {
254 Position pos((
double) cgeom->getX(j), (
double) cgeom->getY(j), (
double) cgeom->getZ(j));
256 WRITE_WARNINGF(
"Unable to project coordinates for edge '%'.",
id);
267 from =
new NBNode(from_node, from_pos);
269 WRITE_ERROR(
"Node '" + from_node +
"' could not be added");
281 to =
new NBNode(to_node, to_pos);
283 WRITE_ERROR(
"Node '" + to_node +
"' could not be added");
291 WRITE_WARNINGF(
"Edge '%' connects identical nodes, skipping.",
id);
297 int index = poFeature->GetDefnRef()->GetFieldIndex(
"DIR_TRAVEL");
298 if (index >= 0 && poFeature->IsFieldSet(index)) {
299 dir = poFeature->GetFieldAsString(index);
301 const std::string origID = saveOrigIDs ? id :
"";
305 if (existing !=
nullptr || existingReverse !=
nullptr) {
306 std::string duplicateID = existing !=
nullptr ? id : existingReverse->
getID();
307 if ((existing != 0 && existing->
getGeometry() == shape)
309 WRITE_ERROR(
"Edge '" + duplicateID +
" is not unique");
311 if (idIndex.count(
id) == 0) {
318 WRITE_WARNING(
"street-id '" + idPrefix +
"' is not unique. Renaming subsequent edge to '" +
id +
"'");
319 warnNotUnique =
false;
324 if (dir ==
"B" || dir ==
"F" || dir ==
"" ||
myOptions.
getBool(
"shapefile.all-bidirectional")) {
327 NBEdge* edge =
new NBEdge(
id, from, to, type, speed, nolanes, priority, width,
NBEdge::UNSPECIFIED_OFFSET, shape, name, origID, spread);
331 addParams(edge, poFeature, params);
333 WRITE_ERROR(
"Could not create edge '" +
id +
"'. An edge with the same id already exists");
337 if ((dir ==
"B" || dir ==
"T" ||
myOptions.
getBool(
"shapefile.all-bidirectional")) && !oneway) {
340 NBEdge* edge =
new NBEdge(
"-" +
id, to, from, type, speed, nolanes, priority, width,
NBEdge::UNSPECIFIED_OFFSET, shape.
reverse(), name, origID, spread);
344 addParams(edge, poFeature, params);
346 WRITE_ERROR(
"Could not create edge '-" +
id +
"'. An edge with the same id already exists");
350 OGRFeature::DestroyFeature(poFeature);
353 #if GDAL_VERSION_MAJOR < 2
354 OGRDataSource::DestroyDataSource(poDS);
360 WRITE_ERROR(
"SUMO was compiled without GDAL support.");
366 NIImporter_ArcView::getSpeed(OGRFeature& poFeature,
const std::string& edgeid) {
368 int index = poFeature.GetDefnRef()->GetFieldIndex(
myOptions.
getString(
"shapefile.speed").c_str());
369 if (index >= 0 && poFeature.IsFieldSet(index)) {
370 const double speed = poFeature.GetFieldAsDouble(index);
374 +
"': '" + std::string(poFeature.GetFieldAsString(index)) +
"'");
385 int index = poFeature.GetDefnRef()->GetFieldIndex(
"speed");
386 if (index >= 0 && poFeature.IsFieldSet(index)) {
387 return (
double) poFeature.GetFieldAsDouble(index);
389 index = poFeature.GetDefnRef()->GetFieldIndex(
"SPEED");
390 if (index >= 0 && poFeature.IsFieldSet(index)) {
391 return (
double) poFeature.GetFieldAsDouble(index);
394 index = poFeature.GetDefnRef()->GetFieldIndex(
"SPEED_CAT");
395 if (index >= 0 && poFeature.IsFieldSet(index)) {
396 std::string def = poFeature.GetFieldAsString(index);
404 NIImporter_ArcView::getLaneNo(OGRFeature& poFeature,
const std::string& edgeid,
407 int index = poFeature.GetDefnRef()->GetFieldIndex(
myOptions.
getString(
"shapefile.laneNumber").c_str());
408 if (index >= 0 && poFeature.IsFieldSet(index)) {
409 const int laneNumber = poFeature.GetFieldAsInteger(index);
410 if (laneNumber <= 0) {
413 +
"': '" + std::string(poFeature.GetFieldAsString(index)) +
"'");
424 int index = poFeature.GetDefnRef()->GetFieldIndex(
"nolanes");
425 if (index >= 0 && poFeature.IsFieldSet(index)) {
426 return (
int) poFeature.GetFieldAsInteger(index);
428 index = poFeature.GetDefnRef()->GetFieldIndex(
"NOLANES");
429 if (index >= 0 && poFeature.IsFieldSet(index)) {
430 return (
int) poFeature.GetFieldAsInteger(index);
432 index = poFeature.GetDefnRef()->GetFieldIndex(
"rnol");
433 if (index >= 0 && poFeature.IsFieldSet(index)) {
434 return (
int) poFeature.GetFieldAsInteger(index);
436 index = poFeature.GetDefnRef()->GetFieldIndex(
"LANE_CAT");
437 if (index >= 0 && poFeature.IsFieldSet(index)) {
438 std::string def = poFeature.GetFieldAsString(index);
446 NIImporter_ArcView::getPriority(OGRFeature& poFeature,
const std::string& ) {
452 int index = poFeature.GetDefnRef()->GetFieldIndex(
"priority");
453 if (index >= 0 && poFeature.IsFieldSet(index)) {
454 return poFeature.GetFieldAsInteger(index);
456 index = poFeature.GetDefnRef()->GetFieldIndex(
"PRIORITY");
457 if (index >= 0 && poFeature.IsFieldSet(index)) {
458 return poFeature.GetFieldAsInteger(index);
461 index = poFeature.GetDefnRef()->GetFieldIndex(
"FUNC_CLASS");
462 if (index >= 0 && poFeature.IsFieldSet(index)) {
463 return poFeature.GetFieldAsInteger(index);
469 NIImporter_ArcView::checkSpread(
NBEdge* e) {
478 NIImporter_ArcView::getStringEntry(OGRFeature* poFeature,
const std::string& optionName,
const char* defaultName,
bool prune, std::string& into) {
479 std::string v(defaultName);
483 if (poFeature->GetFieldIndex(v.c_str()) < 0) {
491 into = poFeature->GetFieldAsString((
char*)v.c_str());
498 std::vector<std::string>
499 NIImporter_ArcView::getFieldNames(OGRFeature* poFeature)
const {
500 std::vector<std::string> fields;
501 for (
int i = 0; i < poFeature->GetFieldCount(); i++) {
502 fields.push_back(poFeature->GetFieldDefnRef(i)->GetNameRef());
508 NIImporter_ArcView::addParams(
NBEdge* edge, OGRFeature* poFeature,
const std::vector<std::string>& params)
const {
509 for (
const std::string& p : params) {
510 int index = poFeature->GetDefnRef()->GetFieldIndex(p.c_str());
511 if (index >= 0 && poFeature->IsFieldSet(index)) {
512 edge->
setParameter(p, poFeature->GetFieldAsString(index));
#define WRITE_WARNINGF(...)
#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 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
const std::string & getID() const
NBNode * getToNode() const
Returns the destination node of the edge.
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_OFFSET
unspecified lane offset
NBNode * getFromNode() const
Returns the origin node of the edge.
Instance responsible for building networks.
NBTypeCont & getTypeCont()
Returns a reference to the type container.
static bool transformCoordinate(Position &from, bool includeInBoundary=true, GeoConvHelper *from_srs=0)
transforms loaded coordinates handles projections, offsets (using GeoConvHelper) and import of height...
NBEdgeCont & getEdgeCont()
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 char *what, const char *by)
static std::string prune(const std::string &str)
Removes trailing and leading whitechars.