Fixes issue #104. Heading and Azimuth get computed now.
This commit is contained in:
parent
c98f19c5a6
commit
5e275b3935
@ -28,12 +28,13 @@ struct SegmentInformation {
|
|||||||
NodeID nameID;
|
NodeID nameID;
|
||||||
unsigned length;
|
unsigned length;
|
||||||
unsigned duration;
|
unsigned duration;
|
||||||
|
double bearing;
|
||||||
short turnInstruction;
|
short turnInstruction;
|
||||||
bool necessary;
|
bool necessary;
|
||||||
SegmentInformation(const _Coordinate & loc, const NodeID nam, const unsigned len, const unsigned dur, const short tInstr, const bool nec) :
|
SegmentInformation(const _Coordinate & loc, const NodeID nam, const unsigned len, const unsigned dur, const short tInstr, const bool nec) :
|
||||||
location(loc), nameID(nam), length(len), duration(dur), turnInstruction(tInstr), necessary(nec) {}
|
location(loc), nameID(nam), length(len), duration(dur), bearing(0.), turnInstruction(tInstr), necessary(nec) {}
|
||||||
SegmentInformation(const _Coordinate & loc, const NodeID nam, const unsigned len, const unsigned dur, const short tInstr) :
|
SegmentInformation(const _Coordinate & loc, const NodeID nam, const unsigned len, const unsigned dur, const short tInstr) :
|
||||||
location(loc), nameID(nam), length(len), duration(dur), turnInstruction(tInstr), necessary(tInstr != 0) {}
|
location(loc), nameID(nam), length(len), duration(dur), bearing(0.), turnInstruction(tInstr), necessary(tInstr != 0) {}
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif /* SEGMENTINFORMATION_H_ */
|
#endif /* SEGMENTINFORMATION_H_ */
|
||||||
|
@ -24,10 +24,18 @@ DescriptionFactory::DescriptionFactory() { }
|
|||||||
|
|
||||||
DescriptionFactory::~DescriptionFactory() { }
|
DescriptionFactory::~DescriptionFactory() { }
|
||||||
|
|
||||||
double DescriptionFactory::GetAngleBetweenCoordinates() const {
|
double DescriptionFactory::GetAzimuth(const _Coordinate& A, const _Coordinate& B) const {
|
||||||
return 0.;//GetAngleBetweenTwoEdges(previousCoordinate, currentCoordinate, nextCoordinate);
|
double lonDiff = (A.lon-B.lon)/100000.;
|
||||||
|
double angle = atan2(sin(lonDiff)*cos(B.lat/100000.),
|
||||||
|
cos(A.lat/100000.)*sin(B.lat/100000.)-sin(A.lat/100000.)*cos(B.lat/100000.)*cos(lonDiff));
|
||||||
|
angle*=180/M_PI;
|
||||||
|
while(angle < 0)
|
||||||
|
angle += 360;
|
||||||
|
|
||||||
|
return angle;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void DescriptionFactory::SetStartSegment(const PhantomNode & _startPhantom) {
|
void DescriptionFactory::SetStartSegment(const PhantomNode & _startPhantom) {
|
||||||
startPhantom = _startPhantom;
|
startPhantom = _startPhantom;
|
||||||
AppendSegment(_startPhantom.location, _PathData(0, _startPhantom.nodeBasedEdgeNameID, 10, _startPhantom.weight1));
|
AppendSegment(_startPhantom.location, _PathData(0, _startPhantom.nodeBasedEdgeNameID, 10, _startPhantom.weight1));
|
||||||
@ -91,5 +99,12 @@ unsigned DescriptionFactory::Run(const unsigned zoomLevel) {
|
|||||||
dp.Run(pathDescription, zoomLevel);
|
dp.Run(pathDescription, zoomLevel);
|
||||||
|
|
||||||
//fix what needs to be fixed else
|
//fix what needs to be fixed else
|
||||||
|
for(unsigned i = 0; i < pathDescription.size()-1 && pathDescription.size() >= 2; ++i){
|
||||||
|
if(pathDescription[i].necessary) {
|
||||||
|
int angle = 100*GetAzimuth(pathDescription[i].location, pathDescription[i+1].location);
|
||||||
|
pathDescription[i].bearing = angle/100.;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return entireLength;
|
return entireLength;
|
||||||
}
|
}
|
||||||
|
@ -41,7 +41,7 @@ public:
|
|||||||
std::vector <SegmentInformation> pathDescription;
|
std::vector <SegmentInformation> pathDescription;
|
||||||
DescriptionFactory();
|
DescriptionFactory();
|
||||||
virtual ~DescriptionFactory();
|
virtual ~DescriptionFactory();
|
||||||
double GetAngleBetweenCoordinates() const;
|
double GetAzimuth(const _Coordinate& C, const _Coordinate& B) const;
|
||||||
void AppendEncodedPolylineString(std::string &output);
|
void AppendEncodedPolylineString(std::string &output);
|
||||||
void AppendUnencodedPolylineString(std::string &output);
|
void AppendUnencodedPolylineString(std::string &output);
|
||||||
void AppendSegment(const _Coordinate & coordinate, const _PathData & data);
|
void AppendSegment(const _Coordinate & coordinate, const _PathData & data);
|
||||||
|
@ -27,6 +27,7 @@ or see http://www.gnu.org/licenses/agpl.txt.
|
|||||||
#include "DescriptionFactory.h"
|
#include "DescriptionFactory.h"
|
||||||
#include "../DataStructures/SegmentInformation.h"
|
#include "../DataStructures/SegmentInformation.h"
|
||||||
#include "../DataStructures/TurnInstructions.h"
|
#include "../DataStructures/TurnInstructions.h"
|
||||||
|
#include "../Util/Azimuth.h"
|
||||||
#include "../Util/StringUtil.h"
|
#include "../Util/StringUtil.h"
|
||||||
|
|
||||||
template<class SearchEngineT>
|
template<class SearchEngineT>
|
||||||
@ -36,6 +37,7 @@ private:
|
|||||||
_RouteSummary summary;
|
_RouteSummary summary;
|
||||||
DescriptionFactory descriptionFactory;
|
DescriptionFactory descriptionFactory;
|
||||||
_Coordinate current;
|
_Coordinate current;
|
||||||
|
|
||||||
struct {
|
struct {
|
||||||
int startIndex;
|
int startIndex;
|
||||||
int nameID;
|
int nameID;
|
||||||
@ -100,7 +102,7 @@ public:
|
|||||||
unsigned prefixSumOfNecessarySegments = 0;
|
unsigned prefixSumOfNecessarySegments = 0;
|
||||||
roundAbout.leaveAtExit = 0;
|
roundAbout.leaveAtExit = 0;
|
||||||
roundAbout.nameID = 0;
|
roundAbout.nameID = 0;
|
||||||
std::string tmpDist, tmpLength, tmpDuration;
|
std::string tmpDist, tmpLength, tmpDuration, tmpBearing;
|
||||||
//Fetch data from Factory and generate a string from it.
|
//Fetch data from Factory and generate a string from it.
|
||||||
BOOST_FOREACH(SegmentInformation & segment, descriptionFactory.pathDescription) {
|
BOOST_FOREACH(SegmentInformation & segment, descriptionFactory.pathDescription) {
|
||||||
if(TurnInstructions.TurnIsNecessary( segment.turnInstruction) ) {
|
if(TurnInstructions.TurnIsNecessary( segment.turnInstruction) ) {
|
||||||
@ -134,9 +136,12 @@ public:
|
|||||||
reply.content += tmpDuration;
|
reply.content += tmpDuration;
|
||||||
reply.content += ",\"";
|
reply.content += ",\"";
|
||||||
reply.content += tmpLength;
|
reply.content += tmpLength;
|
||||||
//TODO: fix heading
|
reply.content += "\",\"";
|
||||||
reply.content += "\",\"NE\",22.5";
|
reply.content += Azimuth::Get(segment.bearing);
|
||||||
reply.content += "]";
|
reply.content += "\",";
|
||||||
|
doubleToStringWithTwoDigitsBehindComma(segment.bearing, tmpBearing);
|
||||||
|
reply.content += tmpBearing;
|
||||||
|
reply.content += "]";
|
||||||
}
|
}
|
||||||
} else if(TurnInstructions.StayOnRoundAbout == segment.turnInstruction) {
|
} else if(TurnInstructions.StayOnRoundAbout == segment.turnInstruction) {
|
||||||
++roundAbout.leaveAtExit;
|
++roundAbout.leaveAtExit;
|
||||||
|
@ -93,6 +93,14 @@ static inline void doubleToString(const double value, std::string & output){
|
|||||||
output = buffer ;
|
output = buffer ;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static inline void doubleToStringWithTwoDigitsBehindComma(const double value, std::string & output){
|
||||||
|
// The largest 32-bit integer is 4294967295, that is 10 chars
|
||||||
|
// On the safe side, add 1 for sign, and 1 for trailing zero
|
||||||
|
char buffer[12] ;
|
||||||
|
sprintf(buffer, "%g", value) ;
|
||||||
|
output = buffer ;
|
||||||
|
}
|
||||||
|
|
||||||
inline std::string & replaceAll(std::string &s, const std::string &sub, const std::string &other) {
|
inline std::string & replaceAll(std::string &s, const std::string &sub, const std::string &other) {
|
||||||
assert(!sub.empty());
|
assert(!sub.empty());
|
||||||
size_t b = 0;
|
size_t b = 0;
|
||||||
|
Loading…
Reference in New Issue
Block a user