def test_as_list(self): self.assertEqual([1], convert.as_list(1)) self.assertEqual([1, 2, 3], convert.as_list([1, 2, 3])) self.assertEqual(["string"], convert.as_list("string")) self.assertEqual((1, 2), convert.as_list((1, 2)))
def test_as_list(self): self.assertEqual([1], convert.as_list(1)) self.assertEqual([1, 2, 3], convert.as_list([1, 2, 3])) self.assertEqual(["string"], convert.as_list("string")) self.assertEqual((1, 2), convert.as_list((1, 2))) a_dict = {"a": 1} self.assertEqual([a_dict], convert.as_list(a_dict))
def snapped_speed_limits(client, path): """Returns the posted speed limit (in km/h) for given road segments. The provided points will first be snapped to the most likely roads the vehicle was traveling along. :param path: The path of points to be snapped. A list of (or single) latitude/longitude tuples. :type path: list or tuple :rtype: a dict with both a list of speed limits and a list of the snapped points. """ if type(path) is tuple: path = [path] path = convert.join_list( "|", [convert.latlng(k) for k in convert.as_list(path)]) params = {"path": path} return client._get("/v1/speedLimits", params, base_url=_ROADS_BASE_URL, accepts_clientid=False, extract_body=_roads_extract)
def snapped_speed_limits(client, path): """Returns the posted speed limit (in km/h) for given road segments. The provided points will first be snapped to the most likely roads the vehicle was traveling along. :param path: The path of points to be snapped. A list of (or single) latitude/longitude tuples. :type path: list or tuple :rtype: a dict with both a list of speed limits and a list of the snapped points. """ if type(path) is tuple: path = [path] path = convert.join_list("|", [convert.latlng(k) for k in convert.as_list(path)]) params = { "path": path } return client._get("/v1/speedLimits", params, base_url=_ROADS_BASE_URL, accepts_clientid=False, extract_body=_roads_extract)
def elevation_along_path(client, path, samples): """ Provides elevation data sampled along a path on the surface of the earth. :param path: A encoded polyline string, or a list of latitude/longitude tuples from which you wish to calculate elevation data. :type path: str or list :param samples: The number of sample points along a path for which to return elevation data. :type samples: int :rtype: list of elevation data responses """ if type(path) is str: path = "enc:%s" % path else: path = convert.join_list( "|", [convert.latlng(k) for k in convert.as_list(path)]) params = {"path": path, "samples": samples} return client._get("/maps/api/elevation/json", params)["results"]
def elevation_along_path(client, path, samples): """ Provides elevation data sampled along a path on the surface of the earth. :param path: A encoded polyline string, or a list of latitude/longitude tuples from which you wish to calculate elevation data. :type path: str or list :param samples: The number of sample points along a path for which to return elevation data. :type samples: int :rtype: list of elevation data responses """ if type(path) is str: path = "enc:%s" % path else: path = convert.join_list("|", [convert.latlng(k) for k in convert.as_list(path)]) params = { "path": path, "samples": samples } return client._get("/maps/api/elevation/json", params)["results"]
def speed_limits(client, place_ids): #Returns the posted speed limit (in km/h) for given road segments params = [("placeId", place_id) for place_id in convert.as_list(place_ids)] return client._request("/v1/speedLimits", params, base_url=_ROADS_BASE_URL, accepts_clientid=False, extract_body=_roads_extract).get("speedLimits", [])
def _convert_path(waypoints): # Handle the single-tuple case if type(waypoints) is tuple: waypoints = [waypoints] else: waypoints = as_list(waypoints) return convert.join_list( "|", [(k if convert.is_string(k) else convert.latlng(k)) for k in waypoints])
def _convert_path(waypoints): # Handle the single-tuple case if type(waypoints) is tuple: waypoints = [waypoints] else: waypoints = as_list(waypoints) return convert.join_list("|", [(k if convert.is_string(k) else convert.latlng(k)) for k in waypoints])
async def speed_limits(client, place_ids): params = [('placeId', place_id) for place_id in convert.as_list(place_ids)] result = await client._request( '/v1/speedLimits', params, base_url=_ROADS_BASE_URL, accepts_clientid=False, extract_body=_roads_extract, ) return result.get('speedLimits', [])
def speed_limits(client, place_ids): """Returns the posted speed limit (in km/h) for given road segments. :param place_ids: The Place ID of the road segment. Place IDs are returned by the snap_to_roads function. You can pass up to 100 Place IDs. :type place_ids: str or list :rtype: list of speed limits. """ params = [("placeId", place_id) for place_id in convert.as_list(place_ids)] return client._request("/v1/speedLimits", params, base_url=_ROADS_BASE_URL, accepts_clientid=False, extract_body=_roads_extract).get("speedLimits", [])
def speed_limits(client, place_ids): """Returns the posted speed limit (in km/h) for given road segments. :param place_ids: The Place ID of the road segment. Place IDs are returned by the snap_to_roads function. You can pass up to 100 Place IDs. :type place_ids: str or list :rtype: list of speed limits. """ params = [("placeId", place_id) for place_id in convert.as_list(place_ids)] return client._get("/v1/speedLimits", params, base_url=_ROADS_BASE_URL, accepts_clientid=False, extract_body=_roads_extract)["speedLimits"]
def elevation(client, locations): """ Provides elevation data for locations provided on the surface of the earth, including depth locations on the ocean floor (which return negative values) :param locations: A single latitude/longitude tuple or dict, or a list of latitude/longitude tuples or dicts from which you wish to calculate elevation data. :type locations: list or tuple :rtype: list of elevation data responses """ params = {} if type(locations) is tuple: locations = [locations] params["locations"] = convert.join_list("|", [convert.latlng(k) for k in convert.as_list(locations)]) return client._get("/maps/api/elevation/json", params)["results"]
def elevation(client, locations): """ Provides elevation data for locations provided on the surface of the earth, including depth locations on the ocean floor (which return negative values) :param locations: A single latitude/longitude tuple or dict, or a list of latitude/longitude tuples or dicts from which you wish to calculate elevation data. :type locations: list or tuple :rtype: list of elevation data responses """ params = {} if type(locations) is tuple: locations = [locations] params["locations"] = convert.join_list( "|", [convert.latlng(k) for k in convert.as_list(locations)]) return client._get("/maps/api/elevation/json", params)["results"]
def snap_to_roads(client, path, interpolate=False): """Snaps a path to the most likely roads travelled. Takes up to 100 GPS points collected along a route, and returns a similar set of data with the points snapped to the most likely roads the vehicle was traveling along. :param path: The path to be snapped. A list of latitude/longitude tuples. :type path: list :param interpolate: Whether to interpolate a path to include all points forming the full road-geometry. When true, additional interpolated points will also be returned, resulting in a path that smoothly follows the geometry of the road, even around corners and through tunnels. Interpolated paths may contain more points than the original path. :type interpolate: bool :rtype: A list of snapped points. """ if type(path) is tuple: path = [path] path = convert.join_list("|", [convert.latlng(k) for k in convert.as_list(path)]) params = { "path": path } if interpolate: params["interpolate"] = "true" return client._get("/v1/snapToRoads", params, base_url=_ROADS_BASE_URL, accepts_clientid=False, extract_body=_roads_extract)["snappedPoints"]
def snap_to_roads(client, path, interpolate=False): """Snaps a path to the most likely roads travelled. Takes up to 100 GPS points collected along a route, and returns a similar set of data with the points snapped to the most likely roads the vehicle was traveling along. :param path: The path to be snapped. A list of latitude/longitude tuples. :type path: list :param interpolate: Whether to interpolate a path to include all points forming the full road-geometry. When true, additional interpolated points will also be returned, resulting in a path that smoothly follows the geometry of the road, even around corners and through tunnels. Interpolated paths may contain more points than the original path. :type interpolate: bool :rtype: A list of snapped points. """ if type(path) is tuple: path = [path] path = convert.join_list( "|", [convert.latlng(k) for k in convert.as_list(path)]) params = {"path": path} if interpolate: params["interpolate"] = "true" return client._get("/v1/snapToRoads", params, base_url=_ROADS_BASE_URL, accepts_clientid=False, extract_body=_roads_extract)["snappedPoints"]
def directions(client, origin, destination, mode=None, waypoints=None, alternatives=False, avoid=None, language=None, units=None, region=None, departure_time=None, arrival_time=None, optimize_waypoints=False, transit_mode=None, transit_routing_preference=None): """Get directions between an origin point and a destination point. :param origin: The address or latitude/longitude value from which you wish to calculate directions. :type origin: string or dict or tuple :param destination: The address or latitude/longitude value from which you wish to calculate directions. :type destination: string or dict or tuple :param mode: Specifies the mode of transport to use when calculating directions. One of "driving", "walking", "bicycling" or "transit" :type mode: string :param waypoints: Specifies an array of waypoints. Waypoints alter a route by routing it through the specified location(s). :param alternatives: If True, more than one route may be returned in the response. :type alternatives: bool :param avoid: Indicates that the calculated route(s) should avoid the indicated features. :type avoid: list or string :param language: The language in which to return results. :type language: string :param units: Specifies the unit system to use when displaying results. "metric" or "imperial" :type units: string :param region: The region code, specified as a ccTLD ("top-level domain" two-character value. :type region: string :param departure_time: Specifies the desired time of departure. :type departure_time: int or datetime.datetime :param arrival_time: Specifies the desired time of arrival for transit directions. Note: you can't specify both departure_time and arrival_time. :type arrival_time: int or datetime.datetime :param optimize_waypoints: Optimize the provided route by rearranging the waypoints in a more efficient order. :type optimize_waypoints: bool :param transit_mode: Specifies one or more preferred modes of transit. This parameter may only be specified for requests where the mode is transit. Valid values are "bus", "subway", "train", "tram", "rail". "rail" is equivalent to ["train", "tram", "subway"]. :type transit_mode: string or list of strings :param transit_routing_preference: Specifies preferences for transit requests. Valid values are "less_walking" or "fewer_transfers" :type transit_routing_preference: string :rtype: list of routes """ params = { "origin": _convert_waypoint(origin), "destination": _convert_waypoint(destination) } if mode: # NOTE(broady): the mode parameter is not validated by the Maps API # server. Check here to prevent silent failures. if mode not in ["driving", "walking", "bicycling", "transit"]: raise ValueError("Invalid travel mode.") params["mode"] = mode if waypoints: waypoints = convert.as_list(waypoints) waypoints = [_convert_waypoint(waypoint) for waypoint in waypoints] if optimize_waypoints: waypoints = ["optimize:true"] + waypoints params["waypoints"] = convert.join_list("|", waypoints) if alternatives: params["alternatives"] = "true" if avoid: params["avoid"] = convert.join_list("|", avoid) if language: params["language"] = language if units: params["units"] = units if region: params["region"] = region if departure_time: params["departure_time"] = convert.time(departure_time) if arrival_time: params["arrival_time"] = convert.time(arrival_time) if departure_time and arrival_time: raise ValueError("Should not specify both departure_time and" "arrival_time.") if transit_mode: params["transit_mode"] = convert.join_list("|", transit_mode) if transit_routing_preference: params["transit_routing_preference"] = transit_routing_preference return client._get("/maps/api/directions/json", params)["routes"]