Take the 2-minute tour ×
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

Using ArcGIS 10.1 (Server and Desktop) I've been trying to publish a geoprocessing service based on a python script I wrote. Of course, it all works flawlessly from ArcGIS Desktop but I run into all sorts of problems when publishing.

I'm pretty sure the problem is related to the types of my output parameters or something to that effect. Here's the python script, minus comments and messages to GUI...

import arcpy
import json
import sys
import os

from arcpy import env

class Result(object): pass

out = Result();

arcpy.env.overwriteOutput = True

config = arcpy.GetParameterAsText(0)    # A string containing a path to a JSON config file
source = arcpy.GetParameter(1)          # A string containing the name of a layer
sWhere = arcpy.GetParameter(2)          # A String containig a where clause
distan = arcpy.GetParameter(3)          # A String containing a distance linear unit
target = arcpy.GetParameter(4)          # An Array containing multiple layer names

try:
    f = open(config)

    try:
    jsonCfg = json.load(f)

    finally:
    f.close()

except:
    pass

# jsonCfg['connection'] is a path to an SDE connection 
fc = os.path.join(jsonCfg['connection'], source)
scratch = os.path.abspath(jsonCfg['scratch'])

arcpy.MakeFeatureLayer_management(fc,"source_lyr")
arcpy.SelectLayerByAttribute_management("source_lyr", "NEW_SELECTION", sWhere)
bufLyrNam = os.path.join(scratch, "source_buf")
arcpy.Buffer_analysis("source_lyr", bufLyrNam, distan)

buffer = arcpy.FeatureSet()
buffer.load(bufLyrNam)

nLayers = len(target)

selection = []

for i in range(0, nLayers):
    lyrNam = "target_lyr_" + str(i);
    tgtNam = os.path.join(jsonCfg['connection'], target[i])

    arcpy.MakeFeatureLayer_management(tgtNam, lyrNam)
    arcpy.SelectLayerByLocation_management(lyrNam, "INTERSECT", bufLyrNam)
    cpyNam = os.path.join(scratch, target[i].replace(".",""))
    arcpy.CopyFeatures_management(lyrNam, cpyNam)

    fs = arcpy.FeatureSet()
    fs.load(cpyNam)
    selection.append(fs)

out.selection = selection

arcpy.SetParameter(5, out)

At first, I wanted to output the "out" object but apparently, this is not allowed in geoprocessing services. I can still publish the service but the output is converted to an unusable string.

I then tried to output only the "buffer" variable (containing a featureset) using an output parameter of type Any Value, Feature Class, Feature Layer... etc. and tried to output the selection variable as a Multiple Value Feature Class with no success.

In fact, something weird happens when I try to output the buffer. Once my service is published, I cannot access its REST endpoint, I always get a error code 500 page. This leaves me thinking that the arcpy.SetParameter must correspond to the output parameter type in order to even access the REST endpoint.

I've been working on this for a couple of days and I'm out of ideas which is why I created an account and asked my question. Can anyone help me figure out the problem here?

Thanks,

Ggilmann

share|improve this question
add comment

1 Answer 1

I had to ask to find the answer, sorry for being hasty, although I have been spending way too much time on this in the last few days.

Apparently you don't set the output parameter to the object but to the path of the resulting feature class. Seems a bit counter-intuitive to me but then again, I don't believe ESRI is known for providing intuitive products. It's probably related to the way server's work or something.

Everything seems to be working fine right now, the results come back as expected. Though I might have asked too hastily, I hope my thought process can help someone else in the future.

Cheers,

Ggilmann

share|improve this answer
    
I think this has happened to everyone; you ask a question and moments later you solve your own problem. I'm sure someone will find this info useful. Hope you stick around, this is an awesome place to both learn and teach. –  dchaboya Jan 4 '13 at 16:55
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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