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 bool warnNotUnique =
true;
167 std::string idPrefix =
"";
169 while ((poFeature = poLayer->GetNextFeature()) != NULL) {
171 if (featureIndex == 0) {
176 std::string from_node;
178 if (!getStringEntry(poFeature,
"shapefile.street-id",
"LINK_ID",
true,
id)) {
179 WRITE_ERROR(
"Needed field '" +
id +
"' (street-id) is missing.");
186 getStringEntry(poFeature,
"shapefile.name",
"ST_NAME",
true, name);
189 if (!getStringEntry(poFeature,
"shapefile.from-id",
"REF_IN_ID",
true, from_node)) {
190 WRITE_ERROR(
"Needed field '" + from_node +
"' (from node id) is missing.");
193 if (!getStringEntry(poFeature,
"shapefile.to-id",
"NREF_IN_ID",
true, to_node)) {
194 WRITE_ERROR(
"Needed field '" + to_node +
"' (to node id) is missing.");
198 if (from_node ==
"" || to_node ==
"") {
206 }
else if (poFeature->GetFieldIndex(
"ST_TYP_AFT") >= 0) {
207 type = poFeature->GetFieldAsString(
"ST_TYP_AFT");
210 WRITE_WARNING(
"Unknown type '" + type +
"' for edge '" +
id +
"'");
214 double speed = getSpeed(*poFeature,
id);
215 int nolanes = getLaneNo(*poFeature,
id, speed);
216 int priority = getPriority(*poFeature,
id);
217 if (nolanes <= 0 || speed <= 0) {
224 WRITE_ERROR(
"Required field '" + lanesField +
"' or '" + speedField +
"' is missing (add fields or set option --shapefile.use-defaults-on-failure).");
226 OGRFeature::DestroyFeature(poFeature);
231 speed = speed / (double) 3.6;
236 OGRGeometry* poGeometry = poFeature->GetGeometryRef();
237 OGRwkbGeometryType gtype = poGeometry->getGeometryType();
238 if (gtype != wkbLineString && gtype != wkbLineString25D) {
239 OGRFeature::DestroyFeature(poFeature);
240 WRITE_ERROR(
"Road geometry must be of type 'linestring' or 'linestring25D' (found '" +
toString(gtype) +
"')");
243 OGRLineString* cgeom = (OGRLineString*) poGeometry;
246 cgeom->transform(poCT);
250 for (
int j = 0; j < cgeom->getNumPoints(); j++) {
251 Position pos((
double) cgeom->getX(j), (double) cgeom->getY(j), (double) cgeom->getZ(j));
253 WRITE_WARNING(
"Unable to project coordinates for edge '" +
id +
"'.");
264 from =
new NBNode(from_node, from_pos);
266 WRITE_ERROR(
"Node '" + from_node +
"' could not be added");
278 to =
new NBNode(to_node, to_pos);
280 WRITE_ERROR(
"Node '" + to_node +
"' could not be added");
288 WRITE_WARNING(
"Edge '" +
id +
"' connects identical nodes, skipping.");
294 int index = poFeature->GetDefnRef()->GetFieldIndex(
"DIR_TRAVEL");
295 if (index >= 0 && poFeature->IsFieldSet(index)) {
296 dir = poFeature->GetFieldAsString(index);
298 const std::string origID = saveOrigIDs ? id :
"";
302 if (existing !=
nullptr || existingReverse !=
nullptr) {
303 std::string duplicateID = existing !=
nullptr ? id : existingReverse->
getID();
304 if ((existing != 0 && existing->
getGeometry() == shape)
306 WRITE_ERROR(
"Edge '" + duplicateID +
" is not unique");
308 if (
id != idPrefix) {
314 WRITE_WARNING(
"street-id '" + idPrefix +
"' is not unique. Renaming subsequent edge to '" +
id +
"'");
315 warnNotUnique =
false;
321 if (dir ==
"B" || dir ==
"F" || dir ==
"" ||
myOptions.
getBool(
"shapefile.all-bidirectional")) {
324 NBEdge* edge =
new NBEdge(
id, from, to, type, speed, nolanes, priority, width,
NBEdge::UNSPECIFIED_OFFSET, shape, name, origID, spread);
328 addParams(edge, poFeature, params);
330 WRITE_ERROR(
"Could not create edge '" +
id +
"'. An edge with the same id already exists");
334 if ((dir ==
"B" || dir ==
"T" ||
myOptions.
getBool(
"shapefile.all-bidirectional")) && !oneway) {
337 NBEdge* edge =
new NBEdge(
"-" +
id, to, from, type, speed, nolanes, priority, width,
NBEdge::UNSPECIFIED_OFFSET, shape.
reverse(), name, origID, spread);
341 addParams(edge, poFeature, params);
343 WRITE_ERROR(
"Could not create edge '-" +
id +
"'. An edge with the same id already exists");
347 OGRFeature::DestroyFeature(poFeature);
350 #if GDAL_VERSION_MAJOR < 2 351 OGRDataSource::DestroyDataSource(poDS);
357 WRITE_ERROR(
"SUMO was compiled without GDAL support.");
363 NIImporter_ArcView::getSpeed(OGRFeature& poFeature,
const std::string& edgeid) {
365 int index = poFeature.GetDefnRef()->GetFieldIndex(
myOptions.
getString(
"shapefile.speed").c_str());
366 if (index >= 0 && poFeature.IsFieldSet(index)) {
367 const double speed = poFeature.GetFieldAsDouble(index);
371 +
"': '" + std::string(poFeature.GetFieldAsString(index)) +
"'");
382 int index = poFeature.GetDefnRef()->GetFieldIndex(
"speed");
383 if (index >= 0 && poFeature.IsFieldSet(index)) {
384 return (
double) poFeature.GetFieldAsDouble(index);
386 index = poFeature.GetDefnRef()->GetFieldIndex(
"SPEED");
387 if (index >= 0 && poFeature.IsFieldSet(index)) {
388 return (
double) poFeature.GetFieldAsDouble(index);
391 index = poFeature.GetDefnRef()->GetFieldIndex(
"SPEED_CAT");
392 if (index >= 0 && poFeature.IsFieldSet(index)) {
393 std::string def = poFeature.GetFieldAsString(index);
401 NIImporter_ArcView::getLaneNo(OGRFeature& poFeature,
const std::string& edgeid,
404 int index = poFeature.GetDefnRef()->GetFieldIndex(
myOptions.
getString(
"shapefile.laneNumber").c_str());
405 if (index >= 0 && poFeature.IsFieldSet(index)) {
406 const int laneNumber = poFeature.GetFieldAsInteger(index);
407 if (laneNumber <= 0) {
410 +
"': '" + std::string(poFeature.GetFieldAsString(index)) +
"'");
421 int index = poFeature.GetDefnRef()->GetFieldIndex(
"nolanes");
422 if (index >= 0 && poFeature.IsFieldSet(index)) {
423 return (
int) poFeature.GetFieldAsInteger(index);
425 index = poFeature.GetDefnRef()->GetFieldIndex(
"NOLANES");
426 if (index >= 0 && poFeature.IsFieldSet(index)) {
427 return (
int) poFeature.GetFieldAsInteger(index);
429 index = poFeature.GetDefnRef()->GetFieldIndex(
"rnol");
430 if (index >= 0 && poFeature.IsFieldSet(index)) {
431 return (
int) poFeature.GetFieldAsInteger(index);
433 index = poFeature.GetDefnRef()->GetFieldIndex(
"LANE_CAT");
434 if (index >= 0 && poFeature.IsFieldSet(index)) {
435 std::string def = poFeature.GetFieldAsString(index);
443 NIImporter_ArcView::getPriority(OGRFeature& poFeature,
const std::string& ) {
449 int index = poFeature.GetDefnRef()->GetFieldIndex(
"priority");
450 if (index >= 0 && poFeature.IsFieldSet(index)) {
451 return poFeature.GetFieldAsInteger(index);
453 index = poFeature.GetDefnRef()->GetFieldIndex(
"PRIORITY");
454 if (index >= 0 && poFeature.IsFieldSet(index)) {
455 return poFeature.GetFieldAsInteger(index);
458 index = poFeature.GetDefnRef()->GetFieldIndex(
"FUNC_CLASS");
459 if (index >= 0 && poFeature.IsFieldSet(index)) {
460 return poFeature.GetFieldAsInteger(index);
466 NIImporter_ArcView::checkSpread(
NBEdge* e) {
475 NIImporter_ArcView::getStringEntry(OGRFeature* poFeature,
const std::string& optionName,
const char* defaultName,
bool prune, std::string& into) {
476 std::string v(defaultName);
480 if (poFeature->GetFieldIndex(v.c_str()) < 0) {
488 into = poFeature->GetFieldAsString((
char*)v.c_str());
495 std::vector<std::string>
496 NIImporter_ArcView::getFieldNames(OGRFeature* poFeature)
const {
497 std::vector<std::string> fields;
498 for (
int i = 0; i < poFeature->GetFieldCount(); i++) {
499 fields.push_back(poFeature->GetFieldDefnRef(i)->GetNameRef());
505 NIImporter_ArcView::addParams(
NBEdge* edge, OGRFeature* poFeature,
const std::vector<std::string>& params)
const {
506 for (
const std::string& p : params) {
507 int index = poFeature->GetDefnRef()->GetFieldIndex(p.c_str());
508 if (index >= 0 && poFeature->IsFieldSet(index)) {
509 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)
const std::string & getID() const
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)
const PositionVector & getGeometry() const
Returns the geometry of the edge.
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.