How to use the routingpy.convert._delimit_list function in routingpy

To help you get started, we’ve selected a few routingpy examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github gis-ops / routing-py / tests / test_osrm.py View on Github external
def test_full_matrix(self):
        query = ENDPOINTS_QUERIES[self.name]['matrix']
        coords = convert._delimit_list([convert._delimit_list(pair) for pair in query['locations']], ';')

        responses.add(
            responses.GET,
            'https://router.project-osrm.org/table/v1/{}/{}'.format(query['profile'], coords),
            status=200,
            json=ENDPOINTS_RESPONSES['osrm']['matrix'],
            content_type='application/json'
        )

        matrix = self.client.matrix(**query)

        self.assertEqual(1, len(responses.calls))
        self.assertURLEqual(
            'https://router.project-osrm.org/table/v1/car/8.688641,49.420577;8.680916,49.415776;8.780916,49.445776',
            responses.calls[0].request.url
        )
github gis-ops / routing-py / routingpy / routers / google.py View on Github external
params['destination'] = convert._delimit_list(list(reversed(destination)))
        elif isinstance(origin, self.WayPoint):
            raise TypeError("The first and last locations must be list/tuple of [lon, lat]")

        if len(locations) > 2:
            waypoints = []
            s = slice(1, -1)
            for coord in locations[s]:
                if isinstance(coord, (list, tuple)):
                    waypoints.append(convert._delimit_list(list(reversed(coord))))
                elif isinstance(coord, self.WayPoint):
                    waypoints.append(coord.make_waypoint())
            if optimize:
                waypoints.insert(0, 'optimize:true')

            params['waypoints'] = convert._delimit_list(waypoints, '|')

        if self.key is not None:
            params["key"] = self.key

        if alternatives is not None:
            params['alternatives'] = convert._convert_bool(alternatives)

        if avoid:
            params['avoid'] = convert._delimit_list(avoid, '|')

        if language:
            params['language'] = language

        if region:
            params['region'] = region
github gis-ops / routing-py / routingpy / routers / google.py View on Github external
params['units'] = units

        if arrival_time and departure_time:
            raise ValueError("Specify either arrival_time or departure_time.")

        if arrival_time:
            params['arrival_time'] = str(arrival_time)

        if departure_time:
            params['departure_time'] = str(departure_time)

        if traffic_model:
            params['traffic_model'] = traffic_model

        if transit_mode:
            params['transit_mode'] = convert._delimit_list(transit_mode, '|')

        if transit_routing_preference:
            params['transit_routing_preference'] = transit_routing_preference

        return self._parse_direction_json(
            self._request('/directions/json', get_params=params, dry_run=dry_run), alternatives
        )
github gis-ops / routing-py / routingpy / routers / heremaps.py View on Github external
params[wp_index] = wp

        if isinstance(profile, str):
            params["mode"] = mode_type + ';' + profile
        elif isinstance(profile, self.RoutingMode):
            params["mode"] = profile.make_routing_mode()

        if request_id is not None:
            params["requestId"] = request_id

        if avoid_areas is not None:
            params["avoidAreas"] = convert._delimit_list(
                [
                    convert._delimit_list(
                        [
                            convert._delimit_list(
                                [convert._format_float(f) for f in list(reversed(pair))], ','
                            ) for pair in bounding_box
                        ], ';'
                    ) for bounding_box in avoid_areas
                ], '!'
            )

        if avoid_links is not None:
            params["avoidLinks"] = convert._delimit_list(avoid_links, ',')

        if avoid_seasonal_closures is not None:
            params["avoidSeasonalClosures"] = convert._convert_bool(avoid_seasonal_closures)

        if avoid_turns is not None:
            params["avoidTurns"] = avoid_turns
