Select to view content in your preferred language

arcpy.locref.AppendRoutes giving ERROR 160319: Error stopping an edit session with save edits

338
2
07-03-2022 09:27 PM
GraemeBrowning
Regular Contributor

At 160319: Error stopping an edit session with save edits—ArcGIS Pro | Documentation help is requested from anyone encountering that error.

While investigating LRS Line Networks I have stumbled across a procedure that leads to that error every time it is run a second time within an ArcGIS Pro 3.0.0 session.

The code is as below and the way I am running it is as a Python Script tool with no parameters. 

 

If the tool is run once it works.  If it is then run again it gives:

arcgisscripting.ExecuteError: ERROR 160319: Error stopping an edit session with save edits
Error stopping an edit session with save edits [TestLRSNetwork]
Failed to execute (AppendRoutes).

 

# This script is intended to create an empty LRS dataset and load
# the geometries of a test polyline feature class with route IDs (TEXT),
# Route Names (TEXT) and from/to measures (DOUBLE) into it so that an
# LRS Line Network with those routes can be created
import arcpy,uuid

def print_message(msg):
    print(msg)
    arcpy.AddMessage(msg)

arcpy.env.overwriteOutput = True

# Establish coordinate system and geodatabase to be used
srWGS84 = arcpy.SpatialReference("GCS_WGS_1984")
workingFolder = r"C:\temp"
gdbName = "test"
gdb = r"{0}\{1}.gdb".format(workingFolder,gdbName)
lrsName = "TestLRS"
lrsFD = r"{0}\{1}".format(gdb,lrsName)
testFCName = "testFC"
testFC = r"{0}\{1}".format(lrsFD,testFCName)
testStatsTableName = "testStats"
testStatsTable = r"{0}\{1}".format(gdb,testStatsTableName)
testDissolvedFC = r"{0}{1}".format(testFC,"_Dissolve")
calibrationFC = r"{0}\{1}".format(lrsFD,"Calibration_Point")
centerlineFC = r"{0}\{1}".format(lrsFD,"Centerline")
lrsNetworkName = "testLRSNetwork"
lrsNetworkFC = r"{0}\{1}".format(lrsFD,lrsNetworkName)
redlineFC = r"{0}\{1}".format(lrsFD,"Redline")
centerlineSequenceTable = r"{0}\{1}".format(gdb,"Centerline_Sequence")
newCalibrationPointsFCName = "NewCalibrationPoints"
newCalibrationPointsFC = r"{0}\{1}".format(lrsFD,newCalibrationPointsFCName)
newCalibrationPointsFCTempName = newCalibrationPointsFCName+"Temp"
newCalibrationPointsFCtemp = r"{0}\{1}".format(lrsFD,newCalibrationPointsFCTempName)
uniqueCalibrationPointsFCName = "UniqueCalibrationPoints"
uniqueCalibrationPointsFC = r"{0}\{1}".format(lrsFD,uniqueCalibrationPointsFCName)

# Create empty geodatabase for testing
arcpy.management.CreateFileGDB(workingFolder,gdbName)

# Create empty TestLRS dataset 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)        
print_message("Creating LRS dataset named {0} in {1}".format(lrsName,gdb))
arcpy.locref.CreateLRS(gdb,lrsName,"Centerline","Calibration_Point",
                       "Redline","Centerline_Sequence",srWGS84)

# Prepare feature class from which routes will be appended into the LRS Network later
# Create empty feature class and its schema
print_message('Creating "route-ready" polyline feature class ({0}) in LRS dataset ({1})'.format(testFC,lrsFD))
arcpy.management.CreateFeatureclass(lrsFD,"testFC","POLYLINE")
arcpy.management.AddField(testFC,"RouteID","TEXT", None, None, 10)
arcpy.management.AddField(testFC,"RouteName","TEXT", None, None, 10)
arcpy.management.AddField(testFC,"FromMeasure","DOUBLE")
arcpy.management.AddField(testFC,"ToMeasure","DOUBLE")
arcpy.management.AddField(testFC,"FromDate","DATE")
arcpy.management.AddField(testFC,"ToDate","DATE")
# Write three polylines and their route attributes to the feature class
cursor = arcpy.da.InsertCursor(testFC,["SHAPE@","RouteID","RouteName","FromMeasure","ToMeasure"])
array = arcpy.Array([arcpy.Point(0.0,0.0),
                     arcpy.Point(0.0,1.0)])
