Errors in standalone script when copying Route Event Layer to fgb

207
3
07-23-2020 02:02 PM
JeffTrudnak
New Contributor II

I am working on a standalone python script that dissolves speed data across a network to perform a daily refresh a table in our enterprise geodatabase.  I've made the script work several ways when running in the ArcCatalog python window.  I am running into errors when trying to run as a standalone script.  Pretty much generic error codes as noted in the abbreviated script below.  I've tried specifying the event route layer be written to the current workspace and  scratch workspace.   Any suggestions?   Working in 10.7.1.  32 bit execution in catalog and stand alone. Relatively new to python.  Thanks.

import arcpy
arcpy.env.overwriteOutput = True

db_connect = r"Database Connections//GIS on GISD.sde"
arcpy.env.workspace = r'\\GIS_SEVER\Workspace\Speeds_Dissolve\Speeds_Working.gdb'
arcpy.env.scratchWorkspace = r'\\GIS_SERVER\Workspace\Speeds_Dissolve\Scratch.gdb'
outFGB = r'\\GIS_SERVER\Workspace\Speeds_Dissolve\Speeds_Working.gdb'
scratchFGB = r'\\GIS_SERVER\Workspace\Speeds_Dissolve\Scratch.gdb'
ToTable = db_connect + "\GDP_OWN.O_SPEED_SEGMENT_DIS"

#define tables
#multiple tables
speed_dis = outFGB + "\speed_dis"
speed_lrs_dis_lines = outFGB + "\speed_lrs_dis_lines"
speed_mrel = scratchFGB + "\speed_mrel"

#step - clean up data from previous run if exists - successfully completes
#step - use query layer to export LRS layer to fgb (mp_detail_lrs)  - successfully completes
#step - user query layer to export speed data to table - successfully completes
#step - define fields name for speeds, MakeTableView, and save to fgb - successfully completes
#step - DissolveRouteEvents_lr using table from previous step, speed_dis - successfully completes

#step - MakeRouteEventLayer - successfully completes
props = "ROUTE_I LINE BEGIN_GIS_MP_NUM_I END_GIS_MP_NUM_I"
arcpy.MakeRouteEventLayer_lr(mp_detail_lrs,"ROUTE_I", speed_dis, props,speed_mrel,"#","ERROR_FIELD")
result4 = arcpy.GetCount_management(speed_mrel)
print ("Speed QL (speed_mrel) record count:" + str(result4)) #returns count successfully


#step - export/copy Route event layer to fgb - NOT SUCCESSFUL as standalone

#option1 - arcpy.CopyFeatures_management(speed_mrel,speed_lrs_dis_lines)
##--line 2568, in CopyFeatures raise ERROR 999998: Unexpected Error.Failed to execute (CopyFeatures)

#arcpy.CopyRows_management(speed_mrel,speed_lrs_dis_lines)


##option 2 - ArcGIS\Desktop10.7\ArcPy\arcpy\management.py", line 18093, in CopyRows -- ERROR 999998: Unexpected Error.

#option 3 - arcpy.Append_management(speed_mrel, speed_lrs_dis_lines,"NO_TEST")
##Traceback (most recent call last):
##File "Q:\Speeds_Dissolve\dissolve_speeds3.py", line 186, in <module>
##arcpy.Append_management(speed_mrel, speed_lrs_dis_lines,"NO_TEST")
##File "C:\Program Files (x86)\ArcGIS\Desktop10.7\ArcPy\arcpy\management.py", line 4256, in Append
##raise e ExecuteError: ERROR 999998: Unexpected Error. Failed to execute (Append).

#option 4 - Attempting cursor, no error message, no records inserted into fgb table
dsc = arcpy.Describe(speed_mrel) #route event layer
fields = dsc.fields
fieldnames = [field.name for field in fields if field.name != dsc.OIDFieldName and field.name != 'SHAPE.LEN' and field.name != 'Shape']
fieldnames.append('SHAPE@')
print (fieldnames) #expected fields are returned
query = "select * from speed_mrel"
with arcpy.da.SearchCursor(speed_mrel, fieldnames,query)as sCur1:
with arcpy.da.InsertCursor(speed_lrs_dis_lines,fieldnames) as iCur1:
for row in sCur1:
printf = row.getValue(Field1)
print (printf)
iCur1.insertRow(row)

