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());