Ejemplo n.º 1
0
def test_truck_route():
    """Test routing API for truck route."""
    ls = LS(api_key=LS_API_KEY)
    truck = Truck(
        shipped_hazardous_goods=[SHIPPED_HAZARDOUS_GOODS.explosive],
        gross_weight=100,
        weight_per_axle=10,
        height=10,
        width=10,
        length=10,
        tunnel_category="B",
        axle_count=4,
    )
    avoid_areas = [
        AvoidBoundingBox(68.1766451354, 7.96553477623, 97.4025614766,
                         35.4940095078)
    ]
    avoid_features = [ROUTING_AVOID_FEATURES.tollRoad]
    _ = ls.truck_route(
        origin=[52.51375, 13.42462],
        destination=[52.52332, 13.42800],
        via=[(52.52426, 13.43000)],
        return_results=[ROUTING_RETURN.polyline, ROUTING_RETURN.elevation],
        departure_time=datetime.now(),
        spans=[ROUTING_SPANS.names],
        truck=truck,
        avoid_areas=avoid_areas,
        avoid_features=avoid_features,
        exclude=["IND", "NZL", "AUS"],
    )
Ejemplo n.º 2
0
def route(
    ctx,
    transport_mode,
    origin,
    destination,
    via,
    routing_mode,
    alternatives,
    lang,
    apikey,
    raw,
    display,
):
    """
    find route between two or more locations.
    """
    apikey = apikey or os.environ.get("HERE_APIKEY")
    if apikey is None:
        raise ApiKeyNotFoundError(
            "Please pass HERE API KEY as --apikey or set it as environment "
            "variable in HERE_APIKEY "
        )
    ctx.obj["apikey"] = apikey
    ls = LS(api_key=apikey)
    if transport_mode == "car":
        result = ls.car_route(
            origin=origin.split(","),
            destination=destination.split(","),
            via=via if via else None,
            routing_mode=routing_mode,
            alternatives=alternatives,
            lang=lang,
            return_results=[
                ROUTING_RETURN.polyline,
                ROUTING_RETURN.elevation,
                ROUTING_RETURN.instructions,
                ROUTING_RETURN.actions,
            ],
        )
    elif transport_mode == "truck":
        result = ls.truck_route(
            origin=origin.split(","),
            destination=destination.split(","),
            via=via if via else None,
            routing_mode=routing_mode,
            alternatives=alternatives,
            lang=lang,
            return_results=[
                ROUTING_RETURN.polyline,
                ROUTING_RETURN.elevation,
                ROUTING_RETURN.instructions,
                ROUTING_RETURN.actions,
            ],
        )
    elif transport_mode == "pedestrian":
        result = ls.pedestrian_route(
            origin=origin.split(","),
            destination=destination.split(","),
            via=via if via else None,
            routing_mode=routing_mode,
            alternatives=alternatives,
            lang=lang,
            return_results=[
                ROUTING_RETURN.polyline,
                ROUTING_RETURN.elevation,
                ROUTING_RETURN.instructions,
                ROUTING_RETURN.actions,
            ],
        )
    elif transport_mode == "bicycle":
        result = ls.bicycle_route(
            origin=origin.split(","),
            destination=destination.split(","),
            via=via if via else None,
            routing_mode=routing_mode,
            alternatives=alternatives,
            lang=lang,
            return_results=[
                ROUTING_RETURN.polyline,
                ROUTING_RETURN.elevation,
                ROUTING_RETURN.instructions,
                ROUTING_RETURN.actions,
            ],
        )
    elif transport_mode == "scooter":
        result = ls.scooter_route(
            origin=origin.split(","),
            destination=destination.split(","),
            via=via if via else None,
            routing_mode=routing_mode,
            alternatives=alternatives,
            lang=lang,
            return_results=[
                ROUTING_RETURN.polyline,
                ROUTING_RETURN.elevation,
                ROUTING_RETURN.instructions,
                ROUTING_RETURN.actions,
            ],
        )
    if raw:
        click.secho(json.dumps(result.response, indent=2), fg="green")
    elif display:
        geo_display(json.dumps(result.to_geojson(), indent=2))
    else:
        click.secho(json.dumps(result.routes, indent=2), fg="green")