How to use the routingpy.convert 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_convert.py View on Github external
def test_delimit_list(self):

        l = [(8.68864, 49.42058), (8.68092, 49.41578)]
        s = convert._delimit_list([convert._delimit_list(pair, ',') for pair in l], '|')
        self.assertEqual(s, "8.68864,49.42058|8.68092,49.41578")
github gis-ops / routing-py / tests / test_convert.py View on Github external
def test_delimit_list_error(self):

        falses = ['8', 8, {'a': 'b', 3: 'a', 4: 4}]
        for f in falses:
            with self.assertRaises(TypeError):
                convert._delimit_list(f)
github gis-ops / routing-py / tests / test_mapbox_osrm.py View on Github external
def test_few_sources_destinations_matrix(self):
        query = deepcopy(ENDPOINTS_QUERIES[self.name]['matrix'])
        coords = convert._delimit_list([convert._delimit_list(pair) for pair in query['locations']], ';')

        query['sources'] = [1, 2]
        query['destinations'] = [0, 2]

        responses.add(
            responses.GET,
            'https://api.mapbox.com/directions-matrix/v1/mapbox/{}/{}'.format(query['profile'], coords),
            status=200,
            json=ENDPOINTS_RESPONSES['mapbox_osrm']['matrix'],
            content_type='application/json'
        )

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

        self.assertEqual(1, len(responses.calls))
        self.assertURLEqual(
github gis-ops / routing-py / tests / test_osrm.py View on Github external
def test_full_directions_alternatives(self):
        query = ENDPOINTS_QUERIES[self.name]['directions']
        coords = convert._delimit_list([convert._delimit_list(pair) for pair in query['locations']], ';')

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

        routes = self.client.directions(**query)
        self.assertEqual(1, len(responses.calls))
        self.assertURLEqual(
            'https://router.project-osrm.org/route/v1/car/8.688641,49.420577;8.680916,49.415776;8.780916,49.445776?'
            'alternatives=true&annotations=true&bearings=50%2C50%3B50%2C50%3B50%2C50&continue_straight=true&'
            'geometries=geojson&overview=simplified&radiuses=500%3B500%3B500&steps=true',
            responses.calls[0].request.url
github gis-ops / routing-py / tests / test_mapbox_osrm.py View on Github external
def test_full_isochrones(self):
        query = ENDPOINTS_QUERIES[self.name]['isochrones']

        responses.add(
            responses.GET,
            'https://api.mapbox.com/isochrone/v1/{}/{}'.format(
                query["profile"],
                convert._delimit_list(query["locations"]),
            ),
            status=200,
            json=ENDPOINTS_RESPONSES[self.name]['isochrones'],
            content_type='application/json'
        )

        iso = self.client.isochrones(**query)

        self.assertEqual(1, len(responses.calls))
        self.assertURLEqual(
            'https://api.mapbox.com/isochrone/v1/mapbox/driving/8.34234,48.23424?costing=mapbox/driving&access_token=sample_key&'
            'contours_colors=ff0000%2C00FF00&contours_minutes=10%2C20&denoise=0.1&generalize=0.5&polygons=True',
            responses.calls[0].request.url
        )
        self.assertIsInstance(iso, Isochrones)
        self.assertEqual(2, len(iso))
github gis-ops / routing-py / routingpy / routers / osrm.py View on Github external
:param geometries: Returned route geometry format (influences overview and per step). One of ["polyline",
            "polyline6", "geojson". Default polyline.
        :type geometries: str

        :param overview: Add overview geometry either full, simplified according to highest zoom level
            it could be display on, or not at all. One of ["simplified", "full", "false", False]. Default simplified.
        :type overview: str

        :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 = dict()

        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)
github gis-ops / routing-py / routingpy / routers / graphhopper.py View on Github external
:param alternative_route_max_share_factor: If algorithm=alternative_route this parameter specifies how much alternatives
            routes can have maximum in common with the optimal route. Increasing can lead to worse alternatives.
            Default 0.6.
        :type alternative_route_max_share_factor: 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`
        """

        params = [('vehicle', profile)]

        for coordinate in locations:
            coord_latlng = reversed([convert._format_float(f) for f in coordinate])
            params.append(("point", ",".join(coord_latlng)))

        if self.key is not None:
            params.append(("key", self.key))

        if format is not None:
            params.append(("type", format))

        if optimize is not None:
            params.append(("optimize", convert._convert_bool(optimize)))

        if instructions is not None:
            params.append(("instructions", convert._convert_bool(instructions)))

        if locale is not None:
            params.append(("locale", locale))
github gis-ops / routing-py / routingpy / routers / google.py View on Github external
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, '|')

        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, '|')
github gis-ops / routing-py / routingpy / routers / heremaps.py View on Github external
def _build_locations(self, coordinates, matrix=False):
        """Build the locations object for all methods"""

        locations = []

        # Directions and matrix calls which are lists of list
        if isinstance(coordinates[0], (list, tuple, self.Waypoint)):

            for idx, coord in enumerate(coordinates):
                if isinstance(locations, self.Waypoint):
                    locations.append(locations._make_waypoint())
                elif isinstance(locations, (list, tuple)):
                    wp = 'geo!' + convert._delimit_list(
                        [convert._format_float(f) for f in list(reversed(coord))], ','
                    )
                    locations.append(wp)
                else:
                    raise TypeError(
                        "Location type {} at index {} is not supported: {}".format(
                            type(coord), idx, coord
                        )
                    )

        # Isochrones
        elif isinstance(coordinates[0], float):
            center = 'geo!' + convert._delimit_list(
                [convert._format_float(f) for f in list(reversed(coordinates))], ','
            )
            locations.append(center)