Click or drag to resize

ITrafficSource Interface

Verizon Connect Logo
Print this page
Learn more about Verizon Connect GeoBase.
Get information about the latest release
Implemented to resolve a given TMC code and DateTime to a TrafficInfo.

Namespace:  Telogis.GeoBase.Traffic
Assembly:  geobase.net (in geobase.net.dll) Version: 4.99.0.0
Syntax
public interface ITrafficSource : IGenericTrafficSource

The ITrafficSource type exposes the following members.

Properties
  NameDescription
Public propertyCreatedTime
The DateTime when the traffic data was created.
Top
Methods
  NameDescription
Public methodGetTrafficInfo(String, DateTime)
Implemented by derived classes to resolve a given TMC and DateTime to a TrafficInfo.
Public methodGetTrafficInfo(String, DateTime, TimeZone)
Implemented by derived classes to resolve a given TMC code and DateTime to a TrafficInfo.
Top
Remarks

The ITrafficSource interface is implemented to resolve a given TMC (Traffic Message Channel) code and DateTime to a TrafficInfo. A Traffic object will have one or more traffic sources which will be implemented with the ITrafficSource interface. GeoBase provides classes with implementations of this interface in support of the following traffic data:

  • INRIX - incident, predictive, real
  • HERE - incident, predictive, real
For more information, see:

Additional traffic data sources can be added with the ITrafficSource interface. The interface exposes the GetTrafficInfo method, and the CreatedTime property. To implement this interface, code must be provided for both GetTrafficInfo, and CreatedTime.

CreatedTime - gets DateTime when the traffic data was created.

GetTrafficInfo - this method returns the TrafficInfo for the given TMC code at the specified DateTime. The speed can be found from the traffic source data by searching for the given TMC code with the given time, and then extracting the speed from the found TMC code.

Related articles: Routing with Traffic.

Examples
C#
class MyTrafficSource : ITrafficSource {
   private DateTime createdTime;
   private Dictionary<string, int> speeds;


   //Constructor
   public MyTrafficSource(string src) {
          speeds = new Dictionary<string, int>();

          // Populate speeds with traffic information from "src"
          LoadTrafficFile(src);
   }

   // Fill in createdTime and speeds based on the contents of src.
   private void LoadTrafficFile(string src) {    
           // Set createdTime from a timestamp contained within src    
           createdTime = ...    

           // Scan through remainder of src, populating speeds as we go.
           ...
   }

   //ITrafficSource members
   public TrafficInfo GetTrafficInfo(string tmc, DateTime time) {
          return GetTrafficInfo(tmc, time, null);
   }

   //Get TrafficInfo for the specified TMC code and time
   public TrafficInfo GetTrafficInfo(string tmc, DateTime time, Telogis.GeoBase.TimeZone? timezone) {
      int speed;

      if (timezone != null) {
          time = ((Telogis.GeoBase.TimeZone)timezone).ConvertTime(time);
      }

      //Check if data is still valid  
      if (createdTime.AddMinutes(15) < time) {
          return null;
      }

      if (speeds.TryGetValue(tmc, out speed)) {
          return new TrafficInfo(speed);
      }

      return null;
   }

   public DateTime CreatedTime {
      get { return createdTime; }
   }
}
See Also