How to get IFeatureclass from ILayer

03-06-2013 02:31 AM
New Contributor

Can any one help me in getting the IFeatureClass from ILayer instance?

Thanks in Advance
Tags (2)
0 Kudos
3 Replies
Esri Contributor
Hello!  I am going to make some assumptions.  Please correct me if I'm wrong.

Since you are posting on the Network Analyst forum, I will assume that you want to get one of the NAClasses out of an NALayer.  For example, you want to open a Closest Facility layer and access the Facilities as a feature class.

You already have a layer as an ILayer.  Cast your ILayer as an INALayer.

   var naLayer = layer as INALayer;

Via the context and NAClasses, get the naclass and cast it as a feature class.

  var facilitiesFeatureClass = naLayer.Context.NAClasses.get_ItemByName("Facilities") as

IFeatureClass;Here is a code snippet that also works:

public ESRI.ArcGIS.NetworkAnalyst.INAClass GetNAClass(ESRI.ArcGIS.NetworkAnalyst.INALayer3 nalayer, System.String naClassName)
ESRI.ArcGIS.NetworkAnalyst.INAContext naContext = nalayer.Context;  ESRI.ArcGIS.NetworkAnalyst.INamedSet namedSet = naContext.NAClasses;  ESRI.ArcGIS.NetworkAnalyst.INAClass naClass = namedSet.get_ItemByName(naClassName) as ESRI.ArcGIS.NetworkAnalyst.INAClass; // Dynamic Cast  return naClass;
0 Kudos
New Contributor
Hi Patrick Stevens,

Thanks for your help.

Thank You once again.
0 Kudos
New Contributor
Hey Patrick thanks for providing us the good material about getting IFeature class from ILayer.
0 Kudos