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 trying to draw a custom polygon in Dynamic Display but its really not working at all. I can get it to work if I do this:

IPointCollection pc = seg.setRectangle( mapcontrol.map.extent.envelope) as IPointCollection; 

But I want a custom polygon. I tried this following code but I'm getting -2147220968

       IPoint p0 = new PointClass(); 
        IPoint p1 = new PointClass();
        IPoint p2 = new PointClass();
        p0.SpatialReference = gcs;
        p1.SpatialReference = gcs;
        p2.SpatialReference = gcs;

        p0.PutCoords(-94.569168d, 46.697493d);
        p1.PutCoords(-94.052811d, 46.711619d);
        p2.PutCoords(-94.51561d, 46.520131d);

        p0.Project(mapSP); 
        p1.Project(mapSP); 
        p2.Project(mapSP); 

        ILine line = new LineClass();
        ILine line2 = new LineClass();
        ILine line3 = new LineClass();

        line.SpatialReference = mapSP;
        line2.SpatialReference = mapSP;
        line3.SpatialReference = mapSP;

        line.FromPoint= p0; 
        line.ToPoint = p1;

        line2.FromPoint= p1; 
        line2.ToPoint = p2;

        line3.FromPoint= p2; 
        line3.ToPoint = p0;

        ISegmentCollection seg = new PolygonClass();
        seg.AddSegment(line as ISegment);
        seg.AddSegment(line2 as ISegment);
        seg.AddSegment(line3 as ISegment);
        pc = seg as IPointCollection;

                           dynamicSymbolProps.set_DynamicGlyph(esriDynamicSymbolType.esriDSymbolFill, fillGlyph);
try
{
  dynamicDisplay.DrawPolygon(pc);
}
catch (Exception ex)
{
  string m= ex.Message; 
}
share|improve this question

1 Answer 1

up vote 0 down vote accepted

Using the above code and adding the following will get it to work.

ITopologicalOperator toppy = seg as ITopologicalOperator;
toppy.Simplify();
IPointCollection4 pc4 = toppy as IPointCollection4;

dynamicSymbolProps.set_DynamicGlyph(esriDynamicSymbolType.esriDSymbolFill, fillGlyph);

dynamicDisplay.DrawPolygon(pc4);
share|improve this answer

Your Answer

 
discard

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.