Use of geoprocessing in ArcGIS Server

Source: Internet
Author: User
In ArcGIS Server, geoprocessing can be used in ArcGIS Server in two ways: one is to call the geoprocessing service, and the other is to directly call the background geoprocessing tool. Both of these methods can simplify ArcGIS Server programming and save a lot of development workload for developers.

1. directly call the geoprocessing tool in ArcGIS Server

Tools in arctoolbox can basically be called in the server. This call method is no big difference from calling other AO components, because the tools are on the server and run on the server, the DLL libraries in these arctoolboxes are located in a similar installation directory, c: \ Program Files \ ArcGIS \ DOTNET \ toolboxes. For details about these tools, see the description of ArcGIS Server. NET development help, you can also help the desktop product system, including the parameter description. The attachment shows the location of all the tool descriptions in. NET development help.

The following is a tool that calls geoprocessing in the background in ArcGIS Server. datamanagermenttools-> features-> copy is called.

Protected void button#click (Object sender, eventargs E)
{

Iservercontext servercontext = NULL;

Try
{
ESRI. ArcGIS. esrisystem. ivariantarray varray = NULL;

Gisserverconnection serverconnection;
Serverconnection = new gisserverconnection ();

Serverconnection. Connect ("servername ");

Iserverobjectmanager servermanager = serverconnection. serverobjectmanager;

Servercontext = servermanager. createservercontext ("","");

// Directly call the method for creating the gp of the geoprocessing tool on the server:

ESRI. ArcGIS. geoprocessor. geoprocessor Gp = new ESRI. ArcGIS. geoprocessor. geoprocessor (servercontext );
ESRI. ArcGIS. datamanagementtools. copyfeatures = new ESRI. ArcGIS. datamanagementtools. copyfeatures ();

Varray = (ivariantarray) servercontext. Createobject ("esrisystem. vararray ");

// Set parameters

String inputfile = @ "D: \ ArcGIS \ arctutor \ tracking_analyst \ simple ";

String inputfeatureclass = "2000_hrcn.shp ";

String outputfile = @ "D: \ ArcGIS \ arctutor \ tracking_analyst \ simple ";

String outputfeatureclass = "output. SHP ";
Copyfeatures. in_features = @ inputfile + "\" + inputfeatureclass;
Copyfeatures. out_feature_class = @ outputfile + "\" + outputfeatureclass;
Varray. Add (copyfeatures. in_features );
Varray. Add (copyfeatures. out_feature_class );

// Execution Tool
GP. Execute (copyfeatures. toolname + "_" + copyfeatures. Alias, varray, null );
}

Catch (exception ex)
{
System. Diagnostics. Debug. writeline (ex. Message );
System. Diagnostics. Debug. writeline (ex. stacktrace );
}

Finally
{
Servercontext. releasecontext ();
}

}

2. Call the geoprocessing Service

To call the geoprocessing service in ArcGIS Server, first release the tool to ArcGIS Server. The publishing method is very simple. You only need to right-click a toolbox, select release to ArcGIS Server. See the figure below.

Then you can call this service on ArcGIS Server ..

Below is. the net ADF control is used to call geoprocessing services. The parameter classes used in this process all come from the ADF and all come from ESRI. arcGIS. ADF. web. datasources library.

Protected void button#click (Object sender, eventargs E)
{
Igeoprocessingresource IGP = geoprocessingresourcemanager1.getresource (0 );

ESRI. ArcGIS. ADF. Web. datasources. arcgisserver. geoprocessingfunctionality AGP =
(ESRI. ArcGIS. ADF. Web. datasources. arcgisserver. geoprocessingfunctionality)

IGP. createfunctionality (typeof (ESRI. ArcGIS. ADF. Web. CES. igeoprocessingfunctionality), null );

If (! AGP. initialized)
AGP. initialize ();
String taskname = "copy ";
ESRI. ArcGIS. ADF. Web. datasources. gptoolinfo gpti = AGP. gettask (taskname );
// Obtain the parameter information of the tool.
ESRI. ArcGIS. ADF. Web. datasources. gpparameterinfo [] paraminfos = gpti. parameterinfo;
// List the parameter types of the Tool
String parameternames = NULL;
ESRI. ArcGIS. ADF. Web. datasources. gpparameterinfo paraminfo;
For (INT I = 0; I <paraminfos. length; I ++)
{
Paraminfo = paraminfos;
Parameternames + = paraminfo. Name;

If (I! = Paraminfos. Length-1)
Parameternames + = ";";
}

// Set the parameters. In this case, the parameter type obtained above the result and the parameter description in the Help system are required.
ESRI. ArcGIS. ADF. Web. datasources. gpstring gpdatatype = new ESRI. ArcGIS. ADF. Web. datasources. gpstring ();
Gpdatatype. value = "shapefile ";

ESRI. ArcGIS. ADF. Web. datasources. gpstring gpdatafile = new ESRI. ArcGIS. ADF. Web. datasources. gpstring ();
Gpdatafile. value = @ "D: \ ArcGIS \ arctutor \ tracking_analyst \ simple \ 2000_hrcn.shp ";

ESRI. ArcGIS. ADF. Web. datasources. gpstring gpdatafileout = new ESRI. ArcGIS. ADF. Web. datasources. gpstring ();
Gpdatafileout. value = @ "D: \ ArcGIS \ arctutor \ tracking_analyst \ simple \ 2000_hrcnout.shp ";

Gpvalue [] gpvalues = new gpvalue [3];
Gpvalues [0] = gpdatafile;
Gpvalues [1] = gpdatafileout;
Gpvalues [2] = gpdatatype;
String jobid;

// Execute the tool to get the jobid so that it can be used to get the result.
Jobid = AGP. submitjob (taskname, gpvalues );

String returnstring = jobid + "," + taskname + "," + parameternames;
Thread. Sleep (2000 );
// Obtain the running result of the Tool
Gpjobstatus (returnstring );
}

