PLEASE HELP! Features do not get updated in Geoprocessing Service

747
10
Jump to solution
10-11-2013 07:55 AM
ionarawilson1
Occasional Contributor III
I am at my wits end with this and it seems that ESRI does not provide much information about this. My data is in SDE. This script works in ArcMap but it does not update the features when it is run with a geoprocessing service. I don't think I can write an absolute path for the inputs as this gp will be used in a web app. Can anybody help?

# Import arcpy module import os, sys, arcpy, traceback, arcgisscripting  arcpy.env.workspace = "Database Connections\\sars.sde\\" arcpy.env.scratchWorkspace = "d:\\ArcGISData\\SARS\\Python_10April2013\\SARS.gdb"   Input_Polygons = arcpy.GetParameterAsText(0) Counties = arcpy.GetParameterAsText(1)  # create output feature for spatial join if os.path.exists("d:\\ArcGISData\\SARS\\Python_10April2013\\SARS.gdb\\StewardshipCounties"):     os.remove("d:\\ArcGISData\\SARS\\Python_10April2013\\SARS.gdb\\StewardshipCounties") outstewardshipcounties = os.path.join(arcpy.env.scratchGDB, "StewardshipCounties")   with arcpy.da.UpdateCursor(Input_Polygons, ("DateStart", "PlanID", "FFY")) as rows:               for row in rows:          if not (row[1] or "").strip(): #covers blank, one blank space, or Null             Datestarstr1 = row[0]             Datestarstr2 = str(Datestarstr1)                      yearonly = Datestarstr2[0:4]                               row[2] = yearonly              rows.updateRow(row)      arcpy.Identity_analysis(Input_Polygons, Counties, outstewardshipcounties) #run spatial join tool arcpy.CalculateField_management(Input_Polygons, "OID", '!OBJECTID!', "PYTHON_9.3")  #create dictionary  path_dict = { } rows = arcpy.SearchCursor(outstewardshipcounties) for row in rows:          keyrow =  row.OID     valrow = row.FIPS_TXT     path_dict[keyrow] = valrow  urows = arcpy.UpdateCursor(Input_Polygons) for urow in urows:      upkey = urow.OID     if upkey in path_dict:         urow.setValue("County", path_dict[upkey])         urows.updateRow(urow) del row, rows, urow, urows 
Tags (2)
0 Kudos
10 Replies
ionarawilson1
Occasional Contributor III
Ok, I found what the problem was. A parameter cannot have a feature class as an input (go figure!), so if you use arcpy.GetParameterAsText() and then have that parameter as a featureset (which I needed for my gp) it won't work. What I did was to create a variable for that parameter and when I run it inside ArcMap I grab the layer for that feature class (in my case the layer is referencing a feature class in a sde geodatabase). Then I publish the gp, then when I run the geoprocessing service I can grab the file directly from the connection instead of the layer. I hope it will help somebody because it took me a while to figure this out.

 Input_Polygons = "Stewardship"    with arcpy.da.UpdateCursor(Input_Polygons, ("DateStart", "PlanID", "FFY")) as rows:      for row in rows:          if not (row[1] or "").strip(): #covers blank, one blank space, or Null             Datestarstr1 = row[0]             Datestarstr2 = str(Datestarstr1)                      yearonly = Datestarstr2[0:4]                               row[2] = yearonly              rows.updateRow(row)    
0 Kudos