示例#1
0
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 pelias_search(client, text,
                  focus_point=None,
                  rect_min_x=None,
                  rect_min_y=None,
                  rect_max_x=None,
                  rect_max_y=None,
                  circle_point=None,
                  circle_radius=None,
                  sources=None,
                  layers=None,
                  country=None,
                  size=None,
                  dry_run=None):
    """
    Geocoding is the process of converting addresses into geographic
    coordinates.

    This endpoint queries directly against a Pelias instance.

    :param text: Full-text query against search endpoint. Required.
    :type text: string

    :param focus_point: Focusses the search to be around this point and gives
        results within a 100 km radius higher scores.
    :type query: list or tuple of (Long, Lat)

    :param rect_min_x: Min longitude by which to constrain request geographically.
    :type rect_min_x: float

    :param rect_min_y: Min latitude by which to constrain request geographically.
    :type rect_min_y: float

    :param rect_max_x: Max longitude by which to constrain request geographically.
    :type rect_max_x: float

    :param rect_max_y: Max latitude by which to constrain request geographically.
    :type rect_max_y: float

    :param circle_point: Geographical constraint in form a circle.
    :type circle_point: list or tuple of (Long, Lat)

    :param circle_radius: Radius of circle constraint in km. Default 50.
    :type circle_radius: integer

    :param sources: The originating source of the data. One or more of
        ['osm', 'oa', 'wof', 'gn']. Currently only 'osm', 'wof' and 'gn' are
        supported.
    :type sources: list of strings

    :param layers: The administrative hierarchy level for the query. Refer to
        https://github.com/pelias/documentation/blob/master/search.md#filter-by-data-type
        for details.
    :type layers: list of strings

    :param country: Constrain query by country. Accepts a alpha-2 or alpha-3
        digit ISO-3166 country code.
    :type country: str

    :param size: The amount of results returned. Default 10.
    :type size: integer
    
    :param dry_run: Print URL and parameters without sending the request.
    :param dry_run: boolean

    :raises ValueError: When parameter has invalid value(s).
    :raises TypeError: When parameter is of the wrong type.

    :rtype: call to Client.request()
    """

    validator.validator(locals(), 'pelias_search')

    params = {'text': text}

    if focus_point:
        params['focus.point.lon'] = convert._format_float(focus_point[0])
        params['focus.point.lat'] = convert._format_float(focus_point[1])

    if rect_min_x:
        params['boundary.rect.min_lon'] = convert._format_float(rect_min_x)  #

    if rect_min_y:
        params['boundary.rect.min_lat'] = convert._format_float(rect_min_y)  #

    if rect_max_x:
        params['boundary.rect.max_lon'] = convert._format_float(rect_max_x)  #

    if rect_max_y:
        params['boundary.rect.max_lat'] = convert._format_float(rect_max_y)  #

    if circle_point:
        params['boundary.circle.lon'] = convert._format_float(circle_point[0])  #
        params['boundary.circle.lat'] = convert._format_float(circle_point[1])  #

    if circle_radius:
        params['boundary.circle.radius'] = circle_radius

    if sources:
        params['sources'] = convert._comma_list(sources)

    if layers:
        params['layers'] = convert._comma_list(layers)

    if country:
        params['boundary.country'] = country

    if size:
        params['size'] = size

    return client.request("/geocode/search", params, dry_run=dry_run)
