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.

BUILDING A COMMAND-LINE JAVA APPLICATION<br />

System.out.println(" - Calculating ... ");<br />

Tin tin = new Tin(tinAdv);<br />

3. Next, get the spatial reference of the Tin and send it as a parameter to a<br />

createBasicFields() method that will be defined in the next section. In addition,<br />

you need to send a geometry type point since your resulting feature class will<br />

be a point feature class.<br />

ISpatialReference tinSpatialRef = tin.getSpatialReference();<br />

IFields fields = createBasicFields(esriGeometryType.esriGeometryPoint,<br />

false, true, tinSpatialRef);<br />

4. Now that the basic fields have been generated, the next step is to create an<br />

output shapefile. WorkspaceFactory is used as a dispenser of workspaces to<br />

create an instance of a ShapefileWorkspaceFactory class. The IFeatureWorkspace<br />

interface is used to access and manage datasets. You will cross-cast to the<br />

returned object that implements IWorkspace by creating an instance of the<br />

IFeatureWorkspaceProxy class using its object constructor. Finally, your output<br />

shapefile is generated using the createFeatureClass() method to create a<br />

standalone feature class.<br />

// Create output shapefile.<br />

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

IFeatureWorkspace featureWksp = new IFeatureWorkspaceProxy(<br />

wkspFactory.openFromFile(shapePath, 0));<br />

IFeatureClass outFC = new IFeatureClassProxy(<br />

featureWksp.createFeatureClass( shapeFile,<br />

fields,<br />

null,<br />

null,<br />

esriFeatureType.esriFTSimple,<br />

"Shape",<br />

""));<br />

5. The final step in creating this method is to populate the newly created feature<br />

class with the value of the nodes from your input TIN. The<br />

makeNodeEnumerator() method returns enumerations of nodes based on an<br />

extent and a criteria. The extent used is that of the input TIN dataset, and all<br />

data inside the TIN is used as the criteria. Once an enumeration object is filled<br />

with your TIN nodes, use a FeatureCursor as a data access object to iterate over<br />

the set of rows in your newly created feature class and a FeatureBuffer object to<br />

hold the state of the row. Next, create an instance of the Point class and<br />

populate it with your TIN nodes by instantiating an ITinNode interface with<br />

the objects returned by your enumeration. While your node is not null, loop<br />

through them and populate your feature class.<br />

// Get tin node enum.<br />

IEnumTinNode nodeEnum = tin.makeNodeEnumerator(tin.getExtent(),<br />

esriTinQualification.esriTinInsideDataArea, null);<br />

//Store node to shapefile.<br />

IFeatureCursor outCursor = outFC.IFeatureClass_insert(true);<br />

IFeatureBuffer outBuffer = outFC.createFeatureBuffer();<br />

IPoint point = new Point();<br />

ITinNode node = nodeEnum.IEnumTinNode_next();<br />

418 • <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!