-
Notifications
You must be signed in to change notification settings - Fork 120
ProSnippets LinearReferencing
UmaHarano edited this page Nov 6, 2024
·
1 revision
Language: C#
Subject: LinearReferencing
Contributor: ArcGIS Pro SDK Team <arcgisprosdk@esri.com>
Organization: esri, http://www.esri.com
Date: 10/22/2024
ArcGIS Pro: 3.4
Visual Studio: 2022
.NET Target Framework: .Net 8
public void CreateRoutes(SchemaBuilder schemaBuilder)
{
FieldDescription routeIdDescription = FieldDescription.CreateIntegerField("RouteID");
FieldDescription routeNameDescription = FieldDescription.CreateStringField("RouteName", 100);
ShapeDescription shapeDescription = new ShapeDescription(GeometryType.Polyline, SpatialReferences.WGS84) { HasM = true, HasZ = false };
FeatureClassDescription routeFeatureClassDescription = new FeatureClassDescription("Routes", new List<FieldDescription>() { routeIdDescription, routeNameDescription }, shapeDescription);
//Create an M-enabled poly-line feature class
schemaBuilder.Create(routeFeatureClassDescription);
schemaBuilder.Build();
}
public void CreateEvents(SchemaBuilder schemaBuilder)
{
FieldDescription routeIdDescription = FieldDescription.CreateIntegerField("RID");
FieldDescription measureFieldDescription = new FieldDescription("Measure", FieldType.Double);
FieldDescription offsetFieldDescription = FieldDescription.CreateIntegerField("OffsetValue");
TableDescription eventTableDescription = new TableDescription("LR_EventTable", new List<FieldDescription>() { routeIdDescription, offsetFieldDescription, measureFieldDescription });
schemaBuilder.Create(eventTableDescription);
schemaBuilder.Build();
}
public void CreateRouteInfo(Geodatabase geodatabase, string routeFeatureClassName = "Roads", string routeIdFieldName = "RouteID")
{
using (FeatureClass routeFeatureClass = geodatabase.OpenDataset<FeatureClass>(routeFeatureClassName))
using (FeatureClassDefinition routeFeatureClassDefinition = routeFeatureClass.GetDefinition())
{
if (routeFeatureClassDefinition.HasM())
{
RouteInfo routeInfo = new RouteInfo(routeFeatureClass, routeIdFieldName);
}
}
}
public void CreateEventInfo(Geodatabase geodatabase, string eventTableName = "Accidents", string routeIdFieldName = "RID", string measureFieldName = "Measure", string offsetFieldName = "Offset")
{
using (Table eventTable = geodatabase.OpenDataset<Table>(eventTableName))
{
PointEventInfo eventInfo = new PointEventInfo(eventTable, routeIdFieldName, measureFieldName, offsetFieldName);
// Get event type: Point or Line type
EventType eventTableType = eventInfo.EventType;
}
}
public void CreatePointEventSource(Geodatabase geodatabase, string routeFeatureClassName = "Roads", string eventTableName = "Accidents", string routeIdFieldName = "RID", string measureFieldName = "Measure")
{
using (FeatureClass routesFeatureClass = geodatabase.OpenDataset<FeatureClass>(routeFeatureClassName))
using (Table eventsTable = geodatabase.OpenDataset<Table>(eventTableName))
{
RouteInfo routeInfo = new RouteInfo(routesFeatureClass, routeIdFieldName);
EventInfo eventInfo = new PointEventInfo(eventsTable, routeIdFieldName, measureFieldName);
RouteEventSourceOptions routeEventSourceOptions = new PointEventSourceOptions(AngleType.Tangent) { ComplementAngle = true };
using (RouteEventSource routeEventSource = new RouteEventSource(routeInfo, eventInfo, routeEventSourceOptions))
using (RouteEventSourceDefinition routeEventSourceDefinition = routeEventSource.GetDefinition())
{
// Locating errors
IReadOnlyList<RouteEventSourceError> errors = routeEventSource.GetErrors();
// Route event source fields
IReadOnlyList<Field> routeEventSourceFields = routeEventSourceDefinition.GetFields();
// Add RouteEventSource to the ArcGIS Pro map
FeatureLayerCreationParams layerParams = new FeatureLayerCreationParams(routeEventSource)
{
Name = "RoadAccidents"
};
LayerFactory.Instance.CreateLayer<FeatureLayer>(layerParams, MapView.Active.Map);
}
}
}
public void CreateLineEventSource(Geodatabase geodatabase, string routeFeatureClassName = "Roads", string eventTableName = "Accidents", string routeIdFieldName = "RID", string toMeasureFieldName = "toMeasure", string fromMeasureFieldName = "fromMeasure", string offsetFieldName = "Offset")
{
using (FeatureClass routesFeatureClass = geodatabase.OpenDataset<FeatureClass>(routeFeatureClassName))
using (Table eventsTable = geodatabase.OpenDataset<Table>(eventTableName))
{
RouteInfo routeInfo = new RouteInfo(routesFeatureClass, routeIdFieldName);
EventInfo eventInfo = new LineEventInfo(eventsTable, routeIdFieldName, fromMeasureFieldName, toMeasureFieldName, offsetFieldName);
RouteEventSourceOptions routeEventSourceOptions = new LineEventSourceOptions() { IsPositiveOffsetOnRight = true };
using (RouteEventSource routeEventSource = new RouteEventSource(routeInfo, eventInfo, routeEventSourceOptions))
using (RouteEventSourceDefinition routeEventSourceDefinition = routeEventSource.GetDefinition())
{
// Locating errors
IReadOnlyList<RouteEventSourceError> errors = routeEventSource.GetErrors();
// Route event source fields
IReadOnlyList<Field> routeEventSourceFields = routeEventSourceDefinition.GetFields();
// Add RouteEventSource to the ArcGIS Pro map
FeatureLayerCreationParams layerParams = new FeatureLayerCreationParams(routeEventSource)
{
Name = "HighCrashAreas"
};
LayerFactory.Instance.CreateLayer<FeatureLayer>(layerParams, MapView.Active.Map);
}
}
}
public void LocateLineFeaturesAlongRoutes(Geodatabase geodatabase, string routeFeatureClassName = "Roads", string eventTableName = "Accidents", string routeIdFieldName = "RID", string toMeasureFieldName = "toMeasure", string fromMeasureFieldName = "fromMeasure")
{
// Configure events table
EventTableConfiguration lineEventTableConfiguration = new LineEventTableConfiguration(eventTableName, routeIdFieldName, fromMeasureFieldName, toMeasureFieldName) { KeepAllFields = true, MDirectionOffset = true };
using (FeatureClass routeFeatureClass = geodatabase.OpenDataset<FeatureClass>(routeFeatureClassName))
using (FeatureClass highCrashAreaFeatureClass = geodatabase.OpenDataset<FeatureClass>("HighCrashRegion"))
{
RouteInfo routeInfo = new RouteInfo(routeFeatureClass, routeIdFieldName);
// Creates an event table inside the geodatabase
routeInfo.LocateFeatures(highCrashAreaFeatureClass, 0.5, lineEventTableConfiguration);
// Open newly created event table
using (Table eventTable = geodatabase.OpenDataset<Table>(eventTableName))
{
EventInfo eventInfo = new LineEventInfo(eventTable, routeIdFieldName, fromMeasureFieldName, toMeasureFieldName);
// Create RouteEventSource using new event table
using (RouteEventSource routeEventSource = new RouteEventSource(routeInfo, eventInfo, new LineEventSourceOptions()))
{
// Use the RouteEventSource object
}
}
}
}
Home | API Reference | Requirements | Download | Samples
-
Create a routes feature class using the DDL
-
Create an events table using the DDL
-
Get route information from a polyline feature class with M-values
-
Get event information
-
Create a RouteEventSource via dynamic segmentation process for point events
-
Create a RouteEventSource via dynamic segmentation process for line events
-
Locate features along routes