def __log_download_stats(self, objectids, download_link): pag_download = PagDownload() pag_download.objectids = objectids pag_download.download_link = download_link try: PortailSession.add(pag_download) PortailSession.commit() except Exception as e: log.exception(e) PortailSession.rollback()
def get_route(self): coords = self.request.params.get('waypoints', '').split(',') lang = self.request.params.get('lang', 'fr') transport_mode = int(self.request.params.get('transportMode', 0)) criteria = int(self.request.params.get('criteria', 0)) avoid = self.request.params.get('avoid', '').split(',') prefer_bike_road =\ int(self.request.params.get('preferBikeRoad', False)) bike_avoid_hills =\ int(self.request.params.get('bikeAvoidHills', False)) if coords == ['']: coords = [] # At least two waypoints (4 coordinates) are required if len(coords) < 4: routing_success = False return HTTPBadRequest("Not enough waypoints (At least 2 required)") else: # Use Graphhopper for bicycle routing, Mapquest for all other modes if len(coords) <= 10 and transport_mode in [2]: r = GraphhopperRouter(self.config['routing']['graphhopper']) self.__setup_router(coords, lang, transport_mode, criteria, avoid, prefer_bike_road, bike_avoid_hills, r) try: r.execute() except HTTPError as e: if e.code == 429: r = MapquestRouter(self.config['routing']['mapquest']) self.__setup_router(coords, lang, transport_mode, criteria, avoid, prefer_bike_road, bike_avoid_hills, r) r.execute() else: raise e else: r = MapquestRouter(self.config['routing']['mapquest']) self.__setup_router(coords, lang, transport_mode, criteria, avoid, prefer_bike_road, bike_avoid_hills, r) r.execute() if r.geom and len(r.geom) > 0: routing_success = True else: routing_success = False r.errorMessages.append('An error occured') try: routing_stats = RoutingStats() routing_stats.transport_mode = transport_mode routing_stats.transport_criteria = criteria PortailSession.add(routing_stats) PortailSession.commit() except Exception as e: log.exception(e) PortailSession.rollback() if routing_success: json = { "type": "FeatureCollection", "features": [{ 'type': "Feature", 'properties': { 'success': routing_success, 'desc': r.desc, 'dist': int(r.dist), 'time': r.time, 'errorMessages': r.errorMessages, 'attribution': r.attribution }, 'geometry': r.geom }] } else: json = { 'success': routing_success, 'geometry': None, 'desc': [], 'dist': 0, 'time': 0, 'errorMessages': r.errorMessages, 'attribution': r.attribution } return json
def get_route(self): coords = self.request.params.get('waypoints', '').split(',') lang = self.request.params.get('lang', 'fr') transport_mode = int(self.request.params.get('transportMode', 0)) criteria = int(self.request.params.get('criteria', 0)) avoid = self.request.params.get('avoid', '').split(',') prefer_bike_road =\ int(self.request.params.get('preferBikeRoad', False)) bike_avoid_hills =\ int(self.request.params.get('bikeAvoidHills', False)) if coords == ['']: coords = [] # At least two waypoints (4 coordinates) are required if len(coords) < 4: routing_success = False return HTTPBadRequest("Not enough waypoints (At least 2 required)") else: # Use Graphhopper for bicycle routing, Mapquest for all other modes if len(coords) <= 10 and transport_mode in [2]: r = GraphhopperRouter(self.config['routing']['graphhopper']) self.__setup_router(coords, lang, transport_mode, criteria, avoid, prefer_bike_road, bike_avoid_hills, r) try: r.execute() except HTTPError as e: if e.code == 429: r = MapquestRouter(self.config['routing']['mapquest']) self.__setup_router( coords, lang, transport_mode, criteria, avoid, prefer_bike_road, bike_avoid_hills, r) r.execute() else: raise e else: r = MapquestRouter(self.config['routing']['mapquest']) self.__setup_router( coords, lang, transport_mode, criteria, avoid, prefer_bike_road, bike_avoid_hills, r) r.execute() if r.geom and len(r.geom) > 0: routing_success = True else: routing_success = False r.errorMessages.append('An error occured') try: routing_stats = RoutingStats() routing_stats.transport_mode = transport_mode routing_stats.transport_criteria = criteria PortailSession.add(routing_stats) PortailSession.commit() except Exception as e: log.exception(e) PortailSession.rollback() if routing_success: json = { "type": "FeatureCollection", "features": [ {'type': "Feature", 'properties': { 'success': routing_success, 'desc': r.desc, 'dist': int(r.dist), 'time': r.time, 'errorMessages': r.errorMessages, 'attribution': r.attribution}, 'geometry': r.geom}]} else: json = {'success': routing_success, 'geometry': None, 'desc': [], 'dist': 0, 'time': 0, 'errorMessages': r.errorMessages, 'attribution': r.attribution} return json