output of geometry can be triggered by geometry=true/false (thanks Bharath).

route generalization is determined by zoom level. &simplified=true is thereby not valid, use &z=19 for the non-generalized geometry
This commit is contained in:
Dennis Luxen 2011-05-11 11:35:15 +00:00
parent 2784e273bc
commit d2b6ac722b
4 changed files with 53 additions and 27 deletions

View File

@ -4,3 +4,4 @@ Christian Vetter
Dennis Luxen
Ruslan Krenzler
Frederik Ramm
Bharath Vissapragada

View File

@ -25,15 +25,15 @@ or see http://www.gnu.org/licenses/agpl.txt.
static double areaThresholds[19] = { 5000, 5000, 5000, 5000, 5000, 2500, 2000, 1500, 800, 400, 250, 150, 100, 75, 25, 20, 10, 5 };
template<class SearchEngineT, bool SimplifyRoute = false>
template<class SearchEngineT, bool GeometryOn = true, bool InstructionsOn = true>
class JSONDescriptor : public BaseDescriptor<SearchEngineT> {
private:
short zoom;
public:
JSONDescriptor() : zoom(18) {}
void SetZoom(const unsigned short z) {
if(z > 18)
zoom = 18;
if(z > 19)
zoom = 19;
zoom = z;
}
@ -147,8 +147,8 @@ public:
}
double angle = GetAngleBetweenTwoEdges(startOfSegment, current, next);
double area = fabs(0.5*( startOfSegment.lon*(current.lat - next.lat) + current.lon*(next.lat - startOfSegment.lat) + next.lon*(startOfSegment.lat - current.lat) ) );
// std::cout << "Area for: " << area << std::endl;
if(area > areaThresholds[zoom] || false == SimplifyRoute) {
// std::cout << "Area for: " << area << std::endl;
if(area > areaThresholds[zoom] || 19 == zoom) {
painted++;
convertLatLon(current.lat, tmp);
routeGeometryString += "[";
@ -205,7 +205,7 @@ public:
lastPlace = current;
routeInstructionString += "[\"";
if(angle > 160 && angle < 200) {
if(angle > 160 && angle < 200) {
routeInstructionString += /* " (" << angle << ")*/"Continue";
} else if (angle > 290 && angle <= 360) {
routeInstructionString += /*" (" << angle << ")*/ "Turn sharp left";
@ -277,6 +277,8 @@ public:
s << 10*(round(entireDistance/10.));
routeSummaryString += "\"total_distance\":";
routeSummaryString += s.str();
routeSummaryString += ",\"total_time\":";
//give travel time in minutes
int travelTime = distance;
@ -302,10 +304,14 @@ public:
reply.content += routeSummaryString;
reply.content += "},";
reply.content += "\"route_geometry\": [";
reply.content += routeGeometryString;
if(GeometryOn) {
reply.content += routeGeometryString;
}
reply.content += "],";
reply.content += "\"route_instructions\": [";
reply.content += routeInstructionString;
if(GeometryOn || InstructionsOn) {
reply.content += routeInstructionString;
}
reply.content += "],";
reply.content += "\"transactionId\": \"OSRM Routing Engine JSON Descriptor (beta)\"";
reply.content += "}";

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, bool SimplifyRoute = false>
template<class SearchEngineT, bool Geometry = true>
class KMLDescriptor : public BaseDescriptor<SearchEngineT>{
public:
void SetZoom(const unsigned short z) { }
@ -30,6 +30,7 @@ public:
string lineString;
string startName;
string targetName;
double entireDistance = 0;
string direction = "East";
reply.content += ("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n");
reply.content += ("<kml xmlns=\"http://www.opengis.net/kml/2.2\">\n");
@ -85,7 +86,6 @@ public:
stringstream numberString;
double tempDist = 0;
double entireDistance = 0;
double lengthOfInstruction = 0;
NodeID nextID = UINT_MAX;
NodeID nameID = sEngine->GetNameIDForOriginDestinationNodeID(phantomNodes->startNode1, phantomNodes->startNode2);
@ -109,7 +109,7 @@ public:
}
double angle = GetAngleBetweenTwoEdges(startOfSegment, current, next);
if(178 > angle || 182 < angle || false == SimplifyRoute) {
if(178 > angle || 182 < angle) {
convertLatLon(current.lon, tmp);
lineString += tmp;
lineString += ",";
@ -218,6 +218,13 @@ public:
lineString += ",";
convertLatLon(phantomNodes->targetCoord.lat, tmp);
lineString += tmp;
if(!Geometry){
reply.content = ("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n");
reply.content += ("<kml xmlns=\"http://www.opengis.net/kml/2.2\">\n");
reply.content += ("<Document>\n");
}
reply.content += "\t<Placemark>\n"
"\t\t<name><![CDATA[Route from ";
@ -241,15 +248,19 @@ public:
reply.content += s.str();
reply.content += " minutes)]]>"
"</description>\n"
"\t\t<GeometryCollection>\n"
"</description>\n";
if(Geometry) {
reply.content += "\t\t<GeometryCollection>\n"
"\t\t\t<LineString>\n"
"\t\t\t\t<coordinates>";
reply.content += lineString;
reply.content += "</coordinates>\n"
"\t\t\t</LineString>\n"
"\t\t</GeometryCollection>\n"
"\t</Placemark>\n";
"\t\t</GeometryCollection>\n";
}
reply.content += "\t</Placemark>\n";
}
reply.content += "</Document>\n</kml>";
}

View File

@ -102,6 +102,12 @@ public:
int lat2 = static_cast<int>(100000.*atof(routeParameters.parameters[2].c_str()));
int lon2 = static_cast<int>(100000.*atof(routeParameters.parameters[3].c_str()));
bool geometry(true);
if("false" == routeParameters.options["geometry"]) {
geometry = false;
}
if(lat1>90*100000 || lat1 <-90*100000 || lon1>180*100000 || lon1 <-180*100000) {
reply = http::Reply::stockReply(http::Reply::badRequest);
return;
@ -127,8 +133,7 @@ public:
reply.content += "(\n";
}
unsigned descriptorType = descriptorTable[routeParameters.options.Find("output")];
const bool simplifiedRoute = (routeParameters.options.Find("simplified") == "yes");
unsigned short zoom;
unsigned short zoom = 18;
if(routeParameters.options.Find("z") != ""){
zoom = atoi(routeParameters.options.Find("z").c_str());
if(18 < zoom)
@ -137,22 +142,25 @@ public:
//todo: put options in a seperate struct and pass it to the descriptor
switch(descriptorType){
case 0:
if(simplifiedRoute)
desc = new KMLDescriptor<SearchEngine<EdgeData, StaticGraph<EdgeData> >, true >();
if(geometry)
desc = new KMLDescriptor<SearchEngine<EdgeData, StaticGraph<EdgeData> >, true>();
else
desc = new KMLDescriptor<SearchEngine<EdgeData, StaticGraph<EdgeData> >, false >();
desc = new KMLDescriptor<SearchEngine<EdgeData, StaticGraph<EdgeData> >, false>();
break;
case 1:
if(simplifiedRoute)
desc = new JSONDescriptor<SearchEngine<EdgeData, StaticGraph<EdgeData> >, true >();
if(geometry)
desc = new JSONDescriptor<SearchEngine<EdgeData, StaticGraph<EdgeData> >, true>();
else
desc = new JSONDescriptor<SearchEngine<EdgeData, StaticGraph<EdgeData> >, false >();
desc = new JSONDescriptor<SearchEngine<EdgeData, StaticGraph<EdgeData> >, false>();
break;
default:
if(simplifiedRoute)
desc = new KMLDescriptor<SearchEngine<EdgeData, StaticGraph<EdgeData> >, true >();
if(geometry)
desc = new KMLDescriptor<SearchEngine<EdgeData, StaticGraph<EdgeData> >, true>();
else
desc = new KMLDescriptor<SearchEngine<EdgeData, StaticGraph<EdgeData> >, false >();
desc = new KMLDescriptor<SearchEngine<EdgeData, StaticGraph<EdgeData> >, false>();
break;
}
desc->SetZoom(zoom);