polyline string as parameter added
This commit is contained in:
		
							parent
							
								
									b1ef4cfee9
								
							
						
					
					
						commit
						9b0d3dfaeb
					
				@ -88,3 +88,41 @@ PolylineCompressor::get_encoded_string(const std::vector<SegmentInformation> &po
 | 
			
		||||
    }
 | 
			
		||||
    return encode_vector(delta_numbers);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
std::vector<FixedPointCoordinate> PolylineCompressor::decode_string(const std::string geometry_string) const
 | 
			
		||||
{
 | 
			
		||||
    std::vector<FixedPointCoordinate> new_coordinates;
 | 
			
		||||
    int index = 0, len = geometry_string.size();
 | 
			
		||||
    int lat = 0, lng = 0;
 | 
			
		||||
  
 | 
			
		||||
    while (index < len) 
 | 
			
		||||
    {
 | 
			
		||||
        int b, shift = 0, result = 0;
 | 
			
		||||
        do 
 | 
			
		||||
        {
 | 
			
		||||
            b = geometry_string.at(index++) - 63;
 | 
			
		||||
            result |= (b & 0x1f) << shift;
 | 
			
		||||
            shift += 5;
 | 
			
		||||
        } while (b >= 0x20);
 | 
			
		||||
        int dlat = ((result & 1) != 0 ? ~(result >> 1) : (result >> 1));
 | 
			
		||||
        lat += dlat;
 | 
			
		||||
 | 
			
		||||
        shift = 0;
 | 
			
		||||
        result = 0;
 | 
			
		||||
        do 
 | 
			
		||||
        {
 | 
			
		||||
            b = geometry_string.at(index++) - 63;
 | 
			
		||||
            result |= (b & 0x1f) << shift;
 | 
			
		||||
            shift += 5;
 | 
			
		||||
        } while (b >= 0x20);
 | 
			
		||||
        int dlng = ((result & 1) != 0 ? ~(result >> 1) : (result >> 1));
 | 
			
		||||
        lng += dlng;
 | 
			
		||||
 | 
			
		||||
        FixedPointCoordinate p;
 | 
			
		||||
        p.lat = COORDINATE_PRECISION * (((double) lat / 1E5));
 | 
			
		||||
        p.lon = COORDINATE_PRECISION * (((double) lng / 1E5));
 | 
			
		||||
        new_coordinates.push_back(p);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    return new_coordinates;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
@ -30,6 +30,8 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 | 
			
		||||
 | 
			
		||||
struct SegmentInformation;
 | 
			
		||||
 | 
			
		||||
#include <osrm/coordinate.hpp>
 | 
			
		||||
 | 
			
		||||
#include <string>
 | 
			
		||||
#include <vector>
 | 
			
		||||
 | 
			
		||||
@ -42,6 +44,8 @@ class PolylineCompressor
 | 
			
		||||
 | 
			
		||||
  public:
 | 
			
		||||
    std::string get_encoded_string(const std::vector<SegmentInformation> &polyline) const;
 | 
			
		||||
    
 | 
			
		||||
    std::vector<FixedPointCoordinate> decode_string(const std::string geometry_string) const;
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
#endif /* POLYLINECOMPRESSOR_H_ */
 | 
			
		||||
 | 
			
		||||
@ -31,6 +31,8 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 | 
			
		||||
 | 
			
		||||
#include <osrm/route_parameters.hpp>
 | 
			
		||||
 | 
			
		||||
#include "../algorithms/polyline_compressor.hpp"
 | 
			
		||||
 | 
			
		||||
RouteParameters::RouteParameters()
 | 
			
		||||
    : zoom_level(18), print_instructions(false), alternate_route(true), geometry(true),
 | 
			
		||||
      compression(true), deprecatedAPI(false), uturn_default(false), classify(false),
 | 
			
		||||
@ -131,3 +133,9 @@ void RouteParameters::addCoordinate(
 | 
			
		||||
        static_cast<int>(COORDINATE_PRECISION * boost::fusion::at_c<0>(received_coordinates)),
 | 
			
		||||
        static_cast<int>(COORDINATE_PRECISION * boost::fusion::at_c<1>(received_coordinates)));
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void RouteParameters::getCoordinatesFromGeometry(const std::string geometry_string)
 | 
			
		||||
{
 | 
			
		||||
    PolylineCompressor pc;
 | 
			
		||||
    coordinates = pc.decode_string(geometry_string);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
@ -78,6 +78,8 @@ struct RouteParameters
 | 
			
		||||
    void setCompressionFlag(const bool flag);
 | 
			
		||||
 | 
			
		||||
    void addCoordinate(const boost::fusion::vector<double, double> &received_coordinates);
 | 
			
		||||
    
 | 
			
		||||
    void getCoordinatesFromGeometry(const std::string geometry_string);
 | 
			
		||||
 | 
			
		||||
    short zoom_level;
 | 
			
		||||
    bool print_instructions;
 | 
			
		||||
 | 
			
		||||
@ -42,7 +42,7 @@ template <typename Iterator, class HandlerT> struct APIGrammar : qi::grammar<Ite
 | 
			
		||||
                   *(query) >> -(uturns);
 | 
			
		||||
        query = ('?') >> (+(zoom | output | jsonp | checksum | location | hint | timestamp | u | cmp |
 | 
			
		||||
                            language | instruction | geometry | alt_route | old_API | num_results |
 | 
			
		||||
                            matching_beta | gps_precision | classify));
 | 
			
		||||
                            matching_beta | gps_precision | classify | geometry_string));
 | 
			
		||||
 | 
			
		||||
        zoom = (-qi::lit('&')) >> qi::lit('z') >> '=' >>
 | 
			
		||||
               qi::short_[boost::bind(&HandlerT::setZoomLevel, handler, ::_1)];
 | 
			
		||||
@ -83,17 +83,20 @@ template <typename Iterator, class HandlerT> struct APIGrammar : qi::grammar<Ite
 | 
			
		||||
               qi::short_[boost::bind(&HandlerT::setGPSPrecision, handler, ::_1)];
 | 
			
		||||
        classify = (-qi::lit('&')) >> qi::lit("classify") >> '=' >>
 | 
			
		||||
            qi::bool_[boost::bind(&HandlerT::setClassify, handler, ::_1)];
 | 
			
		||||
        geometry_string = (-qi::lit('&')) >> qi::lit("geometry_string") >> '=' >>
 | 
			
		||||
            stringforPolyline[boost::bind(&HandlerT::getCoordinatesFromGeometry, handler, ::_1)];
 | 
			
		||||
 | 
			
		||||
        string = +(qi::char_("a-zA-Z"));
 | 
			
		||||
        stringwithDot = +(qi::char_("a-zA-Z0-9_.-"));
 | 
			
		||||
        stringwithPercent = +(qi::char_("a-zA-Z0-9_.-") | qi::char_('[') | qi::char_(']') |
 | 
			
		||||
                              (qi::char_('%') >> qi::char_("0-9A-Z") >> qi::char_("0-9A-Z")));
 | 
			
		||||
        stringforPolyline = +(qi::char_("a-zA-Z0-9_.-[]{}@?|\\%~`^"));
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    qi::rule<Iterator> api_call, query;
 | 
			
		||||
    qi::rule<Iterator, std::string()> service, zoom, output, string, jsonp, checksum, location,
 | 
			
		||||
        hint, timestamp, stringwithDot, stringwithPercent, language, instruction, geometry, cmp, alt_route, u,
 | 
			
		||||
        uturns, old_API, num_results, matching_beta, gps_precision, classify;
 | 
			
		||||
        uturns, old_API, num_results, matching_beta, gps_precision, classify, geometry_string, stringforPolyline;
 | 
			
		||||
 | 
			
		||||
    HandlerT *handler;
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
		Loading…
	
		Reference in New Issue
	
	Block a user