ariharan3

Spacial Reference not set to IElement.Geometry

Discussion created by ariharan3 on Sep 13, 2011
Latest reply on Oct 8, 2012 by dbarrio
I need to draw a line which have a set of point collection. From the point collection am getting the line. Then i need to pass this line as a Element to Draw in GraphicsContainer. But, the problem is, while casting the line as element, all the values are set except the spatialreference...
What is the reason? Anyone have answer?
 
                                    // create polyline
   IPolyline objLine = null;
   objLine = new PolylineClass();
           
   // get points collection
   IPointCollection objPoints = null;
   objPoints = objLine as IPointCollection;

                                       Point objPoint = new PointClass();

   // copy points from DD to line
   int nItemsCount = objDirections.Count;
   for (int i = 0; i < nItemsCount; i++)
   {
    // get shape from Direction
    ISMDirItem objItem = null;
    objItem = objDirections.get_Item(i) as ISMDirItem;

    ISMPointsCollection objShape = null;
    objShape = objItem.Shape;

                // Add point from Direction to received collection
    int nPointsCount = objShape.Count - 1;
    for (int j = 0; j <= nPointsCount; j++)
    {
     // get point from route
     SMRouterPoint objRouterPoint = objShape.get_Item(j);

                    // Optimization: Not add point if last added point has similar coords
     bool bAddPoint = false;

     if (objPoint.IsEmpty)
      bAddPoint = true;
     else if ((objPoint.X != objRouterPoint.X) & (objPoint.Y != objRouterPoint.Y))
      bAddPoint = true;

     if (bAddPoint)
     {
      // Add point if need
      objPoint.X = objRouterPoint.X;
      objPoint.Y = objRouterPoint.Y;
      objPoint.SpatialReference = m_objSpatialReference;

      object missing = System.Reflection.Missing.Value;
      objPoints.AddPoint(objPoint, ref missing, ref missing);
     }
    }
   }

                                      IElement objElement = null;
   objElement = new LineElementClass();
                                       objElement.Geometry =objLine as IGeometry;

SimpleLineSymbol objSymbol = null;
   objSymbol = new SimpleLineSymbolClass();

   // Set Symbol style and width
   objSymbol.Style = esriSimpleLineStyle.esriSLSSolid;
   objSymbol.Width = 10;

   // Set symbol color
   RgbColor objColor = null;
   objColor = new RgbColorClass();
   objColor.Red = 255;
   objColor.Green = 0;
   objColor.Blue = 0;

   objSymbol.Color = objColor;

   // set line symbol
   ILineElement objLineElement = objElement as ILineElement;
   objLineElement.Symbol = objSymbol as ILineSymbol;


                                       // get Graphic container
   IGraphicsContainer objCont = objMap as IGraphicsContainer;
          
   // Add line to map
   objCont.AddElement(objElement, 0);

Outcomes