18.04.2015 Views

ArcGIS Engine Developer Guide

ArcGIS Engine Developer Guide

ArcGIS Engine Developer Guide

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

BUILDING A COMMAND-LINE JAVA APPLICATION<br />

1. First, insert some logic to ensure that you have the correct number of arguments<br />

in the form of an if/else code block.<br />

This exercise does not implement any logic that<br />

determines whether the arguments being passed<br />

are valid strings or datapaths. This validation<br />

process may be beneficial when developing a<br />

production application.<br />

/*<br />

* Description:<br />

* Main Method - Application Entry Point<br />

*/<br />

public static void main(String[] args) {<br />

if(args.length != 2){<br />

System.out.println( "Tin to Point: <strong>ArcGIS</strong> <strong>Engine</strong> <strong>Developer</strong><br />

Scenario");<br />

System.out.println("Usage: TintoPoint [Path-to-tin] [Path-to-outputshapefile]");<br />

System.exit(0);<br />

}else{<br />

System.out.println( "Tin to Point: <strong>ArcGIS</strong> <strong>Engine</strong> <strong>Developer</strong> Sample");<br />

String inDataset = args[0];<br />

String outDataset = args[1];<br />

This application takes two arguments: an input full path to your TIN dataset and<br />

a full path to the generated output shapefile. Once the application determines the<br />

correct amount of arguments, they can be split into the path and name format<br />

required by the tinToPoint() method generated earlier.<br />

2. Add in the following code below the if/else code break you just created.<br />

String inDataPath = inDataset.substring( 0,<br />

inDataset.lastIndexOf(File.separator));<br />

String inDataName = inDataset.substring(<br />

inDataset.lastIndexOf(File.separator) + 1);<br />

String outDataPath = outDataset.substring( 0,<br />

outDataset.lastIndexOf(File.separator));<br />

String outDataName = outDataset.substring(<br />

outDataset.lastIndexOf(File.separator) + 1);<br />

The next step in creating the main method is to initialize the programming environment.<br />

In the <strong>ArcGIS</strong> Java API, this is handled by calling the static class<br />

<strong>Engine</strong>Initializer. This class is a facade class exposed by the Java API to ensure<br />

optimal use of native ArcObjects for Java. Following that, the static<br />

licenseCheckOut() method described above must be called.<br />

3. Add the following code to the main method.<br />

<strong>Engine</strong>Initializer.initilize<strong>Engine</strong>();<br />

licenseCheckOut();<br />

4. The last step is to call the static worker method tintoPoint() and pass in the<br />

string parameters.<br />

tinToPoint(inDataPath, inDataName, outDataPath, outDataName);<br />

try {<br />

aoInit.shutdown();<br />

} catch (IOException ex) {<br />

ex.printStackTrace();<br />

}<br />

System.out.println("Tin to Point - Done");<br />

}<br />

}<br />

Chapter 6 • <strong>Developer</strong> scenarios • 423

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!