Esempio 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"],
    )
def test_matrix_route():
    """Test Matrix routing."""
    ls = LS(api_key=LS_API_KEY)
    origins = [
        {"lat": 37.76, "lng": -122.42},
        {"lat": 40.63, "lng": -74.09},
        {"lat": 30.26, "lng": -97.74},
    ]
    region_definition = WorldRegion()
    matrix_attributes = [MATRIX_ATTRIBUTES.distances, MATRIX_ATTRIBUTES.travelTimes]
    avoid_areas = AvoidBoundingBox(68.1766451354, 7.96553477623, 97.4025614766, 35.4940095078)
    assert json.loads(avoid_areas.__str__()) == {
        "type": "boundingBox",
        "north": 68.1766451354,
        "south": 7.96553477623,
        "west": 97.4025614766,
        "east": 35.4940095078,
    }
    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,
    )
    result = ls.matrix(
        origins=origins,
        region_definition=region_definition,
        destinations=origins,
        routing_mode=ROUTING_MODE.fast,
        departure_time=datetime.now(tz=pytz.utc),
        transport_mode=ROUTING_TRANSPORT_MODE.truck,
        avoid_features=[AVOID_FEATURES.tollRoad],
        avoid_areas=[avoid_areas],
        truck=truck,
        matrix_attributes=matrix_attributes,
    )
    mat = result.matrix
    assert mat["numOrigins"] == 3
    assert mat["numDestinations"] == 3
    assert len(mat["distances"]) == 9

    profile = PROFILE.carShort
    result2 = ls.matrix(
        origins=origins,
        region_definition=region_definition,
        matrix_attributes=matrix_attributes,
        profile=profile,
    )
    mat2 = result2.matrix
    assert mat2["numOrigins"] == 3
    assert mat2["numDestinations"] == 3
    with pytest.raises(NotImplementedError):
        result2.to_geojson()
Esempio n. 3
0
def test_matrix_route_exception():
    """Test exceptions for Matrix routing."""
    ls = LS(api_key=LS_API_KEY)
    origins = [
        {
            "lat": 37.76,
            "lng": -122.42
        },
        {
            "lat": 40.63,
            "lng": -74.09
        },
        {
            "lat": 30.26,
            "lng": -97.74
        },
        {
            "lat": 40.63,
            "lng": -74.09
        },
    ]
    region_definition = CircleRegion(radius=1000,
                                     center={
                                         "lat": 37.76,
                                         "lng": -122.42
                                     })
    matrix_attributes = [
        MATRIX_ATTRIBUTES.distances, MATRIX_ATTRIBUTES.travelTimes
    ]
    profile = PROFILE.carFast
    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,
    )
    with pytest.raises(ValueError):
        ls.matrix(
            origins=origins,
            region_definition=region_definition,
            profile=profile,
            matrix_attributes=matrix_attributes,
        )

    with pytest.raises(ValueError):
        ls.matrix(
            origins=origins,
            region_definition=region_definition,
            matrix_attributes=matrix_attributes,
            transport_mode=ROUTING_TRANSPORT_MODE.car,
            truck=truck,
        )
Esempio n. 4
0
def test_matrix_route_async():
    """Test Matrix routing."""
    ls = LS(api_key=LS_API_KEY)
    origins = [
        {
            "lat": 37.76,
            "lng": -122.42
        },
        {
            "lat": 40.63,
            "lng": -74.09
        },
        {
            "lat": 30.26,
            "lng": -97.74
        },
    ]
    region_definition = WorldRegion()
    matrix_attributes = [
        MATRIX_ATTRIBUTES.distances, MATRIX_ATTRIBUTES.travelTimes
    ]
    avoid_areas = AvoidBoundingBox(68.1766451354, 7.96553477623, 97.4025614766,
                                   35.4940095078)
    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,
    )
    result = ls.matrix(
        origins=origins,
        region_definition=region_definition,
        async_req=True,
        destinations=origins,
        routing_mode=ROUTING_MODE.fast,
        departure_time="any",
        transport_mode=ROUTING_TRANSPORT_MODE.truck,
        avoid_features=[AVOID_FEATURES.tollRoad],
        avoid_areas=[avoid_areas],
        truck=truck,
        matrix_attributes=matrix_attributes,
    )
    mat = result.matrix
    assert mat["numOrigins"] == 3
    assert mat["numDestinations"] == 3
    assert len(mat["distances"]) == 9