selected polyline feature to a IPolyline

811
2
06-18-2010 12:16 PM
ChrisBradberry
Occasional Contributor
Hey,

I am trying to use the construct offset example, which is basically a copy parallel command. I have a selected polyline feature and I am trying to use the selected feature as an Ipolyline input for the construct offset method.

How do you cast the feature selection to a polyline?

This is for a tool in ArcMap 9.3.1

Thanks, Chris

 pFeatureSelection = (IFeatureSelection)pLayer;
 pSelectionSet = pFeatureSelection.SelectionSet;
 IPolyline inpolyline = null;
 ICursor pCursor;
 pSelectionSet.Search(null, false, out pCursor);
 inpolyline = (IPolyline)pFeatureSelection;               <== crashes here 
                                
 ConstructOffset(inpolyline, offset);                                
                               
0 Kudos
2 Replies
DuncanHornby
MVP Notable Contributor
Chris,

I'm not familiar with the language you are using (C ?) but in VB you need to get the feature from the cursor you created.

Firstly just want to clear up something.  Due to the name of your variable you have chosen (pLayer) this sugggest to me that you are pointing pFeatureSelection at an ILayer object, you must point pFeatureSelection at an IFeatureLayer object.

In your line of code pSelectionSet.Search(null, false, out pCursor); you've created a cursor called pCursor which has all the selected features in your layer. You would then go through your cursor getting the actual polyline object.  So the code below is how you would do this in VB:

Duncan

Dim pFeatureCursor as IFeatureCursor ' Note I'm using a IFeatureCursor and not a ICursor
pSelectionSet.Search nothing,false,pFeatureCursor
Dim pPolyline as IPolyline
Dim pFeature as IFeature
pFeature = pFeatureCursor.NextFeature
do while not pFeature is nothing
    pPolyline = pFeature.Shape

    ' Do something with the polyline

    pFeature = pFeatureCursor.NextFeature
loop
0 Kudos
ChrisBradberry
Occasional Contributor
Duncan,

Thanks for the help.  I am using C#, so it is a bit different from VB.  I have to use the ICursor, but the rest was like yours.

 ICursor pCursor;
 pSelectionSet.Search(null, false, out pCursor);
 IFeatureCursor pFeatureCursor = (IFeatureCursor)pCursor;
 IFeature pFeature = pFeatureCursor.NextFeature();
 inpolyline = (IPolyline)pFeature.Shape;
0 Kudos