50 #pragma GCC diagnostic push 51 #pragma GCC diagnostic ignored "-Wpedantic" 53 #include <ogrsf_frmts.h> 55 #pragma GCC diagnostic pop 68 if (!oc.
isSet(
"shapefile-prefix")) {
73 std::string dbf_file = oc.
getString(
"shapefile-prefix") +
".dbf";
74 std::string shp_file = oc.
getString(
"shapefile-prefix") +
".shp";
75 std::string shx_file = oc.
getString(
"shapefile-prefix") +
".shx";
92 dbf_file, shp_file, oc.
getBool(
"speed-in-kmh"));
105 const std::string& dbf_name,
106 const std::string& shp_name,
125 #if GDAL_VERSION_MAJOR < 2 127 OGRDataSource* poDS = OGRSFDriverRegistrar::Open(
mySHPName.c_str(), FALSE);
130 GDALDataset* poDS = (GDALDataset*)GDALOpenEx(
mySHPName.c_str(), GDAL_OF_VECTOR | GA_ReadOnly, NULL, NULL, NULL);
138 OGRLayer* poLayer = poDS->GetLayer(0);
139 poLayer->ResetReading();
142 OGRSpatialReference* origTransf = poLayer->GetSpatialRef();
143 OGRSpatialReference destTransf;
145 destTransf.SetWellKnownGeogCS(
"WGS84");
146 OGRCoordinateTransformation* poCT = OGRCreateCoordinateTransformation(origTransf, &destTransf);
149 OGRSpatialReference origTransf2;
150 origTransf2.SetWellKnownGeogCS(
"WGS84");
151 poCT = OGRCreateCoordinateTransformation(&origTransf2, &destTransf);
154 WRITE_WARNING(
"Could not create geocoordinates converter; check whether proj.4 is installed.");
159 OGRFeature* poFeature;
160 poLayer->ResetReading();
165 int featureIndex = 0;
166 while ((poFeature = poLayer->GetNextFeature()) != NULL) {
168 if (featureIndex == 0) {
171 std::string id, name, from_node, to_node;
172 if (!getStringEntry(poFeature,
"shapefile.street-id",
"LINK_ID",
true,
id)) {
173 WRITE_ERROR(
"Needed field '" +
id +
"' (street-id) is missing.");
179 getStringEntry(poFeature,
"shapefile.name",
"ST_NAME",
true, name);
182 if (!getStringEntry(poFeature,
"shapefile.from-id",
"REF_IN_ID",
true, from_node)) {
183 WRITE_ERROR(
"Needed field '" + from_node +
"' (from node id) is missing.");
185 if (!getStringEntry(poFeature,
"shapefile.to-id",
"NREF_IN_ID",
true, to_node)) {
186 WRITE_ERROR(
"Needed field '" + to_node +
"' (to node id) is missing.");
189 if (from_node ==
"" || to_node ==
"") {
197 }
else if (poFeature->GetFieldIndex(
"ST_TYP_AFT") >= 0) {
198 type = poFeature->GetFieldAsString(
"ST_TYP_AFT");
201 WRITE_WARNING(
"Unknown type '" + type +
"' for edge '" +
id +
"'");
205 double speed = getSpeed(*poFeature,
id);
206 int nolanes = getLaneNo(*poFeature,
id, speed);
207 int priority = getPriority(*poFeature,
id);
208 if (nolanes <= 0 || speed <= 0) {
215 WRITE_ERROR(
"Required field '" + lanesField +
"' or '" + speedField +
"' is missing (add fields or set option --shapefile.use-defaults-on-failure).");
217 OGRFeature::DestroyFeature(poFeature);
222 speed = speed / (double) 3.6;
227 OGRGeometry* poGeometry = poFeature->GetGeometryRef();
228 OGRwkbGeometryType gtype = poGeometry->getGeometryType();
229 if (gtype != wkbLineString && gtype != wkbLineString25D) {
230 OGRFeature::DestroyFeature(poFeature);
231 WRITE_ERROR(
"Road geometry must be of type 'linestring' or 'linestring25D' (found '" +
toString(gtype) +
"')");
234 OGRLineString* cgeom = (OGRLineString*) poGeometry;
237 cgeom->transform(poCT);
241 for (
int j = 0; j < cgeom->getNumPoints(); j++) {
242 Position pos((
double) cgeom->getX(j), (double) cgeom->getY(j));
244 WRITE_WARNING(
"Unable to project coordinates for edge '" +
id +
"'.");
255 from =
new NBNode(from_node, from_pos);
257 WRITE_ERROR(
"Node '" + from_node +
"' could not be added");
269 to =
new NBNode(to_node, to_pos);
271 WRITE_ERROR(
"Node '" + to_node +
"' could not be added");
279 WRITE_WARNING(
"Edge '" +
id +
"' connects identical nodes, skipping.");
285 int index = poFeature->GetDefnRef()->GetFieldIndex(
"DIR_TRAVEL");
286 if (index >= 0 && poFeature->IsFieldSet(index)) {
287 dir = poFeature->GetFieldAsString(index);
289 const std::string origID = saveOrigIDs ? id :
"";
291 if (dir ==
"B" || dir ==
"F" || dir ==
"" ||
myOptions.
getBool(
"shapefile.all-bidirectional")) {
294 NBEdge* edge =
new NBEdge(
id, from, to, type, speed, nolanes, priority, width,
NBEdge::UNSPECIFIED_OFFSET, shape, name, origID, spread);
298 addParams(edge, poFeature, params);
302 if ((dir ==
"B" || dir ==
"T" ||
myOptions.
getBool(
"shapefile.all-bidirectional")) && !oneway) {
305 NBEdge* edge =
new NBEdge(
"-" +
id, to, from, type, speed, nolanes, priority, width,
NBEdge::UNSPECIFIED_OFFSET, shape.
reverse(), name, origID, spread);
309 addParams(edge, poFeature, params);
313 OGRFeature::DestroyFeature(poFeature);
316 #if GDAL_VERSION_MAJOR < 2 317 OGRDataSource::DestroyDataSource(poDS);
323 WRITE_ERROR(
"SUMO was compiled without GDAL support.");
329 NIImporter_ArcView::getSpeed(OGRFeature& poFeature,
const std::string& edgeid) {
331 int index = poFeature.GetDefnRef()->GetFieldIndex(
myOptions.
getString(
"shapefile.speed").c_str());
332 if (index >= 0 && poFeature.IsFieldSet(index)) {
333 const double speed = poFeature.GetFieldAsDouble(index);
337 +
"': '" + std::string(poFeature.GetFieldAsString(index)) +
"'");
348 int index = poFeature.GetDefnRef()->GetFieldIndex(
"speed");
349 if (index >= 0 && poFeature.IsFieldSet(index)) {
350 return (
double) poFeature.GetFieldAsDouble(index);
352 index = poFeature.GetDefnRef()->GetFieldIndex(
"SPEED");
353 if (index >= 0 && poFeature.IsFieldSet(index)) {
354 return (
double) poFeature.GetFieldAsDouble(index);
357 index = poFeature.GetDefnRef()->GetFieldIndex(
"SPEED_CAT");
358 if (index >= 0 && poFeature.IsFieldSet(index)) {
359 std::string def = poFeature.GetFieldAsString(index);
367 NIImporter_ArcView::getLaneNo(OGRFeature& poFeature,
const std::string& edgeid,
370 int index = poFeature.GetDefnRef()->GetFieldIndex(
myOptions.
getString(
"shapefile.laneNumber").c_str());
371 if (index >= 0 && poFeature.IsFieldSet(index)) {
372 const int laneNumber = poFeature.GetFieldAsInteger(index);
373 if (laneNumber <= 0) {
376 +
"': '" + std::string(poFeature.GetFieldAsString(index)) +
"'");
387 int index = poFeature.GetDefnRef()->GetFieldIndex(
"nolanes");
388 if (index >= 0 && poFeature.IsFieldSet(index)) {
389 return (
int) poFeature.GetFieldAsInteger(index);
391 index = poFeature.GetDefnRef()->GetFieldIndex(
"NOLANES");
392 if (index >= 0 && poFeature.IsFieldSet(index)) {
393 return (
int) poFeature.GetFieldAsInteger(index);
395 index = poFeature.GetDefnRef()->GetFieldIndex(
"rnol");
396 if (index >= 0 && poFeature.IsFieldSet(index)) {
397 return (
int) poFeature.GetFieldAsInteger(index);
399 index = poFeature.GetDefnRef()->GetFieldIndex(
"LANE_CAT");
400 if (index >= 0 && poFeature.IsFieldSet(index)) {
401 std::string def = poFeature.GetFieldAsString(index);
409 NIImporter_ArcView::getPriority(OGRFeature& poFeature,
const std::string& ) {
415 int index = poFeature.GetDefnRef()->GetFieldIndex(
"priority");
416 if (index >= 0 && poFeature.IsFieldSet(index)) {
417 return poFeature.GetFieldAsInteger(index);
419 index = poFeature.GetDefnRef()->GetFieldIndex(
"PRIORITY");
420 if (index >= 0 && poFeature.IsFieldSet(index)) {
421 return poFeature.GetFieldAsInteger(index);
424 index = poFeature.GetDefnRef()->GetFieldIndex(
"FUNC_CLASS");
425 if (index >= 0 && poFeature.IsFieldSet(index)) {
426 return poFeature.GetFieldAsInteger(index);
432 NIImporter_ArcView::checkSpread(
NBEdge* e) {
441 NIImporter_ArcView::getStringEntry(OGRFeature* poFeature,
const std::string& optionName,
const char* defaultName,
bool prune, std::string& into) {
442 std::string v(defaultName);
446 if (poFeature->GetFieldIndex(v.c_str()) < 0) {
454 into = poFeature->GetFieldAsString((
char*)v.c_str());
461 std::vector<std::string>
462 NIImporter_ArcView::getFieldNames(OGRFeature* poFeature)
const {
463 std::vector<std::string> fields;
464 for (
int i = 0; i < poFeature->GetFieldCount(); i++) {
465 fields.push_back(poFeature->GetFieldDefnRef(i)->GetNameRef());
471 NIImporter_ArcView::addParams(
NBEdge* edge, OGRFeature* poFeature,
const std::vector<std::string>& params)
const {
472 for (
const std::string& p : params) {
473 int index = poFeature->GetDefnRef()->GetFieldIndex(p.c_str());
474 if (index >= 0 && poFeature->IsFieldSet(index)) {
475 edge->
setParameter(p, poFeature->GetFieldAsString(index));
NBNode * retrieve(const std::string &id) const
Returns the node with the given name.
int myNameAddition
A running number to assure unique edge ids.
static MsgHandler * getErrorInstance()
Returns the instance to add errors to.
double getSpeed(const std::string &type) const
Returns the maximal velocity for the given type [m/s].
NBTypeCont & getTypeCont()
Returns a reference to the type container.
~NIImporter_ArcView()
Destructor.
static bool transformCoordinate(Position &from, bool includeInBoundary=true, GeoConvHelper *from_srs=0)
transforms loaded coordinates handles projections, offsets (using GeoConvHelper) and import of height...
static bool isReadable(std::string path)
Checks whether the given file is readable.
static double getSpeed(const std::string &id, const std::string &speedClassS)
Returns the speed evaluating the given Navteq-description.
std::string mySHPName
The name of the shape file.
NBTypeCont & myTypeCont
The container to get the types from.
The representation of a single edge during network building.
static void loadNetwork(const OptionsCont &oc, NBNetBuilder &nb)
Loads content of the optionally given ArcView Shape files.
int getPriority(const std::string &type) const
Returns the priority for the given type.
const OptionsCont & myOptions
The options to use.
static const double UNSPECIFIED_OFFSET
unspecified lane offset
void setPermissions(SVCPermissions permissions, int lane=-1)
set allowed/disallowed classes for the given lane or for all lanes if -1 is given ...
void load()
Loads the shape files.
PositionVector reverse() const
reverse position vector
int getNumLanes(const std::string &type) const
Returns the number of lanes for the given type.
bool getBool(const std::string &name) const
Returns the boolean-value of the named option (only for Option_Bool)
#define UNUSED_PARAMETER(x)
#define WRITE_WARNING(msg)
static OptionsCont & getOptions()
Retrieves the options.
double getWidth(const std::string &type) const
Returns the lane width for the given type [m].
NBEdge * getConnectionTo(NBNode *n) const
get connection to certain node
bool isSet(const std::string &name, bool failOnNonExistant=true) const
Returns the information whether the named option is set.
bool knows(const std::string &type) const
Returns whether the named type is in the container.
bool insert(NBEdge *edge, bool ignorePrunning=false)
Adds an edge to the dictionary.
std::string toString(const T &t, std::streamsize accuracy=gPrecision)
A point in 2D or 3D with translation and scaling methods.
NBEdgeCont & getEdgeCont()
std::string getString(const std::string &name) const
Returns the string-value of the named option (only for Option_String)
Storage for edges, including some functionality operating on multiple edges.
std::vector< std::string > getStringVector(const std::string &name) const
Returns the list of string-vector-value of the named option (only for Option_String) ...
Importer for networks stored in ArcView-shape format.
#define PROGRESS_BEGIN_MESSAGE(msg)
void setParameter(const std::string &key, const std::string &value)
Sets a parameter.
double getFloat(const std::string &name) const
Returns the double-value of the named option (only for Option_Float)
static std::string replace(std::string str, const char *what, const char *by)
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 std::string prune(const std::string &str)
Removes trailing and leading whitechars.
NBNodeCont & getNodeCont()
Returns a reference to the node container.
Instance responsible for building networks.
NBNodeCont & myNodeCont
The container to add nodes to.
NBEdge * retrieve(const std::string &id, bool retrieveExtracted=false) const
Returns the edge that has the given id.
A storage for options typed value containers)
bool insert(const std::string &id, const Position &position, NBDistrict *district=0)
Inserts a node into the map.
LaneSpreadFunction
Numbers representing special SUMO-XML-attribute values Information how the edge's lateral offset shal...
int myRunningEdgeID
A running number to assure unique ids (as fallback)
Represents a single node (junction) during network building.
static int getLaneNumber(const std::string &id, const std::string &laneNoS, double speed)
Returns the lane number evaluating the given Navteq-description.
void push_back_noDoublePos(const Position &p)
insert in back a non double position
NBNode * getFromNode() const
Returns the origin node of the edge.
Container for nodes during the netbuilding process.
NBEdgeCont & myEdgeCont
The container to add edges to.
#define PROGRESS_DONE_MESSAGE()
bool getIsOneWay(const std::string &type) const
Returns whether edges are one-way per default for the given type.
void setLaneSpreadFunction(LaneSpreadFunction spread)
(Re)sets how the lanes lateral offset shall be computed
#define WRITE_MESSAGE(msg)
NBNode * getToNode() const
Returns the destination node of the edge.
bool mySpeedInKMH
Whether the speed is given in km/h.
SVCPermissions getPermissions(const std::string &type) const
Returns allowed vehicle classes for the given type.
A storage for available types of edges.