Incomplete Polyline

657
1
Jump to solution
06-19-2012 03:51 AM
EdSurowiec
New Contributor II
I am trying to draw a polyline in a custom tool (BaseTool) on a AxGlobeControl (from 3DAnalyst) but I am not getting a continuous line.  Instead I get an arch with the center missing. 
The process I am using is from the examples.  I am creating a new GlobeGraphicsLayer and adding it to the scene I get from the GlobeHookHelperClass provided in the overridden BaseTool.OnCreate().  I am also creating a Polyline by defining the start and end Points.  I set a LineElement's geometry to the polyline and add it to the layer and this is what I get (the width is 10 so that more of the line displays).
[ATTACH=CONFIG]15312[/ATTACH]
Any ideas what I am missing?  Could there be an issue with the zoom level or camera position?
0 Kudos
1 Solution

Accepted Solutions
EdSurowiec
New Contributor II
The key was to use the MeasurementTool from DefenseSolutions.

        private void DrawRhumbLine(IPoint fromPoint, IPoint toPoint)
        {
            if (fromPoint == null || toPoint == null)
                return;

            try
            {
                IColor rgbColor = new RgbColorClass();
                rgbColor.RGB = 255;

                IPolyline polyline = CreateGeoPolyline(fromPoint, toPoint);

                ISimpleLineSymbol simpleLineSymbol = new SimpleLineSymbolClass();
                simpleLineSymbol.Color = rgbColor;
                simpleLineSymbol.Style = esriSimpleLineStyle.esriSLSSolid;
                simpleLineSymbol.Width = 2;

                ILineElement lineElement = new LineElementClass();
                lineElement.Symbol = simpleLineSymbol;

                IElement element = (IElement)lineElement; // Explicit Cast
                element.Geometry = polyline;

                m_globeGraphicsLayer.AddElement(element, 1);
            }
            catch (Exception ex)
            {
                logger.Error("Draw Rhumb Line encountered and error. {0}", ex.Message);
            }
        }


        private IPolyline CreateGeoPolyline(IPoint startPoint, IPoint endPoint)
        {
            try
            {
                // Set the measurement tool and the GeoPolyline. The measurement tool
                // will be used to calculate the distance and azimuth of the GeoPolyline
                // based on the start and end point coordinates of the line
                GeoPolyline geoPolyline = new ESRI.ArcGIS.DefenseSolutions.GeoPolyline();
                IMeasurementTool measurementTool = new ESRI.ArcGIS.DefenseSolutions.MeasurementTool();

                // Get the GeoPolyline type from the Type dropdown list and set it as
                // the type for both the measurement tool and the GeoPolyline. The options
                // are Geodesic, Great Circle, and Rhumb Line.
                measurementTool.SpecialGeolineType = ESRI.ArcGIS.DefenseSolutions.cjmtkSGType.cjmtkSGTRhumbLine;
                geoPolyline.SpecialGeolineType = ESRI.ArcGIS.DefenseSolutions.cjmtkSGType.cjmtkSGTRhumbLine;

                // Define the spatial reference of the rhumb line.
                // Define the spatial reference to be used for geopolylines,
                // geoellipses, and geopolygons.
                ESRI.ArcGIS.Geometry.ISpatialReferenceFactory2 pSpatRefFact = (ISpatialReferenceFactory2) new ESRI.ArcGIS.Geometry.SpatialReferenceEnvironment();
                ISpatialReference2 spatialReference2 = (ISpatialReference2) pSpatRefFact.CreateSpatialReference((int) ESRI.ArcGIS.Geometry.esriSRGeoCSType.esriSRGeoCS_WGS1984);

                // Initialize the MeasurementTool and define the properties of the line.
                // These properties include the line type, which is a rhumb line in this case, and the
                // spatial reference of the line.            
                measurementTool.SpecialGeolineType = cjmtkSGType.cjmtkSGTRhumbLine;
                measurementTool.SpecialSpatialReference = spatialReference2;

                // Determine the distance and azimuth of the rhumb line based on the start and end point coordinates.
                measurementTool.ConstructByPoints(startPoint, endPoint);
                geoPolyline.MaxPercent = 0.01;
                geoPolyline.UsePercent = true;
               
                IPolyline polyline = measurementTool.get_Polyline(1000);

                return measurementTool.get_Polyline(1000);
            }
            catch (Exception error)
            {
                logger.Error("There was a problem creating the rhumb line. {0}", error.Message);
            }
            return null;
        }


