ArcGIS API for Android case 13

Source: Internet
Author: User
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.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.