github gis-ops / routing-py / routingpy / routers / google.py View on Github external
:param dry_run: bool

        :returns: One or multiple route(s) from provided coordinates and restrictions.
        :rtype: :class:`routingpy.direction.Direction` or :class:`routingpy.direction.Directions`
        """

        params = {'profile': profile}

        origin, destination = locations[0], locations[-1]
        if isinstance(origin, (list, tuple)):
            params['origin'] = convert._delimit_list(list(reversed(origin)))
        elif isinstance(origin, self.WayPoint):
            raise TypeError("The first and last locations must be list/tuple of [lon, lat]")

        if isinstance(destination, (list, tuple)):
            params['destination'] = convert._delimit_list(list(reversed(destination)))
        elif isinstance(origin, self.WayPoint):
            raise TypeError("The first and last locations must be list/tuple of [lon, lat]")

        if len(locations) > 2:
            waypoints = []
            s = slice(1, -1)
            for coord in locations[s]:
                if isinstance(coord, (list, tuple)):
                    waypoints.append(convert._delimit_list(list(reversed(coord))))
                elif isinstance(coord, self.WayPoint):
                    waypoints.append(coord.make_waypoint())
            if optimize:
                waypoints.insert(0, 'optimize:true')

            params['waypoints'] = convert._delimit_list(waypoints, '|')
github gis-ops / routing-py / routingpy / routers / mapbox_osrm.py View on Github external
"""

        coords = convert._delimit_list(
            [convert._delimit_list([convert._format_float(f) for f in pair]) for pair in locations], ';'
        )

        params = {'access_token': self.api_key}

        if sources:
            params['sources'] = convert._delimit_list(sources, ';')

        if destinations:
            params['destinations'] = convert._delimit_list(destinations, ';')

        if annotations:
            params['annotations'] = convert._delimit_list(annotations)

        if fallback_speed:
            params['fallback_speed'] = str(fallback_speed)

        return self._parse_matrix_json(
            self._request(
                "/directions-matrix/v1/mapbox/" + profile + '/' + coords,
                get_params=params,
                dry_run=dry_run
            )
github gis-ops / routing-py / routingpy / routers / google.py View on Github external
the options returned, rather than accepting the default best route chosen by the API. One of ['less_walking',
            'fewer_transfers'].
        :type transit_routing_preference: str

        :param dry_run: Print URL and parameters without sending the request.
        :param dry_run: bool

        :returns: A matrix from the specified sources and destinations.
        :rtype: :class:`routingpy.matrix.Matrix`
        """
        params = {'profile': profile}

        waypoints = []
        for coord in locations:
            if isinstance(coord, (list, tuple)):
                waypoints.append(convert._delimit_list(list(reversed(coord))))
            elif isinstance(coord, self.WayPoint):
                waypoints.append(coord.make_waypoint())

        sources_coords = waypoints
        if sources is not None:
            sources_coords = itemgetter(*sources)(sources_coords)
            if not isinstance(sources_coords, (list, tuple)):
                sources_coords = [sources_coords]
        params['origins'] = convert._delimit_list(sources_coords, '|')

        destinations_coords = waypoints
        if destinations is not None:
            destinations_coords = itemgetter(*destinations)(destinations_coords)
            if not isinstance(destinations_coords, (list, tuple)):
                destinations_coords = [destinations_coords]
        params['destinations'] = convert._delimit_list(destinations_coords, '|')
github gis-ops / routing-py / routingpy / routers / mapbox_osrm.py View on Github external
:param waypoint_targets: List of coordinate pairs used to specify drop-off locations that are distinct from the
            locations specified in coordinates. If this parameter is provided, the Directions API will compute the side
            of the street, left or right, for each target based on the waypoint_targets and the driving direction. The
            maneuver.modifier, banner and voice instructions will be updated with the computed side of street. The
            number of waypoint_targets must be the same as the number of coordinates.
        :type waypoint_targets: list of list of float

        :param dry_run: Print URL and parameters without sending the request.
        :param dry_run: bool

        :returns: One or multiple route(s) from provided coordinates and restrictions.
        :rtype: :class:`routingpy.direction.Direction` or :class:`routingpy.direction.Directions`
        """

        coords = convert._delimit_list(
            [convert._delimit_list([convert._format_float(f) for f in pair]) for pair in locations], ';'
        )

        params = {'coordinates': coords}

        if radiuses:
            params["radiuses"] = convert._delimit_list(radiuses, ';')

        if bearings:
            params["bearings"] = convert._delimit_list(
                [convert._delimit_list(pair) for pair in bearings], ';'
            )

        if alternatives is not None:
            params["alternatives"] = convert._convert_bool(alternatives)