polyline = arcpy.Polyline(array,srWGS84)
cursor.insertRow([polyline,"Route1","Route 1",0.0,750.0])
array = arcpy.Array([arcpy.Point(0.0,1.0),
                     arcpy.Point(1.0,1.0)])
polyline = arcpy.Polyline(array,srWGS84)
cursor.insertRow([polyline,"Route1","Route 1",750.0,2000.0])
array = arcpy.Array([arcpy.Point(1.0,1.0),
                     arcpy.Point(1.0,0.0)])
polyline = arcpy.Polyline(array,srWGS84)
cursor.insertRow([polyline,"Route2","Route 2",0.0,999.0])
del cursor
arcpy.management.CalculateField(testFC, "FromDate", "datetime.datetime.now()", "PYTHON3", '', "TEXT", "NO_ENFORCE_DOMAINS")
print_message('Writing statistics from polyline feature class ({0}) into table ({1})'.format(testFC,testStatsTable))
arcpy.analysis.Statistics(testFC,testStatsTable,"FromMeasure MIN;ToMeasure MAX","RouteID")

# Dissolve testFC so that there's only one polyline per route
print_message("Dissolving {0} primarily on RouteID to create {1}".format(testFC,testDissolvedFC))
arcpy.management.Dissolve(testFC,testDissolvedFC,
                          "RouteID;RouteName;FromDate;ToDate",
                          None, "SINGLE_PART", "UNSPLIT_LINES")

# Add and populate fields to support Lines in LRS Network
print_message("Adding and populating fields to support Lines on 'route-ready' polylines in {1}".format(testFC,testDissolvedFC))
arcpy.management.AddField(testDissolvedFC,"Line_GUID","Text",None,None,255)
arcpy.management.AddField(testDissolvedFC,"LineName","Text",None,None,10)
arcpy.management.AddField(testDissolvedFC,"LineOrder","LONG")
# Only one Line in this test
lineGUID = "{0}".format('{'+str(uuid.uuid4())+'}')
lineOrder = 100
with arcpy.da.UpdateCursor(testDissolvedFC,["Line_GUID","LineName","LineOrder"]) as cursor:
    for row in cursor:
        cursor.updateRow([lineGUID,"Line 1",lineOrder])
        lineOrder+=100
arcpy.management.JoinField(testDissolvedFC,"RouteID",testStatsTable,"RouteID","MIN_FromMeasure;MAX_ToMeasure")


# Create empty TestLRSNetwork in TestLRS dataset 
print_message("Creating LRS Network ({0}) in LRS dataset ({1})".format("TestLRSNetwork","TestLRS"))
arcpy.locref.CreateLRSNetwork(gdb, "TestLRS", "TestLRSNetwork",
                              "RouteID", "RouteName", "FromDate", "ToDate", "DO_NOT_DERIVE", '',
                              "INCLUDE", "LineId", "LineName", "LineOrder", "METERS")
                              # "DO_NOT_INCLUDE", "LineId", "LineName", "LineOrder", "METERS")
lrsNetworkFC = r"{0}\{1}".format(lrsFD,"TestLRSNetwork")

# Append routes from testFC into TestLRSNetwork which should append them into Centerline feature class at the same time
print_message("Appending Routes from {1} into LRS Network ({1}) in LRS dataset ({2})".format(testFC,"TestLRSNetwork","TestLRS"))
arcpy.locref.AppendRoutes(testDissolvedFC,lrsNetworkFC, "RouteID", "RouteName", "FromDate", "ToDate",
                          "Line_GUID","LineName","LineOrder", None, "ADD")

# Generating calibration points and calibrating routes using them
arcpy.locref.GenerateCalibrationPoints(testDissolvedFC,"RouteID","FromDate","ToDate",calibrationFC,
                                       lrsNetworkName, "DIGITIZED_DIRECTION","ATTRIBUTE_FIELDS","MIN_FromMeasure","MAX_ToMeasure")
                                       # lrsNetworkName, "MEASURE_DIRECTION", "GEOMETRY_LENGTH")
arcpy.locref.GenerateRoutes(lrsNetworkFC, "NO_RECORD_CALIBRATION_CHANGES")

 

If I close ArcGIS Pro and run the tool again, it will work, but if I try to run it a second time then it gives the error again.

 

0 Kudos
2 Replies
GraemeBrowning_Aurizon
Occasional Contributor II

This problem has been reproduced by Esri Australia as Esri Case #03097576 and also by Esri Redlands who have recorded it as BUG-000151833 where it currently has a Status of In Review.

0 Kudos
AnneHillyer1
New Contributor II

I'm having the same error when I try to edit a feature class.

0 Kudos