View solution in original post

0 Kudos
1 Reply
EdSurowiec
New Contributor II
The key was to use the MeasurementTool from DefenseSolutions.

        private void DrawRhumbLine(IPoint fromPoint, IPoint toPoint)
        {
            if (fromPoint == null || toPoint == null)
                return;

            try
            {
                IColor rgbColor = new RgbColorClass();
                rgbColor.RGB = 255;

                IPolyline polyline = CreateGeoPolyline(fromPoint, toPoint);

                ISimpleLineSymbol simpleLineSymbol = new SimpleLineSymbolClass();
                simpleLineSymbol.Color = rgbColor;
                simpleLineSymbol.Style = esriSimpleLineStyle.esriSLSSolid;
                simpleLineSymbol.Width = 2;

                ILineElement lineElement = new LineElementClass();
                lineElement.Symbol = simpleLineSymbol;

                IElement element = (IElement)lineElement; // Explicit Cast
                element.Geometry = polyline;

                m_globeGraphicsLayer.AddElement(element, 1);
            }
            catch (Exception ex)
            {
                logger.Error("Draw Rhumb Line encountered and error. {0}", ex.Message);
            }
        }


        private IPolyline CreateGeoPolyline(IPoint startPoint, IPoint endPoint)
        {
            try
            {
                // Set the measurement tool and the GeoPolyline. The measurement tool
                // will be used to calculate the distance and azimuth of the GeoPolyline
                // based on the start and end point coordinates of the line
                GeoPolyline geoPolyline = new ESRI.ArcGIS.DefenseSolutions.GeoPolyline();
                IMeasurementTool measurementTool = new ESRI.ArcGIS.DefenseSolutions.MeasurementTool();

                // Get the GeoPolyline type from the Type dropdown list and set it as
                // the type for both the measurement tool and the GeoPolyline. The options
                // are Geodesic, Great Circle, and Rhumb Line.
                measurementTool.SpecialGeolineType = ESRI.ArcGIS.DefenseSolutions.cjmtkSGType.cjmtkSGTRhumbLine;
                geoPolyline.SpecialGeolineType = ESRI.ArcGIS.DefenseSolutions.cjmtkSGType.cjmtkSGTRhumbLine;

                // Define the spatial reference of the rhumb line.
                // Define the spatial reference to be used for geopolylines,
                // geoellipses, and geopolygons.
                ESRI.ArcGIS.Geometry.ISpatialReferenceFactory2 pSpatRefFact = (ISpatialReferenceFactory2) new ESRI.ArcGIS.Geometry.SpatialReferenceEnvironment();
                ISpatialReference2 spatialReference2 = (ISpatialReference2) pSpatRefFact.CreateSpatialReference((int) ESRI.ArcGIS.Geometry.esriSRGeoCSType.esriSRGeoCS_WGS1984);

                // Initialize the MeasurementTool and define the properties of the line.
                // These properties include the line type, which is a rhumb line in this case, and the
                // spatial reference of the line.            
                measurementTool.SpecialGeolineType = cjmtkSGType.cjmtkSGTRhumbLine;
                measurementTool.SpecialSpatialReference = spatialReference2;

                // Determine the distance and azimuth of the rhumb line based on the start and end point coordinates.
                measurementTool.ConstructByPoints(startPoint, endPoint);
                geoPolyline.MaxPercent = 0.01;
                geoPolyline.UsePercent = true;
               
                IPolyline polyline = measurementTool.get_Polyline(1000);

                return measurementTool.get_Polyline(1000);
            }
            catch (Exception error)
            {
                logger.Error("There was a problem creating the rhumb line. {0}", error.Message);
            }
            return null;
        }


0 Kudos