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.

C++ APPLICATION PROGRAMMING INTERFACE<br />

• ISet—provides access to members that control a simple set of unique objects.<br />

For example, the following code snippet cycles through a map’s layers and<br />

attempts to add all of the unique feature class workspaces that aren’t being<br />

edited to a set.<br />

// ipMap is of type IMapPtr and was previously declared and instantiated.<br />

ISetPtr ipSet(CLSID_Set);<br />

ILayerPtr ipLayer;<br />

IFeatureLayerPtr ipFeatLayer;<br />

IFeatureClassPtr ipFeatClass;<br />

IDatasetPtr ipDataset;<br />

IWorkspacePtr ipWorkspace;<br />

IWorkspaceEditPtr ipWorkspaceEdit;<br />

long layerCount;<br />

hr = ipMap->get_LayerCount(&layerCount);<br />

for (long i=0; iget_Layer(i, &ipLayer);<br />

ipFeatLayer = ipLayer;<br />

// Layer might not be a feature layer.<br />

if (ipFeatLayer == 0 || FAILED(hr)) continue;<br />

hr = ipFeatLayer->get_FeatureClass(&ipFeatClass);<br />

// Layer could reference bogus data.<br />

if (ipFeatClass == 0 || FAILED(hr)) continue;<br />

ipDataset = ipFeatClass;<br />

hr = ipDataset->get_Workspace (&ipWorkspace);<br />

ipWorkspaceEdit = ipWorkspace;<br />

// Some data is not editable.<br />

if (ipWorkspaceEdit == 0 || FAILED(hr)) continue;<br />

VARIANT_BOOL beingEdited;<br />

hr = ipWorkspaceEdit->IsBeingEdited(&beingEdited);<br />

if (!beingEdited)<br />

{<br />

// Only adds unique workspaces<br />

hr = ipSet->Add(ipWorkspace);<br />

}<br />

}<br />

Copy objects<br />

The IClone interface is helpful when comparing and copying objects, saving time,<br />

and computing resources. Many coclasses support the IClone interface. See the<br />

documentation for IClone in <strong>ArcGIS</strong> <strong>Developer</strong> Help for details. The following<br />

code snippet clones a Point object:<br />

// ipMouseClickPoint is of type IPointPtr and was previously declared<br />

// and instantiated.<br />

IClonePtr ipClone (ipMouseClickPoint);<br />

IClonePtr ipCloned;<br />

ipClone->Clone(&ipCloned);<br />

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