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.

JAVA APPLICATION PROGRAMMING INTERFACE<br />

provide an implementation to those interfaces. For each abstract class in<br />

ArcObjects there are subclasses that provide the implementation.<br />

A class cannot be publicly created in ArcObjects; however, objects of this class<br />

type can be created as a property of another class or instantiated by objects from<br />

another class. In the <strong>ArcGIS</strong> API for Java, the default constructor normally used<br />

to create a class is undefined for ArcObjects classes.<br />

/* The constructor for FeatureClass() is unsupported. */<br />

FeatureClass fc = new FeatureClass(); // incorrect usage<br />

The following example illustrates this behavior while guiding you through the<br />

process of opening a feature class.<br />

IWorkspaceFactory wf = new ShapefileWorkspaceFactory();<br />

IFeatureWorkspace fw = new<br />

IFeatureWorkspaceProxy(wf.openFromFile("\\path\\to\\data", 0));<br />

/* Create a Feature Class from FeatureWorkspace. */<br />

IFeatureClass fc = fw.openFeatureClass("featureclass name");<br />

In ArcObjects, a coclass is a publicly creatable class. This means that you can<br />

create your own objects merely by declaring a new object as shown below.<br />

/* Create an Envelope from the Envelope coclass. */<br />

Envelope env = new Envelope();<br />

Structs<br />

A structure defines a new data type made up of elements called members. Java<br />

does not have structures as complex data types. The Java language provides this<br />

functionality through classes; you can simply declare a class with the appropriate<br />

instance variables. For each structure in ArcObjects, there is a representative Java<br />

class with publicly declared instance variables matching the structure members as<br />

outlined below.<br />

ArcObjects Struct<br />

struct WKSPointZ<br />

double x<br />

double y<br />

double z<br />

}<br />

Java Representation<br />

public class _WKSPointZ {<br />

public double x;<br />

public double y;<br />

public double z;<br />

}<br />

You can work with these classes like any other class in Java:<br />

_WKSPointZ pt = new _WKSPointZ();<br />

pt.x = 2.23;<br />

pt.y = -23.14;<br />

pt.z = 4.85;<br />

System.out.println(pt.x + " " + pt.y + " " + pt.z);<br />

Enumerations<br />

Versions of the Java 2 SDK prior to version 5 do not have enum types. To emulate<br />

enumerations in Java, a class or interface must be created that holds constants.<br />

For each enumeration in native ArcObjects, there is a Java interface with<br />

publicly declared static integers representing the enumeration value.<br />

Chapter 4 • <strong>Developer</strong> environments • 187

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

Saved successfully!

Ooh no, something went wrong!