Date:2018-4-17
Development environment:
MyEclipse, JDK 1.8 32-bit (64-bit environment cannot run Arcobject program, only project-referenced JDK), ArcGIS 10.5
Once the ArcGIS software installation is complete, install the Arcobject SDK for Java, after installation, to perform the two development of the AO
Development steps:
1. New ESRI Templates Sample project
The new ESRI Templates project is designed to eliminate the steps to initialize and load Arcobjects.jar ArcGIS license, see:
Select Arcobject Samples in the Pop-up dialog box, select the geoprocessing example, create a new project;
2. Modify the Initializearcgislicenses initialization license function body in the generated code ( This step should be noted )
Because different versions of ArcGIS are installed on everyone's machine, the license is not the same, so initialize the correct license
3, on the code
Public voidProduceformattedjsonfilefromtiff () {LocalDateTime start=Localdatetime.now (); String Projectroot=NewFile (""). GetAbsolutePath (); Try { //ADD The Bestpath Toolbox.Gp.addtoolbox (projectroot + "/RESOURCE/CUSTOMERTOOLBOX/ZCUSTOMER.TBX"); //Generate the array of parameters.Vararray parameters =NewVararray (); //Input TIF pathParameters.Add (projectroot + "/resource/data/rain_2016.flt"); //resampling Category ListParameters.Add ("0 0.013435 1;") + "0.013435 0.037422 2;0.037422 0.080247 3;" + "0.080247 0.156709 4;0.156709 0.293223 5;" + "0.293223 0.536956 6;0.536956 0.972118 7;" + "0.972118 1.749056 8;1.749056 3.136204 9;" + "3.136204 5.612822 10"); //Output JSON pathParameters.Add (projectroot + "/resource/result/rain_2016.json"); //Execute the Model tool by name.Igeoprocessorresult result = Gp.execute ("Producejsonfromfltwithnoproject", parameters,NULL); while(Result.getstatus () = =esrijobstatus.esrijobsucceeded) {System.out.println (Result.getoutputcount ()); String Resultjsonpath=(String) result.getreturnvalue (); System.out.println (Resultjsonpath); //reading JSON filesBufferedReader reader =NewBufferedReader (NewFileReader (NewFile (Resultjsonpath)); StringBuffer SB=NewStringBuffer (); String Line=Reader.readline (); while(Line! =NULL) {sb.append (line); Line=Reader.readline (); } jsonobject Jsonobject=Jsonobject.parseobject (sb.tostring ()); System.out.println (Result.getmessagecount ()); Break; } } Catch(IOException e) {//TODO auto-generated Catch blockE.printstacktrace (); } LocalDateTime End=Localdatetime.now (); Duration Duration=Duration.between (start, end); System.out.println ("Custom GP Run Time:" + duration.tomillis () + "milliseconds"); }
Tail note
The ZCUSTOMER.TBX in the snippet above is generated in the Model Editor in ArcMap, and when you reference the code above, be sure to change to your toolbox and enter the correct parameters for your toolbox.
Attention
When calling custom toolbox, be aware of 2 points: first, the name of the Toolbox tool, and the Order of the Toolbox tool's parameters
Arcobject SDK for Java calling custom Toolbox tools