Select to view content in your preferred language

FGDB to EGDB Workspace error

282
4
09-12-2024 07:45 AM
drWood
by
Regular Contributor

Hey all,

We identified some line geometries that need to have the order of their vertices replaced to utilize arrowhead symbology to visualize flow. We were successfully bale to piece together a script that worked on a feature class in a file gdb, but when trying to execute on our enterprise gdb it did not work and prompted the error message: 

Polyline - Reverse Geometry
=====================
Parameters

Input Feature Class SW Assets\dPipe
=====================
Messages

Start Time: Thursday, September 12, 2024 10:16:00 AM
Traceback (most recent call last):
File "<>\PublicWorksTools.atbx\PolylineReverseGeometry.tool\tool.script.execute.py", line 60, in <module>
File "<>\PublicWorksTools.atbx\PolylineReverseGeometry.tool\tool.script.execute.py", line 17, in reverse_line_geometry
RuntimeError: cannot open workspace

Failed script Polyline - Reverse Geometry...
Failed to execute (PolylineReverseGeometry).
Failed at Thursday, September 12, 2024 10:16:55 AM (Elapsed Time: 54.98 seconds)

 

"""
Script documentation
- Tool parameters are accessed using arcpy.GetParameter() or 
                                     arcpy.GetParameterAsText()
- Update derived parameter values using arcpy.SetParameter() or
                                        arcpy.SetParameterAsText()
"""
import arcpy
def reverse_line_geometry(input_feature_class):
    """
    Reverses the direction of line geometries for selected records in the input feature class.
    
    :param input_feature_class: Path to the input line feature class
    """
    # Start an edit session
    workspace = arcpy.env.workspace
    edit = arcpy.da.Editor(workspace)
    edit.startEditing(False, True)
    edit.startOperation()
    
    try:
        # Use an update cursor to iterate through selected features
        with arcpy.da.UpdateCursor(input_feature_class, ["SHAPE@"]) as cursor:
            for row in cursor:
                # Get the current geometry
                geometry = row[0]
                
                # Reverse the order of points in each part of the polyline
                reversed_parts = []
                for part in geometry:
                    reversed_parts.append(arcpy.Array(part[::-1]))
                
                # Create a new polyline with the reversed parts
                reversed_geometry = arcpy.Polyline(arcpy.Array(reversed_parts))
                
                # Update the row with the reversed geometry
                row[0] = reversed_geometry
                cursor.updateRow(row)
        
        # Stop the edit operation
        edit.stopOperation()
        print("Successfully reversed the direction of selected line geometries.")
    
    except Exception as e:
        # Abort the edit operation in case of an error
        edit.abortOperation()
        print(f"An error occurred: {e}")
    
    finally:
        # Stop the edit session
        edit.stopEditing(True)
if __name__ == "__main__":
    # Retrieve parameters from the tool
    input_feature_class = arcpy.GetParameterAsText(0)
    
    # Set the workspace environment to the appropriate geodatabase
    arcpy.env.workspace = arcpy.Describe(input_feature_class).path
    
    # Call the function to reverse the line geometry
    reverse_line_geometry(input_feature_class)

 

 

Thanks in advance for any insight into how to correct this issue.

0 Kudos
4 Replies
AlfredBaldenweck
MVP Regular Contributor

Is the feature class in a feature dataset? Because that will cause problems for sure. If it is, go up one level to the actual geodatabase.

 

Below is my initial idea for the issue:

Most likely, you're trying to access the Default version of the eGDB, and you don't have permissions to edit on the default. (Or something along those lines, idk)

Try the following:

  1. Copy your SDE file
  2. In Catalog, right-click the copy and hit "Geodatabase Connection Properties"
  3. Change the version you're pointing to.
  4. Plug that the file from that version into your script instead. That is, go to that SDE file to pull out the feature class.
0 Kudos
drWood
by
Regular Contributor

The feature class is indeed in a feature dataset. I'll give the script a  test on a feature class not residing within one and see if that works. Thanks in advance!

 

Update: I ran the script on a standalone feature class within a different SDE and the execution errored out with the message "cannot update the table"

AlfredBaldenweck
MVP Regular Contributor

Dumb question, but do you have permissions to edit it?

0 Kudos
drWood
by
Regular Contributor

Not a dumb question, but I do indeed have editing permissions granted. There happens to be a gp tool called "Flip Line" that one of my interns came across. I for the life of me could not find it using nomenclature used in the GUI approach when "Edit Vertices" is active...

0 Kudos