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:
parent
2784e273bc
commit
d2b6ac722b
@ -3,4 +3,5 @@ The following people contributed code to the Open Source Routing Machine:
|
|||||||
Christian Vetter
|
Christian Vetter
|
||||||
Dennis Luxen
|
Dennis Luxen
|
||||||
Ruslan Krenzler
|
Ruslan Krenzler
|
||||||
Frederik Ramm
|
Frederik Ramm
|
||||||
|
Bharath Vissapragada
|
@ -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 };
|
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> {
|
class JSONDescriptor : public BaseDescriptor<SearchEngineT> {
|
||||||
private:
|
private:
|
||||||
short zoom;
|
short zoom;
|
||||||
public:
|
public:
|
||||||
JSONDescriptor() : zoom(18) {}
|
JSONDescriptor() : zoom(18) {}
|
||||||
void SetZoom(const unsigned short z) {
|
void SetZoom(const unsigned short z) {
|
||||||
if(z > 18)
|
if(z > 19)
|
||||||
zoom = 18;
|
zoom = 19;
|
||||||
zoom = z;
|
zoom = z;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -147,8 +147,8 @@ public:
|
|||||||
}
|
}
|
||||||
double angle = GetAngleBetweenTwoEdges(startOfSegment, current, next);
|
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) ) );
|
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;
|
// std::cout << "Area for: " << area << std::endl;
|
||||||
if(area > areaThresholds[zoom] || false == SimplifyRoute) {
|
if(area > areaThresholds[zoom] || 19 == zoom) {
|
||||||
painted++;
|
painted++;
|
||||||
convertLatLon(current.lat, tmp);
|
convertLatLon(current.lat, tmp);
|
||||||
routeGeometryString += "[";
|
routeGeometryString += "[";
|
||||||
@ -205,7 +205,7 @@ public:
|
|||||||
lastPlace = current;
|
lastPlace = current;
|
||||||
routeInstructionString += "[\"";
|
routeInstructionString += "[\"";
|
||||||
|
|
||||||
if(angle > 160 && angle < 200) {
|
if(angle > 160 && angle < 200) {
|
||||||
routeInstructionString += /* " (" << angle << ")*/"Continue";
|
routeInstructionString += /* " (" << angle << ")*/"Continue";
|
||||||
} else if (angle > 290 && angle <= 360) {
|
} else if (angle > 290 && angle <= 360) {
|
||||||
routeInstructionString += /*" (" << angle << ")*/ "Turn sharp left";
|
routeInstructionString += /*" (" << angle << ")*/ "Turn sharp left";
|
||||||
@ -277,6 +277,8 @@ public:
|
|||||||
s << 10*(round(entireDistance/10.));
|
s << 10*(round(entireDistance/10.));
|
||||||
routeSummaryString += "\"total_distance\":";
|
routeSummaryString += "\"total_distance\":";
|
||||||
routeSummaryString += s.str();
|
routeSummaryString += s.str();
|
||||||
|
|
||||||
|
|
||||||
routeSummaryString += ",\"total_time\":";
|
routeSummaryString += ",\"total_time\":";
|
||||||
//give travel time in minutes
|
//give travel time in minutes
|
||||||
int travelTime = distance;
|
int travelTime = distance;
|
||||||
@ -302,10 +304,14 @@ public:
|
|||||||
reply.content += routeSummaryString;
|
reply.content += routeSummaryString;
|
||||||
reply.content += "},";
|
reply.content += "},";
|
||||||
reply.content += "\"route_geometry\": [";
|
reply.content += "\"route_geometry\": [";
|
||||||
reply.content += routeGeometryString;
|
if(GeometryOn) {
|
||||||
|
reply.content += routeGeometryString;
|
||||||
|
}
|
||||||
reply.content += "],";
|
reply.content += "],";
|
||||||
reply.content += "\"route_instructions\": [";
|
reply.content += "\"route_instructions\": [";
|
||||||
reply.content += routeInstructionString;
|
if(GeometryOn || InstructionsOn) {
|
||||||
|
reply.content += routeInstructionString;
|
||||||
|
}
|
||||||
reply.content += "],";
|
reply.content += "],";
|
||||||
reply.content += "\"transactionId\": \"OSRM Routing Engine JSON Descriptor (beta)\"";
|
reply.content += "\"transactionId\": \"OSRM Routing Engine JSON Descriptor (beta)\"";
|
||||||
reply.content += "}";
|
reply.content += "}";
|
||||||
|
@ -21,7 +21,7 @@ or see http://www.gnu.org/licenses/agpl.txt.
|
|||||||
#ifndef KML_DESCRIPTOR_H_
|
#ifndef KML_DESCRIPTOR_H_
|
||||||
#define KML_DESCRIPTOR_H_
|
#define KML_DESCRIPTOR_H_
|
||||||
|
|
||||||
template<class SearchEngineT, bool SimplifyRoute = false>
|
template<class SearchEngineT, bool Geometry = true>
|
||||||
class KMLDescriptor : public BaseDescriptor<SearchEngineT>{
|
class KMLDescriptor : public BaseDescriptor<SearchEngineT>{
|
||||||
public:
|
public:
|
||||||
void SetZoom(const unsigned short z) { }
|
void SetZoom(const unsigned short z) { }
|
||||||
@ -30,6 +30,7 @@ public:
|
|||||||
string lineString;
|
string lineString;
|
||||||
string startName;
|
string startName;
|
||||||
string targetName;
|
string targetName;
|
||||||
|
double entireDistance = 0;
|
||||||
string direction = "East";
|
string direction = "East";
|
||||||
reply.content += ("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n");
|
reply.content += ("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n");
|
||||||
reply.content += ("<kml xmlns=\"http://www.opengis.net/kml/2.2\">\n");
|
reply.content += ("<kml xmlns=\"http://www.opengis.net/kml/2.2\">\n");
|
||||||
@ -85,7 +86,6 @@ public:
|
|||||||
stringstream numberString;
|
stringstream numberString;
|
||||||
|
|
||||||
double tempDist = 0;
|
double tempDist = 0;
|
||||||
double entireDistance = 0;
|
|
||||||
double lengthOfInstruction = 0;
|
double lengthOfInstruction = 0;
|
||||||
NodeID nextID = UINT_MAX;
|
NodeID nextID = UINT_MAX;
|
||||||
NodeID nameID = sEngine->GetNameIDForOriginDestinationNodeID(phantomNodes->startNode1, phantomNodes->startNode2);
|
NodeID nameID = sEngine->GetNameIDForOriginDestinationNodeID(phantomNodes->startNode1, phantomNodes->startNode2);
|
||||||
@ -109,7 +109,7 @@ public:
|
|||||||
}
|
}
|
||||||
|
|
||||||
double angle = GetAngleBetweenTwoEdges(startOfSegment, current, next);
|
double angle = GetAngleBetweenTwoEdges(startOfSegment, current, next);
|
||||||
if(178 > angle || 182 < angle || false == SimplifyRoute) {
|
if(178 > angle || 182 < angle) {
|
||||||
convertLatLon(current.lon, tmp);
|
convertLatLon(current.lon, tmp);
|
||||||
lineString += tmp;
|
lineString += tmp;
|
||||||
lineString += ",";
|
lineString += ",";
|
||||||
@ -218,6 +218,13 @@ public:
|
|||||||
lineString += ",";
|
lineString += ",";
|
||||||
convertLatLon(phantomNodes->targetCoord.lat, tmp);
|
convertLatLon(phantomNodes->targetCoord.lat, tmp);
|
||||||
lineString += 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"
|
reply.content += "\t<Placemark>\n"
|
||||||
"\t\t<name><![CDATA[Route from ";
|
"\t\t<name><![CDATA[Route from ";
|
||||||
@ -241,15 +248,19 @@ public:
|
|||||||
reply.content += s.str();
|
reply.content += s.str();
|
||||||
|
|
||||||
reply.content += " minutes)]]>"
|
reply.content += " minutes)]]>"
|
||||||
"</description>\n"
|
"</description>\n";
|
||||||
"\t\t<GeometryCollection>\n"
|
|
||||||
|
if(Geometry) {
|
||||||
|
|
||||||
|
reply.content += "\t\t<GeometryCollection>\n"
|
||||||
"\t\t\t<LineString>\n"
|
"\t\t\t<LineString>\n"
|
||||||
"\t\t\t\t<coordinates>";
|
"\t\t\t\t<coordinates>";
|
||||||
reply.content += lineString;
|
reply.content += lineString;
|
||||||
reply.content += "</coordinates>\n"
|
reply.content += "</coordinates>\n"
|
||||||
"\t\t\t</LineString>\n"
|
"\t\t\t</LineString>\n"
|
||||||
"\t\t</GeometryCollection>\n"
|
"\t\t</GeometryCollection>\n";
|
||||||
"\t</Placemark>\n";
|
}
|
||||||
|
reply.content += "\t</Placemark>\n";
|
||||||
}
|
}
|
||||||
reply.content += "</Document>\n</kml>";
|
reply.content += "</Document>\n</kml>";
|
||||||
}
|
}
|
||||||
|
@ -102,6 +102,12 @@ public:
|
|||||||
int lat2 = static_cast<int>(100000.*atof(routeParameters.parameters[2].c_str()));
|
int lat2 = static_cast<int>(100000.*atof(routeParameters.parameters[2].c_str()));
|
||||||
int lon2 = static_cast<int>(100000.*atof(routeParameters.parameters[3].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) {
|
if(lat1>90*100000 || lat1 <-90*100000 || lon1>180*100000 || lon1 <-180*100000) {
|
||||||
reply = http::Reply::stockReply(http::Reply::badRequest);
|
reply = http::Reply::stockReply(http::Reply::badRequest);
|
||||||
return;
|
return;
|
||||||
@ -127,8 +133,7 @@ public:
|
|||||||
reply.content += "(\n";
|
reply.content += "(\n";
|
||||||
}
|
}
|
||||||
unsigned descriptorType = descriptorTable[routeParameters.options.Find("output")];
|
unsigned descriptorType = descriptorTable[routeParameters.options.Find("output")];
|
||||||
const bool simplifiedRoute = (routeParameters.options.Find("simplified") == "yes");
|
unsigned short zoom = 18;
|
||||||
unsigned short zoom;
|
|
||||||
if(routeParameters.options.Find("z") != ""){
|
if(routeParameters.options.Find("z") != ""){
|
||||||
zoom = atoi(routeParameters.options.Find("z").c_str());
|
zoom = atoi(routeParameters.options.Find("z").c_str());
|
||||||
if(18 < zoom)
|
if(18 < zoom)
|
||||||
@ -137,22 +142,25 @@ public:
|
|||||||
//todo: put options in a seperate struct and pass it to the descriptor
|
//todo: put options in a seperate struct and pass it to the descriptor
|
||||||
switch(descriptorType){
|
switch(descriptorType){
|
||||||
case 0:
|
case 0:
|
||||||
if(simplifiedRoute)
|
if(geometry)
|
||||||
desc = new KMLDescriptor<SearchEngine<EdgeData, StaticGraph<EdgeData> >, true >();
|
desc = new KMLDescriptor<SearchEngine<EdgeData, StaticGraph<EdgeData> >, true>();
|
||||||
else
|
else
|
||||||
desc = new KMLDescriptor<SearchEngine<EdgeData, StaticGraph<EdgeData> >, false >();
|
desc = new KMLDescriptor<SearchEngine<EdgeData, StaticGraph<EdgeData> >, false>();
|
||||||
|
|
||||||
break;
|
break;
|
||||||
case 1:
|
case 1:
|
||||||
if(simplifiedRoute)
|
if(geometry)
|
||||||
desc = new JSONDescriptor<SearchEngine<EdgeData, StaticGraph<EdgeData> >, true >();
|
desc = new JSONDescriptor<SearchEngine<EdgeData, StaticGraph<EdgeData> >, true>();
|
||||||
else
|
else
|
||||||
desc = new JSONDescriptor<SearchEngine<EdgeData, StaticGraph<EdgeData> >, false >();
|
desc = new JSONDescriptor<SearchEngine<EdgeData, StaticGraph<EdgeData> >, false>();
|
||||||
|
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
if(simplifiedRoute)
|
if(geometry)
|
||||||
desc = new KMLDescriptor<SearchEngine<EdgeData, StaticGraph<EdgeData> >, true >();
|
desc = new KMLDescriptor<SearchEngine<EdgeData, StaticGraph<EdgeData> >, true>();
|
||||||
else
|
else
|
||||||
desc = new KMLDescriptor<SearchEngine<EdgeData, StaticGraph<EdgeData> >, false >();
|
desc = new KMLDescriptor<SearchEngine<EdgeData, StaticGraph<EdgeData> >, false>();
|
||||||
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
desc->SetZoom(zoom);
|
desc->SetZoom(zoom);
|
||||||
|
Loading…
Reference in New Issue
Block a user