/// <summary>
 /// Create a geodetic ellipse
 /// </summary>
 private IGeometry DrawEllipse()
 {
     try
     {
         var    ellipticArc = new Polyline() as IConstructGeodetic;
         double bearing;
         if (AzimuthType == AzimuthTypes.Mils)
         {
             bearing = GetAzimuthAsDegrees();
         }
         else
         {
             bearing = Azimuth;
         }
         ellipticArc.ConstructGeodesicEllipse(Point1, GetLinearUnit(), MajorAxisDistance, MinorAxisDistance, bearing, esriCurveDensifyMethod.esriCurveDensifyByAngle, 0.01);
         var line = ellipticArc as IPolyline;
         if (line != null)
         {
             AddGraphicToMap(line as IGeometry);
             //Convert ellipse polyline to polygon
             var newPoly = PolylineToPolygon((IPolyline)ellipticArc);
             if (newPoly != null)
             {
                 //Get centroid of polygon
                 var area = newPoly as IArea;
                 //Add text using centroid point
                 DistanceTypes dtVal = (DistanceTypes)LineDistanceType; //Get line distance type
                 AzimuthTypes  atVal = (AzimuthTypes)AzimuthType;       //Get azimuth type
                 if (area != null)
                 {
                     AddTextToMap(area.Centroid, string.Format("{0}:{1} {2}{3}{4}:{5} {6}{7}{8}:{9} {10}",
                                                               "Major Axis",
                                                               Math.Round(majorAxisDistance, 2),
                                                               dtVal.ToString(),
                                                               Environment.NewLine,
                                                               "Minor Axis",
                                                               Math.Round(minorAxisDistance, 2),
                                                               dtVal.ToString(),
                                                               Environment.NewLine,
                                                               "Orientation Angle",
                                                               Math.Round(azimuth, 2),
                                                               atVal.ToString()));
                 }
             }
         }
         return(line as IGeometry);
     }
     catch (Exception ex)
     {
         Console.WriteLine(ex.Message);
         return(null);
     }
 }
        private void UpdateAzimuthFromTo(AzimuthTypes fromType, AzimuthTypes toType)
        {
            try
            {
                double angle = Azimuth.GetValueOrDefault();

                if (fromType == AzimuthTypes.Degrees && toType == AzimuthTypes.Mils)
                {
                    angle *= 17.777777778;
                }
                else if (fromType == AzimuthTypes.Mils && toType == AzimuthTypes.Degrees)
                {
                    angle *= 0.05625;
                }

                Azimuth = angle;
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex);
            }
        }
Beispiel #3
0
        private void UpdateAzimuthFromTo(AzimuthTypes fromType, AzimuthTypes toType)
        {
            try
            {
                double angle = Azimuth;

                if (fromType == AzimuthTypes.Degrees && toType == AzimuthTypes.Mils)
                {
                    angle *= 17.777777778;
                }
                else if (fromType == AzimuthTypes.Mils && toType == AzimuthTypes.Degrees)
                {
                    angle *= 0.05625;
                }

                Azimuth = angle;
            }
            catch (Exception ex)
            {
                System.Diagnostics.Debug.WriteLine(ex);
            }
        }
