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?

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

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
    – KHibma
    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

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

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

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