Hi community,
I'm relatively new to the Linear Referencing stuff, but now diving in the deep sea.
I have the below legacy ArcObjects code from a project to locate events along a route feature class and generate the according geometry (point, line, or center point of the line).
It seems quite straightforward in ArcObjects: initialising a RouteLocator, create a RouteMeasureLineLocationClass or RouteMeasureLineLocationClass which has "measure" property(s) to configure, then use the RouteLocater to locate. It is also flexible as the "measure" property can be calculated from multiple fields, and location error can be easily output.
However, it does not seem a straight process for me in ArcGIS Pro SDK? Seeking everyone's help here to guide me what Pro SDK classes and functions should I look to replicate this process? If Pro SDK not sufficient, what Python functions should I look at?
ArcObjects SDK code snippet:
// Open the route feature class
// Opens a feature class that contains the route features (lines representing linear routes).
IFeatureClass routeFC = sourceFeatureWorkspace.OpenFeatureClass(setting.RouteFeatureClass);
// Set route locator properties
// Create a dataset reference to the route feature class and get its name
IDataset dS = (IDataset)routeFC;
IName name = dS.FullName;
// Initialize a RouteMeasureLocatorName object to configure the route locator
IRouteLocatorName rtLocatorName = new RouteMeasureLocatorNameClass();
rtLocatorName.RouteFeatureClassName = name; // Set the route feature class name
rtLocatorName.RouteIDFieldName = setting.RouteIdField; // Field representing unique route IDs
rtLocatorName.RouteMeasureUnit = esriUnits.esriMeters; // Specify the unit for measures (e.g., meters)
// Create the RouteLocator2 object
name = (IName)rtLocatorName;
IRouteLocator2 rtLocator = (IRouteLocator2)name.Open();
IRouteLocation routeLocation = null; // Generic route location object
// Based on some condition checking, there are three cases below
// CASE 1: Create a point location on the route using a specific measure value
routeLocation = new RouteMeasurePointLocationClass();
IRouteMeasurePointLocation rMPointLoc = (IRouteMeasurePointLocation)routeLocation;
rMPointLoc.Measure = measureValue; // Assign the measure value
// CASE 2: Create a center point location for a line event
routeLocation = new RouteMeasurePointLocationClass();
IRouteMeasurePointLocation rMPointLoc = (IRouteMeasurePointLocation)routeLocation;
rMPointLoc.Measure = Math.Abs(toMeasureValue - fromMeasureValue); // Center point based on event range
// CASE 3: Create a line location for a route event
routeLocation = new RouteMeasureLineLocationClass();
IRouteMeasureLineLocation rMLineLoc = (IRouteMeasureLineLocation)routeLocation;
rMLineLoc.FromMeasure = fromMeasureValue; // Start measure of the line
rMLineLoc.ToMeasure = toMeasureValue; // End measure of the line
// Common properties for route locations
routeLocation.MeasureUnit = esriUnits.esriMeters; // Set unit of measure
routeLocation.RouteID = linearRefIdValue; // Route ID for locating the event
routeLocation.LateralOffset = offsetValue; // Lateral offset from the route (optional)
// Locate the event and retrieve the geometry
esriLocatingError locError;
rtLocator.Locate(routeLocation, out geometry, out locError);
// Error handling for locating issues
if (locError != esriLocatingError.LOCATING_OK)
{
throw new RecoverableException(String.Format(
"Can't convert linear to spatial for record with {0} = {1}: {2}",
keyName, keyValue, GetLocatingErrorMessage(locError)));
}
Solved! Go to Solution.
Hi,
Update:
In the end, I've chosen to shell out a Python script to use arcpy to handle linear referencing related function instead of using the built-in Pro SDK API.
It is because I've found it very hard to use the dynamic feature class generated from the dynamic segmentation. Although the documentation has given an example to add RouteEventSource to the ArcGIS Pro map, it is not the case for me as I am building a corehost application which means I cannot directly interact with map. However, I can use arcpy to save a copy of the dynamic feature class for my further usage.
Thanks for all the suggestion above.
Hi @anbinh, in addition to @GKmieliauskas, please consult the Linear Referencing conceptual doc on accessing the route feature class and locating features along the routes.
The Geometry Engine API provides advanced functionality to manipulate the polylines with m-values.
Hi,
Update:
In the end, I've chosen to shell out a Python script to use arcpy to handle linear referencing related function instead of using the built-in Pro SDK API.
It is because I've found it very hard to use the dynamic feature class generated from the dynamic segmentation. Although the documentation has given an example to add RouteEventSource to the ArcGIS Pro map, it is not the case for me as I am building a corehost application which means I cannot directly interact with map. However, I can use arcpy to save a copy of the dynamic feature class for my further usage.
Thanks for all the suggestion above.