void NIVissimNodeCluster::buildNBNode(NBNodeCont& nc) { if (myConnectors.size() == 0) { return; // !!! Check, whether this can happen } // compute the position PositionVector crossings; IntVector::iterator i, j; // check whether this is a split of an edge only if (myAmEdgeSplit) { // !!! should be assert(myTLID==-1); for (i = myConnectors.begin(); i != myConnectors.end(); i++) { NIVissimConnection* c1 = NIVissimConnection::dictionary(*i); crossings.push_back_noDoublePos(c1->getFromGeomPosition()); } } else { // compute the places the connections cross for (i = myConnectors.begin(); i != myConnectors.end(); i++) { NIVissimAbstractEdge* c1 = NIVissimAbstractEdge::dictionary(*i); c1->buildGeom(); for (j = i + 1; j != myConnectors.end(); j++) { NIVissimAbstractEdge* c2 = NIVissimAbstractEdge::dictionary(*j); c2->buildGeom(); if (c1->crossesEdge(c2)) { crossings.push_back_noDoublePos(c1->crossesEdgeAtPoint(c2)); } } } // alternative way: compute via positions of crossings if (crossings.size() == 0) { for (i = myConnectors.begin(); i != myConnectors.end(); i++) { NIVissimConnection* c1 = NIVissimConnection::dictionary(*i); crossings.push_back_noDoublePos(c1->getFromGeomPosition()); crossings.push_back_noDoublePos(c1->getToGeomPosition()); } } } // get the position (center) Position pos = crossings.getPolygonCenter(); // build the node /* if(myTLID!=-1) { !!! NIVissimTL *tl = NIVissimTL::dictionary(myTLID); if(tl->getType()=="festzeit") { node = new NBNode(getNodeName(), pos.x(), pos.y(), "traffic_light"); } else { node = new NBNode(getNodeName(), pos.x(), pos.y(), "actuated_traffic_light"); } }*/ NBNode* node = new NBNode(getNodeName(), pos, NODETYPE_PRIORITY_JUNCTION); if (!nc.insert(node)) { delete node; throw 1; } myNBNode = node; }
SUMOReal NWWriter_DlrNavteq::getGraphLength(NBEdge* edge) { PositionVector geom = edge->getGeometry(); geom.push_back_noDoublePos(edge->getToNode()->getPosition()); geom.push_front_noDoublePos(edge->getFromNode()->getPosition()); return geom.length(); }
bool NIVissimSingleTypeParser_Verbindungsdefinition::parse(std::istream& from) { int id; from >> id; // type-checking is missing! std::string tag; // Read optional value "Name", skip optional value "Beschriftung" std::string name; while (tag != "von") { tag = overrideOptionalLabel(from); if (tag == "name") { name = readName(from); } } // Read the geometry information NIVissimExtendedEdgePoint from_def = readExtEdgePointDef(from); PositionVector geom; tag = myRead(from); // "ueber" while (tag != "nach") { std::string x = myRead(from); std::string y = myRead(from); if (y != "nach") { geom.push_back_noDoublePos( Position( TplConvert::_2SUMOReal(x.c_str()), TplConvert::_2SUMOReal(y.c_str()) )); tag = myRead(from); try { TplConvert::_2SUMOReal(tag.c_str()); tag = myRead(from); } catch (NumberFormatException&) {} } else { tag = y; } } NIVissimExtendedEdgePoint to_def = readExtEdgePointDef(from); // read some optional values until mandatory "Fahrzeugklassen" occurs SUMOReal dxnothalt = 0; SUMOReal dxeinordnen = 0; SUMOReal zuschlag1, zuschlag2; zuschlag1 = zuschlag2 = 0; SUMOReal seglength = 0; tag = myRead(from); NIVissimConnection::Direction direction = NIVissimConnection::NIVC_DIR_ALL; while (tag != "fahrzeugklassen" && tag != "sperrung" && tag != "auswertung" && tag != "DATAEND") { if (tag == "rechts") { direction = NIVissimConnection::NIVC_DIR_RIGHT; } else if (tag == "links") { direction = NIVissimConnection::NIVC_DIR_LEFT; } else if (tag == "alle") { direction = NIVissimConnection::NIVC_DIR_ALL; } else if (tag == "dxnothalt") { from >> dxnothalt; // type-checking is missing! } else if (tag == "dxeinordnen") {
PositionVector PositionVector::intersectionPoints2D(const Line& line) const { PositionVector ret; for (const_iterator i = begin(); i != end() - 1; i++) { if (GeomHelper::intersects(*i, *(i + 1), line.p1(), line.p2())) { ret.push_back_noDoublePos(GeomHelper::intersection_position2D( *i, *(i + 1), line.p1(), line.p2())); } } return ret; }
PositionVector PositionVector::getSubpart2D(SUMOReal beginOffset, SUMOReal endOffset) const { PositionVector ret; Position begPos = front(); if (beginOffset > POSITION_EPS) { begPos = positionAtOffset2D(beginOffset); } Position endPos = back(); if (endOffset < length() - POSITION_EPS) { endPos = positionAtOffset2D(endOffset); } ret.push_back(begPos); SUMOReal seen = 0; const_iterator i = begin(); // skip previous segments while ((i + 1) != end() && seen + (*i).distanceTo2D(*(i + 1)) < beginOffset) { seen += (*i).distanceTo2D(*(i + 1)); i++; } // append segments in between while ((i + 1) != end() && seen + (*i).distanceTo2D(*(i + 1)) < endOffset) { ret.push_back_noDoublePos(*(i + 1)); /* if(ret.at(-1)!=*(i+1)) { ret.push_back(*(i+1)); } */ seen += (*i).distanceTo2D(*(i + 1)); i++; } // append end ret.push_back_noDoublePos(endPos); return ret; }
void NWWriter_SUMO::writeEdge(OutputDevice& into, const NBEdge& e, bool noNames, bool origNames) { // write the edge's begin into.openTag(SUMO_TAG_EDGE).writeAttr(SUMO_ATTR_ID, e.getID()); into.writeAttr(SUMO_ATTR_FROM, e.getFromNode()->getID()); into.writeAttr(SUMO_ATTR_TO, e.getToNode()->getID()); if (!noNames && e.getStreetName() != "") { into.writeAttr(SUMO_ATTR_NAME, StringUtils::escapeXML(e.getStreetName())); } into.writeAttr(SUMO_ATTR_PRIORITY, e.getPriority()); if (e.getTypeID() != "") { into.writeAttr(SUMO_ATTR_TYPE, e.getTypeID()); } if (e.isMacroscopicConnector()) { into.writeAttr(SUMO_ATTR_FUNCTION, EDGEFUNC_CONNECTOR); } // write the spread type if not default ("right") if (e.getLaneSpreadFunction() != LANESPREAD_RIGHT) { into.writeAttr(SUMO_ATTR_SPREADTYPE, e.getLaneSpreadFunction()); } if (e.hasLoadedLength()) { into.writeAttr(SUMO_ATTR_LENGTH, e.getLoadedLength()); } if (!e.hasDefaultGeometry()) { into.writeAttr(SUMO_ATTR_SHAPE, e.getGeometry()); } // write the lanes const std::vector<NBEdge::Lane>& lanes = e.getLanes(); SUMOReal length = e.getLoadedLength(); if (OptionsCont::getOptions().getBool("no-internal-links") && !e.hasLoadedLength()) { // use length to junction center even if a modified geometry was given PositionVector geom = e.cutAtIntersection(e.getGeometry()); geom.push_back_noDoublePos(e.getToNode()->getCenter()); geom.push_front_noDoublePos(e.getFromNode()->getCenter()); length = geom.length(); } if (length <= 0) { length = POSITION_EPS; } for (unsigned int i = 0; i < (unsigned int) lanes.size(); i++) { const NBEdge::Lane& l = lanes[i]; writeLane(into, e.getID(), e.getLaneID(i), l.speed, l.permissions, l.preferred, l.endOffset, l.width, l.shape, l.origID, length, i, origNames); } // close the edge into.closeTag(); }
void NIImporter_SUMO::addJunction(const SUMOSAXAttributes& attrs) { // get the id, report an error if not given or empty... bool ok = true; std::string id = attrs.getStringReporting(SUMO_ATTR_ID, 0, ok); if (!ok) { return; } if (id[0] == ':') { // internal node return; } SumoXMLNodeType type = NODETYPE_UNKNOWN; std::string typeS = attrs.getStringReporting(SUMO_ATTR_TYPE, id.c_str(), ok); if (SUMOXMLDefinitions::NodeTypes.hasString(typeS)) { type = SUMOXMLDefinitions::NodeTypes.get(typeS); if (type == NODETYPE_DEAD_END_DEPRECATED) { // patch legacy type type = NODETYPE_DEAD_END; } } else { WRITE_WARNING("Unknown node type '" + typeS + "' for junction '" + id + "'."); } Position pos = readPosition(attrs, id, ok); NILoader::transformCoordinates(pos, true, myLocation); // the network may have been built with the option "plain.keep-edge-shape" this // makes accurate reconstruction of legacy networks impossible. We ought to warn about this std::string shapeS = attrs.getStringReporting(SUMO_ATTR_SHAPE, id.c_str(), ok, false); if (shapeS != "") { PositionVector shape = GeomConvHelper::parseShapeReporting( shapeS, attrs.getObjectType(), id.c_str(), ok, false); shape.push_back_noDoublePos(shape[0]); // need closed shape if (!shape.around(pos) && shape.distance(pos) > 1) { // MAGIC_THRESHOLD // WRITE_WARNING("Junction '" + id + "': distance between pos and shape is " + toString(shape.distance(pos))); mySuspectKeepShape = true; } } NBNode* node = new NBNode(id, pos, type); if (!myNodeCont.insert(node)) { WRITE_ERROR("Problems on adding junction '" + id + "'."); delete node; return; } }
void NIImporter_SUMO::addJunction(const SUMOSAXAttributes& attrs) { // get the id, report an error if not given or empty... bool ok = true; std::string id = attrs.getStringReporting(SUMO_ATTR_ID, 0, ok); if (!ok) { return; } if (id[0] == ':') { // internal node return; } SumoXMLNodeType type = attrs.getNodeType(ok); if (ok) { if (type == NODETYPE_DEAD_END_DEPRECATED) { // patch legacy type type = NODETYPE_DEAD_END; } } else { WRITE_WARNING("Unknown node type for junction '" + id + "'."); } Position pos = readPosition(attrs, id, ok); NILoader::transformCoordinates(pos, true, myLocation); // the network may have non-default edge geometry. // accurate reconstruction of legacy networks is not possible. We ought to warn about this if (attrs.hasAttribute(SUMO_ATTR_SHAPE)) { PositionVector shape = attrs.getShapeReporting(SUMO_ATTR_SHAPE, id.c_str(), ok, true); if (shape.size() > 0) { shape.push_back_noDoublePos(shape[0]); // need closed shape if (!shape.around(pos) && shape.distance(pos) > 1) { // MAGIC_THRESHOLD // WRITE_WARNING("Junction '" + id + "': distance between pos and shape is " + toString(shape.distance(pos))); mySuspectKeepShape = true; } } } NBNode* node = new NBNode(id, pos, type); if (!myNodeCont.insert(node)) { WRITE_ERROR("Problems on adding junction '" + id + "'."); delete node; return; } }
void PCLoaderArcView::load(const std::string& file, OptionsCont& oc, PCPolyContainer& toFill, PCTypeMap&) { #ifdef HAVE_GDAL GeoConvHelper& geoConvHelper = GeoConvHelper::getProcessing(); // get defaults std::string prefix = oc.getString("prefix"); std::string type = oc.getString("type"); RGBColor color = RGBColor::parseColor(oc.getString("color")); int layer = oc.getInt("layer"); std::string idField = oc.getString("shapefile.id-column"); bool useRunningID = oc.getBool("shapefile.use-running-id"); // start parsing std::string shpName = file + ".shp"; OGRRegisterAll(); OGRDataSource* poDS = OGRSFDriverRegistrar::Open(shpName.c_str(), FALSE); if (poDS == NULL) { throw ProcessError("Could not open shape description '" + shpName + "'."); } // begin file parsing OGRLayer* poLayer = poDS->GetLayer(0); poLayer->ResetReading(); // build coordinate transformation OGRSpatialReference* origTransf = poLayer->GetSpatialRef(); OGRSpatialReference destTransf; // use wgs84 as destination destTransf.SetWellKnownGeogCS("WGS84"); OGRCoordinateTransformation* poCT = OGRCreateCoordinateTransformation(origTransf, &destTransf); if (poCT == NULL) { if (oc.isSet("shapefile.guess-projection")) { OGRSpatialReference origTransf2; origTransf2.SetWellKnownGeogCS("WGS84"); poCT = OGRCreateCoordinateTransformation(&origTransf2, &destTransf); } if (poCT == 0) { WRITE_WARNING("Could not create geocoordinates converter; check whether proj.4 is installed."); } } OGRFeature* poFeature; poLayer->ResetReading(); unsigned int runningID = 0; while ((poFeature = poLayer->GetNextFeature()) != NULL) { // read in edge attributes std::string id = useRunningID ? toString(runningID) : poFeature->GetFieldAsString(idField.c_str()); ++runningID; id = StringUtils::prune(id); if (id == "") { throw ProcessError("Missing id under '" + idField + "'"); } id = prefix + id; // read in the geometry OGRGeometry* poGeometry = poFeature->GetGeometryRef(); if (poGeometry == 0) { OGRFeature::DestroyFeature(poFeature); continue; } // try transform to wgs84 poGeometry->transform(poCT); OGRwkbGeometryType gtype = poGeometry->getGeometryType(); switch (gtype) { case wkbPoint: { OGRPoint* cgeom = (OGRPoint*) poGeometry; Position pos((SUMOReal) cgeom->getX(), (SUMOReal) cgeom->getY()); if (!geoConvHelper.x2cartesian(pos)) { WRITE_ERROR("Unable to project coordinates for POI '" + id + "'."); } PointOfInterest* poi = new PointOfInterest(id, type, color, pos, (SUMOReal)layer); if (!toFill.insert(id, poi, layer)) { WRITE_ERROR("POI '" + id + "' could not be added."); delete poi; } } break; case wkbLineString: { OGRLineString* cgeom = (OGRLineString*) poGeometry; PositionVector shape; for (int j = 0; j < cgeom->getNumPoints(); j++) { Position pos((SUMOReal) cgeom->getX(j), (SUMOReal) cgeom->getY(j)); if (!geoConvHelper.x2cartesian(pos)) { WRITE_ERROR("Unable to project coordinates for polygon '" + id + "'."); } shape.push_back_noDoublePos(pos); } Polygon* poly = new Polygon(id, type, color, shape, false, (SUMOReal)layer); if (!toFill.insert(id, poly, layer)) { WRITE_ERROR("Polygon '" + id + "' could not be added."); delete poly; } } break; case wkbPolygon: { OGRLinearRing* cgeom = ((OGRPolygon*) poGeometry)->getExteriorRing(); PositionVector shape; for (int j = 0; j < cgeom->getNumPoints(); j++) { Position pos((SUMOReal) cgeom->getX(j), (SUMOReal) cgeom->getY(j)); if (!geoConvHelper.x2cartesian(pos)) { WRITE_ERROR("Unable to project coordinates for polygon '" + id + "'."); } shape.push_back_noDoublePos(pos); } Polygon* poly = new Polygon(id, type, color, shape, true, (SUMOReal)layer); if (!toFill.insert(id, poly, layer)) { WRITE_ERROR("Polygon '" + id + "' could not be added."); delete poly; } } break; case wkbMultiPoint: { OGRMultiPoint* cgeom = (OGRMultiPoint*) poGeometry; for (int i = 0; i < cgeom->getNumGeometries(); ++i) { OGRPoint* cgeom2 = (OGRPoint*) cgeom->getGeometryRef(i); Position pos((SUMOReal) cgeom2->getX(), (SUMOReal) cgeom2->getY()); std::string tid = id + "#" + toString(i); if (!geoConvHelper.x2cartesian(pos)) { WRITE_ERROR("Unable to project coordinates for POI '" + tid + "'."); } PointOfInterest* poi = new PointOfInterest(tid, type, color, pos, (SUMOReal)layer); if (!toFill.insert(tid, poi, layer)) { WRITE_ERROR("POI '" + tid + "' could not be added."); delete poi; } } } break; case wkbMultiLineString: { OGRMultiLineString* cgeom = (OGRMultiLineString*) poGeometry; for (int i = 0; i < cgeom->getNumGeometries(); ++i) { OGRLineString* cgeom2 = (OGRLineString*) cgeom->getGeometryRef(i); PositionVector shape; std::string tid = id + "#" + toString(i); for (int j = 0; j < cgeom2->getNumPoints(); j++) { Position pos((SUMOReal) cgeom2->getX(j), (SUMOReal) cgeom2->getY(j)); if (!geoConvHelper.x2cartesian(pos)) { WRITE_ERROR("Unable to project coordinates for polygon '" + tid + "'."); } shape.push_back_noDoublePos(pos); } Polygon* poly = new Polygon(tid, type, color, shape, false, (SUMOReal)layer); if (!toFill.insert(tid, poly, layer)) { WRITE_ERROR("Polygon '" + tid + "' could not be added."); delete poly; } } } break; case wkbMultiPolygon: { OGRMultiPolygon* cgeom = (OGRMultiPolygon*) poGeometry; for (int i = 0; i < cgeom->getNumGeometries(); ++i) { OGRLinearRing* cgeom2 = ((OGRPolygon*) cgeom->getGeometryRef(i))->getExteriorRing(); PositionVector shape; std::string tid = id + "#" + toString(i); for (int j = 0; j < cgeom2->getNumPoints(); j++) { Position pos((SUMOReal) cgeom2->getX(j), (SUMOReal) cgeom2->getY(j)); if (!geoConvHelper.x2cartesian(pos)) { WRITE_ERROR("Unable to project coordinates for polygon '" + tid + "'."); } shape.push_back_noDoublePos(pos); } Polygon* poly = new Polygon(tid, type, color, shape, true, (SUMOReal)layer); if (!toFill.insert(tid, poly, layer)) { WRITE_ERROR("Polygon '" + tid + "' could not be added."); delete poly; } } } break; default: WRITE_WARNING("Unsupported shape type occured (id='" + id + "')."); break; } OGRFeature::DestroyFeature(poFeature); } PROGRESS_DONE_MESSAGE(); #else WRITE_ERROR("SUMO was compiled without GDAL support."); #endif }
void NIImporter_ArcView::load() { #ifdef HAVE_GDAL PROGRESS_BEGIN_MESSAGE("Loading data from '" + mySHPName + "'"); #if GDAL_VERSION_MAJOR < 2 OGRRegisterAll(); OGRDataSource* poDS = OGRSFDriverRegistrar::Open(mySHPName.c_str(), FALSE); #else GDALAllRegister(); GDALDataset* poDS = (GDALDataset*)GDALOpenEx(mySHPName.c_str(), GDAL_OF_VECTOR | GA_ReadOnly, NULL, NULL, NULL); #endif if (poDS == NULL) { WRITE_ERROR("Could not open shape description '" + mySHPName + "'."); return; } // begin file parsing OGRLayer* poLayer = poDS->GetLayer(0); poLayer->ResetReading(); // build coordinate transformation OGRSpatialReference* origTransf = poLayer->GetSpatialRef(); OGRSpatialReference destTransf; // use wgs84 as destination destTransf.SetWellKnownGeogCS("WGS84"); OGRCoordinateTransformation* poCT = OGRCreateCoordinateTransformation(origTransf, &destTransf); if (poCT == NULL) { if (myOptions.isSet("shapefile.guess-projection")) { OGRSpatialReference origTransf2; origTransf2.SetWellKnownGeogCS("WGS84"); poCT = OGRCreateCoordinateTransformation(&origTransf2, &destTransf); } if (poCT == 0) { WRITE_WARNING("Could not create geocoordinates converter; check whether proj.4 is installed."); } } OGRFeature* poFeature; poLayer->ResetReading(); while ((poFeature = poLayer->GetNextFeature()) != NULL) { // read in edge attributes std::string id, name, from_node, to_node; if (!getStringEntry(poFeature, "shapefile.street-id", "LINK_ID", true, id)) { WRITE_ERROR("Needed field '" + id + "' (from node id) is missing."); } if (id == "") { WRITE_ERROR("Could not obtain edge id."); return; } getStringEntry(poFeature, "shapefile.street-id", "ST_NAME", true, name); name = StringUtils::replace(name, "&", "&"); if (!getStringEntry(poFeature, "shapefile.from-id", "REF_IN_ID", true, from_node)) { WRITE_ERROR("Needed field '" + from_node + "' (from node id) is missing."); } if (!getStringEntry(poFeature, "shapefile.to-id", "NREF_IN_ID", true, to_node)) { WRITE_ERROR("Needed field '" + to_node + "' (to node id) is missing."); } if (from_node == "" || to_node == "") { from_node = toString(myRunningNodeID++); to_node = toString(myRunningNodeID++); } std::string type; if (myOptions.isSet("shapefile.type-id") && poFeature->GetFieldIndex(myOptions.getString("shapefile.type-id").c_str()) >= 0) { type = poFeature->GetFieldAsString(myOptions.getString("shapefile.type-id").c_str()); } else if (poFeature->GetFieldIndex("ST_TYP_AFT") >= 0) { type = poFeature->GetFieldAsString("ST_TYP_AFT"); } SUMOReal width = myTypeCont.getWidth(type); SUMOReal speed = getSpeed(*poFeature, id); int nolanes = getLaneNo(*poFeature, id, speed); int priority = getPriority(*poFeature, id); if (nolanes == 0 || speed == 0) { if (myOptions.getBool("shapefile.use-defaults-on-failure")) { nolanes = myTypeCont.getNumLanes(""); speed = myTypeCont.getSpeed(""); } else { OGRFeature::DestroyFeature(poFeature); WRITE_ERROR("The description seems to be invalid. Please recheck usage of types."); return; } } if (mySpeedInKMH) { speed = speed / (SUMOReal) 3.6; } // read in the geometry OGRGeometry* poGeometry = poFeature->GetGeometryRef(); OGRwkbGeometryType gtype = poGeometry->getGeometryType(); assert(gtype == wkbLineString); UNUSED_PARAMETER(gtype); // ony used for assertion OGRLineString* cgeom = (OGRLineString*) poGeometry; if (poCT != 0) { // try transform to wgs84 cgeom->transform(poCT); } PositionVector shape; for (int j = 0; j < cgeom->getNumPoints(); j++) { Position pos((SUMOReal) cgeom->getX(j), (SUMOReal) cgeom->getY(j)); if (!NBNetBuilder::transformCoordinate(pos)) { WRITE_WARNING("Unable to project coordinates for edge '" + id + "'."); } shape.push_back_noDoublePos(pos); } // build from-node NBNode* from = myNodeCont.retrieve(from_node); if (from == 0) { Position from_pos = shape[0]; from = myNodeCont.retrieve(from_pos); if (from == 0) { from = new NBNode(from_node, from_pos); if (!myNodeCont.insert(from)) { WRITE_ERROR("Node '" + from_node + "' could not be added"); delete from; continue; } } } // build to-node NBNode* to = myNodeCont.retrieve(to_node); if (to == 0) { Position to_pos = shape[-1]; to = myNodeCont.retrieve(to_pos); if (to == 0) { to = new NBNode(to_node, to_pos); if (!myNodeCont.insert(to)) { WRITE_ERROR("Node '" + to_node + "' could not be added"); delete to; continue; } } } if (from == to) { WRITE_WARNING("Edge '" + id + "' connects identical nodes, skipping."); continue; } // retrieve the information whether the street is bi-directional std::string dir; int index = poFeature->GetDefnRef()->GetFieldIndex("DIR_TRAVEL"); if (index >= 0 && poFeature->IsFieldSet(index)) { dir = poFeature->GetFieldAsString(index); } // add positive direction if wanted if (dir == "B" || dir == "F" || dir == "" || myOptions.getBool("shapefile.all-bidirectional")) { if (myEdgeCont.retrieve(id) == 0) { LaneSpreadFunction spread = dir == "B" || dir == "FALSE" ? LANESPREAD_RIGHT : LANESPREAD_CENTER; NBEdge* edge = new NBEdge(id, from, to, type, speed, nolanes, priority, width, NBEdge::UNSPECIFIED_OFFSET, shape, name, id, spread); myEdgeCont.insert(edge); checkSpread(edge); } } // add negative direction if wanted if (dir == "B" || dir == "T" || myOptions.getBool("shapefile.all-bidirectional")) { if (myEdgeCont.retrieve("-" + id) == 0) { LaneSpreadFunction spread = dir == "B" || dir == "FALSE" ? LANESPREAD_RIGHT : LANESPREAD_CENTER; NBEdge* edge = new NBEdge("-" + id, to, from, type, speed, nolanes, priority, width, NBEdge::UNSPECIFIED_OFFSET, shape.reverse(), name, id, spread); myEdgeCont.insert(edge); checkSpread(edge); } } // OGRFeature::DestroyFeature(poFeature); } #if GDAL_VERSION_MAJOR < 2 OGRDataSource::DestroyDataSource(poDS); #else GDALClose(poDS); #endif PROGRESS_DONE_MESSAGE(); #else WRITE_ERROR("SUMO was compiled without GDAL support."); #endif }
// Assume that a class is already given for the object: // Position with coordinates {SUMOReal x, y;} PositionVector simpleHull_2D(const PositionVector& V) { if (V.size() < 3) { throw ProcessError(); } // initialize a deque D[] from bottom to top so that the // 1st three vertices of V[] are a counterclockwise triangle int n = (int) V.size(); std::vector<Position> D(2 * n + 1); int bot = n - 2, top = bot + 3; // initial bottom and top deque indices D[bot] = D[top] = V[2]; // 3rd vertex is at both bot and top if (isLeft(V[0], V[1], V[2]) > 0) { D[bot + 1] = V[0]; D[bot + 2] = V[1]; // ccw vertices are: 2,0,1,2 } else { D[bot + 1] = V[1]; D[bot + 2] = V[0]; // ccw vertices are: 2,1,0,2 } // compute the hull on the deque D[] for (int i = 3; i < n; i++) { // process the rest of vertices // test if next vertex is inside the deque hull if (bot >= (int) D.size() || top - 1 >= (int) D.size() || i >= (int) V.size()) { throw ProcessError(); } if ((isLeft(D[bot], D[bot + 1], V[i]) > 0) && (isLeft(D[top - 1], D[top], V[i]) > 0)) { continue; // skip an interior vertex } // incrementally add an exterior vertex to the deque hull // get the rightmost tangent at the deque bot while (isLeft(D[bot], D[bot + 1], V[i]) <= 0) { ++bot; // remove bot of deque if (bot >= (int) D.size()) { throw ProcessError(); } } if (bot == 0) { throw ProcessError(); } D[--bot] = V[i]; // insert V[i] at bot of deque if (top == 0 || top >= (int) D.size()) { throw ProcessError(); } // get the leftmost tangent at the deque top while (isLeft(D[top - 1], D[top], V[i]) <= 0) { --top; // pop top of deque if (top == 0 || top >= (int) D.size()) { throw ProcessError(); } } if (top + 1 >= (int) D.size()) { throw ProcessError(); } D[++top] = V[i]; // push V[i] onto top of deque } // transcribe deque D[] to the output hull array H[] int h; // hull vertex counter PositionVector H; for (h = 0; h <= (top - bot); h++) { if (bot + h >= (int) D.size()) { throw ProcessError(); } H.push_back_noDoublePos(D[bot + h]); } return H; }
void NIImporter_OpenStreetMap::insertEdge(Edge* e, int index, NBNode* from, NBNode* to, const std::vector<int> &passed, NBEdgeCont& ec, NBTypeCont& tc) { // patch the id std::string id = e->id; if (index >= 0) { id = id + "#" + toString(index); } // convert the shape PositionVector shape; for (std::vector<int>::const_iterator i = passed.begin(); i != passed.end(); ++i) { NIOSMNode* n = myOSMNodes.find(*i)->second; Position pos(n->lon, n->lat); if (!NILoader::transformCoordinates(pos, true)) { throw ProcessError("Unable to project coordinates for edge " + id + "."); } shape.push_back_noDoublePos(pos); } std::string type = e->myHighWayType; if (!tc.knows(type)) { if (type.find(compoundTypeSeparator) != std::string::npos) { // this edge has a combination type which does not yet exist in the TypeContainer StringTokenizer tok = StringTokenizer(type, compoundTypeSeparator); std::set<std::string> types; while (tok.hasNext()) { std::string t = tok.next(); if (tc.knows(t)) { types.insert(t); } else { WRITE_WARNING("Discarding edge " + id + " with type \"" + type + "\" (unknown compound \"" + t + "\")."); return; } } if (types.size() == 2 && types.count("railway.tram") == 1) { // compound types concern mostly the special case of tram tracks on a normal road. // in this case we simply discard the tram information since the default for road is to allow all vclasses types.erase("railway.tram"); std::string otherCompound = *(types.begin()); // XXX if otherCompound does not allow all vehicles (e.g. SVC_DELIVERY), tram will still not be allowed type = otherCompound; } else { // other cases not implemented yet WRITE_WARNING("Discarding edge " + id + " with unknown type \"" + type + "\"."); return; } } else { // we do not know the type -> something else, ignore //WRITE_WARNING("Discarding edge " + id + " with unknown type \"" + type + "\"."); return; } } // otherwise it is not an edge and will be ignored int noLanes = tc.getNumLanes(type); SUMOReal speed = tc.getSpeed(type); bool defaultsToOneWay = tc.getIsOneWay(type); SUMOVehicleClasses allowedClasses = tc.getAllowedClasses(type); SUMOVehicleClasses disallowedClasses = tc.getDisallowedClasses(type); // check directions bool addSecond = true; if (e->myIsOneWay == "true" || e->myIsOneWay == "yes" || e->myIsOneWay == "1" || (defaultsToOneWay && e->myIsOneWay != "no" && e->myIsOneWay != "false" && e->myIsOneWay != "0")) { addSecond = false; } // if we had been able to extract the number of lanes, override the highway type default if (e->myNoLanes >= 0) { if (!addSecond) { noLanes = e->myNoLanes; } else { noLanes = e->myNoLanes / 2; } } // if we had been able to extract the maximum speed, override the type's default if (e->myMaxSpeed != MAXSPEED_UNGIVEN) { speed = (SUMOReal)(e->myMaxSpeed / 3.6); } if (noLanes != 0 && speed != 0) { if (e->myIsOneWay != "" && e->myIsOneWay != "false" && e->myIsOneWay != "no" && e->myIsOneWay != "true" && e->myIsOneWay != "yes" && e->myIsOneWay != "-1" && e->myIsOneWay != "1") { WRITE_WARNING("New value for oneway found: " + e->myIsOneWay); } LaneSpreadFunction lsf = addSecond ? LANESPREAD_RIGHT : LANESPREAD_CENTER; if (e->myIsOneWay != "-1") { NBEdge* nbe = new NBEdge(id, from, to, type, speed, noLanes, tc.getPriority(type), tc.getWidth(type), NBEdge::UNSPECIFIED_OFFSET, shape, e->streetName, lsf); nbe->setVehicleClasses(allowedClasses, disallowedClasses); if (!ec.insert(nbe)) { delete nbe; throw ProcessError("Could not add edge '" + id + "'."); } } if (addSecond) { if (e->myIsOneWay != "-1") { id = "-" + id; } NBEdge* nbe = new NBEdge(id, to, from, type, speed, noLanes, tc.getPriority(type), tc.getWidth(type), NBEdge::UNSPECIFIED_OFFSET, shape.reverse(), e->streetName, lsf); nbe->setVehicleClasses(allowedClasses, disallowedClasses); if (!ec.insert(nbe)) { delete nbe; throw ProcessError("Could not add edge '-" + id + "'."); } } } }