Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
eclipse
GitHub Repository: eclipse/sumo
Path: blob/main/src/netimport/NIImporter_ArcView.cpp
169665 views
1
/****************************************************************************/
2
// Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.dev/sumo
3
// Copyright (C) 2001-2025 German Aerospace Center (DLR) and others.
4
// This program and the accompanying materials are made available under the
5
// terms of the Eclipse Public License 2.0 which is available at
6
// https://www.eclipse.org/legal/epl-2.0/
7
// This Source Code may also be made available under the following Secondary
8
// Licenses when the conditions for such availability set forth in the Eclipse
9
// Public License 2.0 are satisfied: GNU General Public License, version 2
10
// or later which is available at
11
// https://www.gnu.org/licenses/old-licenses/gpl-2.0-standalone.html
12
// SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-or-later
13
/****************************************************************************/
14
/// @file NIImporter_ArcView.cpp
15
/// @author Daniel Krajzewicz
16
/// @author Eric Nicolay
17
/// @author Jakob Erdmann
18
/// @author Thimor Bohn
19
/// @author Michael Behrisch
20
/// @date Sept 2002
21
///
22
// Importer for networks stored in ArcView-shape format
23
/****************************************************************************/
24
#include <config.h>
25
26
#include <string>
27
#include <utils/common/MsgHandler.h>
28
#include <utils/common/ToString.h>
29
#include <utils/common/StringUtils.h>
30
#include <utils/common/StringUtils.h>
31
#include <utils/options/OptionsCont.h>
32
#include <utils/geom/GeomHelper.h>
33
#include <netbuild/NBNetBuilder.h>
34
#include <netbuild/NBHelpers.h>
35
#include <netbuild/NBEdge.h>
36
#include <netbuild/NBEdgeCont.h>
37
#include <netbuild/NBTypeCont.h>
38
#include <netbuild/NBNode.h>
39
#include <netbuild/NBNodeCont.h>
40
#include <netimport/NINavTeqHelper.h>
41
#include <utils/geom/GeoConvHelper.h>
42
#include <utils/common/FileHelpers.h>
43
#include "NILoader.h"
44
#include "NIImporter_ArcView.h"
45
46
#ifdef HAVE_GDAL
47
#ifdef _MSC_VER
48
#pragma warning(push)
49
#pragma warning(disable: 4435 5219 5220)
50
#endif
51
#if __GNUC__ > 3
52
#pragma GCC diagnostic push
53
#pragma GCC diagnostic ignored "-Wpedantic"
54
#endif
55
#include <ogrsf_frmts.h>
56
#if __GNUC__ > 3
57
#pragma GCC diagnostic pop
58
#endif
59
#ifdef _MSC_VER
60
#pragma warning(pop)
61
#endif
62
#endif
63
64
65
// ===========================================================================
66
// method definitions
67
// ===========================================================================
68
// ---------------------------------------------------------------------------
69
// static methods (interface in this case)
70
// ---------------------------------------------------------------------------
71
void
72
NIImporter_ArcView::loadNetwork(const OptionsCont& oc, NBNetBuilder& nb) {
73
if (!oc.isSet("shapefile-prefix")) {
74
return;
75
}
76
// check whether the correct set of entries is given
77
// and compute all file names
78
const std::string dbf_file = oc.getString("shapefile-prefix") + ".dbf";
79
const std::string shp_file = oc.getString("shapefile-prefix") + ".shp";
80
const std::string shx_file = oc.getString("shapefile-prefix") + ".shx";
81
if (!StringUtils::startsWith(shp_file, "/vsi")) {
82
// if we are not using a virtual file system, check whether the files do exist
83
if (!FileHelpers::isReadable(dbf_file)) {
84
WRITE_ERROR("File not accessible: " + dbf_file);
85
}
86
if (!FileHelpers::isReadable(shp_file)) {
87
WRITE_ERROR("File not accessible: " + shp_file);
88
}
89
if (!FileHelpers::isReadable(shx_file)) {
90
WRITE_ERROR("File not accessible: " + shx_file);
91
}
92
}
93
if (MsgHandler::getErrorInstance()->wasInformed()) {
94
return;
95
}
96
// load the arcview files
97
NIImporter_ArcView loader(oc, nb.getNodeCont(), nb.getEdgeCont(), nb.getTypeCont(),
98
shp_file, oc.getBool("speed-in-kmh"));
99
loader.load();
100
}
101
102
103
104
// ---------------------------------------------------------------------------
105
// loader methods
106
// ---------------------------------------------------------------------------
107
NIImporter_ArcView::NIImporter_ArcView(const OptionsCont& oc,
108
NBNodeCont& nc,
109
NBEdgeCont& ec,
110
NBTypeCont& tc,
111
const std::string& shp_name,
112
bool speedInKMH)
113
: myOptions(oc), mySHPName(shp_name),
114
myNameAddition(0),
115
myNodeCont(nc), myEdgeCont(ec), myTypeCont(tc),
116
mySpeedInKMH(speedInKMH),
117
myRunningEdgeID(0),
118
myRunningNodeID(0) {
119
}
120
121
122
NIImporter_ArcView::~NIImporter_ArcView() {}
123
124
125
void
126
NIImporter_ArcView::load() {
127
#ifdef HAVE_GDAL
128
PROGRESS_BEGIN_MESSAGE("Loading data from '" + mySHPName + "'");
129
#if GDAL_VERSION_MAJOR < 2
130
OGRRegisterAll();
131
OGRDataSource* poDS = OGRSFDriverRegistrar::Open(mySHPName.c_str(), FALSE);
132
#else
133
GDALAllRegister();
134
GDALDataset* poDS = (GDALDataset*)GDALOpenEx(mySHPName.c_str(), GDAL_OF_VECTOR | GA_ReadOnly, NULL, NULL, NULL);
135
#endif
136
if (poDS == NULL) {
137
WRITE_ERRORF(TL("Could not open shape description '%'."), mySHPName);
138
return;
139
}
140
141
// begin file parsing
142
OGRLayer* poLayer = poDS->GetLayer(0);
143
poLayer->ResetReading();
144
145
// build coordinate transformation
146
OGRSpatialReference* origTransf = poLayer->GetSpatialRef();
147
OGRSpatialReference destTransf;
148
// use wgs84 as destination
149
destTransf.SetWellKnownGeogCS("WGS84");
150
#if GDAL_VERSION_MAJOR > 2
151
if (myOptions.getBool("shapefile.traditional-axis-mapping") || origTransf != nullptr) {
152
destTransf.SetAxisMappingStrategy(OAMS_TRADITIONAL_GIS_ORDER);
153
}
154
#endif
155
OGRCoordinateTransformation* poCT = origTransf == nullptr ? nullptr : OGRCreateCoordinateTransformation(origTransf, &destTransf);
156
if (poCT == nullptr) {
157
if (myOptions.getBool("shapefile.guess-projection")) {
158
OGRSpatialReference origTransf2;
159
origTransf2.SetWellKnownGeogCS("WGS84");
160
poCT = OGRCreateCoordinateTransformation(&origTransf2, &destTransf);
161
}
162
}
163
164
const bool saveOrigIDs = OptionsCont::getOptions().getBool("output.original-names");
165
OGRFeature* poFeature;
166
poLayer->ResetReading();
167
168
const double nodeJoinDist = myOptions.getFloat("shapefile.node-join-dist");
169
const std::vector<std::string> params = myOptions.getStringVector("shapefile.add-params");
170
171
int featureIndex = 0;
172
bool warnNotUnique = true;
173
bool warnMissingProjection = true;
174
std::string idPrefix = ""; // prefix for non-unique street-id values
175
std::map<std::string, int> idIndex; // running index to make street-id unique
176
while ((poFeature = poLayer->GetNextFeature()) != NULL) {
177
// read in edge attributes
178
if (featureIndex == 0) {
179
WRITE_MESSAGE("Available fields: " + toString(getFieldNames(poFeature)));
180
}
181
std::string id;
182
std::string name;
183
std::string from_node;
184
std::string to_node;
185
if (!getStringEntry(poFeature, "shapefile.street-id", "LINK_ID", true, id)) {
186
WRITE_ERRORF(TL("Needed field '%' (street-id) is missing."), id);
187
id = "";
188
}
189
if (id == "") {
190
id = toString(myRunningEdgeID++);
191
}
192
193
getStringEntry(poFeature, "shapefile.name", "ST_NAME", true, name);
194
name = StringUtils::replace(name, "&", "&amp;");
195
196
if (!getStringEntry(poFeature, "shapefile.from-id", "REF_IN_ID", true, from_node)) {
197
WRITE_ERRORF(TL("Needed field '%' (from node id) is missing."), from_node);
198
from_node = "";
199
}
200
if (!getStringEntry(poFeature, "shapefile.to-id", "NREF_IN_ID", true, to_node)) {
201
WRITE_ERRORF(TL("Needed field '%' (to node id) is missing."), to_node);
202
to_node = "";
203
}
204
205
if (from_node == "" || to_node == "") {
206
from_node = toString(myRunningNodeID++);
207
to_node = toString(myRunningNodeID++);
208
}
209
210
std::string type;
211
if (myOptions.isSet("shapefile.type-id") && poFeature->GetFieldIndex(myOptions.getString("shapefile.type-id").c_str()) >= 0) {
212
type = poFeature->GetFieldAsString(myOptions.getString("shapefile.type-id").c_str());
213
} else if (poFeature->GetFieldIndex("ST_TYP_AFT") >= 0) {
214
type = poFeature->GetFieldAsString("ST_TYP_AFT");
215
}
216
if ((type != "" || myOptions.isSet("shapefile.type-id")) && !myTypeCont.knows(type)) {
217
WRITE_WARNINGF(TL("Unknown type '%' for edge '%'"), type, id);
218
}
219
bool oneway = myTypeCont.knows(type) ? myTypeCont.getEdgeTypeIsOneWay(type) : false;
220
double speed = getSpeed(*poFeature, id);
221
int nolanes = getLaneNo(*poFeature, id, speed);
222
int priority = getPriority(*poFeature, id);
223
double width = getLaneWidth(*poFeature, id, nolanes);
224
double length = getLength(*poFeature, id);
225
if (nolanes <= 0 || speed <= 0) {
226
if (myOptions.getBool("shapefile.use-defaults-on-failure")) {
227
nolanes = nolanes <= 0 ? myTypeCont.getEdgeTypeNumLanes(type) : nolanes;
228
speed = speed <= 0 ? myTypeCont.getEdgeTypeSpeed(type) : speed;
229
} else {
230
const std::string lanesField = myOptions.isSet("shapefile.laneNumber") ? myOptions.getString("shapefile.laneNumber") : "nolanes";
231
const std::string speedField = myOptions.isSet("shapefile.speed") ? myOptions.getString("shapefile.speed") : "speed";
232
WRITE_ERRORF(TL("Required field '%' or '%' is missing (add fields or set option --shapefile.use-defaults-on-failure)."), lanesField, speedField);
233
WRITE_ERROR("Available fields: " + toString(getFieldNames(poFeature)));
234
OGRFeature::DestroyFeature(poFeature);
235
return;
236
}
237
}
238
if (mySpeedInKMH) {
239
speed /= 3.6;
240
}
241
242
243
// read in the geometry
244
OGRGeometry* poGeometry = poFeature->GetGeometryRef();
245
OGRwkbGeometryType gtype = poGeometry->getGeometryType();
246
if (gtype != wkbLineString && gtype != wkbLineString25D) {
247
OGRFeature::DestroyFeature(poFeature);
248
WRITE_ERRORF(TL("Road geometry must be of type 'linestring' or 'linestring25D' (found '%')"), toString(gtype));
249
return;
250
}
251
OGRLineString* cgeom = (OGRLineString*) poGeometry;
252
if (poCT == nullptr && warnMissingProjection) {
253
int outOfRange = 0;
254
for (int j = 0; j < cgeom->getNumPoints(); j++) {
255
if (fabs(cgeom->getX(j)) > 180 || fabs(cgeom->getY(j)) > 90) {
256
outOfRange++;
257
}
258
}
259
if (2 * outOfRange > cgeom->getNumPoints()) {
260
WRITE_WARNING(TL("No coordinate system found and coordinates look already projected."));
261
GeoConvHelper::init("!", GeoConvHelper::getProcessing().getOffset(), GeoConvHelper::getProcessing().getOrigBoundary(), GeoConvHelper::getProcessing().getConvBoundary());
262
} else {
263
WRITE_WARNING(TL("Could not find geo coordinate system, assuming WGS84."));
264
}
265
warnMissingProjection = false;
266
}
267
if (poCT != nullptr) {
268
// try transform to wgs84
269
cgeom->transform(poCT);
270
}
271
272
PositionVector shape;
273
for (int j = 0; j < cgeom->getNumPoints(); j++) {
274
Position pos(cgeom->getX(j), cgeom->getY(j), cgeom->getZ(j));
275
if (!NBNetBuilder::transformCoordinate(pos)) {
276
WRITE_WARNINGF(TL("Unable to project coordinates for edge '%'."), id);
277
}
278
shape.push_back_noDoublePos(pos);
279
}
280
281
// build from-node
282
NBNode* from = myNodeCont.retrieve(from_node);
283
if (from == nullptr) {
284
Position from_pos = shape[0];
285
std::vector<NBNode*> cands = myNodeCont.retrieveByPos(from_pos, nodeJoinDist);
286
if (!cands.empty()) {
287
from = cands.front();
288
}
289
if (from == nullptr) {
290
from = new NBNode(from_node, from_pos);
291
if (!myNodeCont.insert(from)) {
292
WRITE_ERRORF(TL("Node '%' could not be added"), from_node);
293
delete from;
294
continue;
295
}
296
}
297
}
298
// build to-node
299
NBNode* to = myNodeCont.retrieve(to_node);
300
if (to == nullptr) {
301
Position to_pos = shape[-1];
302
std::vector<NBNode*> cands = myNodeCont.retrieveByPos(to_pos, nodeJoinDist);
303
if (!cands.empty()) {
304
to = cands.front();
305
}
306
if (to == nullptr) {
307
to = new NBNode(to_node, to_pos);
308
if (!myNodeCont.insert(to)) {
309
WRITE_ERRORF(TL("Node '%' could not be added"), to_node);
310
delete to;
311
continue;
312
}
313
}
314
}
315
316
if (from == to) {
317
WRITE_WARNINGF(TL("Edge '%' connects identical nodes, skipping."), id);
318
continue;
319
}
320
321
// retrieve the information whether the street is bi-directional
322
std::string dir;
323
int index = poFeature->GetDefnRef()->GetFieldIndex("DIR_TRAVEL");
324
if (index >= 0 && poFeature->IsFieldSet(index)) {
325
dir = poFeature->GetFieldAsString(index);
326
}
327
const std::string origID = saveOrigIDs ? id : "";
328
// check for duplicate ids
329
NBEdge* const existing = myEdgeCont.retrieve(id);
330
NBEdge* const existingReverse = myEdgeCont.retrieve("-" + id);
331
if (existing != nullptr || existingReverse != nullptr) {
332
if ((existing != nullptr && existing->getGeometry() == shape)
333
|| (existingReverse != nullptr && existingReverse->getGeometry() == shape.reverse())) {
334
WRITE_ERRORF(TL("Edge '%' is not unique."), (existing != nullptr ? id : existingReverse->getID()));
335
} else {
336
if (idIndex.count(id) == 0) {
337
idIndex[id] = 0;
338
}
339
idIndex[id]++;
340
idPrefix = id;
341
id += "#" + toString(idIndex[id]);
342
if (warnNotUnique) {
343
WRITE_WARNINGF(TL("Edge '%' is not unique. Renaming subsequent edge to '%'."), idPrefix, id);
344
warnNotUnique = false;
345
}
346
}
347
}
348
// add positive direction if wanted
349
if (dir == "B" || dir == "F" || dir == "" || myOptions.getBool("shapefile.all-bidirectional")) {
350
if (myEdgeCont.retrieve(id) == 0) {
351
LaneSpreadFunction spread = dir == "B" || dir == "FALSE" ? LaneSpreadFunction::RIGHT : LaneSpreadFunction::CENTER;
352
if (spread == LaneSpreadFunction::RIGHT && OptionsCont::getOptions().getString("default.spreadtype") == toString(LaneSpreadFunction::ROADCENTER)) {
353
spread = LaneSpreadFunction::ROADCENTER;
354
}
355
NBEdge* edge = new NBEdge(id, from, to, type, speed, NBEdge::UNSPECIFIED_FRICTION, nolanes, priority, width, NBEdge::UNSPECIFIED_OFFSET, shape, spread, name, origID);
356
edge->setPermissions(myTypeCont.getEdgeTypePermissions(type));
357
edge->setLoadedLength(length);
358
myEdgeCont.insert(edge);
359
checkSpread(edge);
360
addParams(edge, poFeature, params);
361
} else {
362
WRITE_ERRORF(TL("Could not create edge '%'. An edge with the same id already exists."), id);
363
}
364
}
365
// add negative direction if wanted
366
if ((dir == "B" || dir == "T" || myOptions.getBool("shapefile.all-bidirectional")) && !oneway) {
367
if (myEdgeCont.retrieve("-" + id) == 0) {
368
LaneSpreadFunction spread = dir == "B" || dir == "FALSE" ? LaneSpreadFunction::RIGHT : LaneSpreadFunction::CENTER;
369
if (spread == LaneSpreadFunction::RIGHT && OptionsCont::getOptions().getString("default.spreadtype") == toString(LaneSpreadFunction::ROADCENTER)) {
370
spread = LaneSpreadFunction::ROADCENTER;
371
}
372
NBEdge* edge = new NBEdge("-" + id, to, from, type, speed, NBEdge::UNSPECIFIED_FRICTION, nolanes, priority, width, NBEdge::UNSPECIFIED_OFFSET, shape.reverse(), spread, name, origID);
373
edge->setPermissions(myTypeCont.getEdgeTypePermissions(type));
374
edge->setLoadedLength(length);
375
myEdgeCont.insert(edge);
376
checkSpread(edge);
377
addParams(edge, poFeature, params);
378
} else {
379
WRITE_ERRORF(TL("Could not create edge '-%'. An edge with the same id already exists."), id);
380
}
381
}
382
//
383
OGRFeature::DestroyFeature(poFeature);
384
featureIndex++;
385
}
386
#if GDAL_VERSION_MAJOR < 2
387
OGRDataSource::DestroyDataSource(poDS);
388
#else
389
GDALClose(poDS);
390
#endif
391
PROGRESS_DONE_MESSAGE();
392
#else
393
WRITE_ERROR(TL("SUMO was compiled without GDAL support."));
394
#endif
395
}
396
397
#ifdef HAVE_GDAL
398
double
399
NIImporter_ArcView::getSpeed(OGRFeature& poFeature, const std::string& edgeid) {
400
if (myOptions.isSet("shapefile.speed")) {
401
int index = poFeature.GetDefnRef()->GetFieldIndex(myOptions.getString("shapefile.speed").c_str());
402
if (index >= 0 && poFeature.IsFieldSet(index)) {
403
const double speed = poFeature.GetFieldAsDouble(index);
404
if (speed <= 0) {
405
WRITE_WARNING("invalid value for field: '"
406
+ myOptions.getString("shapefile.speed")
407
+ "': '" + std::string(poFeature.GetFieldAsString(index)) + "'");
408
} else {
409
return speed;
410
}
411
}
412
}
413
if (myOptions.isSet("shapefile.type-id")) {
414
return myTypeCont.getEdgeTypeSpeed(poFeature.GetFieldAsString((char*)(myOptions.getString("shapefile.type-id").c_str())));
415
}
416
// try to get definitions as to be found in SUMO-XML-definitions
417
// idea by John Michael Calandrino
418
int index = poFeature.GetDefnRef()->GetFieldIndex("speed");
419
if (index >= 0 && poFeature.IsFieldSet(index)) {
420
return (double) poFeature.GetFieldAsDouble(index);
421
}
422
index = poFeature.GetDefnRef()->GetFieldIndex("SPEED");
423
if (index >= 0 && poFeature.IsFieldSet(index)) {
424
return (double) poFeature.GetFieldAsDouble(index);
425
}
426
// try to get the NavTech-information
427
index = poFeature.GetDefnRef()->GetFieldIndex("SPEED_CAT");
428
if (index >= 0 && poFeature.IsFieldSet(index)) {
429
std::string def = poFeature.GetFieldAsString(index);
430
return NINavTeqHelper::getSpeed(edgeid, def);
431
}
432
return -1;
433
}
434
435
436
double
437
NIImporter_ArcView::getLaneWidth(OGRFeature& poFeature, const std::string& edgeid, int laneNumber) {
438
if (myOptions.isSet("shapefile.width")) {
439
int index = poFeature.GetDefnRef()->GetFieldIndex(myOptions.getString("shapefile.width").c_str());
440
if (index >= 0 && poFeature.IsFieldSet(index)) {
441
const double width = poFeature.GetFieldAsDouble(index);
442
if (width <= 0) {
443
WRITE_WARNING("invalid value for field: '"
444
+ myOptions.getString("shapefile.width")
445
+ "' of edge '" + edgeid
446
+ "': '" + std::string(poFeature.GetFieldAsString(index)) + "'");
447
} else {
448
return width / laneNumber;
449
}
450
}
451
}
452
if (myOptions.isSet("shapefile.type-id")) {
453
return myTypeCont.getEdgeTypeWidth(poFeature.GetFieldAsString((char*)(myOptions.getString("shapefile.type-id").c_str())));
454
}
455
return NBEdge::UNSPECIFIED_WIDTH;
456
}
457
458
459
460
double
461
NIImporter_ArcView::getLength(OGRFeature& poFeature, const std::string& edgeid) {
462
if (myOptions.isSet("shapefile.length")) {
463
int index = poFeature.GetDefnRef()->GetFieldIndex(myOptions.getString("shapefile.length").c_str());
464
if (index >= 0 && poFeature.IsFieldSet(index)) {
465
const double length = poFeature.GetFieldAsDouble(index);
466
if (length <= 0) {
467
WRITE_WARNING("invalid value for field: '"
468
+ myOptions.getString("shapefile.length")
469
+ "' of edge '" + edgeid
470
+ "': '" + std::string(poFeature.GetFieldAsString(index)) + "'");
471
} else {
472
return length;
473
}
474
}
475
}
476
return NBEdge::UNSPECIFIED_LOADED_LENGTH;
477
}
478
479
480
int
481
NIImporter_ArcView::getLaneNo(OGRFeature& poFeature, const std::string& edgeid,
482
double speed) {
483
if (myOptions.isSet("shapefile.laneNumber")) {
484
int index = poFeature.GetDefnRef()->GetFieldIndex(myOptions.getString("shapefile.laneNumber").c_str());
485
if (index >= 0 && poFeature.IsFieldSet(index)) {
486
const int laneNumber = poFeature.GetFieldAsInteger(index);
487
if (laneNumber <= 0) {
488
WRITE_WARNING("invalid value for field '"
489
+ myOptions.getString("shapefile.laneNumber")
490
+ "': '" + std::string(poFeature.GetFieldAsString(index)) + "'");
491
} else {
492
return laneNumber;
493
}
494
}
495
}
496
if (myOptions.isSet("shapefile.type-id")) {
497
return (int) myTypeCont.getEdgeTypeNumLanes(poFeature.GetFieldAsString((char*)(myOptions.getString("shapefile.type-id").c_str())));
498
}
499
// try to get definitions as to be found in SUMO-XML-definitions
500
// idea by John Michael Calandrino
501
int index = poFeature.GetDefnRef()->GetFieldIndex("nolanes");
502
if (index >= 0 && poFeature.IsFieldSet(index)) {
503
return (int) poFeature.GetFieldAsInteger(index);
504
}
505
index = poFeature.GetDefnRef()->GetFieldIndex("NOLANES");
506
if (index >= 0 && poFeature.IsFieldSet(index)) {
507
return (int) poFeature.GetFieldAsInteger(index);
508
}
509
index = poFeature.GetDefnRef()->GetFieldIndex("rnol");
510
if (index >= 0 && poFeature.IsFieldSet(index)) {
511
return (int) poFeature.GetFieldAsInteger(index);
512
}
513
index = poFeature.GetDefnRef()->GetFieldIndex("LANE_CAT");
514
if (index >= 0 && poFeature.IsFieldSet(index)) {
515
std::string def = poFeature.GetFieldAsString(index);
516
return NINavTeqHelper::getLaneNumber(edgeid, def, speed);
517
}
518
return 0;
519
}
520
521
522
int
523
NIImporter_ArcView::getPriority(OGRFeature& poFeature, const std::string& /*edgeid*/) {
524
if (myOptions.isSet("shapefile.type-id")) {
525
return myTypeCont.getEdgeTypePriority(poFeature.GetFieldAsString((char*)(myOptions.getString("shapefile.type-id").c_str())));
526
}
527
// try to get definitions as to be found in SUMO-XML-definitions
528
// idea by John Michael Calandrino
529
int index = poFeature.GetDefnRef()->GetFieldIndex("priority");
530
if (index >= 0 && poFeature.IsFieldSet(index)) {
531
return poFeature.GetFieldAsInteger(index);
532
}
533
index = poFeature.GetDefnRef()->GetFieldIndex("PRIORITY");
534
if (index >= 0 && poFeature.IsFieldSet(index)) {
535
return poFeature.GetFieldAsInteger(index);
536
}
537
// try to determine priority from NavTechs FUNC_CLASS attribute
538
index = poFeature.GetDefnRef()->GetFieldIndex("FUNC_CLASS");
539
if (index >= 0 && poFeature.IsFieldSet(index)) {
540
return poFeature.GetFieldAsInteger(index);
541
}
542
return 0;
543
}
544
545
void
546
NIImporter_ArcView::checkSpread(NBEdge* e) {
547
NBEdge* ret = e->getToNode()->getConnectionTo(e->getFromNode());
548
if (ret != 0) {
549
e->setLaneSpreadFunction(LaneSpreadFunction::RIGHT);
550
ret->setLaneSpreadFunction(LaneSpreadFunction::RIGHT);
551
}
552
}
553
554
bool
555
NIImporter_ArcView::getStringEntry(OGRFeature* poFeature, const std::string& optionName, const char* defaultName, bool prune, std::string& into) {
556
std::string v(defaultName);
557
if (myOptions.isSet(optionName)) {
558
v = myOptions.getString(optionName);
559
}
560
if (poFeature->GetFieldIndex(v.c_str()) < 0) {
561
if (myOptions.isSet(optionName)) {
562
into = v;
563
return false;
564
}
565
into = "";
566
return true;
567
}
568
into = poFeature->GetFieldAsString((char*)v.c_str());
569
if (prune) {
570
into = StringUtils::prune(into);
571
}
572
return true;
573
}
574
575
std::vector<std::string>
576
NIImporter_ArcView::getFieldNames(OGRFeature* poFeature) const {
577
std::vector<std::string> fields;
578
for (int i = 0; i < poFeature->GetFieldCount(); i++) {
579
fields.push_back(poFeature->GetFieldDefnRef(i)->GetNameRef());
580
}
581
return fields;
582
}
583
584
void
585
NIImporter_ArcView::addParams(NBEdge* edge, OGRFeature* poFeature, const std::vector<std::string>& params) const {
586
for (const std::string& p : params) {
587
int index = poFeature->GetDefnRef()->GetFieldIndex(p.c_str());
588
if (index >= 0 && poFeature->IsFieldSet(index)) {
589
edge->setParameter(p, poFeature->GetFieldAsString(index));
590
}
591
}
592
}
593
594
#endif
595
596
597
/****************************************************************************/
598
599