0

I am trying to covert my feature class to feature layer so that i can pass "IQueryByLayer" over my feature class.

Till now i have my feature class ---

FeatureClass className = new FeatureClass(cc);

want to do something like

IFeatureLayer newLayer = className.as---(FeatureLayer)

Can anybody point out a correct way to impliment it.

2
  • Is this code running in an ArcMap addin/ ArcObjects custom class? Jun 19, 2013 at 10:02
  • No a destop tool where i am providing user to select two different feature classes////
    – NewBee
    Jun 19, 2013 at 11:12

1 Answer 1

1

IFeatureLayer only make sense when your code is working within ArcMap. If that is your case, have a look at this code:

IFeatureLayer featureLayer = new FeatureLayerClass();
featureLayer.FeatureClass = featureWorkspace.OpenFeatureClass("2000_hrcn");
ILayer layer = (ILayer)featureLayer;
layer.Name = featureLayer.FeatureClass.AliasName;
// Add the layer to the focus map.
ESRI.ArcGIS.ArcMapUI.IMxDocument mxDocument = (ESRI.ArcGIS.ArcMapUI.IMxDocument)(m_application.Document);
IMap map = mxDocument.FocusMap;
map.AddLayer(layer);
//now you can use the the IFeatureLayer

Also note that A featureclass cannot be instantiated directly. You can only get it as a result from other methods like IfeatureWorkspace.OpenFeatureClass method.

Code like FeatureClass className = new FeatureClass(cc); will not compile

2
  • 1
    I know i am getting it through IFeatureClass itration...Isn't there any way so that i can convert my feature class to layer and use it in IQueryByLayer...
    – NewBee
    Jun 19, 2013 at 11:16
  • No, It will work only within ArcMap Jun 19, 2013 at 11:56

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.