| Products: ArcView: VBA Platforms: WindowsRequires: ArcEditor at 9.0; ArcView at 9.1 Minimum ArcGIS Release: 9.0 |
Public SubAddLineEventLayer()'+++ VBA code that shows how to add a line RouteEventSource as a layer in the MapOn Error GoToeh'+++ Get the event table. It is called 'pavement'.DimpMxDocAsIMxDocumentDimpTblCollAsITableCollectionDimpEventTableAsITableDimiAs Long DimpMapAsIMapDimpDSAsIDatasetSetpMxDoc = ThisDocumentSetpMap = pMxDoc.FocusMapSetpTblColl = pMapFori = 0TopTblColl.TableCount - 1SetpDS = pTblColl.Table(i)IfLCase(pDS.BrowseName) = "pavement"Then SetpEventTable = pDSExit For End If NextiIfpEventTableIs Nothing ThenMsgBox "Could not find event table", vbExclamation, "AddLineEventLayer"Exit Sub End If'+++ Get the route feature class. It is called 'roads_route_hwy'.DimpLayerAsILayerDimpFLayerAsIFeatureLayerDimpRouteFcAsIFeatureClassFori = 0TopMap.LayerCount - 1SetpLayer = pMap.Layer(i)IfLCase(pLayer.Name) = "roads_route_hwy"Then If TypeOfpLayerIsIFeatureLayerThen SetpFLayer = pLayerSetpRouteFc = pFLayer.FeatureClassExit For End If End If NextiIfpRouteFcIs Nothing ThenMsgBox "Could not find the route feature class", vbExclamation, "AddLineEventLayer"Exit Sub End If'+++ Create the route event source ...'+++ The route locatorDimpNameAsINameDimpRMLNameAsIRouteLocatorNameSetpDS = pRouteFcSetpName = pDS.FullNameSetpRMLName =NewRouteMeasureLocatorNameWithpRMLNameSet.RouteFeatureClassName = pName .RouteIDFieldName = "rkey" .RouteIDIsUnique =True.RouteMeasureUnit = esriUnknownUnits'.RouteWhereClause = ""End With'+++ Create the route event properties'+++ We will be using IRouteEventProperties2 to take advantage of adding an error fieldDimpRtPropAsIRouteEventProperties2DimpRMLnPropAsIRouteMeasureLinePropertiesSetpRtProp =NewRouteMeasureLinePropertiesWithpRtProp .EventMeasureUnit = esriUnknownUnits .EventRouteIDFieldName = "rkey"'.LateralOffsetFieldName = "offset".AddErrorField =True'add field for locating errors.ErrorFieldName = "LOC_ERRORS"'specify name for the locating errors fieldEnd With SetpRMLnProp = pRtProp pRMLnProp.FromMeasureFieldName = "fmp" pRMLnProp.ToMeasureFieldName = "tmp"SetpDS = pEventTableSetpName = pDS.FullNameDimpRESNAsIRouteEventSourceNameSetpRESN =NewRouteEventSourceNameWithpRESNSet.EventTableName = pNameSet.EventProperties = pRMLnPropSet.RouteLocatorName = pRMLNameEnd With'+++ By opening a route event source name object, you have a 'dynamic''+++ feature class ...DimpEventFCAsIFeatureClassSetpName = pRESNSetpEventFC = pName.Open'+++ Create the layer and add it to the current mapDimpActiveAsIActiveViewSetpFLayer =NewFeatureLayerSetpFLayer.FeatureClass = pEventFC pFLayer.Name = pDS.BrowseName + "_Events"'+++ "Pavement_Events"pMap.AddLayer pFLayerSetpActive = pMxDoc.ActiveView pActive.RefreshExit Subeh:DimlNumAs Long, sDescAs String, sSrcAs StringlNum = Err.Number sDesc = Err.Description sSrc = Err.Source Err.Raise lNum, sSrc, sDescEnd Sub