How to force python script (=geoprocessing service) to return results???

2665
1
Jump to solution
10-16-2014 08:40 AM
J_B__K_
New Contributor III

Hi!

I need to make a little geoprocessing service based on python script...

Meaning of the service is easy: receive JSON, look if there are any features of one feature class in geodatabase and return the count of features...

General idea of script (as it looks like as a desktop script - thats why there are "AddMessage") is this:

import arcpy data="Database Connections\myDB.sde\MYDB.DATAOWNER.data" data_fl=arcpy.MakeFeatureLayer_management(data) json=arcpy.GetParameter(0) sr=arcpy.Describe(vo).spatialReference polygon=arcpy.AsShape(json,True) polygon.projectAs(sr) polygon_fl=arcpy.MakeFeatureLayer_management(polygon) arcpy.SelectLayerByLocation_management(data_fl,"INTERSECT",polygon) if arcpy.GetCount_management(data_fl).getOutput(0)!="0":     arcpy.arcpy.AddMessage("you have chosen "+arcpy.GetCount_management(data_fl).getOutput(0)+" features") else:     arcpy.arcpy.AddMessage("no chosen features")

 

But - I know this is not way how to get some results from geoprocessing service (if i publish this script). How to force python script (=geoprocessing service) to return results??? It must be easy, I think this is kind of "newbie" question, Im still learning...

 

Thanks for any help!

0 Kudos
1 Solution

Accepted Solutions
JasonScheirer
Regular Contributor II

Add a second parameter, datatype Long and type Output. At the end of your script do this:

count = int(arcpy.GetCount_management(data_fl)[0])

if count > 0:

    arcpy.arcpy.AddMessage("you have chosen {0} features".format(count))

else:

    arcpy.arcpy.AddMessage("no chosen features")

# Set as actual output

arcpy.SetParameter(1, count)

View solution in original post

0 Kudos
1 Reply
JasonScheirer
Regular Contributor II

Add a second parameter, datatype Long and type Output. At the end of your script do this:

count = int(arcpy.GetCount_management(data_fl)[0])

if count > 0:

    arcpy.arcpy.AddMessage("you have chosen {0} features".format(count))

else:

    arcpy.arcpy.AddMessage("no chosen features")

# Set as actual output

arcpy.SetParameter(1, count)

View solution in original post

0 Kudos