3

Can python GP services returns json data to client through REST?

Imagine I have a python GP service that creates buffers around points and then merge the polygons together. I would like to send the output in esri json format as the response of the REST request made by the javascript client.

The client could use ajax to make the REST request. How would I make the GP to return the json to the client when job is finished?

PolyGeo
65.5k29 gold badges115 silver badges350 bronze badges
asked Apr 28, 2016 at 15:43

2 Answers 2

3

You can get the result of a GP Service in JSON by simply asking for the response format to be returned as JSON. You just need f=json in the request.

For example (emphasis added, but removes it from the clickable link), the following will output JSON. JSON Features actually, similiar output to what you'd get when doing your buffer-merge workflow.

http://gpdemos.esri.com/arcgis/rest/services/Viewshed/GPServer/Viewshed/execute?inPts=%7B%0D%0A++%22displayFieldName%22+%3A+%22%22%2C%0D%0A++%22fieldAliases%22+%3A+%7B%0D%0A++++%22OBJECTID%22+%3A+%22OBJECTID%22%0D%0A++%7D%2C%0D%0A++%22geometryType%22+%3A+%22esriGeometryPoint%22%2C%0D%0A++%22spatialReference%22+%3A+%7B%0D%0A++++%22wkid%22+%3A+4326%2C%0D%0A++++%22latestWkid%22+%3A+4326%0D%0A++%7D%2C%0D%0A++%22fields%22+%3A+%5B%0D%0A++++%7B%0D%0A++++++%22name%22+%3A+%22OBJECTID%22%2C%0D%0A++++++%22type%22+%3A+%22esriFieldTypeOID%22%2C%0D%0A++++++%22alias%22+%3A+%22OBJECTID%22%0D%0A++++%7D%0D%0A++%5D%2C%0D%0A++%22features%22+%3A+%5B%0D%0A++++%7B%0D%0A++++++%22attributes%22+%3A+%7B%0D%0A++++++++%22OBJECTID%22+%3A+4%0D%0A++++++%7D%2C%0D%0A++++++%22geometry%22+%3A+%7B%0D%0A++++++++%22x%22+%3A+-79.389018005999958%2C%0D%0A++++++++%22y%22+%3A+43.64121821100008%0D%0A++++++%7D%0D%0A++++%7D%0D%0A++%5D%0D%0A%7D&distance=%7B%0D%0A+%22distance%22%3A+15000%2C%0D%0A+%22units%22%3A+%22esriMeters%22%0D%0A%7D&env%3AoutSR=&env%3AprocessSR=&returnZ=false&returnM=false &f=json

answered Apr 28, 2016 at 21:01
2
  • ok so if the output is a feature class, the response format would be esri json? Commented Apr 29, 2016 at 11:27
  • Yes, thats how it works Commented Apr 29, 2016 at 13:25
2

I think that this is possible as long as the gp service that you have dumps it as a json and then you can make the call to that output from your JS.

See this thread for more info.

RESTful Geoprocessing Service Request returns empty Result object without errors

answered Apr 28, 2016 at 16:05
2
  • Ok, so if I understand, it's kind of hack because you have to transform the json into string and use the Message parameter as the transfer channel... It was not designed to do it initialy. Commented Apr 28, 2016 at 16:25
  • I wouldn't say it's so much of a hack, because if you have a Python GP service you have the ability to dump your output as a JSON. But yes, to answer your question, the message parameter will consume that dumped JSON. Commented Apr 28, 2016 at 16:35

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.