Take the 2-minute tour ×
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

I'm new in programming . i'd like to write a simple code that can create offset from a polyline . i wrote the below code but when run the code i encounter to the error " Null reference exception was unhandled by user code" in line construct.ConstructOffset(pfeaturelayer as IPolyline, 100.3 , missing,missing); how can i solve the problem ?

public partial class copyparallel : Form
        IApplication papp;
        public IHookHelper phookhelper;
         IPolycurve ppolycurve;

        public copyparallel()

        private void button1_Click(object sender, EventArgs e)

            IFeatureLayer pfeaturelayer;
            IFeatureClass pfc;

            pfeaturelayer = (IFeatureLayer) phookhelper.FocusMap.get_Layer(0);
           pfc = pfeaturelayer.FeatureClass;

           IConstructCurve construct = new PolylineClass();
           object offset = esriConstructOffsetEnum.esriConstructOffsetMitered;

           object missing = Type.Missing;
           construct.ConstructOffset(pfeaturelayer as IPolyline, 100.3 , missing,missing);

           IFeatureClass poutfc;
           IFeature newf = pfc.CreateFeature();
           newf.Shape = (IGeometry)construct;


share|improve this question

1 Answer 1

up vote 3 down vote accepted

You'll have to loop through each feature in the feature class to get a polyline instead of trying to cast the entire featurelayer to a polyline.

*To answer your comment, it would look something like this. You'll have to translate into C#

Dim pFCur As IFeatureCursor
Dim pFeat As IFeature

pFCur = pfc.Search(Nothing, False)
pFeat = pFCur.NextFeature
Do Until pFeat Is Nothing
    Dim pPolyline As IPolyline
    pPolyline = pFeat.ShapeCopy

    'your code to construct the offset

    pFeat = pFCur.NextFeature
share|improve this answer
could you please describe detail ? how can i loop through each feature class to get a polyline ? –  wetland Sep 26 '12 at 21:25
your code work properly . –  wetland Sep 26 '12 at 22:40
How can i use IGPparameter to set parameter for Ipolyline? i want to use this application in toolbox. –  wetland Sep 30 '12 at 9:24

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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