1

I am trying to create a Python script that automate the update of roads source used in a network dataset stored in a Enterprise Geodatabase (SDE). In short, I want to truncate the roads feature class and append the new roads data into it without have to recreate the network dataset.

When I try to edit the roads feature class, I encounter an error because arcpy can't edit a feature class used by a network dataset outside an edit session.

I tried using an update cursor in an edit session but I get RuntimeError: workspace already in transaction mode

import arcpy, os, time
time1 = time.time()

ROADS_INPUT = os.path.join(r"\\dd734dd", "geo", "Geobase", "GEO03_ADDRESS.gdb", "GEO03_ADDRESS", "GEO03E08_ROADS")
WORKSPACE = os.path.join(r"\\dd734dd", "geo", "ArcGIS Server", "Connections", "Enterprise.sde")
ROADS_NA = os.path.join(r"\\dd734dd", "geo", "ArcGIS Server", "Connections", "Enterprise.sde", "NA", "ROADS_2018_04")

editSession = arcpy.da.Editor(WORKSPACE)
editSession.startEditing(False, True)
editSession.startOperation()

#truncating the NA roads table
with arcpy.da.UpdateCursor(ROADS_NA, field_names="*") as u_cursor:
    for row in u_cursor:
        cursor.deleteRow()

#inserting rows from input to NA roads
with arcpy.da.SearchCursor(ROADS_INPUT, field_names="*") as s_cursor:
    with arcpy.da.InsertCursor(ROADS_NA, field_names="*") as i_cursor:
        for row in s_cursor:
            i_cursor.insertRow(row)

editSession.stopOperation()
editSession.stopEditing(True)
time2 = time.time()
print "script took {:.3f} ms".format((time2-time1)*1000.0)

Is there a strategy I could try to achieve what I am trying to do?

Note: The network dataset is stored in Enterprise Geodatabase (SDE)

EDIT:

Using arcpy.DeleteFeatures_management() and arcpy.Append_management() instead of cursors results in error 99999 Objects in this class cannot be updated outside and edit session [Enterprise.ROADS_2018_04]

import arcpy, os, time
time1 = time.time()

ROADS_INPUT = os.path.join(r"\\dd734dd", "geo", "Geobase", "GEO03_ADDRESS.gdb", "GEO03_ADDRESS", "GEO03E08_ROADS")
WORKSPACE = os.path.join(r"\\dd734dd", "geo", "ArcGIS Server", "Connections", "Enterprise.sde")
ROADS_NA = os.path.join(r"\\dd734dd", "geo", "ArcGIS Server", "Connections", "Enterprise.sde", "NA", "ROADS_2018_04")

editSession = arcpy.da.Editor(WORKSPACE)
editSession.startEditing(False, True)
editSession.startOperation()

arcpy.DeleteFeatures_management(ROADS_NA)
arcpy.Append_management(ROADS_INPUT, ROADS_NA)

editSession.stopOperation()
editSession.stopEditing(True)
time2 = time.time()
print "script took {:.3f} ms".format((time2-time1)*1000.0)
8
  • What happens when you kill the locks on the SDE and then try?
    – ed.hank
    Commented Dec 6, 2018 at 15:32
  • I see locks but I cant kill them from the ArcCatalog dialog box Commented Dec 6, 2018 at 15:38
  • Ok the locks were created by PyScripter. After closing it, I launch the script in cmd but I got the same workspace already in transaction mode error Commented Dec 6, 2018 at 16:00
  • Hmm ... that is strange then. let me ask around here at work and see if anyone may know.
    – ed.hank
    Commented Dec 6, 2018 at 16:10
  • Why are you using cursors? Surely it would be quicker to use DeleteFeatures resources.arcgis.com/en/help/main/10.2/index.html#//… on a layer made with a where_clause then use Append resources.arcgis.com/en/help/main/10.2/index.html#//… to add the new objects to your feature class. From your code you're deleting all of the roads is that really what you want to do? Commented Dec 7, 2018 at 0:47

1 Answer 1

1

What I have found so far, is that a Network Dataset can only be updated by creating a new version, and the Network dataset metadata is updated when the version are made Default. So you must use versioning. If the resulting Network dataset are to be consumed by ie an Closes Facility Service from ArcGIS Server, it could be a solution for you creating a complete new Network dataset, then change the source from the old to the new Network dataset, then republish and later drop the old dataset. A bit messy, but it works.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.