Protected void gpjobstatus (string EA)
{
Char [] parser_char = {','};
String [] messages = EA. Split (parser_char );
String jobid = messages [0];
String taskname = messages [1];
String [] parameternames = messages [2]. Split (';');
Igeoprocessingresource IGP = geoprocessingresourcemanager1.getresource (0 );
ESRI. ArcGIS. ADF. Web. datasources. arcgisserver. geoprocessingfunctionality AGP =
(ESRI. ArcGIS. ADF. Web. datasources. arcgisserver. geoprocessingfunctionality)
IGP. createfunctionality (typeof (ESRI. ArcGIS. ADF. Web. CES. igeoprocessingfunctionality), null );

If (! AGP. initialized)
AGP. initialize ();
If (AGP. getjobstatus (jobid )! = Jobstatus. succeeded)
{
Textbox1.text = "Not finished yet. Thank you! ";
Return;
}

ESRI. ArcGIS. ADF. Web. datasources. gpresult GPR = AGP. getjobresult (taskname, jobid, parameternames, false );
Int Ic = GPR. Messages. length;
For (INT I = 0; I <IC; I ++)
{
Textbox1.text = textbox1.text + GPR. Messages. messagedesc. tostring ();
}
Gpvalue [] gpvs = GPR. values;

// Graphicslayer can be directly obtained without generating it by yourself, so the result can be easily added to the map control.
Gpfeaturegraphicslayer GFL = (gpfeaturegraphicslayer) gpvs [0];
Featuregraphicslayer glayer = GFL. layer;
Ienumerable GFC = map1.getfunctionalities ();
ESRI. ArcGIS. ADF. Web. datasources. Graphics. mapresource gresource = NULL;

Foreach (igisfunctionality gfunc in GFC)
{
If (gfunc. Resource. Name = "copy ")
{
Gresource = (ESRI. ArcGIS. ADF. Web. datasources. Graphics. mapresource) gfunc. resource;
Break;
}
}
If (gresource = NULL)
{Throw new exception ("no graphics layer .");}
Gresource. Graphics. Tables. Clear ();
Gresource. Graphics. Tables. Add (glayer );
If (map1.imageblendingmode = imageblendingmode. webtier)
{
Map1.refresh ();
}
Else if (map1.imageblendingmode = imageblendingmode. browser)
{
Map1.refreshresource (gresource. Name );
}
}

3. Comparison between the two

1) The geoprocessing service, as a standard web service, can be called in a standard way and is suitable for shared calls between enterprises. The direct call method is based on the principle of using DCOM, and the call of commonAOThe call principle of components is the same, and is suitable for internal use in enterprises.

2) The results are in different directories: directly call the tool. The output result is placed in the specified directory of the parameter. For example, copy the specified directory d in the preceding example: \ ArcGIS \ arctutor \ tracking_analyst \ simple, the result is in the directory of the server. When geoproessing is used to call a tool, the result is stored in the directory c: \ arcgisserver \ arcgisjobs \ datamanagementtools_gpserver \ j860384ada84d428586196e5813e000042. The name of the last folder isProgramThe jobid number returned during running, and the gpresult obtained by the program will have a result like grapchislayer that can be directly displayed in the map control.

[From: http://www.gisbing.com/index/showtopic-483.aspx]

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.