Considering a given Combined Transport
This article discusses the use case of routing A route corresponds to a path of a vehicle through the underlying transport network. The main attributes of a route are the distance and the time that the vehicle travels along the path. with combined transport The combined transport is a form of transport where the vehicle in question does not drive itself but is transported by a boat or by rail (piggyback).. Combined transport is a form of intermodal transport, where vehicles The term vehicle describes what is being routed or planned for. Vehicles are used in route calculation, distance matrix calculation and effectively also in tour planning. In route calculation, vehicle properties like overall size, weight and speed are in focus. In tour planning, it is vehicle properties like capacity and availability. Commonly a vehicle is motorized, like a truck - including its trailer or a car. However also a bike or even a pedestrian are included in this definition. are transported by ferries or trains. PTV xRoute offers the possibility to calculate a route that will inevitably take a desired combined transport.
Benefits
Thanks to this feature, the user can plan a route knowing that he will pass through this combined transport. This can be used, for example, by a company that has an agreement with a ferry operator.
Prerequisites
Check if the following prerequisites are fulfilled before you start with the use case.
- Installed and licensed PTV xRoute, xData and xMap services.
Programming Guide
To force the route to go through a specific combined transport, the user can use the CombinedTransportViaWaypoint. This kind of waypoint A waypoint is a geographic location used to specify start, destination and possible stopovers for a route. can only be a via waypoint (it can not be a start or destination). It has no coordinates, the desired connection is identified using its combinedTransportId. To retrieve the combinedTransportId, we can use the PTV xData service with a getSegment operation.
There are 3 possibilities to request the segments: SegmentsByCoordinateRequest, SegmentsByIntersectingPolylineRequest and SegmentsBySurroundingPolygonRequest.
For example, a user wants to have all combined transport that start from Bristol, near Providence in the USA. He can perform a SegmentsBySurroundingPolygonRequest with segment option includedSegmentTypes to filter only COMBINED_TRANSPORT segment type.
const colors = ['#455AD9','#9c0c0c']; let outputString = ''; let bottomLeft = { "x": -71.28496170043947, "y": 41.66137072301873 }; let bottomRight = { "x": -71.26676559448244, "y": 41.66137072301873 }; let topRight = { "x": -71.26676559448244, "y": 41.67663017666532 }; let topLeft = { "x": -71.28496170043947, "y": 41.67663017666532 }; let map = new L.Map('map', { center: [41.6200623030133, -71.30796432495119], zoom: 12 }); // Add tile layer to map let tileUrl = xServerUrl + '/services/rest/XMap/tile/{z}/{x}/{y}'; let tileLayer = new L.TileLayer(tileUrl, { minZoom: 3, maxZoom: 18, noWrap: true }).addTo(map); function getSegments() { xdata.getSegments({ "$type": "SegmentsBySurroundingPolygonRequest", "polygon": { "plain": { "$type": "Polygon", "polygonRings": [{ "polyline": [bottomLeft, bottomRight, topRight, topLeft ] }] } }, "resultFields": { "combinedTransport": true, "descriptors": true, "polyline": true }, "segmentsOptions": { "includedSegmentTypes": ["COMBINED_TRANSPORT"] }, "geometryOptions": { "responseGeometryTypes": ["GEOJSON"] } }, function(segmentResponse, exception) { for (var i = 0; i < segmentResponse.segments.length; ++i) { displayGeoJson(segmentResponse.segments[i].polyline.geoJSON, colors[i], 5); outputString += `${segmentResponse.segments[i].combinedTransport.name}, `; } print(outputString); }); }; function displayGeoJson(geoJson, color, weight) { var jsonObject = JSON.parse(geoJson); var geoJsonLayer = new L.GeoJSON(jsonObject, { style: { color: color, weight: weight } }).addTo(map); }; new L.Polygon([ [bottomLeft.y, bottomLeft.x], [bottomRight.y, bottomRight.x], [topRight.y, topRight.x], [topLeft.y, topLeft.x] ]).addTo(map); getSegments();Once the combined transports identifiers have been retrieved using the PTV xData, the user can use one of them in a CombinedTransportViaWaypoint. For example, a user located in Providence wants his itinerary to always take the ferry that goes from Bristol to Prudence Island.
let outputString = ''; let map = new L.Map('map', { center: [41.64302894794068, -71.29354476928712], zoom: 12 }); // Add tile layer to map let tileUrl = xServerUrl + '/services/rest/XMap/tile/{z}/{x}/{y}'; let tileLayer = new L.TileLayer(tileUrl, { minZoom: 3, maxZoom: 18, noWrap: true }).addTo(map); let combinedTransportId = "SEGM000274c5a4c7v6PFAeoSAeY72m4o4CTyYUuwNcABR9Mckhs2yGGBUQ74Js5bAP8l8mAB0SWsGjfII8FtCoht8Ucg/TX2egnAAJkeJPpCgFEC+ynwUzn1D+RXJfAHhTZtjBLaeT+yeuZ1HuV6nFYJwgfGTjOrT9loIuoNzwg99BE="; let start = { "x": -71.25938415527345, "y": 41.673424709209556 }; let destination = { "x": -71.31929397583009, "y": 41.611720434791025 }; let combinedTransportLocation = { "x": -71.278392879, "y": 41.668480221 }; function calculateRoute() { xroute.calculateRoute({ "waypoints": [{ "$type": "OffRoadWaypoint", "location": { "offRoadCoordinate": start } }, { "$type": "CombinedTransportViaWaypoint", "combinedTransportId": combinedTransportId, }, { "$type": "OffRoadWaypoint", "location": { "offRoadCoordinate": destination } }], "resultFields": { "waypoints": true, "polyline": true }, "geometryOptions": { "responseGeometryTypes": ["GEOJSON"] } }, function(route, exception) { displayGeoJson(route.polyline.geoJSON, '#9c0c0c', 5); outputString = `travelTime (s): ${route.travelTime}, distance (m): ${route.distance}`; print(outputString); }); }; function displayGeoJson(geoJson, color, weight) { var jsonObject = JSON.parse(geoJson); var geoJsonLayer = new L.GeoJSON(jsonObject, { style: { color: color, weight: weight } }).addTo(map); }; new L.Marker([destination.y, destination.x]).addTo(map); new L.Marker([start.y, start.x]).addTo(map); new L.Marker([combinedTransportLocation.y, combinedTransportLocation.x]).addTo(map); calculateRoute();Besides, to customize the combined transport handling, the user can modify the boatPenalty field in the routing profile A profile is a collection of parameters used to configure the request. Full profiles consist of a number of specialized sub-profiles like the VehicleProfile which describes the properties of a vehicle..