Linestring is generalized by an untuned (Ramer-)Douglas-Peucker
algorithm. Distance computation is still a naive implementation and can be further sped up if necessary
This commit is contained in:
@@ -18,9 +18,6 @@
|
||||
or see http://www.gnu.org/licenses/agpl.txt.
|
||||
*/
|
||||
|
||||
#include <boost/foreach.hpp>
|
||||
|
||||
#include "../typedefs.h"
|
||||
#include "DescriptionFactory.h"
|
||||
|
||||
DescriptionFactory::DescriptionFactory() { }
|
||||
@@ -38,25 +35,11 @@ void DescriptionFactory::SetStartSegment(const PhantomNode & _startPhantom) {
|
||||
|
||||
void DescriptionFactory::SetEndSegment(const PhantomNode & _targetPhantom) {
|
||||
targetPhantom = _targetPhantom;
|
||||
AppendSegment(_targetPhantom.location, _PathData(0, _targetPhantom.nodeBasedEdgeNameID, 0, _targetPhantom.weight1));
|
||||
pathDescription.push_back(SegmentInformation(_targetPhantom.location, _targetPhantom.nodeBasedEdgeNameID, 0, _targetPhantom.weight1, 0, true) );
|
||||
}
|
||||
|
||||
void DescriptionFactory::AppendSegment(const _Coordinate & coordinate, const _PathData & data ) {
|
||||
//Segment information has following format:
|
||||
//["instruction","streetname",length,position,time,"length","earth_direction",azimuth]
|
||||
//Example: ["Turn left","High Street",200,4,10,"200m","NE",22.5]
|
||||
//See also: http://developers.cloudmade.com/wiki/navengine/JSON_format
|
||||
// (_Coordinate & loc, NodeID nam, unsigned len, unsigned dur, short tInstr)
|
||||
|
||||
//Is a new instruction necessary?
|
||||
//yes: data.turnInstruction != 0;
|
||||
//no: data.turnInstruction == 0;
|
||||
inline void DescriptionFactory::AppendSegment(const _Coordinate & coordinate, const _PathData & data ) {
|
||||
pathDescription.push_back(SegmentInformation(coordinate, data.nameID, 0, data.durationOfSegment, data.turnInstruction) );
|
||||
|
||||
}
|
||||
|
||||
void DescriptionFactory::AppendRouteInstructionString(std::string & output) {
|
||||
output += "[\"Turn left\",\"High Street\",200,0,10,\"200m\",\"NE\",22.5]";
|
||||
}
|
||||
|
||||
void DescriptionFactory::AppendEncodedPolylineString(std::string & output, bool isEncoded) {
|
||||
@@ -74,7 +57,7 @@ void DescriptionFactory::AppendUnencodedPolylineString(std::string &output) {
|
||||
pc.printUnencodedString(pathDescription, output);
|
||||
}
|
||||
|
||||
unsigned DescriptionFactory::Run() {
|
||||
unsigned DescriptionFactory::Run(const unsigned zoomLevel) {
|
||||
if(0 == pathDescription.size())
|
||||
return 0;
|
||||
|
||||
@@ -105,10 +88,7 @@ unsigned DescriptionFactory::Run() {
|
||||
}
|
||||
|
||||
//Generalize poly line
|
||||
BOOST_FOREACH(SegmentInformation & segment, pathDescription) {
|
||||
//TODO: Replace me by real generalization
|
||||
segment.necessary = true;
|
||||
}
|
||||
dp.Run(pathDescription, zoomLevel);
|
||||
|
||||
//fix what needs to be fixed else
|
||||
return entireLength;
|
||||
|
||||
@@ -23,6 +23,8 @@
|
||||
|
||||
#include <vector>
|
||||
|
||||
#include "../typedefs.h"
|
||||
#include "../Algorithms/DouglasPeucker.h"
|
||||
#include "../Algorithms/PolylineCompressor.h"
|
||||
#include "../DataStructures/ExtractorStructs.h"
|
||||
#include "../DataStructures/SegmentInformation.h"
|
||||
@@ -31,6 +33,7 @@
|
||||
* and produces the description plus the encoded polyline */
|
||||
|
||||
class DescriptionFactory {
|
||||
DouglasPeucker<SegmentInformation> dp;
|
||||
PolylineCompressor pc;
|
||||
PhantomNode startPhantom, targetPhantom;
|
||||
public:
|
||||
@@ -42,11 +45,10 @@ public:
|
||||
void AppendEncodedPolylineString(std::string &output);
|
||||
void AppendUnencodedPolylineString(std::string &output);
|
||||
void AppendSegment(const _Coordinate & coordinate, const _PathData & data);
|
||||
void AppendRouteInstructionString(std::string & output);
|
||||
void SetStartSegment(const PhantomNode & startPhantom);
|
||||
void SetEndSegment(const PhantomNode & startPhantom);
|
||||
void AppendEncodedPolylineString(std::string & output, bool isEncoded);
|
||||
unsigned Run();
|
||||
unsigned Run(const unsigned zoomLevel);
|
||||
|
||||
// static inline void getDirectionOfInstruction(double angle, DirectionOfInstruction & dirInst) {
|
||||
// if(angle >= 23 && angle < 67) {
|
||||
|
||||
@@ -44,8 +44,6 @@ public:
|
||||
|
||||
void Run(http::Reply & reply, RawRouteData &rawRoute, PhantomNodes &phantomNodes, SearchEngineT &sEngine, unsigned durationOfTrip) {
|
||||
WriteHeaderToOutput(reply.content);
|
||||
//We do not need to do much, if there is no route ;-)
|
||||
|
||||
if(durationOfTrip != INT_MAX && rawRoute.routeSegments.size() > 0) {
|
||||
summary.startName = sEngine.GetEscapedNameForNameID(phantomNodes.startPhantom.nodeBasedEdgeNameID);
|
||||
descriptionFactory.SetStartSegment(phantomNodes.startPhantom);
|
||||
@@ -62,12 +60,12 @@ public:
|
||||
}
|
||||
descriptionFactory.SetEndSegment(phantomNodes.targetPhantom);
|
||||
} else {
|
||||
//no route found
|
||||
//We do not need to do much, if there is no route ;-)
|
||||
reply.content += "207,"
|
||||
"\"status_message\": \"Cannot find route between points\",";
|
||||
}
|
||||
|
||||
summary.BuildDurationAndLengthStrings(descriptionFactory.Run(), durationOfTrip);
|
||||
summary.BuildDurationAndLengthStrings(descriptionFactory.Run(config.z), durationOfTrip);
|
||||
|
||||
reply.content += "\"route_summary\": {"
|
||||
"\"total_distance\":";
|
||||
@@ -94,11 +92,14 @@ public:
|
||||
reply.content += ","
|
||||
"\"route_instructions\": [";
|
||||
if(config.instructions) {
|
||||
//Segment information has following format:
|
||||
//["instruction","streetname",length,position,time,"length","earth_direction",azimuth]
|
||||
//Example: ["Turn left","High Street",200,4,10,"200m","NE",22.5]
|
||||
//See also: http://developers.cloudmade.com/wiki/navengine/JSON_format
|
||||
unsigned prefixSumOfNecessarySegments = 0;
|
||||
std::string tmpDist, tmpLength, tmp;
|
||||
//Fetch data from Factory and generate a string from it.
|
||||
BOOST_FOREACH(SegmentInformation segment, descriptionFactory.pathDescription) {
|
||||
//["instruction","streetname",length,position,time,"length","earth_direction",azimuth]
|
||||
if(0 != segment.turnInstruction) {
|
||||
if(0 != prefixSumOfNecessarySegments)
|
||||
reply.content += ",";
|
||||
@@ -123,8 +124,6 @@ public:
|
||||
if(segment.necessary)
|
||||
++prefixSumOfNecessarySegments;
|
||||
}
|
||||
// descriptionFactory.AppendRouteInstructionString(reply.content);
|
||||
|
||||
}
|
||||
reply.content += "],";
|
||||
//list all viapoints so that the client may display it
|
||||
|
||||
Reference in New Issue
Block a user