Пример #1
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);
            }
        }