I am using ArcGIS Pro 2.9.3 with the Location Referencing extension.
I am trying to create an LRS dataset so that I can start using the Location Referencing tab on the ribbon to edit routes. I have a line feature class (testFC) with fields for RouteID, FromMeasure and ToMeasure that I can easily create a route feature class from but that does not make the Location Referencing tab become available.
My test data is simple – see picture below:
I use the code below to create the test data above (testFC), an empty LRS dataset (testLRS), and an intermediate feature dataset (testFD) into which I've copied testFC as intermediateFC as well as the empty Calibration_Point and Redline feature classes from testLRS because they need to be there to use the Create LRS From Existing Dataset tool.
import arcpy
arcpy.env.overwriteOutput = True
# Create empty feature class and its schema
sr = arcpy.SpatialReference("GCS_WGS_1984")
arcpy.management.CreateFileGDB(r"C:\temp","test")
arcpy.management.CreateFeatureclass(r"C:\temp\test.gdb","testFC","POLYLINE")
arcpy.management.DefineProjection(r"C:\temp\test.gdb\testFC",sr)
arcpy.management.AddField(r"C:\temp\test.gdb\testFC","RouteID","LONG")
arcpy.management.AddField(r"C:\temp\test.gdb\testFC","FromMeasure","DOUBLE")
arcpy.management.AddField(r"C:\temp\test.gdb\testFC","ToMeasure","DOUBLE")
# Write two lines and their attributes to the feature class
cursor = arcpy.da.InsertCursor(r"C:\temp\test.gdb\testFC",["SHAPE@","RouteID","FromMeasure","ToMeasure"])
array = arcpy.Array([arcpy.Point(0.0,0.0),
arcpy.Point(0.0,1.0)])
polyline = arcpy.Polyline(array,sr)
cursor.insertRow([polyline,1,0.0,1.0])
array = arcpy.Array([arcpy.Point(0.0,1.0),
arcpy.Point(1.0,1.0)])
polyline = arcpy.Polyline(array,sr)
cursor.insertRow([polyline,2,1.0,2.0])
del cursor
# Create empty TestLRS dataset and TestLRSNetwork for testing, and copying schema from
# Create empty LRS dataset (TestLRS), with default names for three feature classes (Calibration_Point,Centerline,
# Redline) and an LRS Hierarchy (TestLRS) within it, and three tables (Centerline_Sequence, Lrs_Edit_Log,Lrs_Locks)
gdb = r"C:\temp\test.gdb"
if arcpy.Exists(r"{0}\{1}".format(gdb,"TestLRS")):
arcpy.management.Delete(r"{0}\{1}".format(gdb,"TestLRS"))
if arcpy.Exists(r"{0}\{1}".format(gdb,"Centerline_Sequence")):
arcpy.management.Delete(r"{0}\{1}".format(gdb,"Centerline_Sequence"))
if arcpy.Exists(r"{0}\{1}".format(gdb,"Lrs_Edit_Log")):
arcpy.management.Delete(r"{0}\{1}".format(gdb,"Lrs_Edit_Log"))
if arcpy.Exists(r"{0}\{1}".format(gdb,"Lrs_Locks")):
arcpy.management.Delete(r"{0}\{1}".format(gdb,"Lrs_Locks"))
if arcpy.Exists(r"{0}\{1}".format(gdb,"TestLRS")):
arcpy.management.Delete(r"{0}\{1}".format(gdb,"TestLRS"))
print("Creating LRS dataset named {0}".format("TestLRS"))
arcpy.locref.CreateLRS(gdb,"TestLRS","Centerline","Calibration_Point","Redline","Centerline_Sequence",sr,
"8.98315284119521E-09 DecimalDegrees","0.001 Meters",
"0.000000001 DecimalDegrees","0.0001 Meters")
print("Creating LRS Network ({0}) in LRS dataset ({1}".format("TestLRSNetwork","TestLRS"))
arcpy.locref.CreateLRSNetwork(gdb, "TestLRS", "TestLRSNetwork",
"RouteId", "RouteName", "FromDate", "ToDate", "DO_NOT_DERIVE", '',
"DO_NOT_INCLUDE", "LineId", "LineName", "LineOrder", "KILOMETERS")
print("Creating intermediate feature dataset")
arcpy.management.CreateFeatureDataset(gdb,"IntermediateFD")
arcpy.management.DefineProjection(r"{0}\{1}".format(gdb,"IntermediateFD"),sr)
print("Copying testFC into IntermediateFD as IntermediateCL")
arcpy.management.CopyFeatures(r"C:\temp\test.gdb\testFC",r"C:\temp\test.gdb\IntermediateFD\IntermediateFC")
emptyCalibrationFC = r"{0}\{1}\Calibration_Point".format(gdb,"TestLRS")
intermediateCalibrationFC = r"{0}\{1}\IntermediateCalibration".format(gdb,"IntermediateFD")
arcpy.management.CopyFeatures(emptyCalibrationFC,intermediateCalibrationFC)
emptyRoutelineFC = r"{0}\{1}\Redline".format(gdb,"TestLRS")
intermediateRoutelineFC = r"{0}\{1}\IntermediateRedline".format(gdb,"IntermediateFD")
arcpy.management.CopyFeatures(emptyRoutelineFC,intermediateRoutelineFC)
After running the code above my test.gdb looks like this:
I think I now have what is needed to create a FinalLRS using the Create LRS From Existing Dataset tool but when I start to use them to populate its parameters I get three warnings:
- WARNING 130172 which I suspect will be easy to address by making testFC (and therefore IntermediateFC) z-aware.
- WARNING 130010 telling me "The field has not been mapped" which I do not yet know how to address.
- WARNING 130018 telling me "The chosen dataset is already being used with another LRS" which I suspect is correct but I do not yet know how to address it.
When I try to Run the tool it bails out because I've not addressed the first warning.
Before I expend more effort trying to address each of the three warnings, is there another (hopefully much simpler) way to create an LRS dataset from a "route-ready" line feature class (like my testFC with fields for RouteID, FromMeasure and ToMeasure)?
I am trying separately to find additional documentation/help via the Esri Community at Creating LRS Dataset from existing line/route feature class.
Best Answer
It took more effort than I originally anticipated but I ended up getting measured routes in an LRS dataset and network, as seen below, from test data generated and processed using the code and output that follows.