Skip to main content

RoutingServiceClient

Struct RoutingServiceClient 

Source
pub struct RoutingServiceClient<'a> { /* private fields */ }
Expand description

Client for interacting with an ArcGIS Routing Service (Network Analyst Server).

Provides operations for routing, service areas, closest facility, and origin-destination matrices.

§Example

use arcgis::{ApiKeyAuth, ArcGISClient, RoutingServiceClient};

let auth = ApiKeyAuth::new("YOUR_API_KEY");
let client = ArcGISClient::new(auth);

let routing_service = RoutingServiceClient::new(
    "https://route.arcgis.com/arcgis/rest/services/World/Route/NAServer/Route_World",
    &client,
);

Implementations§

Source§

impl<'a> RoutingServiceClient<'a>

Source

pub fn new(base_url: impl Into<String>, client: &'a ArcGISClient) -> Self

Creates a new Routing Service client.

§Arguments
  • base_url - The base URL of the routing service (e.g., https://route.arcgis.com/.../Route_World)
  • client - Reference to an authenticated ArcGIS client
§Example
use arcgis::{ApiKeyAuth, ArcGISClient, RoutingServiceClient};

let auth = ApiKeyAuth::new("YOUR_API_KEY");
let client = ArcGISClient::new(auth);
let routing_service = RoutingServiceClient::new(
    "https://route.arcgis.com/arcgis/rest/services/World/Route/NAServer/Route_World",
    &client
);
Source

pub async fn solve_route(&self, params: RouteParameters) -> Result<RouteResult>

Solves a route between multiple stops.

Calculates the optimal route connecting all stops, with options for turn-by-turn directions, barriers, and traffic-aware routing.

§Arguments
  • params - Route parameters including stops and routing options
§Example
use arcgis::{ApiKeyAuth, ArcGISClient, RoutingServiceClient, ArcGISPoint, ArcGISGeometry};
use arcgis::{RouteParameters, NALocation};

let auth = ApiKeyAuth::new("YOUR_API_KEY");
let client = ArcGISClient::new(auth);
let routing_service = RoutingServiceClient::new(
    "https://route.arcgis.com/arcgis/rest/services/World/Route/NAServer/Route_World",
    &client
);

let stop1 = NALocation::new(ArcGISGeometry::Point(ArcGISPoint {
    x: -122.4194,
    y: 37.7749,
    z: None,
    m: None,
    spatial_reference: None,
})).with_name("San Francisco");

let stop2 = NALocation::new(ArcGISGeometry::Point(ArcGISPoint {
    x: -118.2437,
    y: 34.0522,
    z: None,
    m: None,
    spatial_reference: None,
})).with_name("Los Angeles");

let params = RouteParameters::builder()
    .stops(vec![stop1, stop2])
    .return_directions(true)
    .return_routes(true)
    .return_stops(true)
    .build()
    .expect("Valid parameters");

let result = routing_service.solve_route(params).await?;
Source

pub async fn solve_service_area( &self, params: ServiceAreaParameters, ) -> Result<ServiceAreaResult>

Calculates service areas (drive-time or distance polygons).

Generates polygons showing areas reachable from facilities within specified break values (time or distance).

§Arguments
  • params - Service area parameters including facilities and break values
§Example
use arcgis::{ApiKeyAuth, ArcGISClient, RoutingServiceClient, ArcGISPoint, ArcGISGeometry};
use arcgis::{ServiceAreaParameters, NALocation};

let auth = ApiKeyAuth::new("YOUR_API_KEY");
let client = ArcGISClient::new(auth);
let routing_service = RoutingServiceClient::new(
    "https://route.arcgis.com/arcgis/rest/services/World/ServiceAreas/NAServer/ServiceArea_World",
    &client
);

let facility = NALocation::new(ArcGISGeometry::Point(ArcGISPoint {
    x: -122.4194,
    y: 37.7749,
    z: None,
    m: None,
    spatial_reference: None,
})).with_name("Store");

let params = ServiceAreaParameters::builder()
    .facilities(vec![facility])
    .default_breaks(vec![5.0, 10.0, 15.0])  // 5, 10, 15 minute drive times
    .build()
    .expect("Valid parameters");

let result = routing_service.solve_service_area(params).await?;
Source

pub async fn solve_closest_facility( &self, params: ClosestFacilityParameters, ) -> Result<ClosestFacilityResult>

Finds the closest facilities from incidents.

Calculates routes from incidents to the N nearest facilities, useful for emergency response, service allocation, etc.

§Arguments
  • params - Closest facility parameters including incidents and facilities
§Example
use arcgis::{ApiKeyAuth, ArcGISClient, RoutingServiceClient, ArcGISPoint, ArcGISGeometry};
use arcgis::{ClosestFacilityParameters, NALocation};

let auth = ApiKeyAuth::new("YOUR_API_KEY");
let client = ArcGISClient::new(auth);
let routing_service = RoutingServiceClient::new(
    "https://route.arcgis.com/arcgis/rest/services/World/ClosestFacility/NAServer/ClosestFacility_World",
    &client
);

let incident = NALocation::new(ArcGISGeometry::Point(ArcGISPoint {
    x: -122.4194,
    y: 37.7749,
    z: None,
    m: None,
    spatial_reference: None,
})).with_name("Emergency");

let facility = NALocation::new(ArcGISGeometry::Point(ArcGISPoint {
    x: -122.4,
    y: 37.8,
    z: None,
    m: None,
    spatial_reference: None,
})).with_name("Hospital");

let params = ClosestFacilityParameters::builder()
    .incidents(vec![incident])
    .facilities(vec![facility])
    .default_target_facility_count(1)
    .return_routes(true)
    .build()
    .expect("Valid parameters");

let result = routing_service.solve_closest_facility(params).await?;
Source

pub async fn generate_od_cost_matrix( &self, params: ODCostMatrixParameters, ) -> Result<ODCostMatrixResult>

Generates an origin-destination cost matrix.

Calculates travel costs between all origin-destination pairs, useful for logistics, fleet management, and coverage analysis.

§Arguments
  • params - OD cost matrix parameters including origins and destinations
§Example
use arcgis::{ApiKeyAuth, ArcGISClient, RoutingServiceClient, ArcGISPoint, ArcGISGeometry};
use arcgis::{ODCostMatrixParameters, NALocation};

let auth = ApiKeyAuth::new("YOUR_API_KEY");
let client = ArcGISClient::new(auth);
let routing_service = RoutingServiceClient::new(
    "https://route.arcgis.com/arcgis/rest/services/World/OriginDestinationCostMatrix/NAServer/OriginDestinationCostMatrix_World",
    &client
);

let origin = NALocation::new(ArcGISGeometry::Point(ArcGISPoint {
    x: -122.4194,
    y: 37.7749,
    z: None,
    m: None,
    spatial_reference: None,
})).with_name("Warehouse");

let destination = NALocation::new(ArcGISGeometry::Point(ArcGISPoint {
    x: -118.2437,
    y: 34.0522,
    z: None,
    m: None,
    spatial_reference: None,
})).with_name("Customer");

let params = ODCostMatrixParameters::builder()
    .origins(vec![origin])
    .destinations(vec![destination])
    .build()
    .expect("Valid parameters");

let result = routing_service.generate_od_cost_matrix(params).await?;

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> PolicyExt for T
where T: ?Sized,

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more