def isochrones( client, locations, profile='driving-car', range_type='time', intervals=None, segments=None, units=None, location_type=None, smoothing=None, attributes=None, # options=None, intersections=None, dry_run=None): """ Gets travel distance and time for a matrix of origins and destinations. :param locations: One pair of lng/lat values. :type locations: list or tuple of lng,lat values :param profile: Specifies the mode of transport to use when calculating directions. One of ["driving-car", "driving-hgv", "foot-walking", "foot-hiking", "cycling-regular", "cycling-road", "cycling-safe", "cycling-mountain", "cycling-tour", "cycling-electric",]. Default "driving-car". :type profile: string :param range_type: Set 'time' for isochrones or 'distance' for equidistants. Default 'time'. :type sources: string :param intervals: Ranges to calculate distances/durations for. This can be a list of multiple ranges, e.g. [600, 1200, 1400] or a single value list. In the latter case, you can also specify the 'segments' variable to break the single value into more isochrones. In meters or seconds. Default [60]. :type intervals: list of integer(s) :param segments: Segments isochrones or equidistants for one 'intervals' value. Only has effect if used with a single value 'intervals' parameter. In meters or seconds. Default 20. :type segments: integer :param units: Specifies the unit system to use when displaying results. One of ["m", "km", "m"]. Default "m". :type units: string :param location_type: 'start' treats the location(s) as starting point, 'destination' as goal. Default 'start'. :type location_type: string :param smoothing: Applies a level of generalisation to the isochrone polygons generated. Value between 0 and 1, whereas a value closer to 1 will result in a more generalised shape. :type smoothing: float :param attributes: 'area' returns the area of each polygon in its feature properties. 'reachfactor' returns a reachability score between 0 and 1. 'total_pop' returns population statistics from https://ghsl.jrc.ec.europa.eu/about.php. One or more of ['area', 'reachfactor', 'total_pop']. Default 'area'. :type attributes: list of string(s) :param options: not implemented right now. :type options: dict :param intersections: not implented right now. :type intersections: boolean :param dry_run: Print URL and parameters without sending the request. :param dry_run: boolean :raises ValueError: When parameter has invalid value(s). :rtype: call to Client.request() """ validator.validator(locals(), 'isochrones') params = {"locations": convert._build_coords(locations)} if profile: params["profile"] = profile if range_type: params["range_type"] = range_type if intervals: params["range"] = convert._comma_list(intervals) if segments: params["interval"] = str(segments) if units: # if units and (range_type == None or range_type == 'time'): # raise ValueError("For range_type time, units cannot be specified.") params["units"] = units if location_type: params["location_type"] = location_type if smoothing: params["smoothing"] = convert._format_float(smoothing) if attributes: params["attributes"] = convert._pipe_list(attributes) return client.request("/isochrones", params, dry_run=dry_run)
def isochrones( client, locations, profile='driving-car', range_type=None, intervals=[60], segments=30, units=None, location_type=None, attributes=None, #options=None, intersections=None, dry_run=None): """ Gets travel distance and time for a matrix of origins and destinations. :param locations: One pair of lng/lat values. :type locations: list or tuple of lng,lat values :param profile: Specifies the mode of transport to use when calculating directions. One of ["driving-car", "driving-hgv", "foot-walking", "foot-hiking", "cycling-regular", "cycling-road", "cycling-safe", "cycling-mountain", "cycling-tour", "cycling-electric",]. Default "driving-car". :type profile: string :param range_type: Set 'time' for isochrones or 'distance' for equidistants. Default 'time'. :type sources: string :param intervals: Ranges to calculate distances/durations for. This can be a list of multiple ranges, e.g. [600, 1200, 1400] or a single value list. In the latter case, you can also specify the 'segments' variable to break the single value into more isochrones. In meters or seconds. Default [60]. :type intervals: list of integer(s) :param segments: Segments isochrones or equidistants for one 'intervals' value. Only has effect if used with a single value 'intervals' parameter. In meters or seconds. Default 20. :type segments: integer :param units: Specifies the unit system to use when displaying results. One of ["m", "km", "m"]. Default "m". :type units: string :param location_type: 'start' treats the location(s) as starting point, 'destination' as goal. Default 'start'. :type location_type: string :param attributes: 'area' returns the area of each polygon in its feature properties. 'reachfactor' returns a reachability score between 0 and 1. One or more of ['area', 'reachfactor']. Default 'area'. :type attributes: list of string(s) :param options: not implemented right now. :type options: dict :param intersections: not implented right now. :type intersections: boolean as string :raises ValueError: When parameter has invalid value(s). :rtype: call to Client.request() """ params = {"locations": convert._build_coords(locations)} if profile: # NOTE(broady): the mode parameter is not validated by the Maps API # server. Check here to prevent silent failures. if profile not in [ "driving-car", "driving-hgv", "foot-walking", "foot-hiking", "cycling-regular", "cycling-road", "cycling-safe", "cycling-mountain", "cycling-tour", "cycling-electric", ]: raise ValueError("Invalid travel mode.") params["profile"] = profile if range_type: params["range_type"] = range_type if intervals: params["range"] = convert._comma_list(intervals) if segments: params["interval"] = str(segments) if units: if units and (range_type == None or range_type == 'time'): raise ValueError("For range_type time, units cannot be specified.") params["units"] = units if location_type: params["location_type"] = location_type if attributes: params["attributes"] = convert._pipe_list(attributes) return client.request("/isochrones", params, dry_run=dry_run)
def test_pipe_list_bad_argument(self): with self.assertRaises(TypeError): convert._pipe_list(5)
def distance_matrix(client, locations, profile='driving-car', sources='all', destinations='all', metrics=None, resolve_locations=None, units=None, optimized='true', dry_run=None): """ Gets travel distance and time for a matrix of origins and destinations. :param locations: One or more pairs of lng/lat values. :type locations: a single location, or a list of locations, where a location is a list or tuple of lng,lat values :param profile: Specifies the mode of transport to use when calculating directions. One of ["driving-car", "driving-hgv", "foot-walking", "foot-hiking", "cycling-regular", "cycling-road", "cycling-safe", "cycling-mountain", "cycling-tour", "cycling-electric",]. Default "driving-car". :type profile: string :param sources: A list of indices that refer to the list of locations (starting with 0) or 'all'. Default 'all'. :type sources: One or more indices inside a list; or 'all' (string). :param destinations: A list of indices that refer to the list of locations (starting with 0) or 'all'. Default 'all'. :type destinations: One or more indices inside a list; or 'all' (string). :param metrics: Specifies a list of returned metrics. One or more of ["distance", "duration"]. Default ['duration']. :type metrics: list of strings :param resolve_locations: Specifies whether given locations are resolved or not. If set 'true', every element in destinations and sources will contain the name element that identifies the name of the closest street. 'true' or 'false'. Default 'false'. :type resolve_locations: boolean as string :param units: Specifies the unit system to use when displaying results. One of ["m", "km", "m"]. Default "m". :type units: string :param optimized: Specifies whether Dijkstra algorithm ('false') or any available technique to speed up shortest-path routing ('true') is used. For normal Dijkstra the number of visited nodes is limited to 100000. Default 'true'. :type optimized: boolean as string :raises ValueError: When profile parameter has wrong value. :rtype: call to Client.request() """ params = { "locations": locations, "sources": sources, "destinations": destinations } get_params = {} if profile: if profile not in [ "driving-car", "driving-hgv", "foot-walking", "foot-hiking", "cycling-regular", "cycling-road", "cycling-safe", "cycling-mountain", "cycling-tour", "cycling-electric", ]: raise ValueError("Invalid travel mode.") params["profile"] = profile get_params['profile'] = profile if sources: if sources == 'all': params["sources"] = sources else: params["sources"] = convert._comma_list(sources) if destinations: if destinations == 'all': params["destinations"] = destinations else: params["destinations"] = convert._comma_list(destinations) if metrics: params["metrics"] = convert._pipe_list(metrics) if resolve_locations: params["resolve_locations"] = resolve_locations if units: params["units"] = units if optimized: # not checked on backend, check here convert._checkBool(optimized) params["optimized"] = optimized return client.request("/matrix", get_params, post_json=params, dry_run=dry_run)
def directions( client, coordinates, profile='driving-car', format_out=None, preference=None, units=None, language=None, geometry=None, geometry_format=None, geometry_simplify=None, instructions=None, instructions_format=None, roundabout_exits=None, #attributes=None, #maneuvers=None, radiuses=None, bearings=None, continue_straight=None, elevation=None, extra_info=None, optimized='true', options=None, dry_run=None): """Get directions between an origin point and a destination point. For more information, visit https://go.openrouteservice.org/documentation/. :param coordinates: The coordinates tuple the route should be calculated from. In order of visit. :type origin: list or tuple of coordinate lists or tuples :param profile: Specifies the mode of transport to use when calculating directions. One of ["driving-car", "driving-hgv", "foot-walking", "foot-hiking", "cycling-regular", "cycling-road",requests_kwargs "cycling-safe", "cycling-mountain", "cycling-tour", "cycling-electric",]. Default "driving-car". :type mode: string :param preference: Specifies the routing preference. One of ["fastest, "shortest", "recommended"]. Default "fastest". :type preference: string :param units: Specifies the distance unit. One of ["m", "km", "mi"]. Default "m". :type units: string :param language: Language for routing instructions. One of ["en", "de", "cn", "es", "ru", "dk", "fr", "it", "nl", "br", "se", "tr", "gr"]. Default "en". :type language: string :param language: The language in which to return results. :type language: string :param geometry: Specifies whether geometry should be returned. "true" or "false". Default "true". :type geometry: string :param geometry_format: Specifies which geometry format should be returned. One of ["encodedpolyline", "geojson", "polyline"]. Default: "encodedpolyline". :type geometry_format: string :param geometry_simplify: Specifies whether to simplify the geometry. "true" or "false". Default "false". :type geometry_simplify: boolean as string :param instructions: Specifies whether to return turn-by-turn instructions. "true" or "false". Default "true". :type instructions: string :param instructions_format: Specifies the the output format for instructions. One of ["text", "html"]. Default "text". :type instructions_format: string :param roundabout_exits: Provides bearings of the entrance and all passed roundabout exits. Adds the 'exit_bearings' array to the 'step' object in the response. "true" or "false". Default "false". :type roundabout_exits: string :param radiuses: A list of maximum distances (measured in meters) that limit the search of nearby road segments to every given waypoint. The values must be greater than 0, the value of -1 specifies no limit in the search. The number of radiuses must correspond to the number of waypoints. Default None. :type radiuses: list or tuple :param bearings: Specifies a list of pairs (bearings and deviations) to filter the segments of the road network a waypoint can snap to. For example bearings=[[45,10],[120,20]]. Each pair is a comma-separated list that can consist of one or two float values, where the first value is the bearing and the second one is the allowed deviation from the bearing. The bearing can take values between 0 and 360 clockwise from true north. If the deviation is not set, then the default value of 100 degrees is used. The number of pairs must correspond to the number of waypoints. Setting optimized=false is mandatory for this feature to work for all profiles. The number of bearings corresponds to the length of waypoints-1 or waypoints. If the bearing information for the last waypoint is given, then this will control the sector from which the destination waypoint may be reached. :type bearings: list or tuple or lists or tuples :param continue_straight: Forces the route to keep going straight at waypoints restricting u-turns even if u-turns would be faster. This setting will work for all profiles except for driving-*. In this case you will have to set optimized=false for it to work. True or False. Default False. :type continue_straight: boolean :param elevation: Specifies whether to return elevation values for points. "true" or "false". Default "false". :type elevation: boolean as string :param extra_info: Returns additional information on ["steepness", "suitability", "surface", "waycategory", "waytype", "tollways", "traildifficulty"]. Must be a list of strings. Default None. :type extra_info: list or tuple of strings :param optimized: If set True, uses Contraction Hierarchies. "true" or "false". Default "true". :type optimized: boolean as string :param options: Refer to https://go.openrouteservice.org/documentation for detailed documentation. Construct your own dict() following the example of the minified options object. Will be converted to json automatically. :type options: dict :raises ValueError: When parameter has wrong value. :raises TypeError: When parameter is of wrong type. :rtype: call to Client.request() """ params = {"coordinates": convert._build_coords(coordinates)} if profile: # NOTE(broady): the mode parameter is not validated by the Maps API # server. Check here to prevent silent failures. if profile not in [ "driving-car", "driving-hgv", "foot-walking", "foot-hiking", "cycling-regular", "cycling-road", "cycling-safe", "cycling-mountain", "cycling-tour", "cycling-electric", ]: raise ValueError("Invalid travel mode.") params["profile"] = profile if format_out: params["format"] = format_out if preference: params["preference"] = preference if units: params["units"] = units if language: params["language"] = language if geometry: # not checked on backend, check here convert._checkBool(geometry) params["geometry"] = geometry if geometry_format: params["geometry_format"] = geometry_format if geometry_simplify: # not checked on backend, check here convert._checkBool(geometry_simplify) if extra_info: params["geometry_simplify"] = 'false' else: params["geometry_simplify"] = geometry_simplify if instructions: # not checked on backend, check here convert._checkBool(instructions) params["instructions"] = instructions if instructions_format: params["instructions_format"] = instructions_format if roundabout_exits: # not checked on backend, check here convert._checkBool(roundabout_exits) params["roundabout_exits"] = roundabout_exits if radiuses: if len(radiuses) != len(coordinates): raise ValueError( "Amount of radiuses must match the number of waypoints.") params["radiuses"] = convert._pipe_list(radiuses) if bearings: if len(bearings) != len(coordinates) and len( bearings) != len(coordinates) - 1: raise ValueError( "Provide as many bearings as waypoints or one less.") if not convert._is_list(bearings): raise TypeError("Expected a list or tuple of bearing pairs, " "but got {}".format(type(bearings).__name__)) if not all(convert._is_list(t) for t in bearings): raise TypeError("Expected bearing pairs to be a list or tuple") params["bearings"] = convert._pipe_list( [convert._comma_list(pair) for pair in bearings]) if continue_straight: # not checked on backend, check here convert._checkBool(continue_straight) params["continue_straight"] = continue_straight if elevation: # not checked on backend, check here convert._checkBool(elevation) params["elevation"] = elevation if extra_info: # not checked on backend, check here opts = [ "steepness", "suitability", "surface", "waycategory", "waytype", "tollways", "traildifficulty" ] if not all((info in opts) for info in extra_info): raise ValueError("Contains invalid extra_info parameter(s).") params["extra_info"] = convert._pipe_list(extra_info) if optimized: # not checked on backend, check here convert._checkBool(optimized) if optimized == 'true' and (bearings or continue_straight == 'true'): params["optimized"] = 'false' print( "Set optimized='false' due to incompatible parameter settings." ) else: params["optimized"] = optimized if options: # check if valid dict if not isinstance(options, dict): raise TypeError( "Expected options object to be a dict, but got {}".format( type(options))) params['options'] = json.dumps(options) return client.request("/directions", params, dry_run=dry_run)