kaspatoo

How to add a FeatureClass to ArcMap?

Discussion created by kaspatoo on Feb 24, 2012
Latest reply on Feb 28, 2012 by kaspatoo
Hello,

I wonder how to create a layer best. I have a featureClass which I want to add as a Layer in ArcMap.
I also will save this layer as Layer-File (for both this operations I still know the methods, where in both cases an ILayer object is used).

There are two ways to create an ILayer as I think (FeatureLayer vs. FeatureLayerFactoryClass; see code below);
While the first one works fine, the usage of the factory will result in an empty enumeration.

I also heard about the IGxLayer interface. But when its as simple as I think, then do I really would need this IGxLayer?
Have someone some experience in here?

Thanks.

FeatureLayer ftLayer = new FeatureLayerClass();
ftLayer.FeatureClass = featureClass;
ILayer layer = ftLayer as ILayer;

--------------vs.----------------

ILayerFactory layerFactory = new FeatureLayerFactoryClass();
IEnumLayer enumLayer = layerFactory.Create(featureClass);
ILayer layer = enumLayer.Next(); //this will return null

Outcomes