public AddLineEvent
{
try
{
// Get the event table. It is called 'pavement'.
IMxDocument pMxDoc;
ITableCollection pTblColl;
ITable pEventTable = null;
IMap pMap;
IDataset pDS;
pMxDoc = (IMxDocument) m_app.Document;
pMap = (IMap) pMxDoc.FocusMap;
pTblColl = (ITableCollection) pMap;
for (int i = 0; i < pTblColl.TableCount; i++)
{
pDS = (IDataset) pTblColl.get_Table(i);
if (pDS.BrowseName.ToLower() == "pavement")
{
pEventTable = (ITable) pDS;
break;
}
}
if (pEventTable == null)
{
MessageBox.Show("Could not find the event table", "AddLineEventLayer", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
return;
}
// Get the route feature class. It is called 'roads_route_hwy'
ILayer pLayer;
IFeatureLayer pFLayer;
IFeatureClass pRouteFc = null;
for (int i = 0; i < pMap.LayerCount; i++)
{
pLayer = pMap.get_Layer(i);
if (pLayer.Name.ToLower() == "roads_route_hwy")
{
pFLayer = pLayer as IFeatureLayer;
if (pFLayer != null)
{
pRouteFc = (IFeatureClass) pFLayer.FeatureClass;
}
}
}
if (pRouteFc == null)
{
MessageBox.Show("Could not find the route feature class", "AddLineEventLayer", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
return;
}
// Create the route event source...
//The route locator
IName pName;
IRouteLocatorName pRMLName = new RouteMeasureLocatorNameClass();
pDS = (IDataset) pRouteFc;
pName = (IName) pDS.FullName;
pRMLName.RouteFeatureClassName = pName;
pRMLName.RouteIDFieldName = "rkey";
pRMLName.RouteIDIsUnique = true;
pRMLName.RouteMeasureUnit = 0; // esriUnknownUnit type
pRMLName.RouteWhereClause = "";
// Create the route event properties
// We will be using IRouteEventProperties2 to take advantage of adding an error field
IRouteEventProperties2 pRtProp = new RouteMeasureLinePropertiesClass();
IRouteMeasureLineProperties pRMLnProp;
pRtProp.EventMeasureUnit = 0; // esriUnknownUnit type
pRtProp.EventRouteIDFieldName = "rkey";
pRtProp.LateralOffsetFieldName = "offset";
pRtProp.AddErrorField = true; // add field for locating errors
pRtProp.ErrorFieldName = "LOC_ERRORS"; // specify name for the locating errors field
pRMLnProp = (IRouteMeasureLineProperties) pRtProp;
pRMLnProp.FromMeasureFieldName = "fmp";
pRMLnProp.ToMeasureFieldName = "tmp";
pDS = (IDataset) pEventTable;
pName = (IName) pDS.FullName;
IRouteEventSourceName pRESN = new RouteEventSourceNameClass();
pRESN.EventTableName = pName;
pRESN.EventProperties = (IRouteEventProperties) pRMLnProp;
pRESN.RouteLocatorName = pRMLName;
// By opening a route event source name object, you have a 'dynamic' feature class ...
IFeatureClass pEventFC;
pName = (IName) pRESN;
pEventFC = (IFeatureClass) pName.Open();
// Create the layer and add it to the current map
IActiveView pActive;
pFLayer = new FeatureLayerClass();
pFLayer.FeatureClass = pEventFC;
pFLayer.Name = pDS.BrowseName + "_Events"; // "Pavement_Events"
pMap.AddLayer(pFLayer);
pActive = (IActiveView) pMxDoc.ActiveView;
pActive.Refresh();
}
catch (COMException COMEx)
{
MessageBox.Show(COMEx.Message,"COM Error: " + COMEx.ErrorCode.ToString(),MessageBoxButtons.OK,MessageBoxIcon.Warning);
}
catch (System.Exception SysEx)
{
MessageBox.Show(SysEx.Message,".NET Error: ",MessageBoxButtons.OK,MessageBoxIcon.Warning);
}
}