I. background description
By calling the GP service, the android client can also implement professional and complex GIS analysis and processing functions to increase the practical value of applications.
The GP Service released by ArcGIS Server is divided into two types: synchronous and asynchronous. Generally, GP services with many execution steps and long elapsed time adopt asynchronous methods, services with fast execution speed adopt synchronization mode. If you are not sure whether the GP service is synchronous or asynchronous, you can view it in the service directory, for example:
This article describes how to call the GP Service asynchronously (the synchronous method is simple in the SDK sample program). The GP service called in this example comes from ArcGIS online and the service address is: bytes. The service-related business data service is. The GP Service provides the data extraction function, that is, extract data based on the layer to be extracted, the extraction range, and the output format selected by the user, and package the data back to the client. The customer downloads the zip package. Let's take a look at the parameter requirements of the GP service:
The service provides three input parameters: the layer to be extracted, the extraction range, and the output format. In addition, an output parameter is provided to obtain the extraction result.
Ii. Example results
In this example, the execution result is as follows:
1. basemap and business data to be extracted:
2. Draw the polygon range for extraction:
3. Submit the extraction task and start the extraction operation:
4. After the extraction task is completed, obtain the extracted result URL (above the image) and click to download it:
5. Download and extract the results:
6.in the downloaded directory, download the result output-1.zip:
Iii. key code
1. Set Parameters
Public void startasynchronous (polygon aoigeometry) {// cropping target layer gpstring pointlayer = new gpstring (); pointlayer. setvalue ("incident points"); gpstring linelayer = new gpstring (); pointlayer. setvalue ("incident lines"); gpstring polygonlayer = new gpstring (); pointlayer. setvalue ("Incident areas"); gpmultivalue <gpstring> cliplayers = new gpmultivalue <gpstring> ("layers_to_clip"); cliplayers. addvalue (pointlayer); cliplayers. addvalue (linelayer); cliplayers. addvalue (polygonlayer); // The cropping range: graphic G = new graphic (aoigeometry, fillsymbol); paiaoi = new gpfeaturerecordsetlayer ("area_of_interest"); Aoi. setgeometrytype (geometry. type. polygon); Aoi. addgraphic (g); // The returned data format is gpstring format = new gpstring ("feature_format"); format. setvalue ("shapefile-SHP -. SHP "); params2 = new arraylist <gpparameter> (); params2.add (cliplayers); params2.add (AOI); params2.add (format); try {dialog = progressdialog. show (Viewshed. this, "", "extacting. please wait... ", true, true); gpextract = new geoprocessor (" http://sampleserver4.arcgisonline.com/ArcGIS/rest/services/HomelandSecurity/Incident_Data_Extraction/GPServer/Extract%20Data%20Task "); gpextract. setoutsr (map. getspatialreference (); gpextract. setprocesssr (map. getspatialreference (); extractrunable queryrunable = new extractrunable (); thread = new thread (queryrunable); thread. start ();} catch (exception e) {e. printstacktrace ();}}
2. Submit the task and start asynchronous execution.
class ExtractRunable implements Runnable {@Overridepublic void run() {GPJobResource jobResource = null;try {jobResource = gpExtract.submitJob(params2);} catch (Exception e1) {e1.printStackTrace();}jobID = jobResource.getJobID();} }
3. Use timer to regularly Query Task status and process results
Class extractrunable implements runnable {@ overridepublic void run () {gpjobresource jobresource = NULL; try {jobresource = gpextract. submitjob (params2);} catch (exception E1) {e1.printstacktrace ();} jobid = jobresource. getjobid (); // query the job status checkjobstatustmer = new timer (); checkjobstatustmer every 2 seconds through the timer. schedule (New timertask () {@ overridepublic void run () {gpjobresource jobres = NULL; try {jobres = gpextract. checkjobstatus (jobid);} catch (exception e) {e. printstacktrace ();} If (jobres = NULL) return; jobstatus status = jobres. getjobstatus (); Switch (Status) {Case cancelled: Toast. maketext (Viewshed. this, "cancelled", toast. length_long ). show (); break; Case deleted: Toast. maketext (Viewshed. this, "deleted", toast. length_long ). show (); break; case failed: gpmessage [] Message = jobres. getmessages (); toast. maketext (Viewshed. this, "failed:" + message [0]. tostring (), toast. length_long ). show (); break; Case succeeded: Try {gpdatafile result = (gpdatafile) gpextract. getresultdata (jobid, "output_zip_file"); url = result. geturl (); uihandler. sendemptymessage (close_loading_window);} catch (exception e) {e. printstacktrace ();} break; Case timed_out: Toast. maketext (Viewshed. this, "timed_out", toast. length_long ). show (); break; default: break; }}, 1000,200 0 );}}
The above is the key code of this example. If you need the complete code, please leave a mailbox in the comment.