Changeset 6a2986b


Ignore:
Timestamp:
01/31/17 02:02:30 (4 weeks ago)
Author:
Martin Kolman <martin.kolman@…>
Branches:
master
Children:
78f8f86
Parents:
3b5a1bc
git-author:
Martin Kolman <martin.kolman@…> (01/31/17 02:01:51)
git-committer:
Martin Kolman <martin.kolman@…> (01/31/17 02:02:30)
Message:

Add support for using the OSM Scout Server for routing

To enable OSM Scout server routing visit Options->Navigation
and set OSM Scout Server as the routing provider.

So far it looks like the routing works surprisingly well,
even though it seems a bit slower than Monav. :)

Files:
4 edited

Legend:

Unmodified
Added
Removed
  • core/constants.py

    rb39fdd5 r6a2986b  
    5050THREAD_ROUTING_ONLINE_GOOGLE = "modRanaRoutingOnlineGoogle" 
    5151THREAD_ROUTING_OFFLINE_MONAV = "modRanaRoutingOfflineMonav" 
     52THREAD_ROUTING_OFFLINE_OSM_SCOUT_SERVER = "modRanaRoutingOfflineOSMScoutServer" 
    5253THREAD_GPSD_CONSUMER = "modRanaGPSDConsumer" 
    5354# tile down-/loading 
     
    112113ROUTING_PROVIDER_MONAV_LIGHT = "MonavLight" 
    113114ROUTING_PROVIDER_ROUTINO = "Routino" 
     115ROUTING_PROVIDER_OSM_SCOUT = "OSMScoutServer" 
    114116 
    115117ROUTING_PROVIDER_NAMES = { 
  • core/routing_providers.py

    r8f69088 r6a2986b  
    66from core.backports import six 
    77 
     8try:  # Python 2 
     9    from urllib import urlencode 
     10    from urllib2 import urlopen, Request, HTTPError, URLError 
     11except ImportError:  # Python 3 
     12    from urllib.request import urlopen, Request 
     13    from urllib.parse import urlencode 
     14    from urllib.error import HTTPError, URLError 
     15 
    816try: 
    917    import json 
     
    1523 
    1624from core.providers import RoutingProvider, DummyController, RouteParameters, RoutingResult 
     25 
     26OSM_SCOUT_SERVER_ROUTING_URL = "http://localhost:8553/v1/route?" 
    1727 
    1828class MonavServerRouting(RoutingProvider): 
     
    279289        return route, returnCode, errorMessage 
    280290 
    281  
    282  
    283  
    284  
    285  
    286  
    287  
    288  
    289  
    290  
    291  
    292  
    293  
    294  
    295  
    296  
    297  
     291class OSMScoutServerRouting(RoutingProvider): 
     292    """Provider that does offline point to point routing 
     293       using the Monav offline routing server API. 
     294    """ 
     295 
     296    def __init__(self): 
     297        threadName = constants.THREAD_ROUTING_OFFLINE_OSM_SCOUT_SERVER 
     298        RoutingProvider.__init__(self, threadName=threadName) 
     299 
     300    def search(self, waypoints, route_params=None, controller=DummyController()): 
     301        routingStart = time.time() 
     302        controller.status = "OSM Scout Server routing" 
     303        try: 
     304            route_type = "car" # car directions are the default 
     305            if route_params.routeMode == constants.ROUTE_BIKE: 
     306                route_type = "bicycle" 
     307            elif route_params.routeMode == constants.ROUTE_PEDESTRIAN: 
     308                route_type = "foot" 
     309 
     310            # TODO: support for middle points 
     311            start = waypoints[0] 
     312            destination = waypoints[-1] 
     313 
     314            params = { 
     315                'type': route_type, 
     316                'p[0][lat]': "%f" % start.lat, 
     317                'p[0][lng]': "%f" % start.lon, 
     318                'p[1][lat]': "%f" % destination.lat, 
     319                'p[1][lng]': "%f" % destination.lon, 
     320                'radius': 10000,  #TODO: make this configurable 
     321                'gpx' : '0', 
     322            } 
     323            queryUrl = OSM_SCOUT_SERVER_ROUTING_URL + urlencode(params) 
     324            reply = urlopen(queryUrl) 
     325            if reply: 
     326                # json in Python 3 really needs it encoded like this 
     327                replyData = reply.read().decode("utf-8") 
     328                jsonReply = json.loads(replyData) 
     329                route = Way.from_osm_scout_json(jsonReply) 
     330                return RoutingResult(route, 
     331                                     route_params, 
     332                                     constants.ROUTING_SUCCESS, 
     333                                     lookupDuration=time.time() - routingStart) 
     334        except Exception: 
     335            log.exception("OSM Scout Server routing: failed with exception") 
     336 
     337 
     338 
  • modules/gui_modules/gui_qt5/qml/OptionsNavigationPage.qml

    r8f69088 r6a2986b  
    2727                    text : "Monav - on device" 
    2828                    value : "MonavLight" 
     29                } 
     30                ListElement { 
     31                    text : "OSM Scout Server - on device" 
     32                    value : "OSMScoutServer" 
    2933                } 
    3034            } 
  • modules/mod_route/mod_route.py

    r24ae074 r6a2986b  
    477477        elif provider_id == constants.ROUTING_PROVIDER_GOOGLE: 
    478478            provider = routing_providers.GoogleRouting() 
     479            provider.searchAsync( 
     480                callback, 
     481                waypoints, 
     482                route_params=route_params 
     483            ) 
     484        elif provider_id == constants.ROUTING_PROVIDER_OSM_SCOUT: 
     485            provider = routing_providers.OSMScoutServerRouting() 
    479486            provider.searchAsync( 
    480487                callback, 
Note: See TracChangeset for help on using the changeset viewer.