def pelias_reverse(client, point,
                   circle_radius=None,
                   sources=None,
                   layers=None,
                   country=None,
                   size=None,
                   dry_run=None):
    """
    Reverse geocoding is the process of converting geographic coordinates into a
    human-readable address.

    This endpoint queries directly against a Pelias instance.

    :param point: Coordinate tuple. Required.
    :type point: list or tuple of [Lon, Lat]

    :param circle_radius: Radius around point to limit query in km. Default 1.
    :type circle_radius: integer

    :param sources: The originating source of the data. One or more of
        ['osm', 'oa', 'wof', 'gn']. Currently only 'osm', 'wof' and 'gn' are
        supported.
    :type sources: list of strings

    :param layers: The administrative hierarchy level for the query. Refer to
        https://github.com/pelias/documentation/blob/master/search.md#filter-by-data-type
        for details.
    :type layers: list of strings

    :param country: Constrain query by country. Accepts a alpha-2 or alpha-3
        digit ISO-3166 country codes.
    :type country: str

    :param size: The amount of results returned. Default 10.
    :type size: integer
    
    :param dry_run: Print URL and parameters without sending the request.
    :param dry_run: boolean

    :raises ValueError: When parameter has invalid value(s).

    :rtype: dict from JSON response
    """

    validator.validator(locals(), 'pelias_reverse')

    params = dict()

    params['point.lon'] = convert._format_float(point[0])
    params['point.lat'] = convert._format_float(point[1])

    if circle_radius:
        params['boundary.circle.radius'] = str(circle_radius)

    if sources:
        params['sources'] = convert._comma_list(sources)

    if layers:
        params['layers'] = convert._comma_list(layers)

    if country:
        params['boundary.country'] = country

    if size:
        params['size'] = size

    return client.request("/geocode/reverse", params, dry_run=dry_run)
示例#4
0
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 pelias_autocomplete(client, text,
                        focus_point=None,
                        rect_min_x=None,
                        rect_min_y=None,
                        rect_max_x=None,
                        rect_max_y=None,
                        country=None,
                        sources=None,
                        layers=None,
                        dry_run=None):
    """
    Autocomplete geocoding can be used alongside /search to enable real-time feedback.
    It represents a type-ahead functionality, which helps to find the desired location,
    without to require a fully specified search term.

    This endpoint queries directly against a Pelias instance.
    For fully documentation, please see https://github.com/pelias/documentation/blob/master/autocomplete.md

    :param text: Full-text query against search endpoint. Required.
    :type text: string

    :param focus_point: Focusses the search to be around this point and gives
        results within a 100 km radius higher scores.
    :type query: list or tuple of (Long, Lat)

    :param rect_min_x: Min longitude by which to constrain request geographically.
    :type rect_min_x: float

    :param rect_min_y: Min latitude by which to constrain request geographically.
    :type rect_min_y: float

    :param rect_max_x: Max longitude by which to constrain request geographically.
    :type rect_max_x: float

    :param rect_max_y: Max latitude by which to constrain request geographically.
    :type rect_max_y: float

    :param country: Constrain query by country. Accepts a alpha-2 or alpha-3
        digit ISO-3166 country codes.
    :type country: str

    :param sources: The originating source of the data. One or more of
        ['osm', 'oa', 'wof', 'gn']. Currently only 'osm', 'wof' and 'gn' are
        supported.
    :type sources: list of strings

    :param layers: The administrative hierarchy level for the query. Refer to
        https://github.com/pelias/documentation/blob/master/search.md#filter-by-data-type
        for details.
    :type layers: list of strings
    
    :param dry_run: Print URL and parameters without sending the request.
    :param dry_run: boolean

    :raises ValueError: When parameter has invalid value(s).
    :raises TypeError: When parameter is of the wrong type.

    :rtype: dict from JSON response
    """

    validator.validator(locals(), 'pelias_autocomplete')

    params = {'text': text}

    if focus_point:
        params['focus.point.lon'] = convert._format_float(focus_point[0])
        params['focus.point.lat'] = convert._format_float(focus_point[1])

    if rect_min_x:
        params['boundary.rect.min_lon	'] = convert._format_float(rect_min_x)

    if rect_min_y:
        params['boundary.rect.min_lat	'] = convert._format_float(rect_min_y)

    if rect_max_x:
        params['boundary.rect.max_lon	'] = convert._format_float(rect_max_x)

    if rect_max_y:
        params['boundary.rect.max_lon	'] = convert._format_float(rect_max_y)

    if country:
        params['boundary.country'] = country

    if sources:
        params['sources'] = convert._comma_list(sources)

    if layers:
        params['layers'] = convert._comma_list(layers)

    return client.request("/geocode/autocomplete", params, dry_run=dry_run)
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 test_comma_list_bad_argument(self):
     with self.assertRaises(TypeError):
         convert._comma_list(5)
