Geographic Processing Service
Figure 31 Viewshed example of calling the GP Service
In ArcGIS Android API, it is an interesting example to demonstrate the calling of the GP Service (Viewshed). This example allows users to draw a dot on the screen, then, send a request to call the GP service through the button executed in the upper left corner. When the GP service is successfully called, some polygon are returned to the client, these polygon indicate the areas that can be seen by someone standing in the position of the user's painting point.
Now, if you open the exampleSource codeYou can easily find the method of calling the GP service from the event listener of the "go" button in the upper left corner:
Gpfeaturerecordsetlayer GPF =NewGpfeaturerecordsetlayer (
"Input_observation_point ");
GPF. setspatialreference (Map. getspatialreference ());
GPF. setgeometrytype ("esrigeometrypoint ");
Graphic F =NewGraphic ();
F. setgeometry (mappoint );
GPF. addgraphic (f );
Gplinearunit GPL =NewGplinearunit ("viewshed_distance ");
GPL. setunits ("esrimeters ");
GPL. setdistance (8046.72 );
Params =NewArraylist ();
Params. Add (GPF );
Params. Add (GPL );
Try{
Dialog = progressdialog. Show (Viewshed.This,"",
"Loading. Please wait ...",True,True);
NewViewshedquery(cmd.exe cute (Params );
Cancelviewshed =NewTimer ();
Cancelviewshed. Schedule (NewTimertask (){
@ Override
Public VoidRun (){
Uihandler. sendemptymessage (cancel_loading_window );
}
},60000 );
}Catch(Exception e ){
E. printstacktrace ();
}
AboveCodeThe first thing is to prepare the arraylist parameter required for executing the GP service. The other thing is to start calling the GP service. In this example, the calling of the GP service is also encapsulated. In fact, the core code can be seen from the highlighted section of the following code (the code is slightly modified ):
ClassViewshedqueryExtends
Asynctask, void, gpparameter []> {
Gpparameter [] outparams =Null;
@ Override
Protected VoidOnpostexecute (gpparameter [] result ){
...
}
@ Override
ProtectedGpparameter [] doinbackground (
Arraylist ... Params1 ){
Gp =NewGeoprocessor ("http://sampleserver1.arcgisonline.com/ArcGIS
/Rest/services/Elevation/esri_elevation_world/gpserver/Viewshed ");
GP. setoutsr (Map. getspatialreference (). GETID ());
Try{
Gpresultresource uplr = gp.exe cute (params1 [0]);
Outparams = maid ();
}Catch(Exception e ){
E. printstacktrace ();
}
ReturnOutparams;
}
Obviously, this GP service is a synchronous execution service. Therefore, the execute method of the geoprocessor object is called here. If it is an asynchronous GP service, it should be the submitjob Method for executing geoprocessor. If you are interested, try again.