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,
128 #if GDAL_VERSION_MAJOR < 2 130 OGRDataSource* poDS = OGRSFDriverRegistrar::Open(
mySHPName.c_str(), FALSE);
133 GDALDataset* poDS = (GDALDataset*)GDALOpenEx(
mySHPName.c_str(), GDAL_OF_VECTOR | GA_ReadOnly, NULL, NULL, NULL);
141 OGRLayer* poLayer = poDS->GetLayer(0);
142 poLayer->ResetReading();
145 OGRSpatialReference* origTransf = poLayer->GetSpatialRef();
146 OGRSpatialReference destTransf;
148 destTransf.SetWellKnownGeogCS(
"WGS84");
149 OGRCoordinateTransformation* poCT = OGRCreateCoordinateTransformation(origTransf, &destTransf);
152 OGRSpatialReference origTransf2;
153 origTransf2.SetWellKnownGeogCS(
"WGS84");
154 poCT = OGRCreateCoordinateTransformation(&origTransf2, &destTransf);
157 WRITE_WARNING(
"Could not create geocoordinates converter; check whether proj.4 is installed.");
161 OGRFeature* poFeature;
162 poLayer->ResetReading();
163 while ((poFeature = poLayer->GetNextFeature()) != NULL) {
165 std::string id, name, from_node, to_node;
166 if (!getStringEntry(poFeature,
"shapefile.street-id",
"LINK_ID",
true,
id)) {
167 WRITE_ERROR(
"Needed field '" +
id +
"' (from node id) is missing.");
174 getStringEntry(poFeature,
"shapefile.street-id",
"ST_NAME",
true, name);
177 if (!getStringEntry(poFeature,
"shapefile.from-id",
"REF_IN_ID",
true, from_node)) {
178 WRITE_ERROR(
"Needed field '" + from_node +
"' (from node id) is missing.");
180 if (!getStringEntry(poFeature,
"shapefile.to-id",
"NREF_IN_ID",
true, to_node)) {
181 WRITE_ERROR(
"Needed field '" + to_node +
"' (to node id) is missing.");
184 if (from_node ==
"" || to_node ==
"") {
192 }
else if (poFeature->GetFieldIndex(
"ST_TYP_AFT") >= 0) {
193 type = poFeature->GetFieldAsString(
"ST_TYP_AFT");
196 SUMOReal speed = getSpeed(*poFeature,
id);
197 int nolanes = getLaneNo(*poFeature,
id, speed);
198 int priority = getPriority(*poFeature,
id);
199 if (nolanes == 0 || speed == 0) {
204 OGRFeature::DestroyFeature(poFeature);
205 WRITE_ERROR(
"The description seems to be invalid. Please recheck usage of types.");
215 OGRGeometry* poGeometry = poFeature->GetGeometryRef();
216 OGRwkbGeometryType gtype = poGeometry->getGeometryType();
217 assert(gtype == wkbLineString);
219 OGRLineString* cgeom = (OGRLineString*) poGeometry;
222 cgeom->transform(poCT);
226 for (
int j = 0; j < cgeom->getNumPoints(); j++) {
229 WRITE_WARNING(
"Unable to project coordinates for edge '" +
id +
"'.");
240 from =
new NBNode(from_node, from_pos);
242 WRITE_ERROR(
"Node '" + from_node +
"' could not be added");
254 to =
new NBNode(to_node, to_pos);
256 WRITE_ERROR(
"Node '" + to_node +
"' could not be added");
264 WRITE_WARNING(
"Edge '" +
id +
"' connects identical nodes, skipping.");
270 int index = poFeature->GetDefnRef()->GetFieldIndex(
"DIR_TRAVEL");
271 if (index >= 0 && poFeature->IsFieldSet(index)) {
272 dir = poFeature->GetFieldAsString(index);
275 if (dir ==
"B" || dir ==
"F" || dir ==
"" ||
myOptions.
getBool(
"shapefile.all-bidirectional")) {
278 NBEdge* edge =
new NBEdge(
id, from, to, type, speed, nolanes, priority, width,
NBEdge::UNSPECIFIED_OFFSET, shape, name,
id, spread);
284 if (dir ==
"B" || dir ==
"T" ||
myOptions.
getBool(
"shapefile.all-bidirectional")) {
287 NBEdge* edge =
new NBEdge(
"-" +
id, to, from, type, speed, nolanes, priority, width,
NBEdge::UNSPECIFIED_OFFSET, shape.
reverse(), name, id, spread);
293 OGRFeature::DestroyFeature(poFeature);
295 #if GDAL_VERSION_MAJOR < 2 296 OGRDataSource::DestroyDataSource(poDS);
302 WRITE_ERROR(
"SUMO was compiled without GDAL support.");
308 NIImporter_ArcView::getSpeed(OGRFeature& poFeature,
const std::string& edgeid) {
314 int index = poFeature.GetDefnRef()->GetFieldIndex(
"speed");
315 if (index >= 0 && poFeature.IsFieldSet(index)) {
316 return (
SUMOReal) poFeature.GetFieldAsDouble(index);
318 index = poFeature.GetDefnRef()->GetFieldIndex(
"SPEED");
319 if (index >= 0 && poFeature.IsFieldSet(index)) {
320 return (
SUMOReal) poFeature.GetFieldAsDouble(index);
323 index = poFeature.GetDefnRef()->GetFieldIndex(
"SPEED_CAT");
324 if (index >= 0 && poFeature.IsFieldSet(index)) {
325 std::string def = poFeature.GetFieldAsString(index);
333 NIImporter_ArcView::getLaneNo(OGRFeature& poFeature,
const std::string& edgeid,
340 int index = poFeature.GetDefnRef()->GetFieldIndex(
"nolanes");
341 if (index >= 0 && poFeature.IsFieldSet(index)) {
342 return (
int) poFeature.GetFieldAsInteger(index);
344 index = poFeature.GetDefnRef()->GetFieldIndex(
"NOLANES");
345 if (index >= 0 && poFeature.IsFieldSet(index)) {
346 return (
int) poFeature.GetFieldAsInteger(index);
348 index = poFeature.GetDefnRef()->GetFieldIndex(
"rnol");
349 if (index >= 0 && poFeature.IsFieldSet(index)) {
350 return (
int) poFeature.GetFieldAsInteger(index);
352 index = poFeature.GetDefnRef()->GetFieldIndex(
"LANE_CAT");
353 if (index >= 0 && poFeature.IsFieldSet(index)) {
354 std::string def = poFeature.GetFieldAsString(index);
362 NIImporter_ArcView::getPriority(OGRFeature& poFeature,
const std::string& ) {
368 int index = poFeature.GetDefnRef()->GetFieldIndex(
"priority");
369 if (index >= 0 && poFeature.IsFieldSet(index)) {
370 return poFeature.GetFieldAsInteger(index);
372 index = poFeature.GetDefnRef()->GetFieldIndex(
"PRIORITY");
373 if (index >= 0 && poFeature.IsFieldSet(index)) {
374 return poFeature.GetFieldAsInteger(index);
377 index = poFeature.GetDefnRef()->GetFieldIndex(
"FUNC_CLASS");
378 if (index >= 0 && poFeature.IsFieldSet(index)) {
379 return poFeature.GetFieldAsInteger(index);
385 NIImporter_ArcView::checkSpread(
NBEdge* e) {
394 NIImporter_ArcView::getStringEntry(OGRFeature* poFeature,
const std::string& optionName,
const char* defaultName,
bool prune, std::string& into) {
395 std::string v(defaultName);
399 if (poFeature->GetFieldIndex(v.c_str()) < 0) {
407 into = poFeature->GetFieldAsString((
char*)v.c_str());
NBNode * retrieve(const std::string &id) const
Returns the node with the given name.
SUMOReal getSpeed(const std::string &type) const
Returns the maximal velocity for the given type [m/s].
int myNameAddition
A running number to assure unique edge ids.
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.
SUMOReal getWidth(const std::string &type) const
Returns the lane width for the given type [m].
static bool isReadable(std::string path)
Checks whether the given file is readable.
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.
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)
static const SUMOReal UNSPECIFIED_OFFSET
unspecified lane offset
#define UNUSED_PARAMETER(x)
#define WRITE_WARNING(msg)
NBEdge * getConnectionTo(NBNode *n) const
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.
A point in 2D or 3D with translation and scaling methods.
NBEdgeCont & getEdgeCont()
Returns the edge container.
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)
std::string toString(const T &t, std::streamsize accuracy=OUTPUT_ACCURACY)
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.
static std::string prune(const std::string &str)
Removes trailing and leading whitechars.
NBNodeCont & getNodeCont()
Returns 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.
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.
static int getLaneNumber(const std::string &id, const std::string &laneNoS, SUMOReal speed)
Returns the lane number evaluating the given Navteq-description.