Python Toolbox as Geoprocessing Service in Web App?

4293
7
10-02-2013 09:14 AM
ionarawilson1
Occasional Contributor III
Is it possible to publish a geoprocessing service generated from a python toolbox? This will be used in a web app, so is it possible that all the custom messages that were created in the python toolbox will appear in the web app when the geoprocessing service is used (the user will click a button to run the geoprocessing service)? Or do I have to write special code in javascript to create alerts that will be created from results of the geoprocessing service? The python toolbox works wonders in ArcMap so I am trying to figure out how to create a web app with a geoprocessing service resulting from that.

Thank you!
Tags (2)
0 Kudos
7 Replies
MarcoBoeringa
MVP Regular Contributor
I may not be telling something new, but you will need ArcGIS for Server for this, and setup a Geoprocessing Service.

Two entry points most relevant in the Help are probably:

What is a geoprocessing service?

An overview of geoprocessing REST Services
0 Kudos
ionarawilson1
Occasional Contributor III
Yes, Marco. I have created geoprocessing services from toolboxes but never from a python toolbox and never using in a web app so I am not sure that would work. Would it?
0 Kudos
SchoppMatthieu
New Contributor III
If you mean publishing your script as a geoprocessing service, yes it will work 😄

Here is a great step-by-step tutorial that covers the whole scope. It is about a printing geoprocessing service.

http://resources.arcgis.com/en/help/main/10.1/index.html#/Tutorial_Advanced_high_quality_web_map_pri...
0 Kudos
ionarawilson1
Occasional Contributor III
Hi Matt, the example shows a python tool, but can I also publish the results of a python toolbox and would the messages created in it, pop up in a web app?

http://resources.arcgis.com/en/help/main/10.1/index.html#//001500000022000000
0 Kudos
KevinHibma
Esri Regular Contributor
Yes.
Python toolboxes can be published as a GP Service.
0 Kudos
ionarawilson1
Occasional Contributor III
Thank you Kevin. Would the messages created appear if I run the gp service or in a web app?
0 Kudos
SchoppMatthieu
New Contributor III
I usually script my stuff into a python.py file.
Then I add my python script to a toolbox.
And finally I publish the gp result as a geoprocessing service as shown on the tutorial I recommended above.

After a quick look at python toolboxes, it seems to me that it is almost the same thing except that my two first steps are merged in one.

Then to publish it a geoprocessing service, it works the same way.

You can define inputs but you don't have to if you don't need any inputs from the webapp.

input = arcpy.GetParameterAsText(0) #It should be working the same in a python toolbox or it should be something similar


You can define an output too if you want (that could be the "message" you are talking about) :

if the script works :
       output = "job done"
else :
       output = "job not completed"

arcpy.SetParameterAsText(1, output)


- > in GetParameterAsText(0) and SetParameterAsText(1), 0 and 1 refer to the row number of the parameters list.

What I don't know is how to define the inputs, output data-type (String, File), direction (Input, Output) and type (Optional, Derived) from a python toolbox (parameters don't appear in the toolbox properties). It might be filling out automatically with python toolbox.

Then,  when you call your geoprocessing service from you webapp, it will return an output if you defined one.
0 Kudos