//Set the sampling size for one or all of the layers in the map //The sampling size determines how many messages are factored into the message rate calculation. //For instance a sampling size of 500 will store the times the last 500 messages were received. //The message rate is calculated as the (oldest timestamp - current time) / number of messages private void SetSampleSize() { try { int samplingSize = Convert.ToInt32(txtSampleSize.Text); ITemporalLayer temporalLayer = GetSelectedTemporalLayer(); if (temporalLayer == null) { if (m_amsWorkspaceFactory == null) { m_amsWorkspaceFactory = new AMSWorkspaceFactoryClass(); } //Get the AMS Workspace Factory Statistics interface ITemporalWorkspaceStatistics temporalWsfStatistics = (ITemporalWorkspaceStatistics)m_amsWorkspaceFactory; temporalWsfStatistics.SetAllSampleSizes(samplingSize); } else { ITemporalFeatureClassStatistics temporalFCStats = (ITemporalFeatureClassStatistics)((IFeatureLayer)temporalLayer).FeatureClass; temporalFCStats.SampleSize = samplingSize; } } catch (Exception ex) { statusBarXY.Text = ex.Message; } }
//Reset the statistic's message rate for one or all of the layers in the map private void btnResetMsgRate_Click(object sender, EventArgs e) { try { ITemporalLayer temporalLayer = GetSelectedTemporalLayer(); if (temporalLayer == null) { if (m_amsWorkspaceFactory == null) { m_amsWorkspaceFactory = new AMSWorkspaceFactoryClass(); } //Get the AMS Workspace Factory Statistics interface ITemporalWorkspaceStatistics temporalWsfStatistics = (ITemporalWorkspaceStatistics)m_amsWorkspaceFactory; temporalWsfStatistics.ResetAllMessageRates(); } else { ITemporalFeatureClassStatistics temporalFCStats = (ITemporalFeatureClassStatistics)((IFeatureLayer)temporalLayer).FeatureClass; temporalFCStats.ResetMessageRate(); } } catch (Exception ex) { statusBarXY.Text = ex.Message; } }
private void setupLayerLabels(ITemporalLayer trackingLayer, string labelField) { //cast TrackingLayerLabels from the temporal layer ITrackingLayerLabels layerLabels = (ITrackingLayerLabels)trackingLayer; //set the labels properties layerLabels.LabelFieldName = labelField; layerLabels.LabelFeatures = true; // create text symbol ITextSymbol textSymbol = new TextSymbolClass(); textSymbol.Color = (IColor)Converter.ToRGBColor(Color.Red); textSymbol.Size = 15; textSymbol.Font = Converter.ToStdFont(new Font(new FontFamily("Arial"), 15.0f, FontStyle.Regular)); textSymbol.HorizontalAlignment = esriTextHorizontalAlignment.esriTHARight; textSymbol.VerticalAlignment = esriTextVerticalAlignment.esriTVABaseline; layerLabels.TextSymbol = textSymbol; }
//Get the tracking layer that is selected in the combo box according to its name private ITemporalLayer GetSelectedTemporalLayer() { ITemporalLayer temporalLayer = null; if (cbTrackingServices.SelectedIndex > 0) { ILayer lyr = null; IEnumLayer temporalLayers = GetAllTrackingLayers(); string selectedLayerName = cbTrackingServices.Text; while ((lyr = temporalLayers.Next()) != null) { if (lyr.Name == selectedLayerName) { temporalLayer = (ITemporalLayer)lyr; } } } return(temporalLayer); }
private void RefreshStatistics() { try { ITemporalLayer temporalLayer = GetSelectedTemporalLayer(); //If a temporal layer is selected in the combo box only update that layer's stats if (temporalLayer == null) { RefreshAllStatistics(); } else { RefreshLayerStatistics(temporalLayer.Name, (ITemporalFeatureClassStatistics)((IFeatureLayer)temporalLayer).FeatureClass); } } catch (Exception ex) { statusBarXY.Text = ex.Message; } }
protected override void OnClick() { if (!m_bIsConnected) { try { //open the shapefile with the recorded data IFeatureClass featureClass = openPlaybackData(); if (null == featureClass) { return; } //get the map container object mapObj = ArcMap.Application; //load the Tracking Analyst extension ITrackingEnvironment3 trackingEnv = setupTrackingEnv(ref mapObj); //set the mode to historic, since you need to do playback trackingEnv.DefaultTemporalReference.TemporalMode = enumTemporalMode.enumHistoric; //set the units of the temporal period to days trackingEnv.DefaultTemporalReference.TemporalPeriodUnits = enumTemporalUnits.enumDays; //set the update mode to manual so that it will be controlled by the application trackingEnv.DisplayManager.ManualUpdate = true; //set the temporal perspective to Aug 03 2000 7PM. trackingEnv.DefaultTemporalReference.TemporalPerspective = "8/3/2000 7:0:00 PM"; // Stop using the map's time to allow the layer to draw based on it's TemporalPerspective ITimeData timeData = m_temporalLayer as ITimeData; timeData.UseTime = false; //create a temporal operator that will serve as a base time for the tracking environment ITemporalOperator3 temporalOpBaseTime = new TemporalOperatorClass() as ITemporalOperator3; //set the base time to 6PM, Aug 3 2000 temporalOpBaseTime.SetDateTime(2000, 8, 3, 18, 0, 0, 0); //create the renderer for the temporal layer ITemporalRenderer temporalRenderer = setRenderer(featureClass, "DATE_TIME", "EVENTID"); //create the temporal layer for the playback data m_temporalLayer = new TemporalFeatureLayerClass(); //assign the featureclass for the layer ((IFeatureLayer)m_temporalLayer).FeatureClass = featureClass; //set the base time to initialize the time window of the layer m_temporalLayer.RelativeTimeOperator = (ITemporalOperator)temporalOpBaseTime; //set the renderer for the temporal layer m_temporalLayer.Renderer = temporalRenderer as IFeatureRenderer; //set the flag in order to display the track of previous locations m_temporalLayer.DisplayOnlyLastKnownEvent = false; //initialize labels for the event name setupLayerLabels(m_temporalLayer, "EVENTID"); m_activeView = ArcMap.Document.ActiveView; m_temporalEnv = trackingEnv; m_baseTime = temporalOpBaseTime; //add the temporal layer to the map ArcMap.Document.FocusMap.AddLayer((ILayer)m_temporalLayer); //enable the timer m_timer.Enabled = true; } catch (Exception ex) { System.Diagnostics.Trace.WriteLine(ex.Message); } } else { //disable the timer m_timer.Enabled = false; if (null == m_temporalLayer) { return; } //remove the layer ArcMap.Document.FocusMap.DeleteLayer((ILayer)m_temporalLayer); m_temporalLayer = null; } m_bIsConnected = !m_bIsConnected; m_docEvent = ArcMap.Document as IDocumentEvents_Event; m_docEvent.CloseDocument += new IDocumentEvents_CloseDocumentEventHandler(docEvent_CloseDocument); ArcMap.Application.CurrentTool = null; }
protected override void OnClick() { if (!m_bIsConnected) { try { //open the shapefile with the recorded data IFeatureClass featureClass = openPlaybackData(); if (null == featureClass) return; //get the map container object mapObj = ArcMap.Application; //load the Tracking Analyst extension ITrackingEnvironment3 trackingEnv = setupTrackingEnv(ref mapObj); //set the mode to historic, since you need to do playback trackingEnv.DefaultTemporalReference.TemporalMode = enumTemporalMode.enumHistoric; //set the units of the temporal period to days trackingEnv.DefaultTemporalReference.TemporalPeriodUnits = enumTemporalUnits.enumDays; //set the update mode to manual so that it will be controlled by the application trackingEnv.DisplayManager.ManualUpdate = true; //set the temporal perspective to Aug 03 2000 7PM. trackingEnv.DefaultTemporalReference.TemporalPerspective = "8/3/2000 7:0:00 PM"; // Stop using the map's time to allow the layer to draw based on it's TemporalPerspective ITimeData timeData = m_temporalLayer as ITimeData; timeData.UseTime = false; //create a temporal operator that will serve as a base time for the tracking environment ITemporalOperator3 temporalOpBaseTime = new TemporalOperatorClass() as ITemporalOperator3; //set the base time to 6PM, Aug 3 2000 temporalOpBaseTime.SetDateTime(2000, 8, 3, 18, 0, 0, 0); //create the renderer for the temporal layer ITemporalRenderer temporalRenderer = setRenderer(featureClass, "DATE_TIME", "EVENTID"); //create the temporal layer for the playback data m_temporalLayer = new TemporalFeatureLayerClass(); //assign the featureclass for the layer ((IFeatureLayer)m_temporalLayer).FeatureClass = featureClass; //set the base time to initialize the time window of the layer m_temporalLayer.RelativeTimeOperator = (ITemporalOperator)temporalOpBaseTime; //set the renderer for the temporal layer m_temporalLayer.Renderer = temporalRenderer as IFeatureRenderer; //set the flag in order to display the track of previous locations m_temporalLayer.DisplayOnlyLastKnownEvent = false; //initialize labels for the event name setupLayerLabels(m_temporalLayer, "EVENTID"); m_activeView = ArcMap.Document.ActiveView; m_temporalEnv = trackingEnv; m_baseTime = temporalOpBaseTime; //add the temporal layer to the map ArcMap.Document.FocusMap.AddLayer((ILayer)m_temporalLayer); //enable the timer m_timer.Enabled = true; } catch (Exception ex) { System.Diagnostics.Trace.WriteLine(ex.Message); } } else { //disable the timer m_timer.Enabled = false; if (null == m_temporalLayer) return; //remove the layer ArcMap.Document.FocusMap.DeleteLayer((ILayer)m_temporalLayer); m_temporalLayer = null; } m_bIsConnected = !m_bIsConnected; m_docEvent = ArcMap.Document as IDocumentEvents_Event; m_docEvent.CloseDocument += new IDocumentEvents_CloseDocumentEventHandler(docEvent_CloseDocument); ArcMap.Application.CurrentTool = null; }