Beispiel #4
0
        private void UpdateAzimuthFromTo(AzimuthTypes fromType, AzimuthTypes toType)
        {
            try
            {
                double angle = Azimuth.GetValueOrDefault();

                if (fromType == AzimuthTypes.Degrees && toType == AzimuthTypes.Mils)
                {
                    angle *= ValueConverterConstant.DegreeToMils;
                }
                else if (fromType == AzimuthTypes.Degrees && toType == AzimuthTypes.Gradians)
                {
                    angle *= ValueConverterConstant.DegreeToGradian;
                }
                else if (fromType == AzimuthTypes.Mils && toType == AzimuthTypes.Degrees)
                {
                    angle *= ValueConverterConstant.MilsToDegree;
                }
                else if (fromType == AzimuthTypes.Mils && toType == AzimuthTypes.Gradians)
                {
                    angle *= ValueConverterConstant.MilsToGradian;
                }
                else if (fromType == AzimuthTypes.Gradians && toType == AzimuthTypes.Degrees)
                {
                    angle *= ValueConverterConstant.GradianToDegree;
                }
                else if (fromType == AzimuthTypes.Gradians && toType == AzimuthTypes.Mils)
                {
                    angle *= ValueConverterConstant.GradianToMils;
                }

                Azimuth = angle;
            }
            catch (Exception ex)
            {
                System.Diagnostics.Debug.WriteLine(ex);
            }
        }
        /// <summary>
        /// Create a geodetic line
        /// </summary>
        private IGeometry CreatePolyline()
        {
            try
            {
                if (Point1 == null || Point2 == null)
                {
                    return(null);
                }

                var construct = new Polyline() as IConstructGeodetic;

                if (construct == null)
                {
                    return(null);
                }

                if (srf3 == null)
                {
                    // if you don't use the activator, you will get exceptions
                    Type srType = Type.GetTypeFromProgID("esriGeometry.SpatialReferenceEnvironment");
                    srf3 = Activator.CreateInstance(srType) as ISpatialReferenceFactory3;
                }

                var linearUnit        = srf3.CreateUnit((int)esriSRUnitType.esriSRUnit_Meter) as ILinearUnit;
                esriGeodeticType type = GetEsriGeodeticType();
                IGeometry        geo  = Point1;
                if (LineFromType == LineFromTypes.Points)
                {
                    construct.ConstructGeodeticLineFromPoints(GetEsriGeodeticType(), Point1, Point2, GetLinearUnit(), esriCurveDensifyMethod.esriCurveDensifyByDeviation, -1.0);
                }
                else
                {
                    Double bearing = 0.0;
                    if (LineAzimuthType == AzimuthTypes.Mils)
                    {
                        bearing = GetAzimuthAsDegrees();
                    }
                    else
                    {
                        bearing = (double)Azimuth;
                    }
                    construct.ConstructGeodeticLineFromDistance(type, Point1, GetLinearUnit(), Distance, bearing, esriCurveDensifyMethod.esriCurveDensifyByDeviation, -1.0);
                }
                var mxdoc = ArcMap.Application.Document as IMxDocument;
                var av    = mxdoc.FocusMap as IActiveView;
                if (LineFromType == LineFromTypes.Points)
                {
                    UpdateDistance(construct as IGeometry);
                    UpdateAzimuth(construct as IGeometry);
                }

                IDictionary <String, System.Object> lineAttributes = new Dictionary <String, System.Object>();
                lineAttributes.Add("distance", Distance);
                lineAttributes.Add("distanceunit", LineDistanceType.ToString());
                lineAttributes.Add("angle", (double)Azimuth);
                lineAttributes.Add("angleunit", LineAzimuthType.ToString());
                lineAttributes.Add("startx", Point1.X);
                lineAttributes.Add("starty", Point1.Y);
                lineAttributes.Add("endx", Point2.X);
                lineAttributes.Add("endy", Point2.Y);
                var color = new RgbColorClass()
                {
                    Red = 255
                } as IColor;
                AddGraphicToMap(construct as IGeometry, color, attributes: lineAttributes);

                if (HasPoint1 && HasPoint2)
                {
                    //Get line distance type
                    DistanceTypes dtVal = (DistanceTypes)LineDistanceType;
                    //Get azimuth type
                    AzimuthTypes atVal = (AzimuthTypes)LineAzimuthType;
                    //Get mid point of geodetic line
                    var midPoint = new Point() as IPoint;
                    ((IPolyline)((IGeometry)construct)).QueryPoint(esriSegmentExtension.esriNoExtension, 0.5, false, midPoint);
                    //Create text symbol using text and midPoint
                    AddTextToMap(midPoint != null ? midPoint : Point2,
                                 string.Format("{0}:{1} {2}{3}{4}:{5} {6}",
                                               "Distance",
                                               Math.Round(Distance, 2).ToString("N2"),
                                               dtVal.ToString(),
                                               Environment.NewLine,
                                               "Angle",
                                               Math.Round(azimuth.Value, 2),
                                               atVal.ToString()), (double)Azimuth, LineAzimuthType);
                }

                ResetPoints();

                return(construct as IGeometry);
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex);
                return(null);
            }
        }
        private void UpdateAzimuthFromTo(AzimuthTypes fromType, AzimuthTypes toType)
        {
            try
            {
                double angle = Azimuth.GetValueOrDefault();

                if (fromType == AzimuthTypes.Degrees && toType == AzimuthTypes.Mils)
                    angle *= 17.777777778;
                else if (fromType == AzimuthTypes.Mils && toType == AzimuthTypes.Degrees)
                    angle *= 0.05625;

                Azimuth = angle;
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex);
            }
        }
 /// <summary>
 /// Create a geodetic ellipse
 /// </summary>
 private IGeometry DrawEllipse()
 {
     try
     {
         var    ellipticArc = new Polyline() as IConstructGeodetic;
         double bearing;
         if (AzimuthType == AzimuthTypes.Mils)
         {
             bearing = GetAzimuthAsDegrees();
         }
         else
         {
             bearing = Azimuth;
         }
         ellipticArc.ConstructGeodesicEllipse(Point1, GetLinearUnit(), MajorAxisDistance, MinorAxisDistance, bearing, esriCurveDensifyMethod.esriCurveDensifyByAngle, 0.01);
         var line = ellipticArc as IPolyline;
         if (line != null)
         {
             var color = new RgbColorClass()
             {
                 Red = 255
             } as IColor;
             IDictionary <String, System.Object> ellipseAttributes = new Dictionary <String, System.Object>();
             ellipseAttributes.Add("majoraxis", MajorAxisDistance);
             ellipseAttributes.Add("minoraxis", MinorAxisDistance);
             ellipseAttributes.Add("azimuth", Azimuth);
             ellipseAttributes.Add("centerx", Point1.X);
             ellipseAttributes.Add("centery", Point1.Y);
             ellipseAttributes.Add("distanceunit", LineDistanceType.ToString());
             ellipseAttributes.Add("angleunit", AzimuthType.ToString());
             AddGraphicToMap(line as IGeometry, color, attributes: ellipseAttributes);
             //Convert ellipse polyline to polygon
             var newPoly = PolylineToPolygon((IPolyline)ellipticArc);
             if (newPoly != null)
             {
                 //Get centroid of polygon
                 var area = newPoly as IArea;
                 //Add text using centroid point
                 DistanceTypes dtVal       = (DistanceTypes)LineDistanceType; //Get line distance type
                 AzimuthTypes  atVal       = (AzimuthTypes)AzimuthType;       //Get azimuth type
                 EllipseTypes  ellipseType = EllipseType;
                 double        majDist     = majorAxisDistance;
                 double        minDist     = minorAxisDistance;
                 if (ellipseType == EllipseTypes.Full)
                 {
                     majDist = majorAxisDistance * 2;
                     minDist = minorAxisDistance * 2;
                 }
                 if (area != null)
                 {
                     AddTextToMap(area.Centroid, string.Format("{0}:{1} {2}{3}{4}:{5} {6}{7}{8}:{9} {10}",
                                                               "Major Axis",
                                                               Math.Round(majDist, 2),
                                                               dtVal.ToString(),
                                                               Environment.NewLine,
                                                               "Minor Axis",
                                                               Math.Round(minDist, 2),
                                                               dtVal.ToString(),
                                                               Environment.NewLine,
                                                               "Orientation Angle",
                                                               Math.Round(azimuth, 2),
                                                               atVal.ToString()));
                 }
             }
         }
         return(line as IGeometry);
     }
     catch (Exception ex)
     {
         Console.WriteLine(ex.Message);
         return(null);
     }
 }