0 Kudos
3 Replies
UriGilad_EsriAu
Esri Contributor

Hi Jeff,

A few suggestions:

Try to change your path to the full path. Instead of:

db_connect = r"Database Connections//GIS on GISD.sde"  

which will work from within Catalog, try something like:

db_connect = r" C:\Users\USERNAME\AppData\Roaming\Esri\ArcGISPro.......sde" (you can get the full path from the sde properties window)

Note that in line 4 

GIS_SEVER

I assume it should be 

GIS_SERVER

Add two backslashes or r in path. Instead of:

speed_mrel = scratchFGB + "\speed_mrel"

Write:

speed_mrel = scratchFGB + "\\speed_mrel"

or 

speed_mrel = scratchFGB + r"\speed_mrel"

Hope this helps,

Uri


If this answer solved your question or if you found it helpful please mark it accordingly to help others who have the same question.

0 Kudos
JeffTrudnak
New Contributor II

Thanks for the suggestions.  I tried multiple ways of specifying the path, but still no luck with exporting the Route Event Layer to the fgb.   The script successfully reads from the enterprise db, creates and copies query layers to the fgb, creates and copies a table view from/to the fgb.  I just don't know what is different between the route event layer and the other in memory tables that are working without issue.  I've tried handling the route event layer the same way as the query layers/table view where I don't specify a full path.  I find it interesting that the copy features command is creating the table in the fgb before failing.

speeds_lrs_errors = outFGB + "\speeds_lrs_errors"
speed_mrel = scratchFGB + r"\speed_mrel"
arcpy.MakeRouteEventLayer_lr(mp_detail_lrs,"ROUTE_I", speed_dis, props,"speed_mrel","#","ERROR_FIELD")
arcpy.CopyFeatures_management(speed_mrel,speed_lrs_dis_lines)

works in catalog, as standalone creates speed_lrs_dis_lines in FGB then fails
--
speeds_lrs_errors = outFGB + "\speeds_lrs_errors"
speed_mrel = scratchFGB + r"\speed_mrel"
arcpy.MakeRouteEventLayer_lr(mp_detail_lrs,"ROUTE_I", speed_dis, props,"speed_mrel","#","ERROR_FIELD")
arcpy.Append_management(speed_mrel,speed_lrs_dis_lines,"NO_TEST")

works in catalog, fails as stand alone
--
speed_lrs_dis_lines = outFGB + "\\speed_lrs_dis_lines"
speed_mrel = scratchFGB + "\\speed_mrel"
arcpy.MakeRouteEventLayer_lr(mp_detail_lrs,"ROUTE_I", speed_dis, props,"speed_mrel","#","ERROR_FIELD")
arcpy.CopyFeatures_management(speed_mrel,speed_lrs_dis_lines)

works in catalog, as standalone creates speed_lrs_dis_lines in FGB then fails
--
speed_lrs_dis_lines = outFGB + "\\speed_lrs_dis_lines"
speed_mrel = scratchFGB + "\\speed_mrel"
arcpy.MakeRouteEventLayer_lr(mp_detail_lrs,"ROUTE_I", speed_dis, props,"speed_mrel","#","ERROR_FIELD")
arcpy.Append_management(speed_mrel,speed_lrs_dis_lines,"NO_TEST")

works in catalog, fails as stand alone

0 Kudos
JeffTrudnak
New Contributor II

So there was nothing wrong with the script itself.  The python script resides on one of our servers used for scheduled jobs.  I had access to a shared directory on the server, but could not login to the server.  I had been trying to execute the script from my workstation by accessing the shared directory.  When I asked our server admin to run the script while logged into the server, the script ran without issue.   Again, not sure why this is an issue for the event layer when working with the query layers in the script before the event layer were successful.