publicvoidCreateRoutes(SchemaBuilderschemaBuilder){FieldDescriptionrouteIdDescription=FieldDescription.CreateIntegerField("RouteID");FieldDescriptionrouteNameDescription=FieldDescription.CreateStringField("RouteName",100);ShapeDescriptionshapeDescription=newShapeDescription(GeometryType.Polyline,SpatialReferences.WGS84){HasM=true,HasZ=false};FeatureClassDescriptionrouteFeatureClassDescription=newFeatureClassDescription("Routes",newList<FieldDescription>(){routeIdDescription,routeNameDescription},shapeDescription);//Create an M-enabled poly-line feature class schemaBuilder.Create(routeFeatureClassDescription);schemaBuilder.Build();}
publicvoidCreateEventInfo(Geodatabasegeodatabase,stringeventTableName="Accidents",stringrouteIdFieldName="RID",stringmeasureFieldName="Measure",stringoffsetFieldName="Offset"){using(TableeventTable=geodatabase.OpenDataset<Table>(eventTableName)){PointEventInfoeventInfo=newPointEventInfo(eventTable,routeIdFieldName,measureFieldName,offsetFieldName);// Get event type: Point or Line typeEventTypeeventTableType=eventInfo.EventType;}}
Create a RouteEventSource via dynamic segmentation process for point events
publicvoidCreatePointEventSource(Geodatabasegeodatabase,stringrouteFeatureClassName="Roads",stringeventTableName="Accidents",stringrouteIdFieldName="RID",stringmeasureFieldName="Measure"){using(FeatureClassroutesFeatureClass=geodatabase.OpenDataset<FeatureClass>(routeFeatureClassName))using(TableeventsTable=geodatabase.OpenDataset<Table>(eventTableName)){RouteInforouteInfo=newRouteInfo(routesFeatureClass,routeIdFieldName);EventInfoeventInfo=newPointEventInfo(eventsTable,routeIdFieldName,measureFieldName);RouteEventSourceOptionsrouteEventSourceOptions=newPointEventSourceOptions(AngleType.Tangent){ComplementAngle=true};using(RouteEventSourcerouteEventSource=newRouteEventSource(routeInfo,eventInfo,routeEventSourceOptions))using(RouteEventSourceDefinitionrouteEventSourceDefinition=routeEventSource.GetDefinition()){// Locating errors IReadOnlyList<RouteEventSourceError>errors=routeEventSource.GetErrors();// Route event source fields IReadOnlyList<Field>routeEventSourceFields=routeEventSourceDefinition.GetFields();// Add RouteEventSource to the ArcGIS Pro mapFeatureLayerCreationParamslayerParams=newFeatureLayerCreationParams(routeEventSource){Name="RoadAccidents"};LayerFactory.Instance.CreateLayer<FeatureLayer>(layerParams,MapView.Active.Map);}}}
Create a RouteEventSource via dynamic segmentation process for line events
publicvoidCreateLineEventSource(Geodatabasegeodatabase,stringrouteFeatureClassName="Roads",stringeventTableName="Accidents",stringrouteIdFieldName="RID",stringtoMeasureFieldName="toMeasure",stringfromMeasureFieldName="fromMeasure",stringoffsetFieldName="Offset"){using(FeatureClassroutesFeatureClass=geodatabase.OpenDataset<FeatureClass>(routeFeatureClassName))using(TableeventsTable=geodatabase.OpenDataset<Table>(eventTableName)){RouteInforouteInfo=newRouteInfo(routesFeatureClass,routeIdFieldName);EventInfoeventInfo=newLineEventInfo(eventsTable,routeIdFieldName,fromMeasureFieldName,toMeasureFieldName,offsetFieldName);RouteEventSourceOptionsrouteEventSourceOptions=newLineEventSourceOptions(){IsPositiveOffsetOnRight=true};using(RouteEventSourcerouteEventSource=newRouteEventSource(routeInfo,eventInfo,routeEventSourceOptions))using(RouteEventSourceDefinitionrouteEventSourceDefinition=routeEventSource.GetDefinition()){// Locating errors IReadOnlyList<RouteEventSourceError>errors=routeEventSource.GetErrors();// Route event source fields IReadOnlyList<Field>routeEventSourceFields=routeEventSourceDefinition.GetFields();// Add RouteEventSource to the ArcGIS Pro mapFeatureLayerCreationParamslayerParams=newFeatureLayerCreationParams(routeEventSource){Name="HighCrashAreas"};LayerFactory.Instance.CreateLayer<FeatureLayer>(layerParams,MapView.Active.Map);}}}
Locate features along routes
publicvoidLocateLineFeaturesAlongRoutes(Geodatabasegeodatabase,stringrouteFeatureClassName="Roads",stringeventTableName="Accidents",stringrouteIdFieldName="RID",stringtoMeasureFieldName="toMeasure",stringfromMeasureFieldName="fromMeasure"){// Configure events tableEventTableConfigurationlineEventTableConfiguration=newLineEventTableConfiguration(eventTableName,routeIdFieldName,fromMeasureFieldName,toMeasureFieldName){KeepAllFields=true,MDirectionOffset=true};using(FeatureClassrouteFeatureClass=geodatabase.OpenDataset<FeatureClass>(routeFeatureClassName))using(FeatureClasshighCrashAreaFeatureClass=geodatabase.OpenDataset<FeatureClass>("HighCrashRegion")){RouteInforouteInfo=newRouteInfo(routeFeatureClass,routeIdFieldName);// Creates an event table inside the geodatabaserouteInfo.LocateFeatures(highCrashAreaFeatureClass,0.5,lineEventTableConfiguration);// Open newly created event tableusing(TableeventTable=geodatabase.OpenDataset<Table>(eventTableName)){EventInfoeventInfo=newLineEventInfo(eventTable,routeIdFieldName,fromMeasureFieldName,toMeasureFieldName);// Create RouteEventSource using new event tableusing(RouteEventSourcerouteEventSource=newRouteEventSource(routeInfo,eventInfo,newLineEventSourceOptions())){// Use the RouteEventSource object }}}}