Beispiel #8
0
        /// <summary>
        /// Create a geodetic line
        /// </summary>
        private IGeometry CreatePolyline()
        {
            try
            {
                if ((Point1 == null) || (Point2 == null))
                {
                    return(null);
                }

                var construct = (IConstructGeodetic) new Polyline();

                if (srf3 == null)
                {
                    // if you don't use the activator, you will get exceptions
                    Type srType = Type.GetTypeFromProgID("esriGeometry.SpatialReferenceEnvironment");
                    srf3 = Activator.CreateInstance(srType) as ISpatialReferenceFactory3;
                }

                if (srf3 == null)
                {
                    return(null);
                }

                esriGeodeticType type = GetEsriGeodeticType();
                if (LineFromType == LineFromTypes.Points)
                {
                    construct.ConstructGeodeticLineFromPoints(GetEsriGeodeticType(), Point1, Point2, GetLinearUnit(), esriCurveDensifyMethod.esriCurveDensifyByDeviation, -1.0);
                }
                else
                {
                    Double bearing = 0.0;
                    if (LineAzimuthType == AzimuthTypes.Mils)
                    {
                        bearing = GetAzimuthAsDegrees();
                    }
                    else
                    {
                        bearing = (double)Azimuth;
                    }
                    construct.ConstructGeodeticLineFromDistance(type, Point1, GetLinearUnit(), Distance, bearing, esriCurveDensifyMethod.esriCurveDensifyByDeviation, -1.0);
                }

                if (LineFromType == LineFromTypes.Points)
                {
                    UpdateDistance(construct as IGeometry);
                    UpdateAzimuth(construct as IGeometry);
                }

                IDictionary <String, System.Object> lineAttributes = new Dictionary <String, System.Object>();
                lineAttributes.Add("distance", Distance);
                lineAttributes.Add("distanceunit", LineDistanceType.ToString());
                lineAttributes.Add("angle", (double)Azimuth);
                lineAttributes.Add("angleunit", LineAzimuthType.ToString());
                lineAttributes.Add("startx", Point1.X);
                lineAttributes.Add("starty", Point1.Y);
                lineAttributes.Add("endx", Point2.X);
                lineAttributes.Add("endy", Point2.Y);
                var color = new RgbColorClass()
                {
                    Red = 255
                } as IColor;
                AddGraphicToMap(construct as IGeometry, color, attributes: lineAttributes);

                if (HasPoint1 && HasPoint2)
                {
                    if (Point1.SpatialReference != ArcMap.Document.FocusMap.SpatialReference)
                    {
                        Point1.Project(ArcMap.Document.FocusMap.SpatialReference);
                    }
                    //Get line distance type
                    DistanceTypes dtVal = (DistanceTypes)LineDistanceType;
                    //Get azimuth type
                    AzimuthTypes atVal = (AzimuthTypes)LineAzimuthType;
                    //Create text symbol using text and Point1
                    AddTextToMap(Point1, /* Use the start point for label */
                                 string.Format("{0}:{3}{1} {2}{3}{4}:{3}{5} {6}",
                                               "Distance",
                                               Math.Round(Distance, 2).ToString("N2"),
                                               dtVal.ToString(),
                                               Environment.NewLine,
                                               "Angle",
                                               Math.Round(azimuth.Value, 2),
                                               atVal.ToString()), (double)Azimuth, LineAzimuthType, false);
                }

                ResetPoints();

                return(construct as IGeometry);
            }
            catch (Exception ex)
            {
                System.Diagnostics.Debug.WriteLine(ex);
                return(null);
            }
        }
