Support for additional parameter '&simplified=yes' that outputs a simplified geometry that does not depict all of the small road segments but omits some. Usually, this is not visible to the user.

This commit is contained in:
Dennis Luxen 2011-04-19 16:03:48 +00:00
parent fb2a414839
commit 90bd34d8ac
3 changed files with 44 additions and 26 deletions

View File

@ -23,7 +23,7 @@ or see http://www.gnu.org/licenses/agpl.txt.
#ifndef JSONDESCRIPTOR_H_
#define JSONDESCRIPTOR_H_
template<class SearchEngineT>
template<class SearchEngineT, bool SimplifyRoute = false>
class JSONDescriptor : public BaseDescriptor<SearchEngineT> {
public:
void Run(http::Reply& reply, std::vector< _PathData > * path, PhantomNodes * phantomNodes, SearchEngineT * sEngine, unsigned distance) {
@ -102,7 +102,7 @@ public:
position++;
_Coordinate previous(phantomNodes->startCoord.lat, phantomNodes->startCoord.lon);
_Coordinate next, current, lastPlace;
_Coordinate next, current, lastPlace, startOfSegment;
stringstream numberString;
stringstream intNumberString;
@ -118,14 +118,7 @@ public:
short prevType = SHRT_MAX;
for(vector< _PathData >::iterator it = path->begin(); it != path->end(); it++) {
sEngine->getNodeInfo(it->node, current);
convertLatLon(current.lat, tmp);
routeGeometryString += " [";
routeGeometryString += tmp;
routeGeometryString += ", ";
convertLatLon(current.lon, tmp);
routeGeometryString += tmp;
routeGeometryString += "],\n";
position++;
startOfSegment = previous;
if(it==path->end()-1){
next = _Coordinate(phantomNodes->targetCoord.lat, phantomNodes->targetCoord.lon);
@ -138,7 +131,18 @@ public:
nextType = sEngine->GetTypeOfEdgeForOriginDestinationNodeID(it->node, (it+1)->node);
durationOfInstruction += sEngine->GetWeightForOriginDestinationNodeID(it->node, (it+1)->node);
}
double angle = GetAngleBetweenTwoEdges(startOfSegment, current, next);
if(178 > angle || 182 < angle || false == SimplifyRoute) {
convertLatLon(current.lat, tmp);
routeGeometryString += " [";
routeGeometryString += tmp;
routeGeometryString += ", ";
convertLatLon(current.lon, tmp);
routeGeometryString += tmp;
routeGeometryString += "],\n";
position++;
startOfSegment = current;
}
if(nextID == nameID) {
tempDist += ApproximateDistance(previous.lat, previous.lon, current.lat, current.lon);
} else {
@ -182,8 +186,7 @@ public:
lastPlace = current;
routeInstructionString += " [\"";
double angle = GetAngleBetweenTwoEdges(previous, current, next);
if(angle > 160 && angle < 200) {
if(angle > 160 && angle < 200) {
routeInstructionString += /* " (" << angle << ")*/"Continue";
} else if (angle > 290 && angle <= 360) {
routeInstructionString += /*" (" << angle << ")*/ "Turn sharp left";

View File

@ -21,7 +21,7 @@ or see http://www.gnu.org/licenses/agpl.txt.
#ifndef KML_DESCRIPTOR_H_
#define KML_DESCRIPTOR_H_
template<class SearchEngineT>
template<class SearchEngineT, bool SimplifyRoute = false>
class KMLDescriptor : public BaseDescriptor<SearchEngineT>{
public:
void Run(http::Reply& reply, std::vector< _PathData > * path, PhantomNodes * phantomNodes, SearchEngineT * sEngine, unsigned distance) {
@ -80,7 +80,7 @@ public:
reply.content += ("\t</Placemark>\n");
_Coordinate previous(phantomNodes->startCoord.lat, phantomNodes->startCoord.lon);
_Coordinate next, current, lastPlace;
_Coordinate next, current, lastPlace, startOfSegment;
stringstream numberString;
double tempDist = 0;
@ -96,13 +96,7 @@ public:
reply.content += "\t<Placemark>\n\t\t<name><![CDATA[";
for(vector< _PathData >::iterator it = path->begin(); it != path->end(); it++) {
sEngine->getNodeInfo(it->node, current);
convertLatLon(current.lon, tmp);
lineString += tmp;
lineString += ",";
convertLatLon(current.lat, tmp);
lineString += tmp;
lineString += " ";
startOfSegment = previous;
if(it==path->end()-1){
next = _Coordinate(phantomNodes->targetCoord.lat, phantomNodes->targetCoord.lon);
nextID = sEngine->GetNameIDForOriginDestinationNodeID(phantomNodes->targetNode1, phantomNodes->targetNode2);
@ -113,6 +107,16 @@ public:
nextType = sEngine->GetTypeOfEdgeForOriginDestinationNodeID(it->node, (it+1)->node);
}
double angle = GetAngleBetweenTwoEdges(startOfSegment, current, next);
if(178 > angle || 182 < angle || false == SimplifyRoute) {
convertLatLon(current.lon, tmp);
lineString += tmp;
lineString += ",";
convertLatLon(current.lat, tmp);
lineString += tmp;
lineString += " ";
startOfSegment = current;
}
if(nextID == nameID) {
tempDist += ApproximateDistance(previous.lat, previous.lon, current.lat, current.lon);
@ -122,7 +126,7 @@ public:
if(type != 0 && prevType == 0 )
reply.content += "leave motorway and ";
double angle = GetAngleBetweenTwoEdges(previous, current, next);
//double angle = GetAngleBetweenTwoEdges(previous, current, next);
reply.content += "follow road ";
if(nameID != 0)
reply.content += sEngine->GetNameForNameID(nameID);

View File

@ -126,15 +126,26 @@ public:
reply.content += "(\n";
}
unsigned descriptorType = descriptorTable[routeParameters.options.Find("output")];
const bool simplifiedRoute = (routeParameters.options.Find("simplified") == "yes");
//todo: put options in a seperate struct and pass it to the descriptor
switch(descriptorType){
case 0:
desc = new KMLDescriptor<SearchEngine<EdgeData, StaticGraph<EdgeData> > >();
if(simplifiedRoute)
desc = new KMLDescriptor<SearchEngine<EdgeData, StaticGraph<EdgeData> >, true >();
else
desc = new KMLDescriptor<SearchEngine<EdgeData, StaticGraph<EdgeData> >, false >();
break;
case 1:
desc = new JSONDescriptor<SearchEngine<EdgeData, StaticGraph<EdgeData> > >();
if(simplifiedRoute)
desc = new JSONDescriptor<SearchEngine<EdgeData, StaticGraph<EdgeData> >, true >();
else
desc = new JSONDescriptor<SearchEngine<EdgeData, StaticGraph<EdgeData> >, false >();
break;
default:
desc = new KMLDescriptor<SearchEngine<EdgeData, StaticGraph<EdgeData> > >();
if(simplifiedRoute)
desc = new KMLDescriptor<SearchEngine<EdgeData, StaticGraph<EdgeData> >, true >();
else
desc = new KMLDescriptor<SearchEngine<EdgeData, StaticGraph<EdgeData> >, false >();
break;
}