56 #pragma GCC diagnostic push 57 #pragma GCC diagnostic ignored "-Wpedantic" 59 #include <ogrsf_frmts.h> 61 #pragma GCC diagnostic pop 74 if (!oc.
isSet(
"shapefile-prefix")) {
79 std::string dbf_file = oc.
getString(
"shapefile-prefix") +
".dbf";
80 std::string shp_file = oc.
getString(
"shapefile-prefix") +
".shp";
81 std::string shx_file = oc.
getString(
"shapefile-prefix") +
".shx";
98 dbf_file, shp_file, oc.
getBool(
"speed-in-kmh"));
111 const std::string& dbf_name,
112 const std::string& shp_name,
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 OGRCoordinateTransformation* poCT = OGRCreateCoordinateTransformation(origTransf, &destTransf);
154 OGRSpatialReference origTransf2;
155 origTransf2.SetWellKnownGeogCS(
"WGS84");
156 poCT = OGRCreateCoordinateTransformation(&origTransf2, &destTransf);
159 WRITE_WARNING(
"Could not create geocoordinates converter; check whether proj.4 is installed.");
164 OGRFeature* poFeature;
165 poLayer->ResetReading();
166 while ((poFeature = poLayer->GetNextFeature()) != NULL) {
168 std::string id, name, from_node, to_node;
169 if (!getStringEntry(poFeature,
"shapefile.street-id",
"LINK_ID",
true,
id)) {
170 WRITE_ERROR(
"Needed field '" +
id +
"' (from node id) is missing.");
177 getStringEntry(poFeature,
"shapefile.street-id",
"ST_NAME",
true, name);
180 if (!getStringEntry(poFeature,
"shapefile.from-id",
"REF_IN_ID",
true, from_node)) {
181 WRITE_ERROR(
"Needed field '" + from_node +
"' (from node id) is missing.");
183 if (!getStringEntry(poFeature,
"shapefile.to-id",
"NREF_IN_ID",
true, to_node)) {
184 WRITE_ERROR(
"Needed field '" + to_node +
"' (to node id) is missing.");
187 if (from_node ==
"" || to_node ==
"") {
195 }
else if (poFeature->GetFieldIndex(
"ST_TYP_AFT") >= 0) {
196 type = poFeature->GetFieldAsString(
"ST_TYP_AFT");
199 double speed = getSpeed(*poFeature,
id);
200 int nolanes = getLaneNo(*poFeature,
id, speed);
201 int priority = getPriority(*poFeature,
id);
202 if (nolanes == 0 || speed == 0) {
207 OGRFeature::DestroyFeature(poFeature);
208 WRITE_ERROR(
"Required field 'nolanes' or 'speed' is missing (add fields or set option --shapefile.use-defaults-on-failure).");
213 speed = speed / (double) 3.6;
218 OGRGeometry* poGeometry = poFeature->GetGeometryRef();
219 OGRwkbGeometryType gtype = poGeometry->getGeometryType();
220 if (gtype != wkbLineString) {
221 OGRFeature::DestroyFeature(poFeature);
222 WRITE_ERROR(
"Road geometry must be of type 'linestring'.");
225 OGRLineString* cgeom = (OGRLineString*) poGeometry;
228 cgeom->transform(poCT);
232 for (
int j = 0; j < cgeom->getNumPoints(); j++) {
233 Position pos((
double) cgeom->getX(j), (double) cgeom->getY(j));
235 WRITE_WARNING(
"Unable to project coordinates for edge '" +
id +
"'.");
246 from =
new NBNode(from_node, from_pos);
248 WRITE_ERROR(
"Node '" + from_node +
"' could not be added");
260 to =
new NBNode(to_node, to_pos);
262 WRITE_ERROR(
"Node '" + to_node +
"' could not be added");
270 WRITE_WARNING(
"Edge '" +
id +
"' connects identical nodes, skipping.");
276 int index = poFeature->GetDefnRef()->GetFieldIndex(
"DIR_TRAVEL");
277 if (index >= 0 && poFeature->IsFieldSet(index)) {
278 dir = poFeature->GetFieldAsString(index);
280 const std::string origID = saveOrigIDs ? id :
"";
282 if (dir ==
"B" || dir ==
"F" || dir ==
"" ||
myOptions.
getBool(
"shapefile.all-bidirectional")) {
285 NBEdge* edge =
new NBEdge(
id, from, to, type, speed, nolanes, priority, width,
NBEdge::UNSPECIFIED_OFFSET, shape, name, origID, spread);
291 if (dir ==
"B" || dir ==
"T" ||
myOptions.
getBool(
"shapefile.all-bidirectional")) {
294 NBEdge* edge =
new NBEdge(
"-" +
id, to, from, type, speed, nolanes, priority, width,
NBEdge::UNSPECIFIED_OFFSET, shape.
reverse(), name, origID, spread);
300 OGRFeature::DestroyFeature(poFeature);
302 #if GDAL_VERSION_MAJOR < 2 303 OGRDataSource::DestroyDataSource(poDS);
309 WRITE_ERROR(
"SUMO was compiled without GDAL support.");
315 NIImporter_ArcView::getSpeed(OGRFeature& poFeature,
const std::string& edgeid) {
321 int index = poFeature.GetDefnRef()->GetFieldIndex(
"speed");
322 if (index >= 0 && poFeature.IsFieldSet(index)) {
323 return (
double) poFeature.GetFieldAsDouble(index);
325 index = poFeature.GetDefnRef()->GetFieldIndex(
"SPEED");
326 if (index >= 0 && poFeature.IsFieldSet(index)) {
327 return (
double) poFeature.GetFieldAsDouble(index);
330 index = poFeature.GetDefnRef()->GetFieldIndex(
"SPEED_CAT");
331 if (index >= 0 && poFeature.IsFieldSet(index)) {
332 std::string def = poFeature.GetFieldAsString(index);
340 NIImporter_ArcView::getLaneNo(OGRFeature& poFeature,
const std::string& edgeid,
347 int index = poFeature.GetDefnRef()->GetFieldIndex(
"nolanes");
348 if (index >= 0 && poFeature.IsFieldSet(index)) {
349 return (
int) poFeature.GetFieldAsInteger(index);
351 index = poFeature.GetDefnRef()->GetFieldIndex(
"NOLANES");
352 if (index >= 0 && poFeature.IsFieldSet(index)) {
353 return (
int) poFeature.GetFieldAsInteger(index);
355 index = poFeature.GetDefnRef()->GetFieldIndex(
"rnol");
356 if (index >= 0 && poFeature.IsFieldSet(index)) {
357 return (
int) poFeature.GetFieldAsInteger(index);
359 index = poFeature.GetDefnRef()->GetFieldIndex(
"LANE_CAT");
360 if (index >= 0 && poFeature.IsFieldSet(index)) {
361 std::string def = poFeature.GetFieldAsString(index);
369 NIImporter_ArcView::getPriority(OGRFeature& poFeature,
const std::string& ) {
375 int index = poFeature.GetDefnRef()->GetFieldIndex(
"priority");
376 if (index >= 0 && poFeature.IsFieldSet(index)) {
377 return poFeature.GetFieldAsInteger(index);
379 index = poFeature.GetDefnRef()->GetFieldIndex(
"PRIORITY");
380 if (index >= 0 && poFeature.IsFieldSet(index)) {
381 return poFeature.GetFieldAsInteger(index);
384 index = poFeature.GetDefnRef()->GetFieldIndex(
"FUNC_CLASS");
385 if (index >= 0 && poFeature.IsFieldSet(index)) {
386 return poFeature.GetFieldAsInteger(index);
392 NIImporter_ArcView::checkSpread(
NBEdge* e) {
401 NIImporter_ArcView::getStringEntry(OGRFeature* poFeature,
const std::string& optionName,
const char* defaultName,
bool prune, std::string& into) {
402 std::string v(defaultName);
406 if (poFeature->GetFieldIndex(v.c_str()) < 0) {
414 into = poFeature->GetFieldAsString((
char*)v.c_str());
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...
int myRunningNodeID
A running number to assure unique node ids.
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 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 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.
Importer for networks stored in ArcView-shape format.
#define PROGRESS_BEGIN_MESSAGE(msg)
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...
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()
void setLaneSpreadFunction(LaneSpreadFunction spread)
(Re)sets how the lanes lateral offset shall be computed
NBNode * getToNode() const
Returns the destination node of the edge.
bool mySpeedInKMH
Whether the speed is given in km/h.
A storage for available types of edges.