Can run a geoproces from ArcMap using an SDE connection. However when I publish the geoproces service I can't access the server directly. So I need a way to pass the SDE connection in the script. Tried to pass both a connection and a constant string but then I get the following error on the SearchCursor:
Error executing tool. Get Netwerkcell ID from Point Job ID: j085f9066b9994287b75a02abee7b878b : Traceback (most recent call last): File "PATH TO SERVICE\NetwerkIDFromPoint.GPServer\extracted\v101\arcgishomefolder\select_point.py", line 16, in env.workspace = arcpy.arcpy.env.packageWorkspace(2) TypeError: 'unicode' object is not callable Failed to execute (NetwerkIDFromPoint). Failed to execute (Get Netwerkcell ID from Point).
Intention of the script is a simple query of a point to get an ID, this works correct in ArcMap.
However on the server this does not run, I assume that it does something with the provided parameters, tried to change the type from connection to SDE but this did not solve the problem.
What is the concise way to pass an SDE connection to the server and what are the best practices for passing connections in a DTAP environement?
The database is also registered under datastores, how can I link the registered datastore to my package environement so I can skip the offending line?
env.workspace = arcpy.GetParameterAsText(2)
Becomes
env.workspace = arcpy.arcpy.env.packageWorkspace(2)
Changed this to
env.workspace = os.path.join(sys.path[0], 'arcgishomefolder', 'SQL.sde')
This seems to work, however this gives a high exception:
SEVERITY | STATUS | CODE | DESCRIPTION | NAME | TYPE |
---|---|---|---|---|---|
High | Unresolved | 24032 | Data source used by Script SelectPoint is not registered with the server and will be copied to the server: H:\dev\gis4all\lekzoekenPlus\arcgishomefolder Tool | SelectPoint | Tool |
However when I register the datasource it says that it already has this connection:
Performance is orders of magnitude slower, don't know if this is the most concise way to get a connection to an SDE. Any thoughts?
Script is relativly straightforward:
import arcpy from arcpy.da import SearchCursor from arcpy import env from datetime import datetime # O: env.workspace = r"PATH TO D ENVIRONMENT.sde" # T: env.workspace = r"PATH TO T ENVIRONMENT.sde" env.workspace = arcpy.GetParameterAsText(2) network_cell_table = r"VSDWHT.history.se_hm13_t1_networkcell" lek_x = 197552.6619 lek_y = 488500.8892 # Script arguments NieuweLekLocatie = arcpy.GetParameterAsText(0) arcpy.AddMessage( str(NieuweLekLocatie)) if NieuweLekLocatie: # Create a FeatureSet object and load in_memory feature class feature_set = arcpy.FeatureSet() feature_set.load(NieuweLekLocatie) with arcpy.da.SearchCursor(feature_set, ["SHAPE@XY"]) as cursor: # Iterate through list of coordinates and add to cursor for row in cursor: lek_x = row[0][0] lek_y = row[0][1] arcpy.AddMessage("Leklocatie x={0}, y={1}".format(lek_x,lek_y)) wktPoint = "POINT ({0} {1})".format(lek_x,lek_y) cell_cursor = SearchCursor(network_cell_table, 'se_fld0_id', "se_fld6_bufferedextent.STIntersects(geometry::STGeomFromText('{0}',28992)) = 1 AND {1} >= '{2}'".format(wktPoint,'se_history_validto',datetime(9998, 12, 31, 23, 59, 59))) for nc in cell_cursor: c = nc[0] arcpy.SetParameter(1,c)