Click or drag to resize

Avoiding a Given Area

Verizon Connect Logo
Print this page
Learn more about Verizon Connect GeoBase.
Get information about the latest release
Overview

In many instances it may be undesirable for a vehicle to be routed through a certain area (for example, a courier may be restricted to only traveling within a certain 'zone', or hazardous waste may not be permitted to travel through a residential area).

In this section of the routing tutorial we will use classes within the Telogis.GeoBase.GeoFence namespace to 'fence off' a geographical area.

Using a GeoFence for Route Exclusion

Our example route starts at 17927 San Fernando Mission Boulevard and ends at 16567 Chatsworth Street. Both addresses are in Granada Hills, Los Angeles (USA). A screenshot of GeoBase's default route is shown below in green. We will create a GeoFence to exclude the area bounded by Index Street, Balboa Boulevard, Chatsworth Street and Louise Avenue (as shown in red).

routing exclusion 1

The following code segment creates three objects: a GeoFenceCollection, a RectangleGeoFence and a BoundingBox. The bounding box is created by geocoding the street addresses on two opposite corners of the exclusion area.

C#
/* define variables */
GeoFenceCollection allMyFences = new GeoFenceCollection();
RectangleFence myFence = new RectangleFence();
BoundingBox myBox = new BoundingBox();

/* add corner points to bounding box */
myBox.Add(GeoCoder.GeoCode("Louise & Chatsworth, Granada Hills, Los Angeles", Country.USA)[0].Location);
myBox.Add(GeoCoder.GeoCode("Balboa & Index, Granada Hills, Los Angeles", Country.USA)[0].Location);

/* add box to fence, and fence to collection */
myFence.Box = myBox; 
allMyFences.Add(myFence);

Now that the GeoFence has been defined we can instruct the routing engine to avoid the defined area:

C#
/* instruct our route to exclude the area in allMyFences */
myRoute.Strategy.KeepOut = allMyFences;
Note Note

A route can have only one KeepOut area (of type GeoFence). However by using a GeoFenceCollection we may define multiple exclusion areas for each route. Even if only one exclusion area is originally defined, it is still a good idea to use a GeoFenceCollection as it allows other exclusion areas to be easily added at a later stage.

After defining the keep-out area for the route the GeoBase routing engine creates the following route:

routing exclusion 2

Note Note

To fully exclude Chatsworth Street from our route we could increase the size of the bounding box to include addresses on the south side of Chatsworth Street (that is, inflate the bounding box to contain 1780 Chatsworth Street).

Note Note

In certain circumstances, it may be necessary to call IRoute.ForceRecalculate after making changes to VehicleSpec or RoutingStrategy. See ForceRecalculate for more details.

Next Topic