AnsweredAssumed Answered

Method to get IFeatureClass

Question asked by ryan.hawkins on Feb 14, 2013
Latest reply on Feb 15, 2013 by ryan.hawkins
I am trying to create a method where I am able to select a specific layer and return the IFeatureClass of that layer. I used a return type double and it returns the correct value: 50. I would normally have return featureclass; but I am using the double to test the logic. I am unsure of when I would normally return 0, how I return an IFeatureClass. I am going to use this method to select two different featureclasses for spatial queries. Any suggestions from how to solve this problem to critiques on my coding techniques will be greatly appreciated! Below is the code I currently have:

public double GetFeatureLayer(string layerName)
{
try
{
IMap map = ArcMap.Document.FocusMap;

//Bail if map has no layers.
if (map.LayerCount == 0)
{
MessageBox.Show("There are no layers importerd. Please add Layers and try again");
return 0;
}

//Fetch all the feauture layers in the focus map
//to determine if at least one is selectable
IUID uid = new UIDClass();
uid.Value = "{40A9E885-5533-11D0-98BE-00805F7CED21}";
IEnumLayer enumLayer = map.get_Layers((UID)uid, true);
enumLayer.Reset();
IFeatureLayer featureLayer = (IFeatureLayer)enumLayer.Next();

while (featureLayer != null)
{
if (featureLayer.Name.ToString() == "Structure")
{
IFeatureClass featureClass = featureLayer.FeatureClass;
return 50;
}

else
{
featureLayer = (IFeatureLayer)enumLayer.Next();
}
}
return 0;
}
catch (Exception ex)
{
MessageBox.Show(ex.StackTrace);
return 0;
}
}

Outcomes