Beispiel #9
0
        /// <summary>
        /// Create a geodetic ellipse
        /// </summary>
        private IGeometry DrawEllipse()
        {
            try
            {
                var ellipticArc = (IConstructGeodetic) new Polyline();

                double bearing;
                bearing = GetAzimuthAsDegrees();
                ellipticArc.ConstructGeodesicEllipse(Point1, GetLinearUnit(), MajorAxisDistance, MinorAxisDistance, bearing, esriCurveDensifyMethod.esriCurveDensifyByAngle, 0.01);
                var line = ellipticArc as IPolyline;
                if (line != null)
                {
                    var color = (IColor) new RgbColorClass()
                    {
                        Red = 255
                    };

                    var displayValue = new EnumToFriendlyNameConverter();
                    var unitLabel    = Convert.ToString(displayValue.Convert(LineDistanceType, typeof(string), new object(), CultureInfo.CurrentCulture));

                    IDictionary <String, System.Object> ellipseAttributes = new Dictionary <String, System.Object>();
                    ellipseAttributes.Add("majoraxis", MajorAxisDistance);
                    ellipseAttributes.Add("minoraxis", MinorAxisDistance);
                    ellipseAttributes.Add("azimuth", Azimuth);
                    ellipseAttributes.Add("centerx", Point1.X);
                    ellipseAttributes.Add("centery", Point1.Y);
                    ellipseAttributes.Add("distanceunit", unitLabel.ToString());
                    ellipseAttributes.Add("angleunit", AzimuthType.ToString());

                    AddGraphicToMap((IGeometry)line, color, attributes: ellipseAttributes);

                    //Convert ellipse polyline to polygon
                    var newPoly = PolylineToPolygon((IPolyline)ellipticArc);
                    if (newPoly != null)
                    {
                        //Get centroid of polygon
                        var area = newPoly as IArea;
                        //Add text using centroid point
                        DistanceTypes dtVal       = (DistanceTypes)LineDistanceType; //Get line distance type
                        AzimuthTypes  atVal       = (AzimuthTypes)AzimuthType;       //Get azimuth type
                        EllipseTypes  ellipseType = EllipseType;
                        double        majAxisDist = majorAxisDistance * 2;
                        double        minAxisDist = minorAxisDistance * 2;

                        if (area != null)
                        {
                            AddTextToMap(area.LabelPoint, string.Format("{0}:{1} {2}{3}{4}:{5} {6}{7}{8}:{9} {10}",
                                                                        StringParser.GetStringValue(LabelTypes.MajorAxis),
                                                                        Math.Round(majAxisDist, 2),
                                                                        StringParser.GetStringValue(dtVal),
                                                                        Environment.NewLine,
                                                                        StringParser.GetStringValue(LabelTypes.MinorAxis),
                                                                        Math.Round(minAxisDist, 2),
                                                                        StringParser.GetStringValue(dtVal),
                                                                        Environment.NewLine,
                                                                        StringParser.GetStringValue(LabelTypes.Angle),
                                                                        Math.Round(azimuth, 0),
                                                                        StringParser.GetStringValue(atVal)));
                        }
                    }
                }
                return((IGeometry)line);
            }
            catch (Exception ex)
            {
                System.Diagnostics.Debug.WriteLine(ex.Message);
                return(null);
            }
        }