How to cast a FeatureClass?

2843
2
12-02-2014 07:26 AM
ShaningYu
Frequent Contributor

I need to cast a featureclass to IPolyline.  In this piece of code below

IFeatureClass fcR = gHelp.GetFeatureClass(pWS2, fNameR);

ESRI.ArcGIS.Geometry.IPolyline refLine = fcR as ESRI.ArcGIS.Geometry.IPolyline;

the IPolyline refLine is null.  What's wrong in this piece of code?  Thanks if you can help.

Tags (1)
0 Kudos
2 Replies
ShaningYu
Frequent Contributor

I found my mistake in my post.  The correct way is to cast a line feature of a featureclass as an IPolyline: 

ESRI.ArcGIS.Geometry.IPolyline pLine = (ESRI.ArcGIS.Geometry.IPolyline)feature.ShapeCopy;

Thanks for your review.

0 Kudos
FreddieGibson
Occasional Contributor III

Hi Shuping,

You are correct in your findings. You cannot cast a FeatureClass to IPolyline because a feature class is a collection of polyline. As you discovered, you'd first need to get a feature (IFeature) from the polyline feature class and then you could cast its shape to IPolyline.

0 Kudos