/* ---- This file is part of SECONDO. Copyright (C) 2004, University in Hagen, Department of Computer Science, Database Systems for New Applications. SECONDO is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. SECONDO is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with SECONDO; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA ---- //paragraph [1] Title: [{\Large \bf \begin {center}] [\end {center}}] //[TOC] [\tableofcontents] //[_] [\_] [1] Header File of ONetworkEdge (Edge of Network based on ordered relation) April, 2012. Matthias Roth [TOC] 1 Overview This header file contains the class ~ONetworkEdge~ 2 Defines and includes */ #ifndef __ONETWORKEDGE_H_ #define __ONETWORKEDGE_H_ #include "Algebras/Spatial/SpatialAlgebra.h" #include "satof.h" class Tuple; template class ONetwork; #include #include #include #include "Algebras/FText/FTextAlgebra.h" #include "MapMatchingUtil.h" /* 3 class ONetworkEdge Edge of Network based on ordered relation The template parameter is the int-type used, e.g., CcInt or LongInt. */ template class ONetworkEdge { public: ONetworkEdge(); ONetworkEdge(Tuple* pTupleEdge, const ONetwork* pONetwork, bool bIncReference = true); ONetworkEdge(const ONetworkEdge& rEdge); ~ONetworkEdge(); ONetworkEdge& operator=(const ONetworkEdge& rEdge); bool operator==(const ONetworkEdge& rEdge) const; bool IsDefined(void) const {return m_pTupleEdge != NULL;} //int GetSourceId(void) const; //int GetTargetId(void) const; T* GetSource(void) const; T* GetTarget(void) const; Point GetSourcePoint(void) const; Point GetTargetPoint(void) const; SimpleLine* GetCurve(void) const; std::string GetRoadName(void) const; std::string GetRoadType(void) const; double GetMaxSpeed(void) const; // km/h T* GetWayId(void) const; double GetCurveLength(const double dScale) const; void Print(std::ostream& os) const; const Tuple* GetTuple(void) const {return m_pTupleEdge;} private: Tuple* m_pTupleEdge; const ONetwork* m_pONetwork; mutable double m_dCurveLength; mutable double m_dMaxSpeed; }; /* 1 Implementation */ template ONetworkEdge::ONetworkEdge() :m_pTupleEdge(NULL), m_pONetwork(NULL), m_dCurveLength(-1.0), m_dMaxSpeed(-1.0) { } template ONetworkEdge::ONetworkEdge(Tuple* pTupleEdge, const ONetwork* pONetwork, bool bIncReference) :m_pTupleEdge(pTupleEdge), m_pONetwork(pONetwork), m_dCurveLength(-1.0), m_dMaxSpeed(-1.0) { if (bIncReference && m_pTupleEdge != NULL) m_pTupleEdge->IncReference(); } template ONetworkEdge::ONetworkEdge(const ONetworkEdge& rEdge) :m_pTupleEdge(rEdge.m_pTupleEdge), m_pONetwork(rEdge.m_pONetwork), m_dCurveLength(rEdge.m_dCurveLength), m_dMaxSpeed(rEdge.m_dMaxSpeed) { if (m_pTupleEdge != NULL) m_pTupleEdge->IncReference(); } template ONetworkEdge::~ONetworkEdge() { if (m_pTupleEdge != NULL) m_pTupleEdge->DeleteIfAllowed(); m_pTupleEdge = NULL; m_pONetwork = NULL; } template ONetworkEdge& ONetworkEdge::operator=(const ONetworkEdge& rEdge) { if (&rEdge != this) { if (m_pTupleEdge != NULL) { m_pTupleEdge->DeleteIfAllowed(); m_pTupleEdge = NULL; } m_pTupleEdge = rEdge.m_pTupleEdge; if (m_pTupleEdge != NULL) m_pTupleEdge->IncReference(); m_pONetwork = rEdge.m_pONetwork; m_dCurveLength = rEdge.m_dCurveLength; m_dMaxSpeed = rEdge.m_dMaxSpeed; } return *this; } template bool ONetworkEdge::operator==(const ONetworkEdge& rEdge) const { if (m_pTupleEdge != NULL && rEdge.m_pTupleEdge != NULL) { return (m_pTupleEdge->GetTupleId() == rEdge.m_pTupleEdge->GetTupleId() && m_pONetwork == rEdge.m_pONetwork); } else { return m_pTupleEdge == rEdge.m_pTupleEdge; } } template T* ONetworkEdge::GetSource(void) const { if (m_pTupleEdge != NULL && m_pONetwork != NULL) { const int nIdx = m_pONetwork->m_EdgeAttrIndexes.m_IdxSource; if (nIdx >= 0) return static_cast(m_pTupleEdge->GetAttribute(nIdx)); else return NULL; } else { return NULL; } } template T* ONetworkEdge::GetTarget(void) const { if (m_pTupleEdge != NULL) { const int nIdx = m_pONetwork->m_EdgeAttrIndexes.m_IdxTarget; if (nIdx >= 0) return static_cast(m_pTupleEdge->GetAttribute(nIdx)); else return NULL; } else { return NULL; } } template Point ONetworkEdge::GetSourcePoint(void) const { if (m_pTupleEdge != NULL && m_pONetwork != NULL) { const int nIdx = m_pONetwork->m_EdgeAttrIndexes.m_IdxSourcePos; if (nIdx >= 0) { Point* pPtSource = static_cast( m_pTupleEdge->GetAttribute(nIdx)); return pPtSource != NULL ? *pPtSource : Point(false); } else return Point(false); } else { return Point(false); } } template Point ONetworkEdge::GetTargetPoint(void) const { if (m_pTupleEdge != NULL && m_pONetwork != NULL) { const int nIdx = m_pONetwork->m_EdgeAttrIndexes.m_IdxTargetPos; if (nIdx >= 0) { Point* pPtTarget = static_cast( m_pTupleEdge->GetAttribute(nIdx)); return pPtTarget != NULL ? *pPtTarget : Point(false); } else { return Point(false); } } else { return Point(false); } } template SimpleLine* ONetworkEdge::GetCurve(void) const { if (m_pTupleEdge != NULL && m_pONetwork != NULL) { const int nIdx = m_pONetwork->m_EdgeAttrIndexes.m_IdxCurve; if (nIdx >= 0) { return static_cast(m_pTupleEdge->GetAttribute(nIdx)); } else return NULL; } else { return NULL; } } template std::string ONetworkEdge::GetRoadName(void) const { if (m_pTupleEdge != NULL && m_pONetwork != NULL) { const int nIdx = m_pONetwork->m_EdgeAttrIndexes.m_IdxRoadName; if (nIdx >= 0) { FText* pRoadName = static_cast( m_pTupleEdge->GetAttribute(nIdx)); if (pRoadName != NULL && pRoadName->IsDefined()) return pRoadName->GetValue(); else return ""; } else { return ""; } } else { return ""; } } template std::string ONetworkEdge::GetRoadType(void) const { if (m_pTupleEdge != NULL && m_pONetwork != NULL) { const int nIdx = m_pONetwork->m_EdgeAttrIndexes.m_IdxRoadType; if (nIdx >= 0) { FText* pRoadType = static_cast( m_pTupleEdge->GetAttribute(nIdx)); if (pRoadType != NULL && pRoadType->IsDefined()) return pRoadType->GetValue(); else return ""; } else return ""; } else { return ""; } } static double convStrToDouble (const char* pszStr) { if (pszStr == NULL) return 0.0; return satof(pszStr); } template double ONetworkEdge::GetMaxSpeed(void) const { /* * http://wiki.openstreetmap.org/wiki/Key:maxspeed * * maxspeed=60 -> km/h * maxspeed=50 mph -> mph * maxspeed=10 knots -> knots * */ if (m_pTupleEdge != NULL && m_pONetwork != NULL && m_dMaxSpeed < 0.0) { const int nIdx = m_pONetwork->m_EdgeAttrIndexes.m_IdxMaxSpeed; if (nIdx >= 0) { FText* pMaxSpeed = static_cast( m_pTupleEdge->GetAttribute(nIdx)); if (pMaxSpeed != NULL && pMaxSpeed->IsDefined()) { m_dMaxSpeed = convStrToDouble(pMaxSpeed->GetValue().c_str()); // convert to km/h if (pMaxSpeed->GetValue().find("mph") != std::string::npos) { m_dMaxSpeed *= 1.609344; } else if (pMaxSpeed->GetValue().find("knots") != std::string::npos) { m_dMaxSpeed *= 1.852; } } else m_dMaxSpeed = 0.0; } else m_dMaxSpeed = 0.0; } return m_dMaxSpeed; } template T* ONetworkEdge::GetWayId(void) const { if (m_pTupleEdge != NULL && m_pONetwork != NULL) { const int nIdx = m_pONetwork->m_EdgeAttrIndexes.m_IdxWayId; if (nIdx >= 0) return static_cast(m_pTupleEdge->GetAttribute(nIdx)); else return NULL; } else { return NULL; } } template double ONetworkEdge::GetCurveLength(const double dScale) const { if (m_dCurveLength < 0.) { m_dCurveLength = mapmatch::MMUtil::CalcLengthCurve(GetCurve(), dScale); } return m_dCurveLength; } template void ONetworkEdge::Print(std::ostream& os) const { os << "Source: "; GetSource()->Print(os); os << endl; os << "Target: "; GetTarget()->Print(os); os << endl; os << "Source-Point: "; GetSourcePoint().Print(os); os << endl; os << "Target-Point: "; GetTargetPoint().Print(os); os << endl; os << "Curve: "; GetCurve()->Print(os); os << endl; os << "RoadName: " << GetRoadName() << endl; os << "RoadType: " << GetRoadType() << endl; os << "MaxSpeed: " << GetMaxSpeed() << endl; os << "WayId: " << GetWayId() << endl; } #endif /* __ONETWORKEDGE_H_ */