56 #include <ogrsf_frmts.h>
59 #ifdef CHECK_MEMORY_LEAKS
61 #endif // CHECK_MEMORY_LEAKS
72 if (!oc.
isSet(
"shapefile-prefix")) {
77 std::string dbf_file = oc.
getString(
"shapefile-prefix") +
".dbf";
78 std::string shp_file = oc.
getString(
"shapefile-prefix") +
".shp";
79 std::string shx_file = oc.
getString(
"shapefile-prefix") +
".shx";
96 dbf_file, shp_file, oc.
getBool(
"speed-in-kmh"));
109 const std::string& dbf_name,
110 const std::string& shp_name,
112 : myOptions(oc), mySHPName(shp_name),
114 myNodeCont(nc), myEdgeCont(ec), myTypeCont(tc),
115 mySpeedInKMH(speedInKMH),
129 OGRDataSource* poDS = OGRSFDriverRegistrar::Open(
mySHPName.c_str(), FALSE);
136 OGRLayer* poLayer = poDS->GetLayer(0);
137 poLayer->ResetReading();
140 OGRSpatialReference* origTransf = poLayer->GetSpatialRef();
141 OGRSpatialReference destTransf;
143 destTransf.SetWellKnownGeogCS(
"WGS84");
144 OGRCoordinateTransformation* poCT = OGRCreateCoordinateTransformation(origTransf, &destTransf);
147 OGRSpatialReference origTransf2;
148 origTransf2.SetWellKnownGeogCS(
"WGS84");
149 poCT = OGRCreateCoordinateTransformation(&origTransf2, &destTransf);
152 WRITE_WARNING(
"Could not create geocoordinates converter; check whether proj.4 is installed.");
156 OGRFeature* poFeature;
157 poLayer->ResetReading();
158 while ((poFeature = poLayer->GetNextFeature()) != NULL) {
160 std::string id, name, from_node, to_node;
161 if (!getStringEntry(poFeature,
"shapefile.street-id",
"LINK_ID",
true,
id)) {
162 WRITE_ERROR(
"Needed field '" +
id +
"' (from node id) is missing.");
169 getStringEntry(poFeature,
"shapefile.street-id",
"ST_NAME",
true, name);
172 if (!getStringEntry(poFeature,
"shapefile.from-id",
"REF_IN_ID",
true, from_node)) {
173 WRITE_ERROR(
"Needed field '" + from_node +
"' (from node id) is missing.");
175 if (!getStringEntry(poFeature,
"shapefile.to-id",
"NREF_IN_ID",
true, to_node)) {
176 WRITE_ERROR(
"Needed field '" + to_node +
"' (to node id) is missing.");
179 if (from_node ==
"" || to_node ==
"") {
187 }
else if (poFeature->GetFieldIndex(
"ST_TYP_AFT") >= 0) {
188 type = poFeature->GetFieldAsString(
"ST_TYP_AFT");
191 SUMOReal speed = getSpeed(*poFeature,
id);
192 unsigned int nolanes = getLaneNo(*poFeature,
id, speed);
193 int priority = getPriority(*poFeature,
id);
194 if (nolanes == 0 || speed == 0) {
199 OGRFeature::DestroyFeature(poFeature);
200 WRITE_ERROR(
"The description seems to be invalid. Please recheck usage of types.");
210 OGRGeometry* poGeometry = poFeature->GetGeometryRef();
211 OGRwkbGeometryType gtype = poGeometry->getGeometryType();
212 assert(gtype == wkbLineString);
214 OGRLineString* cgeom = (OGRLineString*) poGeometry;
217 cgeom->transform(poCT);
221 for (
int j = 0; j < cgeom->getNumPoints(); j++) {
224 WRITE_WARNING(
"Unable to project coordinates for edge '" +
id +
"'.");
235 from =
new NBNode(from_node, from_pos);
237 WRITE_ERROR(
"Node '" + from_node +
"' could not be added");
249 to =
new NBNode(to_node, to_pos);
251 WRITE_ERROR(
"Node '" + to_node +
"' could not be added");
259 WRITE_WARNING(
"Edge '" +
id +
"' connects identical nodes, skipping.");
265 int index = poFeature->GetDefnRef()->GetFieldIndex(
"DIR_TRAVEL");
266 if (index >= 0 && poFeature->IsFieldSet(index)) {
267 dir = poFeature->GetFieldAsString(index);
270 if (dir ==
"B" || dir ==
"F" || dir ==
"" ||
myOptions.
getBool(
"shapefile.all-bidirectional")) {
273 NBEdge* edge =
new NBEdge(
id, from, to, type, speed, nolanes, priority, width,
NBEdge::UNSPECIFIED_OFFSET, shape,
"", spread);
279 if (dir ==
"B" || dir ==
"T" ||
myOptions.
getBool(
"shapefile.all-bidirectional")) {
283 NBEdge* edge =
new NBEdge(
id, to, from, type, speed, nolanes, priority, width,
NBEdge::UNSPECIFIED_OFFSET, shape.
reverse(),
"", spread);
289 OGRFeature::DestroyFeature(poFeature);
293 WRITE_ERROR(
"SUMO was compiled without GDAL support.");
299 NIImporter_ArcView::getSpeed(OGRFeature& poFeature,
const std::string& edgeid) {
305 int index = poFeature.GetDefnRef()->GetFieldIndex(
"speed");
306 if (index >= 0 && poFeature.IsFieldSet(index)) {
307 return (
SUMOReal) poFeature.GetFieldAsDouble(index);
309 index = poFeature.GetDefnRef()->GetFieldIndex(
"SPEED");
310 if (index >= 0 && poFeature.IsFieldSet(index)) {
311 return (
SUMOReal) poFeature.GetFieldAsDouble(index);
314 index = poFeature.GetDefnRef()->GetFieldIndex(
"SPEED_CAT");
315 if (index >= 0 && poFeature.IsFieldSet(index)) {
316 std::string def = poFeature.GetFieldAsString(index);
324 NIImporter_ArcView::getLaneNo(OGRFeature& poFeature,
const std::string& edgeid,
331 int index = poFeature.GetDefnRef()->GetFieldIndex(
"nolanes");
332 if (index >= 0 && poFeature.IsFieldSet(index)) {
333 return (
unsigned int) poFeature.GetFieldAsInteger(index);
335 index = poFeature.GetDefnRef()->GetFieldIndex(
"NOLANES");
336 if (index >= 0 && poFeature.IsFieldSet(index)) {
337 return (
unsigned int) poFeature.GetFieldAsInteger(index);
339 index = poFeature.GetDefnRef()->GetFieldIndex(
"rnol");
340 if (index >= 0 && poFeature.IsFieldSet(index)) {
341 return (
unsigned int) poFeature.GetFieldAsInteger(index);
343 index = poFeature.GetDefnRef()->GetFieldIndex(
"LANE_CAT");
344 if (index >= 0 && poFeature.IsFieldSet(index)) {
345 std::string def = poFeature.GetFieldAsString(index);
353 NIImporter_ArcView::getPriority(OGRFeature& poFeature,
const std::string& ) {
359 int index = poFeature.GetDefnRef()->GetFieldIndex(
"priority");
360 if (index >= 0 && poFeature.IsFieldSet(index)) {
361 return poFeature.GetFieldAsInteger(index);
363 index = poFeature.GetDefnRef()->GetFieldIndex(
"PRIORITY");
364 if (index >= 0 && poFeature.IsFieldSet(index)) {
365 return poFeature.GetFieldAsInteger(index);
368 index = poFeature.GetDefnRef()->GetFieldIndex(
"FUNC_CLASS");
369 if (index >= 0 && poFeature.IsFieldSet(index)) {
370 return poFeature.GetFieldAsInteger(index);
376 NIImporter_ArcView::checkSpread(
NBEdge* e) {
385 NIImporter_ArcView::getStringEntry(OGRFeature* poFeature,
const std::string& optionName,
const char* defaultName,
bool prune, std::string& into) {
386 std::string v(defaultName);
390 if (poFeature->GetFieldIndex(v.c_str()) < 0) {
398 into = poFeature->GetFieldAsString((
char*)v.c_str());
static MsgHandler * getErrorInstance()
Returns the instance to add errors to.
NBTypeCont & getTypeCont()
Returns the type container.
~NIImporter_ArcView()
Destructor.
static bool transformCoordinates(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.
std::string mySHPName
The name of the shape file.
bool getBool(const std::string &name) const
Returns the boolean-value of the named option (only for Option_Bool)
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.
const OptionsCont & myOptions
The options to use.
void load()
Loads the shape files.
static const SUMOReal UNSPECIFIED_OFFSET
unspecified lane offset
#define UNUSED_PARAMETER(x)
SUMOReal getWidth(const std::string &type) const
Returns the lane width for the given type [m/s].
#define WRITE_WARNING(msg)
PositionVector reverse() const
std::string getString(const std::string &name) const
Returns the string-value of the named option (only for Option_String)
SUMOReal getSpeed(const std::string &type) const
Returns the maximal velocity for the given type [m/s].
bool insert(NBEdge *edge, bool ignorePrunning=false)
Adds an edge to the dictionary.
A point in 2D or 3D with translation and scaling methods.
int getNumLanes(const std::string &type) const
Returns the number of lanes for the given type.
NBEdgeCont & getEdgeCont()
Returns the edge container.
int getPriority(const std::string &type) const
Returns the priority for the given type.
static bool exists(std::string path)
Checks whether the given file exists.
Storage for edges, including some functionality operating on multiple edges.
Importer for networks stored in ArcView-shape format.
#define PROGRESS_BEGIN_MESSAGE(msg)
std::string toString(const T &t, std::streamsize accuracy=OUTPUT_ACCURACY)
NBEdge * getConnectionTo(NBNode *n) const
static unsigned int getLaneNumber(const std::string &id, const std::string &laneNoS, SUMOReal speed)
Returns the lane number evaluating the given Navteq-description.
static SUMOReal getSpeed(const std::string &id, const std::string &speedClassS)
Returns the speed evaluating the given Navteq-description.
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.
NBNode * getToNode() const
Returns the destination node of the edge.
static std::string prune(const std::string &str)
Removes trailing and leading whitechars.
NBEdge * retrieve(const std::string &id, bool retrieveExtracted=false) const
Returns the edge that has the given id.
NBNodeCont & getNodeCont()
Returns the node container.
Instance responsible for building networks.
NBNodeCont & myNodeCont
The container to add nodes to.
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.
void push_back_noDoublePos(const Position &p)
NBNode * retrieve(const std::string &id) const
Returns the node with the given name.
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
bool mySpeedInKMH
Whether the speed is given in km/h.
A storage for available types of edges.
bool isSet(const std::string &name, bool failOnNonExistant=true) const
Returns the information whether the named option is set.
NBNode * getFromNode() const
Returns the origin node of the edge.