How to connect to ArcGIS Tracking Server


Summary The Tracking Analyst extension for ArcGIS can play back recorded temporal data or track real-time feeds served by a tracking server. This topic shows how to connect to a tracking server and use a temporal layer to draw the data.

In this topic


Connecting to ArcGIS Tracking Server

Consuming real-time data using Tracking Server is done through a temporal layer. Once you establish the connection to the Tracking Server and get the workspace from the Tracking Server, you can open any available tracking service as a feature class. Once you assign the feature class to a temporal layer and set its renderer, you can load it in your map and let the Tracking Server update the items as long as the tracking environment's display manager is set to automatic mode.
To connect to ArcGIS Tracking Server, follow these steps:
  1. Create a PropertySet and define the connection properties. For more information on Tracking Server connection properties, see AMSWorkspaceFactoryClass. See the following code example:
[C#]
IPropertySet propSet = new PropertySetClass();
propSet.SetProperty("SERVERNAME", "the name of the server");
propSet.SetProperty("AMS_CONNECTOR_EDITOR", "{1C6BA545-2F59-11D5-B7E2-00010265ADC5}")
    ;
propSet.SetProperty("AMS_CONNECTION_NAME", "the name of the connection");
propSet.SetProperty("AMS_CONNECTOR", "{F6FC70F5-5778-11D6-B841-00010265ADC5}");
propSet.SetProperty("AMS_USER_NAME", "add your username");
propSet.SetProperty("TMS_USER_PWD", "add your password here");
propSet.SetProperty("CONNECTOR_PORT", "5506");
[VB.NET]
Dim propSet As IPropertySet
propSet = New PropertySetClass()
propSet.SetProperty("SERVERNAME", "the name of the server")
propSet.SetProperty("AMS_CONNECTOR_EDITOR", "{1C6BA545-2F59-11D5-B7E2-00010265ADC5}")
propSet.SetProperty("AMS_CONNECTION_NAME", "the name of the connection")
propSet.SetProperty("AMS_CONNECTOR", "{F6FC70F5-5778-11D6-B841-00010265ADC5}")
propSet.SetProperty("AMS_USER_NAME", "add your username")
propSet.SetProperty("TMS_USER_PWD", "add your password here")
propSet.SetProperty("CONNECTOR_PORT", "5506")
  1. Create the WorkspaceFactory and open the workspace as shown in the following code example:
[C#]
IWorkspaceFactory2 workspaceFactory = new AMSWorkspaceFactoryClass()as
    IWorkspaceFactory2;
IWorkspace workspace = workspaceFactory.Open(propSet, 0);
[VB.NET]
Dim workspaceFactory As IWorkspaceFactory2
workspaceFactory = New AMSWorkspaceFactoryClass()
Dim workspace As IWorkspace
workspace = workspaceFactory.Open(propSet, 0)
  1. Open the service; the service is opened as a feature class. See the following code example:
[C#]
IAMSWorkspace amsWorkspace = (IAMSWorkspace)workspace;
IFeatureClass featureClass = amsWorkspace.OpenFeatureClass(
    "The name of the service goes here");
[VB.NET]
Dim amsWorkspace As IAMSWorkspace
amsWorkspace = workspace
Dim featureClass As IFeatureClass
featureClass = amsWorkspace.OpenFeatureClass("The name of the service goes here")

Creating the renderer for the tracking service

In this section, you will instantiate a TrackSymbologyRenderer class, set the name of the temporal field that holds the temporal data in the tracking service, then create the renderer used to symbolize your data in the map.
There are different types of renderers that you can set for your tracking data; for example, you can set a UniqueValueRenderer to symbolize the most current items (items that were recently updated), set a renderer for the trail to display the previous locations of the tracked data, set a labeling renderer, and so on. For more information on assigning renderers to tracking data, see CoTrackSymbologyRendererClass and Play back tracking data.
To create the renderer for the tracking service, follow these steps:
  1. Instantiate the TrackSymbologyRenderer class as shown in the following code example:
[C#]
CoTrackSymbologyRenderer trackingRenderer = new CoTrackSymbologyRendererClass();
[VB.NET]
Dim trackingRenderer As CoTrackSymbologyRenderer
trackingRenderer = New CoTrackSymbologyRendererClass()
  1. Cast TrackSymbologyRenderer into ITemporalRenderer and set the temporal field name. See the following code example:
[C#]
ITemporalRenderer temporalRenderer = (ITemporalRenderer)trackingRenderer;
temporalRenderer.TemporalFieldName = 
    "set the name of the temporal field on the tracking service";
[VB.NET]
Dim temporalRenderer As ITemporalRenderer
temporalRenderer = trackingRenderer
temporalRenderer.TemporalFieldName = "set the name of the temporal field on the tracking service"
  1. Set a new private method to create a simple renderer for the feed. In the following code example, you will create a simple renderer to symbolize only the most current items. However, you can also create other types of renderers, such as UniqueValueRenderer, UniqueValueTextRenderer, and ProportionalSymbolRenderer. Scroll down to the bottom of your class and add the following private method:
[C#]
/// <summary>
/// Creates a simple renderer to be used by the layer.
/// </summary>
/// <returns></returns>
private ISimpleRenderer CreateSimpleRenderer(){}
[VB.NET]
'''<summary>
''' Creates a simple renderer to be used by the layer.
'''</summary>
''' <returns></returns>

Private Function CreateSimpleRenderer()
    
End Function
  1. In the following method, you will create color to be used by the renderer as well as a character marker symbol that will serve as the symbol for the renderer. See the following code example:
[C#]
IRgbColor color = new RgbColorClass();
color.Red = 255;
color.Green = 0;
color.Blue = 0;
[VB.NET]
Dim color As IRgbColor
color = New RgbColorClass()
color.Red = 255
color.Green = 0
color.Blue = 0
  1. Create the character marker symbol used to symbolize the real-time items. Use the Application Developer Framework (ADF) converter to convert the .NET font into IFontDisp. See the following code example:
[C#]
ICharacterMarkerSymbol charMarkersymbol = new CharacterMarkerSymbolClass();
charMarkersymbol.Font = ESRI.ArcGIS.ADF.Connection.Local.Converter.ToStdFont(new
    Font(new FontFamily("ESRI Default Marker"), 10.0f));
charMarkersymbol.CharacterIndex = 111;
charMarkersymbol.Size = 14.0;
charMarkersymbol.Color = (IColor)color;
[VB.NET]
Dim charMarkersymbol As ICharacterMarkerSymbol
charMarkersymbol = New CharacterMarkerSymbolClass()
Dim font As Font
font = New Font(New FontFamily("ESRI Default Marker"), 10.0F)
charMarkersymbol.Font = ESRI.ArcGIS.ADF.Connection.Local.Converter.ToStdFont(font)
charMarkersymbol.CharacterIndex = 111
charMarkersymbol.Size = 14.0
charMarkersymbol.Color = color
  1. Instantiate a new SimpleRenderer and assign it the character marker symbol created in the previous step. See the following code example:
[C#]
ISimpleRenderer simpleRenderer = new SimpleRendererClass();
simpleRenderer.Label = "Airplane";
simpleRenderer.Symbol = (ISymbol)charMarkersymbol;
[VB.NET]
Dim simpleRenderer As ISimpleRenderer
simpleRenderer = New SimpleRendererClass()
simpleRenderer.Label = "Airplane"
simpleRenderer.Symbol = charMarkersymbol
  1. Return the newly created renderer as shown in the following code example:
[C#]
return simpleRenderer;
[VB.NET]
CreateSimpleRenderer = simpleRenderer
  1. Scroll back to where you cast ITemporalRenderer (Step 2 in this section) and use the CreateSimpleRenderer() method to create the renderer used by the temporal layer. See the following code example:
[C#]
ISimpleRenderer simpleRenderer = CreateSimpleRenderer();
[VB.NET]
Dim simpleRenderer As ISimpleRenderer
simpleRenderer = CreateSimpleRenderer()
  1. To orient the real-time items according to their true heading, use the rotational renderer. To use the rotational renderer, you need a heading attribute as part of your tracking service. Cast the rotational renderer from the simple renderer or any other renderer that you are using. See the following code example:
[C#]
IRotationRenderer rotationRenderer = (IRotationRenderer)simpleRenderer;
rotationRenderer.RotationField = "set the heading field name here";
rotationRenderer.RotationType = esriSymbolRotationType.esriRotateSymbolGeographic;
[VB.NET]
Dim rotationRenderer As IRotationRenderer
rotationRenderer = simpleRenderer
rotationRenderer.RotationField = "set the heading field name here"
rotationRenderer.RotationType = esriSymbolRotationType.esriRotateSymbolGeographic
  1. Assign the simple renderer as the layer's most current element renderer. This means that the layer will draw the items that were recently updated using this renderer. See the following code example:
[C#]
((ITemporalRenderer2)temporalRenderer).MostCurrentRenderer = (IFeatureRenderer)
    simpleRenderer;
((ITemporalRenderer2)temporalRenderer).MostCurrentRendererEnabled = true;
[VB.NET]
Dim temporalRenderer2 As ITemporalRenderer2
temporalRenderer2 = temporalRenderer
temporalRenderer2.MostCurrentRenderer = simpleRenderer
temporalRenderer2.MostCurrentRendererEnabled = True

Loading the Tracking Analyst extension

To load the temporal layers to your map, you must load and enable the Tracking Analyst extension. In the following code example, you will use IExtensionManagerAdmin to create the extension and initialize it by passing the map container (MapControl or ArcMap). For that reason, you will first need to obtain the map from the HookHelper.
To load the Tracking Analyst extension, follow these steps:
  1. Get the map from the HookHelper as shown in the following code example:
[C#]
object mapObj = null;
if (m_hookHelper.Hook is IToolbarControl2)
{
    IToolbarControl2 toolbarCtrl = (IToolbarControl2)m_hookHelper.Hook;
    mapObj = toolbarCtrl.Buddy;
}

else
{
    mapObj = m_hookHelper.Hook;
}
[VB.NET]
Dim mapObj
mapObj = My.ArcMap.Application
  1. Create a unique identifier (UID) using the Tracking Engine utility extension's ProgID. See the following code example:
[C#]
UID uid = new UIDClass();
uid.Value = "esriTrackingAnalyst.TrackingEngineUtil";
[VB.NET]
Dim uid As UID
uid = New UIDClass()
uid.Value = "esriTrackingAnalyst.TrackingEngineUtil"
  1. Get a reference to ExtensionManager. ExtensionManager is a singleton object that allows you to enable licensed extensions. See Interacting with singleton objects for details, as well as the following code example:
[C#]
IExtensionManager extensionManager = new ExtensionManagerClass();
[VB.NET]
Dim extensionManager As IExtensionManager
extensionManager = New ExtensionManagerClass()
  1. Add and initialize the Tracking Analyst extension as shown in the following code example:
[C#]
((IExtensionManagerAdmin)extensionManager).AddExtension(uid, ref mapObj);
[VB.NET]
Dim extensionManagerAdmin As IExtensionManagerAdmin
extensionManagerAdmin = extensionManager
extensionManagerAdmin.AddExtension(uid, mapObj)

Initializing the tracking environment

TrackingEnvironment is a singleton object that controls configuration and state information used by the different Tracking Analyst objects. By using the TrackingEnvironment object, you specify whether to work in playback mode or in real-time mode, use default temporal reference for common perspective in time between tracking components, and so on.
 
To initialize the tracking environment, follow these steps:
  1. Get a reference for the tracking environment as shown in the following code example:
[C#]
ITrackingEnvironment trackingEnv = new TrackingEnvironmentClass();
[VB.NET]
Dim trackingEnv As ITrackingEnvironment
trackingEnv = New TrackingEnvironmentClass()
  1. Initialize the tracking environment as shown in the following code example:
[C#]
trackingEnv.Initialize(ref mapObj);
[VB.NET]
trackingEnv.Initialize(mapObj)
  1. Set the temporal mode to real time as shown in the following code example:
[C#]
trackingEnv.DefaultTemporalReference.TemporalMode = enumTemporalMode.enumRealTime;
[VB.NET]
trackingEnv.DefaultTemporalReference.TemporalMode = enumTemporalMode.enumRealTime
  1. Set the update mode to automatic. This means that the visible time stamp and the update of the display are controlled by the tracking service. See the following code example:
[C#]
trackingEnv.DisplayManager.ManualUpdate = false;
[VB.NET]
trackingEnv.DisplayManager.ManualUpdate = False
  1. Set the refresh rate to one second as shown in the following code example:
[C#]
trackingEnv.DisplayManager.RefreshRate = 1.0;
[VB.NET]
trackingEnv.DisplayManager.RefreshRate = 1.0

Creating the temporal layer and hooking it with the service

In this section, you will create a new instance of a temporal layer, assign the service and the renderer to the layer, then add the layer to the map.
  1. Create the temporal layer as shown in the following code example:
[C#]
ITemporalLayer temporalLayer = new TemporalFeatureLayerClass();
[VB.NET]
Dim temporalLayer As ITemporalLayer
temporalLayer = New TemporalFeatureLayerClass()
  1. Assign the tracking service to the temporal layer. Since you are keeping the service as a feature class, assign it to the layer as another feature layer. See the following code example:
[C#]
((IFeatureLayer)temporalLayer).FeatureClass = featureClass
[VB.NET]
Dim featureLayer As IFeatureLayer
featureLayer = temporalLayer
featureLayer.FeatureClass = featureClass
  1. Set the renderer for the layer as shown in the following code example:
[C#]
temporalLayer.Renderer = temporalRenderer as IFeatureRenderer;
[VB.NET]
temporalLayer.Renderer = temporalRenderer
  1. Set the layer so that it only displays the last item's location to prevent it from drawing a trail of previous locations. See the following code example:
[C#]
temporalLayer.DisplayOnlyLastKnownEvent = true;
[VB.NET]
temporalLayer.DisplayOnlyLastKnownEvent = True
  1. Add the layer to the map as shown in the following code example:
[C#]
m_hookHelper.FocusMap.AddLayer((ILayer)temporalLayer);
[VB.NET]
My.ArcMap.Document.FocusMap.AddLayer(temporalLayer)


See Also:

Sample: Play back tracking data
Interacting with singleton objects




Development licensing Deployment licensing
Engine Developer Kit Engine Runtime: Tracking
ArcView: Tracking Analyst ArcView: Tracking Analyst
ArcEditor: Tracking Analyst ArcEditor: Tracking Analyst
ArcInfo: Tracking Analyst ArcInfo: Tracking Analyst