示例#8
0
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)
def geocode(client,
            query,
            lang=None,
            boundary_type=None,
            rect=None,
            circle=None,
            limit=None,
            dry_run=None):
    """
    Geocoding is the process of converting addresses into geographic
    coordinates.

    :param query: Name of location, street address or postal code. For a 
        structured geocoding request, a dict object can be passed. Please refer
        to https://github.com/GIScience/openrouteservice-docs#geocoding-structured-query
        for details. 
    :type query: string or dict of structured geocoding request

    :param lang: Specifies the language of the response. One of ['de', 'en',
        'fr', 'it']. Default 'en'.
    :type lang: string

    :param boundary_type: Specifies the type of spatial search restriction. 
        One of ['rect','circle'].
    :type boundary_type: string

    :param rect: For boundary_type=rect only! Sets the restriction rectangle's
        minimum/maximum longitude/latitude, i.e. [MinLong,MinLat,MaxLong,Maxlat].
    :type rect: list of integers

    :param circle: For boundary_type=circle only! Sets the restriction circle 
        with a center point and a radius in meters, i.e. [Long,Lat,Radius]. 
    :type circle: list of integers

    :param limit: Specifies the maximum number of responses. Default 5.
    :type limit: integer
    dry_run
    :raises ValueError: When parameter has invalid value(s).

    :rtype: call to Client.request()
    """

    params = dict()

    if query:
        # Is not checked on backend
        if isinstance(query, dict):
            allowed_keys = [
                'address', 'neighbourhood', 'borough', 'locality', 'county',
                'region', 'postalcode', 'country'
            ]
            if not all((key in allowed_keys) for key in query.keys()):
                raise ValueError(
                    "Geocoding query contains invalid admin parameter.")
        params["query"] = str(query)

    if lang:
        # Is not checked on backend
        if lang not in ['en', 'fr', 'de', 'it']:
            raise ValueError("Invalid language {} specified)".format(lang))
        params["lang"] = lang

    if boundary_type:
        params["boundary_type"] = boundary_type

    if rect:
        params["rect"] = convert._comma_list(rect)

    if circle:
        params["circle"] = convert._comma_list(circle)

    if limit:
        params["limit"] = str(limit)

    return client.request("/geocoding", params)
def reverse_geocode(client,
                    location,
                    lang=None,
                    boundary_type=None,
                    rect=None,
                    circle=None,
                    limit=None,
                    dry_run=None):
    """
    Reverse geocoding is the process of converting geographic coordinates into a
    human-readable address.

    :param location: Coordinate to be inquired.
    :type location: lng/lat pair as list or tuple

    :param lang: Specifies the language of the response. One of ['de', 'en',
        'fr', 'it']. Default 'en'.
    :type lang: string

    :param boundary_type: Specifies the type of spatial search restriction. 
        One of ['rect','circle'].
    :type boundary_type: string

    :param rect: For boundary_type=rect only! Sets the restriction rectangle's
        minimum/maximum longitude/latitude, i.e. [MinLong,MinLat,MaxLong,Maxlat].
    :type rect: list of integers

    :param circle: For boundary_type=circle only! Sets the restriction circle 
        with a center point and a radius in meters, i.e. [Long,Lat,Radius]. 
    :type circle: list of integers

    :param limit: Specifies the maximum number of responses. Default 5.
    :type limit: integer
    
    :raises ValueError: When parameter has invalid value(s).

    :rtype: dict from JSON response
    """

    params = dict()

    # Check if latlng param is a place_id string.
    #  place_id strings do not contain commas; latlng strings do.
    if location:
        params["location"] = convert._comma_list(location)

    if lang:
        # Is not checked on backend
        if lang not in ['en', 'fr', 'de', 'it']:
            raise ValueError("Invalid language {} specified)".format(lang))
        params["lang"] = lang

    if boundary_type:
        params["boundary_type"] = boundary_type

    if rect:
        params["rect"] = convert._comma_list(rect)

    if circle:
        params["circle"] = convert._comma_list(circle)

    if limit:
        params["limit"] = str(limit)

    return client.request("/geocoding", params, dry_run=dry_run)