18.04.2015 Views

ArcGIS Engine Developer Guide

ArcGIS Engine Developer Guide

ArcGIS Engine Developer Guide

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

JAVA APPLICATION PROGRAMMING INTERFACE<br />

System.out.println(" wksp is a RasterWorkspace");<br />

rasWksp = (RasterWorkspace)wksp;<br />

}<br />

else{<br />

try{<br />

rasWksp = (RasterWorkspace)wksp;<br />

rasWksp.openRasterDataset( aRaster );<br />

}<br />

}catch(Exception e){<br />

/* Code executes if wksp is not a RasterWorkspace. */<br />

System.out.println(" wksp is not a RasterWorkspace");<br />

}<br />

Methods that take out parameters<br />

ArcObjects provides many methods that return more than one value. The <strong>ArcGIS</strong><br />

API for Java requires sending single element arrays as parameters to such methods.<br />

Basically, you pass in single element arrays of the object that you want to be<br />

returned, and ArcObjects fills in the first elements of those arrays with the return<br />

value. Upon returning from the method call, the first element of the array contains<br />

the value that has been set during the method call. One such method that<br />

you will be using in this section is the toMapPoint of IARMap interface. Take a<br />

look at the javadoc of this method:<br />

public void toMapPoint(int x,<br />

int y,<br />

double[] xCoord,<br />

double[] yCoord)<br />

throws IOException,<br />

AutomationException<br />

Converts a point in device coordinates (typically pixels) to coordinates in<br />

map units.<br />

Converts the x and y screen coordinates supplied in pixels to x and y map<br />

coordinates. The returned map coordinates will be in MapUnits.<br />

Parameters:<br />

x - The x (in)<br />

y - The y (in)<br />

xCoord - The xCoord (in/out: use single element array)<br />

yCoord - The yCoord (in/out: use single element array)<br />

Notice that the parameters xCoord and yCoord are marked as “in/out: use single<br />

element array”. To use this method, the first two parameters are the x and y<br />

coordinates in pixel units. The next two parameters are actually used to get return<br />

values from the method call. You pass in single-dimensional single element double<br />

arrays:<br />

double [] dXcoord = {0.0};<br />

double [] dYcoord = {0.0};<br />

When the method call completes, you can query the values of dXcoord[0] and<br />

dYcoord[0]. These values will be modified by the method and will actually refer to<br />

the x and y coordinates in map units. A practical example of this method call is<br />

192 • <strong>ArcGIS</strong> <strong>Engine</strong> <strong>Developer</strong> <strong>Guide</strong>

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

Saved successfully!

Ooh no, something went wrong!