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);
213 OGRLineString* cgeom = (OGRLineString*) poGeometry;
216 cgeom->transform(poCT);
220 for (
int j = 0; j < cgeom->getNumPoints(); j++) {
223 WRITE_WARNING(
"Unable to project coordinates for edge '" +
id +
"'.");
234 from =
new NBNode(from_node, from_pos);
236 WRITE_ERROR(
"Node '" + from_node +
"' could not be added");
248 to =
new NBNode(to_node, to_pos);
250 WRITE_ERROR(
"Node '" + to_node +
"' could not be added");
258 WRITE_WARNING(
"Edge '" +
id +
"' connects identical nodes, skipping.");
264 int index = poFeature->GetDefnRef()->GetFieldIndex(
"DIR_TRAVEL");
265 if (index >= 0 && poFeature->IsFieldSet(index)) {
266 dir = poFeature->GetFieldAsString(index);
269 if (dir ==
"B" || dir ==
"F" || dir ==
"" ||
myOptions.
getBool(
"shapefile.all-bidirectional")) {
272 NBEdge* edge =
new NBEdge(
id, from, to, type, speed, nolanes, priority, width,
NBEdge::UNSPECIFIED_OFFSET, shape,
"", spread);
278 if (dir ==
"B" || dir ==
"T" ||
myOptions.
getBool(
"shapefile.all-bidirectional")) {
282 NBEdge* edge =
new NBEdge(
id, to, from, type, speed, nolanes, priority, width,
NBEdge::UNSPECIFIED_OFFSET, shape.
reverse(),
"", spread);
288 OGRFeature::DestroyFeature(poFeature);
292 WRITE_ERROR(
"SUMO was compiled without GDAL support.");
298 NIImporter_ArcView::getSpeed(OGRFeature& poFeature,
const std::string& edgeid) {
304 int index = poFeature.GetDefnRef()->GetFieldIndex(
"speed");
305 if (index >= 0 && poFeature.IsFieldSet(index)) {
306 return (
SUMOReal) poFeature.GetFieldAsDouble(index);
308 index = poFeature.GetDefnRef()->GetFieldIndex(
"SPEED");
309 if (index >= 0 && poFeature.IsFieldSet(index)) {
310 return (
SUMOReal) poFeature.GetFieldAsDouble(index);
313 index = poFeature.GetDefnRef()->GetFieldIndex(
"SPEED_CAT");
314 if (index >= 0 && poFeature.IsFieldSet(index)) {
315 std::string def = poFeature.GetFieldAsString(index);
323 NIImporter_ArcView::getLaneNo(OGRFeature& poFeature,
const std::string& edgeid,
330 int index = poFeature.GetDefnRef()->GetFieldIndex(
"nolanes");
331 if (index >= 0 && poFeature.IsFieldSet(index)) {
332 return (
unsigned int) poFeature.GetFieldAsInteger(index);
334 index = poFeature.GetDefnRef()->GetFieldIndex(
"NOLANES");
335 if (index >= 0 && poFeature.IsFieldSet(index)) {
336 return (
unsigned int) poFeature.GetFieldAsInteger(index);
338 index = poFeature.GetDefnRef()->GetFieldIndex(
"rnol");
339 if (index >= 0 && poFeature.IsFieldSet(index)) {
340 return (
unsigned int) poFeature.GetFieldAsInteger(index);
342 index = poFeature.GetDefnRef()->GetFieldIndex(
"LANE_CAT");
343 if (index >= 0 && poFeature.IsFieldSet(index)) {
344 std::string def = poFeature.GetFieldAsString(index);
352 NIImporter_ArcView::getPriority(OGRFeature& poFeature,
const std::string& ) {
358 int index = poFeature.GetDefnRef()->GetFieldIndex(
"priority");
359 if (index >= 0 && poFeature.IsFieldSet(index)) {
360 return poFeature.GetFieldAsInteger(index);
362 index = poFeature.GetDefnRef()->GetFieldIndex(
"PRIORITY");
363 if (index >= 0 && poFeature.IsFieldSet(index)) {
364 return poFeature.GetFieldAsInteger(index);
367 index = poFeature.GetDefnRef()->GetFieldIndex(
"FUNC_CLASS");
368 if (index >= 0 && poFeature.IsFieldSet(index)) {
369 return poFeature.GetFieldAsInteger(index);
375 NIImporter_ArcView::checkSpread(
NBEdge* e) {
384 NIImporter_ArcView::getStringEntry(OGRFeature* poFeature,
const std::string& optionName,
const char* defaultName,
bool prune, std::string& into) {
385 std::string v(defaultName);
389 if (poFeature->GetFieldIndex(v.c_str()) < 0) {
397 into = poFeature->GetFieldAsString((
char*)v.c_str());