How to get the geometry from an ILayer object in C#

1880
2
03-03-2011 11:28 AM
ReneeCammarere
Occasional Contributor
From reading the documentation, I assumed that this was the way to accomplish that.  However, I got an error when I tried to cast an ILayer object to an IFeatureLayer object.  This is the snippit of code:

ILayer pLayer = aMap.get_Layer(layercount - 1);
IFeatureLayer pFeatureLayer = (IFeatureLayer)pLayer;
IFeatureClass pFeatureClass = pFeatureLayer.FeatureClass;
IFeature pFeature = pFeatureClass.CreateFeature();
IGeometry pGeometry = pFeature.Shape;
0 Kudos
2 Replies
BradChappell
New Contributor
What type of layer is it?  Some layer types do not implement IFeatureLayer; e.g. Raster Layer
0 Kudos
BrianBottoms
New Contributor
Just to build on what was already said, you need to check if your ILayer is a 'TypeOf'  IFeatureLayer

If this returns true then you can check the featureclass ShapeType property.

Brian
0 Kudos