Output format is selectable with additional parameter to URL: &output={kml,json}
This commit is contained in:
parent
66a3da0694
commit
51d0b94e90
@ -19,7 +19,7 @@ or see http://www.gnu.org/licenses/agpl.txt.
|
|||||||
|
|
||||||
Created on: 18.11.2010
|
Created on: 18.11.2010
|
||||||
Author: dennis
|
Author: dennis
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifndef HASHTABLE_H_
|
#ifndef HASHTABLE_H_
|
||||||
#define HASHTABLE_H_
|
#define HASHTABLE_H_
|
||||||
@ -28,40 +28,50 @@ or see http://www.gnu.org/licenses/agpl.txt.
|
|||||||
|
|
||||||
template<typename keyT, typename valueT>
|
template<typename keyT, typename valueT>
|
||||||
class HashTable {
|
class HashTable {
|
||||||
typedef google::sparse_hash_map<keyT, valueT> MyHashTable;
|
typedef google::sparse_hash_map<keyT, valueT> MyHashTable;
|
||||||
public:
|
public:
|
||||||
HashTable() { }
|
typedef typename google::sparse_hash_map<keyT, valueT>::const_iterator MyIterator;
|
||||||
HashTable(const unsigned size) {
|
HashTable() { }
|
||||||
table.resize(size);
|
HashTable(const unsigned size) {
|
||||||
}
|
table.resize(size);
|
||||||
void Add(const keyT& key, const valueT& value){
|
}
|
||||||
table[key] = value;
|
void Add(const keyT& key, const valueT& value){
|
||||||
}
|
table[key] = value;
|
||||||
void Set(const keyT& key, const valueT& value){
|
}
|
||||||
table[key] = value;
|
void Set(const keyT& key, const valueT& value){
|
||||||
}
|
table[key] = value;
|
||||||
valueT Find(const keyT& key) {
|
}
|
||||||
if(table.find(key) == table.end())
|
valueT Find(const keyT& key) {
|
||||||
return valueT();
|
if(table.find(key) == table.end())
|
||||||
return table.find(key)->second;
|
return valueT();
|
||||||
}
|
return table.find(key)->second;
|
||||||
|
}
|
||||||
|
|
||||||
bool Holds(const keyT& key) {
|
bool Holds(const keyT& key) {
|
||||||
if(table.find(key) == table.end())
|
if(table.find(key) == table.end())
|
||||||
return false;
|
return false;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
void EraseAll() {
|
void EraseAll() {
|
||||||
if(table.size() > 0)
|
if(table.size() > 0)
|
||||||
table.clear();
|
table.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
inline
|
inline
|
||||||
valueT & operator[] (keyT key) {
|
valueT & operator[] (keyT key) {
|
||||||
return table[key];
|
return table[key];
|
||||||
}
|
}
|
||||||
|
unsigned Size() const {
|
||||||
|
return table.size();
|
||||||
|
}
|
||||||
|
MyIterator begin() const {
|
||||||
|
return table.begin();
|
||||||
|
}
|
||||||
|
MyIterator end() const {
|
||||||
|
return table.end();
|
||||||
|
}
|
||||||
private:
|
private:
|
||||||
MyHashTable table;
|
MyHashTable table;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif /* HASHTABLE_H_ */
|
#endif /* HASHTABLE_H_ */
|
||||||
|
43
Plugins/BaseDescriptor.h
Normal file
43
Plugins/BaseDescriptor.h
Normal file
@ -0,0 +1,43 @@
|
|||||||
|
/*
|
||||||
|
open source routing machine
|
||||||
|
Copyright (C) Dennis Luxen, 2010
|
||||||
|
|
||||||
|
This program is free software; you can redistribute it and/or modify
|
||||||
|
it under the terms of the GNU AFFERO General Public License as published by
|
||||||
|
the Free Software Foundation; either version 3 of the License, or
|
||||||
|
any later version.
|
||||||
|
|
||||||
|
This program is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
GNU General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU Affero General Public License
|
||||||
|
along with this program; if not, write to the Free Software
|
||||||
|
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||||
|
or see http://www.gnu.org/licenses/agpl.txt.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef BASE_DESCRIPTOR_H_
|
||||||
|
#define BASE_DESCRIPTOR_H_
|
||||||
|
|
||||||
|
#include <cassert>
|
||||||
|
#include <string>
|
||||||
|
#include <vector>
|
||||||
|
#include <cstdio>
|
||||||
|
|
||||||
|
#include "../typedefs.h"
|
||||||
|
#include "../DataStructures/ExtractorStructs.h"
|
||||||
|
#include "../Util/StrIngUtil.h"
|
||||||
|
|
||||||
|
template<class SearchEngineT>
|
||||||
|
class BaseDescriptor {
|
||||||
|
public:
|
||||||
|
BaseDescriptor() { }
|
||||||
|
//Maybe someone can explain the pure virtual destructor thing to me (dennis)
|
||||||
|
virtual ~BaseDescriptor() { }
|
||||||
|
virtual void Run(http::Reply& reply, std::vector< _PathData > * path, PhantomNodes * phantomNodes, SearchEngineT * sEngine, unsigned distance) = 0;
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif /* BASE_DESCRIPTOR_H_ */
|
@ -24,6 +24,8 @@ or see http://www.gnu.org/licenses/agpl.txt.
|
|||||||
#include <cassert>
|
#include <cassert>
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
|
#include "RouteParameters.h"
|
||||||
#include "../Server/BasicDatastructures.h"
|
#include "../Server/BasicDatastructures.h"
|
||||||
|
|
||||||
class BasePlugin {
|
class BasePlugin {
|
||||||
@ -33,7 +35,7 @@ public:
|
|||||||
virtual ~BasePlugin() { }
|
virtual ~BasePlugin() { }
|
||||||
virtual std::string GetDescriptor() = 0;
|
virtual std::string GetDescriptor() = 0;
|
||||||
virtual std::string GetVersionString() = 0;
|
virtual std::string GetVersionString() = 0;
|
||||||
virtual void HandleRequest(std::vector<std::string> parameters, http::Reply& reply) = 0;
|
virtual void HandleRequest(RouteParameters routeParameters, http::Reply& reply) = 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif /* BASEPLUGIN_H_ */
|
#endif /* BASEPLUGIN_H_ */
|
||||||
|
@ -11,20 +11,27 @@
|
|||||||
#include <sstream>
|
#include <sstream>
|
||||||
|
|
||||||
#include "BasePlugin.h"
|
#include "BasePlugin.h"
|
||||||
|
#include "RouteParameters.h"
|
||||||
|
|
||||||
class HelloWorldPlugin : public BasePlugin {
|
class HelloWorldPlugin : public BasePlugin {
|
||||||
public:
|
public:
|
||||||
HelloWorldPlugin() {}
|
HelloWorldPlugin() {}
|
||||||
~HelloWorldPlugin() { /*std::cout << GetDescriptor() << " destructor" << std::endl;*/ }
|
~HelloWorldPlugin() { /*std::cout << GetDescriptor() << " destructor" << std::endl;*/ }
|
||||||
std::string GetDescriptor() { return std::string("hello"); }
|
std::string GetDescriptor() { return std::string("hello"); }
|
||||||
void HandleRequest(std::vector<std::string> parameters, http::Reply& reply) {
|
void HandleRequest(RouteParameters routeParameters, http::Reply& reply) {
|
||||||
std::cout << "[hello world]: runnning handler" << std::endl;
|
std::cout << "[hello world]: runnning handler" << std::endl;
|
||||||
reply.status = http::Reply::ok;
|
reply.status = http::Reply::ok;
|
||||||
reply.content.append("<html><head><title>Hello World Demonstration Document</title></head><body><h1>Hello, World!</h1>");
|
reply.content.append("<html><head><title>Hello World Demonstration Document</title></head><body><h1>Hello, World!</h1>");
|
||||||
std::stringstream content;
|
std::stringstream content;
|
||||||
content << "Number of parameters: " << parameters.size() << "<br>";
|
content << "Number of parameters: " << routeParameters.parameters.size() << "<br>";
|
||||||
for(unsigned i = 0; i < parameters.size(); i++) {
|
for(unsigned i = 0; i < routeParameters.parameters.size(); i++) {
|
||||||
content << parameters[i] << "<br>";
|
content << routeParameters.parameters[i] << "<br>";
|
||||||
|
}
|
||||||
|
content << "Number Of Options: " << routeParameters.options.Size() << "<br>";
|
||||||
|
RouteParameters::OptionsIterator optionsIT = routeParameters.options.begin();
|
||||||
|
for(;optionsIT != routeParameters.options.end(); optionsIT++) {
|
||||||
|
content << "param = " << optionsIT->first << ": ";
|
||||||
|
content << "option = " << optionsIT->second << "<br>";
|
||||||
}
|
}
|
||||||
reply.content.append(content.str());
|
reply.content.append(content.str());
|
||||||
reply.content.append("</body></html>");
|
reply.content.append("</body></html>");
|
||||||
|
@ -18,20 +18,14 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|||||||
or see http://www.gnu.org/licenses/agpl.txt.
|
or see http://www.gnu.org/licenses/agpl.txt.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <cstdio>
|
#include "BaseDescriptor.h"
|
||||||
#include <string>
|
|
||||||
#include <vector>
|
|
||||||
|
|
||||||
#include "../typedefs.h"
|
|
||||||
#include "../DataStructures/ExtractorStructs.h"
|
|
||||||
#include "../Util/StrIngUtil.h"
|
|
||||||
|
|
||||||
#ifndef JSONDESCRIPTOR_H_
|
#ifndef JSONDESCRIPTOR_H_
|
||||||
#define JSONDESCRIPTOR_H_
|
#define JSONDESCRIPTOR_H_
|
||||||
|
|
||||||
class JSONDescriptor {
|
template<class SearchEngineT>
|
||||||
|
class JSONDescriptor : public BaseDescriptor<SearchEngineT> {
|
||||||
public:
|
public:
|
||||||
template<class SearchEngineT>
|
|
||||||
void Run(http::Reply& reply, std::vector< _PathData > * path, PhantomNodes * phantomNodes, SearchEngineT * sEngine, unsigned distance) {
|
void Run(http::Reply& reply, std::vector< _PathData > * path, PhantomNodes * phantomNodes, SearchEngineT * sEngine, unsigned distance) {
|
||||||
string tmp;
|
string tmp;
|
||||||
string routeGeometryString;
|
string routeGeometryString;
|
||||||
|
263
Plugins/KMLDescriptor.h
Normal file
263
Plugins/KMLDescriptor.h
Normal file
@ -0,0 +1,263 @@
|
|||||||
|
/*
|
||||||
|
open source routing machine
|
||||||
|
Copyright (C) Dennis Luxen, others 2010
|
||||||
|
|
||||||
|
This program is free software; you can redistribute it and/or modify
|
||||||
|
it under the terms of the GNU AFFERO General Public License as published by
|
||||||
|
the Free Software Foundation; either version 3 of the License, or
|
||||||
|
any later version.
|
||||||
|
|
||||||
|
This program is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
GNU General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU Affero General Public License
|
||||||
|
along with this program; if not, write to the Free Software
|
||||||
|
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||||
|
or see http://www.gnu.org/licenses/agpl.txt.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef KML_DESCRIPTOR_H_
|
||||||
|
#define KML_DESCRIPTOR_H_
|
||||||
|
|
||||||
|
template<class SearchEngineT>
|
||||||
|
class KMLDescriptor : public BaseDescriptor<SearchEngineT>{
|
||||||
|
public:
|
||||||
|
void Run(http::Reply& reply, std::vector< _PathData > * path, PhantomNodes * phantomNodes, SearchEngineT * sEngine, unsigned distance) {
|
||||||
|
string tmp;
|
||||||
|
string lineString;
|
||||||
|
string startName;
|
||||||
|
string targetName;
|
||||||
|
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");
|
||||||
|
reply.content += ("<Document>\n");
|
||||||
|
|
||||||
|
if(distance != UINT_MAX) {
|
||||||
|
unsigned streetID = sEngine->GetNameIDForOriginDestinationNodeID(phantomNodes->startNode1, phantomNodes->startNode2);
|
||||||
|
startName = sEngine->GetNameForNameID(streetID);
|
||||||
|
streetID = sEngine->GetNameIDForOriginDestinationNodeID(phantomNodes->targetNode1, phantomNodes->targetNode2);
|
||||||
|
targetName = sEngine->GetNameForNameID(streetID);
|
||||||
|
|
||||||
|
reply.content += ("\t<Placemark>\n");
|
||||||
|
reply.content += ("\t\t<name><![CDATA[Start from ");
|
||||||
|
reply.content += startName;
|
||||||
|
reply.content += (" direction ");
|
||||||
|
_Coordinate tmpCoord;
|
||||||
|
if(path->size() > 0)
|
||||||
|
sEngine->getNodeInfo(path->begin()->node, tmpCoord);
|
||||||
|
else
|
||||||
|
tmpCoord = phantomNodes->targetCoord;
|
||||||
|
|
||||||
|
int angle = round(GetAngleBetweenTwoEdges(_Coordinate(phantomNodes->startCoord.lat, phantomNodes->startCoord.lon), tmpCoord, _Coordinate(tmpCoord.lat, tmpCoord.lon-1000)));
|
||||||
|
if(angle >= 23 && angle < 67)
|
||||||
|
direction = "South-East";
|
||||||
|
if(angle >= 67 && angle < 113)
|
||||||
|
direction = "South";
|
||||||
|
if(angle >= 113 && angle < 158)
|
||||||
|
direction = "South-West";
|
||||||
|
if(angle >= 158 && angle < 202)
|
||||||
|
direction = "West";
|
||||||
|
if(angle >= 202 && angle < 248)
|
||||||
|
direction = "North-West";
|
||||||
|
if(angle >= 248 && angle < 292)
|
||||||
|
direction = "North";
|
||||||
|
if(angle >= 292 && angle < 336)
|
||||||
|
direction = "North-East";
|
||||||
|
|
||||||
|
reply.content += direction;
|
||||||
|
|
||||||
|
reply.content += ("]]></name>\n");
|
||||||
|
|
||||||
|
//put start coord to linestring;
|
||||||
|
convertLatLon(phantomNodes->startCoord.lon, tmp);
|
||||||
|
lineString += tmp;
|
||||||
|
lineString += ",";
|
||||||
|
convertLatLon(phantomNodes->startCoord.lat, tmp);
|
||||||
|
lineString += tmp;
|
||||||
|
lineString += " ";
|
||||||
|
|
||||||
|
reply.content += ("\t</Placemark>\n");
|
||||||
|
_Coordinate previous(phantomNodes->startCoord.lat, phantomNodes->startCoord.lon);
|
||||||
|
_Coordinate next, current, lastPlace;
|
||||||
|
stringstream numberString;
|
||||||
|
|
||||||
|
double tempDist = 0;
|
||||||
|
double entireDistance = 0;
|
||||||
|
double lengthOfInstruction = 0;
|
||||||
|
NodeID nextID = UINT_MAX;
|
||||||
|
NodeID nameID = sEngine->GetNameIDForOriginDestinationNodeID(phantomNodes->startNode1, phantomNodes->startNode2);
|
||||||
|
short type = sEngine->GetTypeOfEdgeForOriginDestinationNodeID(phantomNodes->startNode1, phantomNodes->startNode2);
|
||||||
|
lastPlace.lat = phantomNodes->startCoord.lat;
|
||||||
|
lastPlace.lon = phantomNodes->startCoord.lon;
|
||||||
|
short nextType = SHRT_MAX;
|
||||||
|
short prevType = SHRT_MAX;
|
||||||
|
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 += " ";
|
||||||
|
|
||||||
|
if(it==path->end()-1){
|
||||||
|
next = _Coordinate(phantomNodes->targetCoord.lat, phantomNodes->targetCoord.lon);
|
||||||
|
nextID = sEngine->GetNameIDForOriginDestinationNodeID(phantomNodes->targetNode1, phantomNodes->targetNode2);
|
||||||
|
nextType = sEngine->GetTypeOfEdgeForOriginDestinationNodeID(phantomNodes->targetNode1, phantomNodes->targetNode2);
|
||||||
|
} else {
|
||||||
|
sEngine->getNodeInfo((it+1)->node, next);
|
||||||
|
nextID = sEngine->GetNameIDForOriginDestinationNodeID(it->node, (it+1)->node);
|
||||||
|
nextType = sEngine->GetTypeOfEdgeForOriginDestinationNodeID(it->node, (it+1)->node);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
if(nextID == nameID) {
|
||||||
|
tempDist += ApproximateDistance(previous.lat, previous.lon, current.lat, current.lon);
|
||||||
|
} else {
|
||||||
|
if(type == 0 && prevType != 0)
|
||||||
|
reply.content += "enter motorway and ";
|
||||||
|
if(type != 0 && prevType == 0 )
|
||||||
|
reply.content += "leave motorway and ";
|
||||||
|
|
||||||
|
double angle = GetAngleBetweenTwoEdges(previous, current, next);
|
||||||
|
reply.content += "follow road ";
|
||||||
|
if(nameID != 0)
|
||||||
|
reply.content += sEngine->GetNameForNameID(nameID);
|
||||||
|
/*
|
||||||
|
reply.content += " (type: ";
|
||||||
|
numberString << type;
|
||||||
|
reply.content += numberString.str();
|
||||||
|
numberString.str("");
|
||||||
|
reply.content += ", id: ";
|
||||||
|
numberString << nameID;
|
||||||
|
reply.content += numberString.str();
|
||||||
|
numberString.str("");
|
||||||
|
reply.content += ")";
|
||||||
|
*/
|
||||||
|
reply.content += "]]></name>\n\t\t<description>drive for ";
|
||||||
|
lengthOfInstruction = ApproximateDistance(previous.lat, previous.lon, current.lat, current.lon)+tempDist;
|
||||||
|
entireDistance += lengthOfInstruction;
|
||||||
|
numberString << 10*(round(lengthOfInstruction/10.));;
|
||||||
|
reply.content += numberString.str();
|
||||||
|
numberString.str("");
|
||||||
|
reply.content += "m</description>";
|
||||||
|
string lat; string lon;
|
||||||
|
convertLatLon(lastPlace.lon, lon);
|
||||||
|
convertLatLon(lastPlace.lat, lat);
|
||||||
|
lastPlace = current;
|
||||||
|
// reply.content += "\n <Point>";
|
||||||
|
// reply.content += "<Coordinates>";
|
||||||
|
// reply.content += lon;
|
||||||
|
// reply.content += ",";
|
||||||
|
// reply.content += lat;
|
||||||
|
// reply.content += "</Coordinates></Point>";
|
||||||
|
reply.content += "\n\t</Placemark>\n";
|
||||||
|
reply.content += "\t<Placemark>\n\t\t<name><![CDATA[";
|
||||||
|
if(angle > 160 && angle < 200) {
|
||||||
|
reply.content += /* " (" << angle << ")*/"drive ahead, ";
|
||||||
|
} else if (angle > 290 && angle <= 360) {
|
||||||
|
reply.content += /*" (" << angle << ")*/ "turn sharp left, ";
|
||||||
|
} else if (angle > 230 && angle <= 290) {
|
||||||
|
reply.content += /*" (" << angle << ")*/ "turn left, ";
|
||||||
|
} else if (angle > 200 && angle <= 230) {
|
||||||
|
reply.content += /*" (" << angle << ") */"bear left, ";
|
||||||
|
} else if (angle > 130 && angle <= 160) {
|
||||||
|
reply.content += /*" (" << angle << ") */"bear right, ";
|
||||||
|
} else if (angle > 70 && angle <= 130) {
|
||||||
|
reply.content += /*" (" << angle << ") */"turn right, ";
|
||||||
|
} else {
|
||||||
|
reply.content += /*" (" << angle << ") */"turn sharp right, ";
|
||||||
|
}
|
||||||
|
tempDist = 0;
|
||||||
|
prevType = type;
|
||||||
|
}
|
||||||
|
nameID = nextID;
|
||||||
|
previous = current;
|
||||||
|
type = nextType;
|
||||||
|
}
|
||||||
|
nameID = sEngine->GetNameIDForOriginDestinationNodeID(phantomNodes->targetNode1, phantomNodes->targetNode2);
|
||||||
|
type = sEngine->GetTypeOfEdgeForOriginDestinationNodeID(phantomNodes->targetNode1, phantomNodes->targetNode2);
|
||||||
|
reply.content += "follow road ";
|
||||||
|
reply.content += sEngine->GetNameForNameID(nameID);
|
||||||
|
// reply.content += " (type: ";
|
||||||
|
// numberString << type;
|
||||||
|
// reply.content += numberString.str();
|
||||||
|
// numberString.str("");
|
||||||
|
// reply.content += ", id: ";
|
||||||
|
// numberString << nameID;
|
||||||
|
// reply.content += numberString.str();
|
||||||
|
// numberString.str(")");
|
||||||
|
reply.content += "]]></name>\n\t\t<description>drive for ";
|
||||||
|
lengthOfInstruction = ApproximateDistance(previous.lat, previous.lon, phantomNodes->targetCoord.lat, phantomNodes->targetCoord.lon) + tempDist;
|
||||||
|
entireDistance += lengthOfInstruction;
|
||||||
|
numberString << 10*(round(lengthOfInstruction/10.));
|
||||||
|
reply.content += numberString.str();
|
||||||
|
numberString.str("");
|
||||||
|
reply.content += "m</description>\n ";
|
||||||
|
string lat; string lon;
|
||||||
|
// convertLatLon(lastPlace.lon, lon);
|
||||||
|
// convertLatLon(lastPlace.lat, lat);
|
||||||
|
// reply.content += "<Point><Coordinates>";
|
||||||
|
// reply.content += lon;
|
||||||
|
// reply.content += ",";
|
||||||
|
// reply.content += lat;
|
||||||
|
// reply.content += "</Coordinates></Point>";
|
||||||
|
reply.content += "\t</Placemark>\n";
|
||||||
|
|
||||||
|
//put targetCoord to linestring
|
||||||
|
convertLatLon(phantomNodes->targetCoord.lon, tmp);
|
||||||
|
lineString += tmp;
|
||||||
|
lineString += ",";
|
||||||
|
convertLatLon(phantomNodes->targetCoord.lat, tmp);
|
||||||
|
lineString += tmp;
|
||||||
|
|
||||||
|
reply.content += "\t<Placemark>\n"
|
||||||
|
"\t\t<name><![CDATA[Route from ";
|
||||||
|
reply.content += startName;
|
||||||
|
reply.content += " to ";
|
||||||
|
reply.content += targetName;
|
||||||
|
reply.content += "]]></name>\n"
|
||||||
|
"\t\t<description>"
|
||||||
|
"<![CDATA[Distance: ";
|
||||||
|
|
||||||
|
//give complete distance in meters;
|
||||||
|
ostringstream s;
|
||||||
|
s << 10*(round(entireDistance/10.));
|
||||||
|
reply.content += s.str();
|
||||||
|
reply.content += " m (ca. ";
|
||||||
|
|
||||||
|
//give travel time in minutes
|
||||||
|
int travelTime = (distance/60) + 1;
|
||||||
|
s.str("");
|
||||||
|
s << travelTime;
|
||||||
|
reply.content += s.str();
|
||||||
|
|
||||||
|
reply.content += " minutes)]]>"
|
||||||
|
"</description>\n"
|
||||||
|
"\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";
|
||||||
|
}
|
||||||
|
reply.content += "</Document>\n</kml>";
|
||||||
|
|
||||||
|
reply.headers.resize(3);
|
||||||
|
reply.headers[0].name = "Content-Length";
|
||||||
|
intToString(reply.content.size(), tmp);
|
||||||
|
reply.headers[0].value = tmp;
|
||||||
|
reply.headers[1].name = "Content-Type";
|
||||||
|
reply.headers[1].value = "application/vnd.google-earth.kml+xml; charset=UTF-8";
|
||||||
|
reply.headers[2].name = "Content-Disposition";
|
||||||
|
reply.headers[2].value = "attachment; filename=\"route.kml\"";
|
||||||
|
|
||||||
|
}
|
||||||
|
private:
|
||||||
|
};
|
||||||
|
#endif /* KML_DESCRIPTOR_H_ */
|
@ -24,6 +24,7 @@ or see http://www.gnu.org/licenses/agpl.txt.
|
|||||||
#include <fstream>
|
#include <fstream>
|
||||||
|
|
||||||
#include "BasePlugin.h"
|
#include "BasePlugin.h"
|
||||||
|
#include "RouteParameters.h"
|
||||||
|
|
||||||
#include "../DataStructures/NodeInformationHelpDesk.h"
|
#include "../DataStructures/NodeInformationHelpDesk.h"
|
||||||
|
|
||||||
@ -42,15 +43,15 @@ public:
|
|||||||
}
|
}
|
||||||
std::string GetDescriptor() { return std::string("locate"); }
|
std::string GetDescriptor() { return std::string("locate"); }
|
||||||
std::string GetVersionString() { return std::string("0.3 (DL)"); }
|
std::string GetVersionString() { return std::string("0.3 (DL)"); }
|
||||||
void HandleRequest(std::vector<std::string> parameters, http::Reply& reply) {
|
void HandleRequest(RouteParameters routeParameters, http::Reply& reply) {
|
||||||
//check number of parameters
|
//check number of parameters
|
||||||
if(parameters.size() != 2) {
|
if(routeParameters.parameters.size() != 2) {
|
||||||
reply = http::Reply::stockReply(http::Reply::badRequest);
|
reply = http::Reply::stockReply(http::Reply::badRequest);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
int lat = static_cast<int>(100000.*atof(parameters[0].c_str()));
|
int lat = static_cast<int>(100000.*atof(routeParameters.parameters[0].c_str()));
|
||||||
int lon = static_cast<int>(100000.*atof(parameters[1].c_str()));
|
int lon = static_cast<int>(100000.*atof(routeParameters.parameters[1].c_str()));
|
||||||
|
|
||||||
if(lat>90*100000 || lat <-90*100000 || lon>180*100000 || lon <-180*100000) {
|
if(lat>90*100000 || lat <-90*100000 || lon>180*100000 || lon <-180*100000) {
|
||||||
reply = http::Reply::stockReply(http::Reply::badRequest);
|
reply = http::Reply::stockReply(http::Reply::badRequest);
|
||||||
|
@ -24,6 +24,7 @@ or see http://www.gnu.org/licenses/agpl.txt.
|
|||||||
#include <fstream>
|
#include <fstream>
|
||||||
|
|
||||||
#include "BasePlugin.h"
|
#include "BasePlugin.h"
|
||||||
|
#include "RouteParameters.h"
|
||||||
|
|
||||||
#include "../DataStructures/NodeInformationHelpDesk.h"
|
#include "../DataStructures/NodeInformationHelpDesk.h"
|
||||||
|
|
||||||
@ -42,15 +43,15 @@ public:
|
|||||||
}
|
}
|
||||||
std::string GetDescriptor() { return std::string("nearest"); }
|
std::string GetDescriptor() { return std::string("nearest"); }
|
||||||
std::string GetVersionString() { return std::string("0.3 (DL)"); }
|
std::string GetVersionString() { return std::string("0.3 (DL)"); }
|
||||||
void HandleRequest(std::vector<std::string> parameters, http::Reply& reply) {
|
void HandleRequest(RouteParameters routeParameters, http::Reply& reply) {
|
||||||
//check number of parameters
|
//check number of parameters
|
||||||
if(parameters.size() != 2) {
|
if(routeParameters.parameters.size() != 2) {
|
||||||
reply = http::Reply::stockReply(http::Reply::badRequest);
|
reply = http::Reply::stockReply(http::Reply::badRequest);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
int lat = static_cast<int>(100000.*atof(parameters[0].c_str()));
|
int lat = static_cast<int>(100000.*atof(routeParameters.parameters[0].c_str()));
|
||||||
int lon = static_cast<int>(100000.*atof(parameters[1].c_str()));
|
int lon = static_cast<int>(100000.*atof(routeParameters.parameters[1].c_str()));
|
||||||
|
|
||||||
if(lat>90*100000 || lat <-90*100000 || lon>180*100000 || lon <-180*100000) {
|
if(lat>90*100000 || lat <-90*100000 || lon>180*100000 || lon <-180*100000) {
|
||||||
reply = http::Reply::stockReply(http::Reply::badRequest);
|
reply = http::Reply::stockReply(http::Reply::badRequest);
|
||||||
|
35
Plugins/RouteParameters.h
Normal file
35
Plugins/RouteParameters.h
Normal file
@ -0,0 +1,35 @@
|
|||||||
|
/*
|
||||||
|
open source routing machine
|
||||||
|
Copyright (C) Dennis Luxen, 2010
|
||||||
|
|
||||||
|
This program is free software; you can redistribute it and/or modify
|
||||||
|
it under the terms of the GNU AFFERO General Public License as published by
|
||||||
|
the Free Software Foundation; either version 3 of the License, or
|
||||||
|
any later version.
|
||||||
|
|
||||||
|
This program is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
GNU General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU Affero General Public License
|
||||||
|
along with this program; if not, write to the Free Software
|
||||||
|
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||||
|
or see http://www.gnu.org/licenses/agpl.txt.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef ROUTE_PARAMETERS_H
|
||||||
|
#define ROUTE_PARAMETERS_H
|
||||||
|
|
||||||
|
#include <string>
|
||||||
|
#include <vector>
|
||||||
|
#include "../DataStructures/HashTable.h"
|
||||||
|
|
||||||
|
struct RouteParameters {
|
||||||
|
std::vector<std::string> parameters;
|
||||||
|
HashTable<std::string, std::string> options;
|
||||||
|
typedef HashTable<std::string, std::string>::MyIterator OptionsIterator;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
#endif /*ROUTE_PARAMETERS_H*/
|
@ -26,7 +26,13 @@ or see http://www.gnu.org/licenses/agpl.txt.
|
|||||||
#include <string>
|
#include <string>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
|
#include "BaseDescriptor.h"
|
||||||
#include "BasePlugin.h"
|
#include "BasePlugin.h"
|
||||||
|
#include "RouteParameters.h"
|
||||||
|
#include "KMLDescriptor.h"
|
||||||
|
#include "JSONDescriptor.h"
|
||||||
|
|
||||||
|
#include "../DataStructures/HashTable.h"
|
||||||
#include "../DataStructures/StaticGraph.h"
|
#include "../DataStructures/StaticGraph.h"
|
||||||
#include "../DataStructures/SearchEngine.h"
|
#include "../DataStructures/SearchEngine.h"
|
||||||
|
|
||||||
@ -36,7 +42,6 @@ or see http://www.gnu.org/licenses/agpl.txt.
|
|||||||
typedef ContractionCleanup::Edge::EdgeData EdgeData;
|
typedef ContractionCleanup::Edge::EdgeData EdgeData;
|
||||||
typedef StaticGraph<EdgeData>::InputEdge InputEdge;
|
typedef StaticGraph<EdgeData>::InputEdge InputEdge;
|
||||||
|
|
||||||
template <class DescriptorT>
|
|
||||||
class RoutePlugin : public BasePlugin {
|
class RoutePlugin : public BasePlugin {
|
||||||
public:
|
public:
|
||||||
RoutePlugin(std::string hsgrPath, std::string ramIndexPath, std::string fileIndexPath, std::string nodesPath, std::string namesPath) {
|
RoutePlugin(std::string hsgrPath, std::string ramIndexPath, std::string fileIndexPath, std::string nodesPath, std::string namesPath) {
|
||||||
@ -71,28 +76,30 @@ public:
|
|||||||
|
|
||||||
//init complete search engine
|
//init complete search engine
|
||||||
sEngine = new SearchEngine<EdgeData, StaticGraph<EdgeData> >(graph, nodeHelpDesk, names);
|
sEngine = new SearchEngine<EdgeData, StaticGraph<EdgeData> >(graph, nodeHelpDesk, names);
|
||||||
descriptor = new DescriptorT();
|
descriptorTable.Set("", 0); //default descriptor
|
||||||
|
descriptorTable.Set("kml", 0);
|
||||||
|
descriptorTable.Set("json", 1);
|
||||||
}
|
}
|
||||||
~RoutePlugin() {
|
~RoutePlugin() {
|
||||||
delete names;
|
delete names;
|
||||||
delete sEngine;
|
delete sEngine;
|
||||||
delete graph;
|
delete graph;
|
||||||
delete nodeHelpDesk;
|
delete nodeHelpDesk;
|
||||||
delete descriptor;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string GetDescriptor() { return std::string("route"); }
|
std::string GetDescriptor() { return std::string("route"); }
|
||||||
std::string GetVersionString() { return std::string("0.3 (DL)"); }
|
std::string GetVersionString() { return std::string("0.3 (DL)"); }
|
||||||
void HandleRequest(std::vector<std::string> parameters, http::Reply& reply) {
|
void HandleRequest(RouteParameters routeParameters, http::Reply& reply) {
|
||||||
//check number of parameters
|
//check number of parameters
|
||||||
if(parameters.size() != 4) {
|
if(routeParameters.parameters.size() != 4) {
|
||||||
reply = http::Reply::stockReply(http::Reply::badRequest);
|
reply = http::Reply::stockReply(http::Reply::badRequest);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
int lat1 = static_cast<int>(100000.*atof(parameters[0].c_str()));
|
int lat1 = static_cast<int>(100000.*atof(routeParameters.parameters[0].c_str()));
|
||||||
int lon1 = static_cast<int>(100000.*atof(parameters[1].c_str()));
|
int lon1 = static_cast<int>(100000.*atof(routeParameters.parameters[1].c_str()));
|
||||||
int lat2 = static_cast<int>(100000.*atof(parameters[2].c_str()));
|
int lat2 = static_cast<int>(100000.*atof(routeParameters.parameters[2].c_str()));
|
||||||
int lon2 = static_cast<int>(100000.*atof(parameters[3].c_str()));
|
int lon2 = static_cast<int>(100000.*atof(routeParameters.parameters[3].c_str()));
|
||||||
|
|
||||||
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);
|
||||||
@ -112,8 +119,23 @@ public:
|
|||||||
sEngine->FindRoutingStarts(startCoord, targetCoord, phantomNodes);
|
sEngine->FindRoutingStarts(startCoord, targetCoord, phantomNodes);
|
||||||
unsigned int distance = sEngine->ComputeRoute(phantomNodes, path, startCoord, targetCoord);
|
unsigned int distance = sEngine->ComputeRoute(phantomNodes, path, startCoord, targetCoord);
|
||||||
reply.status = http::Reply::ok;
|
reply.status = http::Reply::ok;
|
||||||
descriptor->Run(reply, path, phantomNodes, sEngine, distance);
|
BaseDescriptor<SearchEngine<EdgeData, StaticGraph<EdgeData> > > * desc;
|
||||||
|
switch(descriptorTable[routeParameters.options.Find("output")]){
|
||||||
|
case 0:
|
||||||
|
desc = new KMLDescriptor<SearchEngine<EdgeData, StaticGraph<EdgeData> > >();
|
||||||
|
break;
|
||||||
|
case 1:
|
||||||
|
desc = new JSONDescriptor<SearchEngine<EdgeData, StaticGraph<EdgeData> > >();
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
desc = new KMLDescriptor<SearchEngine<EdgeData, StaticGraph<EdgeData> > >();
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
// JSONDescriptor<SearchEngine<EdgeData, StaticGraph<EdgeData> > > desc;
|
||||||
|
desc->Run(reply, path, phantomNodes, sEngine, distance);
|
||||||
|
|
||||||
|
std::cout << reply.content << std::endl;
|
||||||
|
delete desc;
|
||||||
delete path;
|
delete path;
|
||||||
delete phantomNodes;
|
delete phantomNodes;
|
||||||
return;
|
return;
|
||||||
@ -123,7 +145,7 @@ private:
|
|||||||
SearchEngine<EdgeData, StaticGraph<EdgeData> > * sEngine;
|
SearchEngine<EdgeData, StaticGraph<EdgeData> > * sEngine;
|
||||||
std::vector<std::string> * names;
|
std::vector<std::string> * names;
|
||||||
StaticGraph<EdgeData> * graph;
|
StaticGraph<EdgeData> * graph;
|
||||||
DescriptorT * descriptor;
|
HashTable<std::string, unsigned> descriptorTable;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
@ -21,14 +21,17 @@ or see http://www.gnu.org/licenses/agpl.txt.
|
|||||||
#ifndef REQUEST_HANDLER_H
|
#ifndef REQUEST_HANDLER_H
|
||||||
#define REQUEST_HANDLER_H
|
#define REQUEST_HANDLER_H
|
||||||
|
|
||||||
|
#include <algorithm>
|
||||||
|
#include <cctype> // std::tolower
|
||||||
|
#include <string>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <boost/lexical_cast.hpp>
|
#include <boost/lexical_cast.hpp>
|
||||||
#include <boost/noncopyable.hpp>
|
#include <boost/noncopyable.hpp>
|
||||||
|
|
||||||
#include "BasicDatastructures.h"
|
#include "BasicDatastructures.h"
|
||||||
|
|
||||||
#include "../DataStructures/HashTable.h"
|
#include "../DataStructures/HashTable.h"
|
||||||
#include "../Plugins/BasePlugin.h"
|
#include "../Plugins/BasePlugin.h"
|
||||||
|
#include "../Plugins/RouteParameters.h"
|
||||||
|
|
||||||
namespace http {
|
namespace http {
|
||||||
|
|
||||||
@ -55,16 +58,25 @@ public:
|
|||||||
try {
|
try {
|
||||||
if(pluginMap.Holds(command)) {
|
if(pluginMap.Holds(command)) {
|
||||||
|
|
||||||
std::vector<std::string> parameters;
|
RouteParameters routeParameters;
|
||||||
std::stringstream ss(( firstAmpPosition == std::string::npos ? "" : request.substr(firstAmpPosition+1) ));
|
std::stringstream ss(( firstAmpPosition == std::string::npos ? "" : request.substr(firstAmpPosition+1) ));
|
||||||
std::string item;
|
std::string item;
|
||||||
while(std::getline(ss, item, '&')) {
|
while(std::getline(ss, item, '&')) {
|
||||||
parameters.push_back(item);
|
size_t found = item.find('=');
|
||||||
|
if(found == std::string::npos) {
|
||||||
|
routeParameters.parameters.push_back(item);
|
||||||
|
} else {
|
||||||
|
std::string p = item.substr(0, found);
|
||||||
|
std::transform(p.begin(), p.end(), p.begin(), (int(*)(int)) std::tolower);
|
||||||
|
std::string o = item.substr(found+1);
|
||||||
|
std::transform(o.begin(), o.end(), o.begin(), (int(*)(int)) std::tolower);
|
||||||
|
routeParameters.options.Set(p, o);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
// std::cout << "[debug] found handler for '" << command << "' at version: " << pluginMap.Find(command)->GetVersionString() << std::endl;
|
// std::cout << "[debug] found handler for '" << command << "' at version: " << pluginMap.Find(command)->GetVersionString() << std::endl;
|
||||||
// std::cout << "[debug] remaining parameters: " << parameters.size() << std::endl;
|
// std::cout << "[debug] remaining parameters: " << parameters.size() << std::endl;
|
||||||
rep.status = Reply::ok;
|
rep.status = Reply::ok;
|
||||||
_pluginVector[pluginMap.Find(command)]->HandleRequest(parameters, rep );
|
_pluginVector[pluginMap.Find(command)]->HandleRequest(routeParameters, rep );
|
||||||
} else {
|
} else {
|
||||||
rep = Reply::stockReply(Reply::badRequest);
|
rep = Reply::stockReply(Reply::badRequest);
|
||||||
}
|
}
|
||||||
|
@ -30,7 +30,6 @@ or see http://www.gnu.org/licenses/agpl.txt.
|
|||||||
#include "Server/ServerConfiguration.h"
|
#include "Server/ServerConfiguration.h"
|
||||||
#include "Server/ServerFactory.h"
|
#include "Server/ServerFactory.h"
|
||||||
|
|
||||||
#include "Plugins/BasicDescriptor.h"
|
|
||||||
#include "Plugins/HelloWorldPlugin.h"
|
#include "Plugins/HelloWorldPlugin.h"
|
||||||
#include "Plugins/LocatePlugin.h"
|
#include "Plugins/LocatePlugin.h"
|
||||||
#include "Plugins/NearestPlugin.h"
|
#include "Plugins/NearestPlugin.h"
|
||||||
@ -75,7 +74,7 @@ int main (int argc, char *argv[])
|
|||||||
serverConfig.GetParameter("nodesData"));
|
serverConfig.GetParameter("nodesData"));
|
||||||
h.RegisterPlugin(nearest);
|
h.RegisterPlugin(nearest);
|
||||||
|
|
||||||
BasePlugin * route = new RoutePlugin<BasicDescriptor>(
|
BasePlugin * route = new RoutePlugin(
|
||||||
serverConfig.GetParameter("hsgrData"),
|
serverConfig.GetParameter("hsgrData"),
|
||||||
serverConfig.GetParameter("ramIndex"),
|
serverConfig.GetParameter("ramIndex"),
|
||||||
serverConfig.GetParameter("fileIndex"),
|
serverConfig.GetParameter("fileIndex"),
|
||||||
|
Loading…
Reference in New Issue
Block a user