Beispiel #1
0
        private Geometry CreateRangeRings(double radius)
        {
            Geometry geom  = null;
            var      param = new GeodesicEllipseParameter();

            param.Center          = new Coordinate2D(Point1);
            param.AxisDirection   = 0.0;
            param.LinearUnit      = GetLinearUnit(LineDistanceType);
            param.OutGeometryType = GeometryType.Polyline;
            param.SemiAxis1Length = radius;
            param.SemiAxis2Length = radius;
            param.VertexCount     = VertexCount;

            geom = GeometryEngine.Instance.GeodesicEllipse(param, MapView.Active.Map.SpatialReference);
            var nameConverter = new EnumToFriendlyNameConverter();
            var displayValue  = nameConverter.Convert(LineDistanceType, typeof(string), new object(), CultureInfo.CurrentCulture);
            // Hold onto the attributes in case user saves graphics to file later
            RangeAttributes rangeAttributes = new RangeAttributes()
            {
                mapPoint     = Point1,
                numRings     = numberOfRings,
                distance     = radius,
                centerx      = Point1.X,
                centery      = Point1.Y,
                distanceunit = displayValue.ToString(),
                ringorradial = "Ring"
            };

            CreateRangeRingOrRadialFeature(geom, rangeAttributes);

            return(geom);
        }
        private void SendOrder(object sender, RoutedEventArgs e)
        {
            var contract = FastOrderContract.SelectedItem == null ? FastOrderContract.Filter : FastOrderContract.SelectedItem.ToString();

            if (LimitTxt.Value != null & !string.IsNullOrEmpty(contract) & SizeTxt != null)
            {
                OrderVM.LimitPrice = LimitTxt.Value.Value;
                OrderVM.Contract   = contract;
                OrderVM.Volume     = (int)SizeTxt.Value;
                var    cvt = new EnumToFriendlyNameConverter();
                string msg = string.Format("是否确认下单?\n合约:{0},价格:{1},手数:{2}, 方向:{3},开平:{4}", OrderVM.Contract, OrderVM.LimitPrice, OrderVM.Volume,
                                           cvt.Convert(OrderVM.Direction, typeof(DirectionType), null, CultureInfo.CurrentUICulture),
                                           cvt.Convert(OrderVM.OpenClose, typeof(OrderOpenCloseType), null, CultureInfo.CurrentUICulture));
                MessageBoxResult dr = System.Windows.MessageBox.Show(msg, "提示", MessageBoxButton.OKCancel, MessageBoxImage.Question);
                if (dr == MessageBoxResult.OK)
                {
                    OrderVM.SendOrder();
                }
            }
        }
Beispiel #3
0
        private Geometry CreatePolyline()
        {
            if (Point1 == null || Point2 == null)
            {
                return(null);
            }

            var nameConverter           = new EnumToFriendlyNameConverter();
            GeodeticCurveType curveType = DeriveCurveType(LineType);
            LinearUnit        lu        = DeriveUnit(LineDistanceType);

            try
            {
                // create line
                var polyline = QueuedTask.Run(() =>
                {
                    var point2Proj = GeometryEngine.Instance.Project(Point2, Point1.SpatialReference);
                    var segment    = LineBuilder.CreateLineSegment(Point1, (MapPoint)point2Proj);
                    return(PolylineBuilder.CreatePolyline(segment));
                }).Result;
                Geometry newline = GeometryEngine.Instance.GeodeticDensifyByLength(polyline, 0, lu, curveType);


                var displayValue = nameConverter.Convert(LineDistanceType, typeof(string), new object(), CultureInfo.CurrentCulture);
                // Hold onto the attributes in case user saves graphics to file later
                LineAttributes lineAttributes = new LineAttributes()
                {
                    mapPoint1    = Point1,
                    mapPoint2    = Point2,
                    distance     = distance,
                    angle        = (double)azimuth,
                    angleunit    = LineAzimuthType.ToString(),
                    distanceunit = displayValue.ToString(),
                    originx      = Point1.X,
                    originy      = Point1.Y,
                    destinationx = Point2.X,
                    destinationy = Point2.Y
                };

                CreateLineFeature(newline, lineAttributes);

                ResetPoints();

                return((Geometry)newline);
            }
            catch (Exception ex)
            {
                // do nothing
                System.Diagnostics.Debug.WriteLine(ex.Message);
                return(null);
            }
        }
Beispiel #4
0
        private Geometry DrawEllipse()
        {
            if (Point1 == null || double.IsNaN(MajorAxisDistance) || double.IsNaN(MinorAxisDistance))
            {
                return(null);
            }

            try
            {
                var nameConverter = new EnumToFriendlyNameConverter();
                var param         = new GeodesicEllipseParameter();

                param.Center          = new Coordinate2D(Point1);
                param.AxisDirection   = GetRadiansFrom360Degrees(GetAzimuthAsDegrees());
                param.LinearUnit      = GetLinearUnit(LineDistanceType);
                param.OutGeometryType = GeometryType.Polygon;
                param.SemiAxis1Length = MajorAxisDistance;
                param.SemiAxis2Length = MinorAxisDistance;
                param.VertexCount     = VertexCount;

                var geom = GeometryEngine.Instance.GeodesicEllipse(param, MapView.Active.Map.SpatialReference);

                // Hold onto the attributes in case user saves graphics to file later
                var displayValue = nameConverter.Convert(LineDistanceType, typeof(string), new object(), CultureInfo.CurrentCulture);

                EllipseAttributes ellipseAttributes = new EllipseAttributes()
                {
                    mapPoint     = Point1,
                    minorAxis    = MinorAxisDistance * 2, // TRICKY: Label/Attribute always shows the "full" value
                    majorAxis    = MajorAxisDistance * 2,
                    angle        = Azimuth,
                    angleunit    = AzimuthType.ToString(),
                    centerx      = Point1.X,
                    centery      = Point1.Y,
                    distanceunit = displayValue.ToString()
                };

                CreateEllipseFeature(geom, ellipseAttributes);

                return((Geometry)geom);
            }
            catch (Exception ex)
            {
                System.Diagnostics.Debug.WriteLine(ex.Message);
                return(null);
            }
        }
Beispiel #5
0
        private void ConstructGeoCircle()
        {
            var construct = (IConstructGeodetic) new Polyline();

            if (construct != null)
            {
                var displayValue = new EnumToFriendlyNameConverter();
                var unitLabel    = Convert.ToString(displayValue.Convert(LineDistanceType, typeof(string), new object(), CultureInfo.CurrentCulture));

                var color = new RgbColorClass()
                {
                    Red = 255
                } as IColor;
                IDictionary <String, System.Object> rrAttributes = new Dictionary <String, System.Object>();
                rrAttributes.Add("rings", NumberOfRings);
                rrAttributes.Add("distance", Distance);
                rrAttributes.Add("centerx", Point1.X);
                rrAttributes.Add("centery", Point1.Y);
                rrAttributes.Add("distanceunit", unitLabel.ToString());

                construct.ConstructGeodesicCircle(Point1, GetLinearUnit(), Distance, esriCurveDensifyMethod.esriCurveDensifyByAngle, 0.45);
                Point2 = ((IPolyline)construct).ToPoint;
                AddGraphicToMap(construct as IGeometry, color, attributes: rrAttributes);
                maxDistance = Math.Max(Distance, maxDistance);

                // Use negative Distance to get the location for the distance label
                construct.ConstructGeodesicCircle(Point1, GetLinearUnit(), -Distance, esriCurveDensifyMethod.esriCurveDensifyByAngle, 0.45);
                // Create a non geodesic circle
                var circleGeom = CreateCircleGeometry(Point1, maxDistance);
                // Get the basemap extent
                var basemapExt = GetBasemapExtent(ArcMap.Document.FocusMap);
                // Check if circle is within the basemap extent. If circle is within basemap boundary,
                // then use the geodesic circle for labeling. If it's not, then use the non-geodesic
                // circle to label.
                bool isWithin = true;
                if (basemapExt != null)
                {
                    isWithin = IsGeometryWithinExtent(circleGeom, basemapExt);
                }
                AddTextToMap((isWithin) ? (IGeometry)construct : circleGeom, String.Format("{0} {1}", Math.Round(Distance, 2).ToString(), StringParser.GetStringValue(lineDistanceType)));
            }
        }
Beispiel #6
0
        private IGeometry CreateRangeRings(double radius)
        {
            IConstructGeodetic construct = null;

            var polyLine = (IPolyline) new Polyline();

            polyLine.SpatialReference = Point1.SpatialReference;
            const double DENSIFY_ANGLE_IN_DEGREES = 5.0;

            construct = (IConstructGeodetic)polyLine;
            construct.ConstructGeodesicCircle(Point1, GetLinearUnit(), radius,
                                              esriCurveDensifyMethod.esriCurveDensifyByAngle, DENSIFY_ANGLE_IN_DEGREES);
            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> rrAttributes = new Dictionary <String, System.Object>();

            rrAttributes.Add("rings", NumberOfRings);
            rrAttributes.Add("distance", radius);
            rrAttributes.Add("distanceunit", unitLabel);
            rrAttributes.Add("centerx", Point1.X);
            rrAttributes.Add("centery", Point1.Y);
            AddGraphicToMap((IGeometry)construct, color, attributes: rrAttributes);

            // Use negative radius to get the location for the distance label
            // TODO: someone explain why we need to construct this circle twice, and what -radius means (top of circle or something)?
            DistanceTypes dtVal = (DistanceTypes)LineDistanceType;

            construct.ConstructGeodesicCircle(Point1, GetLinearUnit(), -radius,
                                              esriCurveDensifyMethod.esriCurveDensifyByAngle, DENSIFY_ANGLE_IN_DEGREES);
            this.AddTextToMap((IGeometry)construct, String.Format("{0} {1}", radius.ToString(), unitLabel));

            return((IGeometry)construct);
        }
Beispiel #7
0
        private void UpdateFeedbackWithGeoCircle()
        {
            if (Point1 == null || double.IsNaN(Distance) || Distance <= 0.0)
            {
                return;
            }

            var param = new GeodesicEllipseParameter();

            param.Center          = new Coordinate2D(Point1);
            param.AxisDirection   = 0.0;
            param.LinearUnit      = GetLinearUnit(LineDistanceType);
            param.OutGeometryType = GeometryType.Polyline;
            param.SemiAxis1Length = Distance;
            param.SemiAxis2Length = Distance;
            param.VertexCount     = VertexCount;

            var geom = GeometryEngine.Instance.GeodesicEllipse(param, MapView.Active.Map.SpatialReference);

            ClearTempGraphics();

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

            // Hold onto the attributes in case user saves graphics to file later
            RangeAttributes rangeAttributes = new RangeAttributes()
            {
                mapPoint     = Point1,
                numRings     = NumberOfRings,
                distance     = Distance,
                centerx      = Point1.X,
                centery      = Point1.Y,
                distanceunit = displayValue.ToString()
            };

            AddGraphicToMap(Point1, ColorFactory.Instance.GreenRGB, null, true, 5.0);
            AddGraphicToMap(geom, ColorFactory.Instance.GreyRGB, rangeAttributes, true);
        }
Beispiel #8
0
        /// <summary>
        /// Create geodetic circle
        /// </summary>
        private Geometry CreateCircle(bool isFeedback)
        {
            if (Point1 == null || double.IsNaN(Distance) || Distance <= 0.0)
            {
                return(null);
            }
            var nameConverter = new EnumToFriendlyNameConverter();
            var param         = new GeodesicEllipseParameter();

            param.Center          = new Coordinate2D(Point1);
            param.AxisDirection   = 0.0;
            param.LinearUnit      = GetLinearUnit(LineDistanceType);
            param.OutGeometryType = GeometryType.Polygon;
            if (isFeedback)
            {
                param.OutGeometryType = GeometryType.Polyline;
            }
            param.SemiAxis1Length = Distance;
            param.SemiAxis2Length = Distance;
            param.VertexCount     = VertexCount;

            var geom = GeometryEngine.Instance.GeodesicEllipse(param, MapView.Active.Map.SpatialReference);

            CIMColor color = new CIMRGBColor()
            {
                R = 255, B = 0, G = 0, Alpha = 25
            };

            if (isFeedback)
            {
                color = ColorFactory.Instance.GreyRGB;
                ClearTempGraphics();
                AddGraphicToMap(Point1, ColorFactory.Instance.GreenRGB, null, true, 5.0);
            }

            // Hold onto the attributes in case user saves graphics to file later
            //CircleAttributes circleAttributes = new CircleAttributes(Point1, Distance, CircleType);
            double        dist = 0.0;
            DistanceTypes distunit;

            if (CircleType == CircleFromTypes.Diameter)
            {
                dist = Distance * 2;
            }
            else
            {
                dist = Distance;
            }

            if (IsDistanceCalcExpanded)
            {
                dist     = ConvertFromTo(LineDistanceType, RateUnit, Distance);
                distunit = RateUnit;
            }
            else
            {
                distunit = LineDistanceType;
            }

            var displayValue = nameConverter.Convert(distunit, typeof(string), new object(), CultureInfo.CurrentCulture);
            CircleAttributes circleAttributes = new CircleAttributes()
            {
                mapPoint = Point1, distance = dist, circleFromTypes = CircleType, circletype = CircleType.ToString(), centerx = Point1.X, centery = Point1.Y, distanceunit = displayValue.ToString()
            };

            if (isFeedback)
            {
                AddGraphicToMap(geom, color, (ProGraphicAttributes)circleAttributes, IsTempGraphic: isFeedback);
            }
            else
            {
                CreateCircleFeature(geom, circleAttributes);
            }

            return((Geometry)geom);
        }
Beispiel #9
0
        /// <summary>
        /// Method to draw the radials inside the range rings
        /// Must have at least 1 radial
        /// All radials are drawn from the center point to the farthest ring
        /// </summary>
        private void DrawRadials()
        {
            // must have at least 1
            if (NumberOfRadials < 1)
            {
                return;
            }


            var    nameConverter = new EnumToFriendlyNameConverter();
            double azimuth       = 0.0;
            double interval      = 360.0 / NumberOfRadials;
            double radialLength  = 0.0;

            if (!(RingType == RingTypes.Fixed))
            {
                radialLength = maxDistance;
            }
            else
            {
                radialLength = Distance * NumberOfRings;
            }

            try
            {
                // for each radial, draw from center point
                for (int x = 0; x < NumberOfRadials; x++)
                {
                    var polyline = QueuedTask.Run(() =>
                    {
                        MapPoint movedMP = null;
                        var mpList       = new List <MapPoint>()
                        {
                            Point1
                        };
                        // get point 2

                        var results = GeometryEngine.Instance.GeodeticMove(mpList,
                                                                           MapView.Active.Map.SpatialReference, radialLength, GetLinearUnit(LineDistanceType), GetAzimuthAsRadians(azimuth), GetCurveType());

                        // update feedback
                        //UpdateFeedback();
                        foreach (var mp in results)
                        {
                            movedMP = mp;
                        }

                        if (movedMP != null)
                        {
                            var movedMPproj = GeometryEngine.Instance.Project(movedMP, Point1.SpatialReference);
                            var segment     = LineBuilder.CreateLineSegment(Point1, (MapPoint)movedMPproj);
                            return(PolylineBuilder.CreatePolyline(segment));
                        }
                        else
                        {
                            return(null);
                        }
                    }).Result;

                    Geometry newline = GeometryEngine.Instance.GeodeticDensifyByLength(polyline, 0, LinearUnit.Meters, GeodeticCurveType.Loxodrome);
                    if (newline != null)
                    {
                        // Hold onto the attributes in case user saves graphics to file later
                        var             displayValue    = nameConverter.Convert(LineDistanceType, typeof(string), new object(), CultureInfo.CurrentCulture);
                        RangeAttributes rangeAttributes = new RangeAttributes()
                        {
                            mapPoint     = Point1,
                            numRings     = NumberOfRings,
                            distance     = radialLength,
                            centerx      = Point1.X,
                            centery      = Point1.Y,
                            distanceunit = displayValue.ToString(),
                            ringorradial = "Radial"
                        };

                        // AddGraphicToMap(newline, rangeAttributes);
                        CreateRangeRingOrRadialFeature(newline, rangeAttributes);
                    }

                    azimuth += interval;
                }
            }
            catch (Exception ex)
            {
                System.Diagnostics.Debug.WriteLine(ex);
            }
        }
Beispiel #10
0
        /// <summary>
        /// Create a geodetic circle
        /// </summary>
        private IGeometry CreateCircle()
        {
            if (Point1 == null && Point2 == null)
            {
                return(null);
            }

            string unitLabel = "";
            // This section including UpdateDistance serves to handle Diameter appropriately
            var polyLine = (IPolyline) new Polyline();

            polyLine.SpatialReference = Point1.SpatialReference;
            var ptCol = (IPointCollection)polyLine;

            ptCol.AddPoint(Point1);
            ptCol.AddPoint(Point2);

            UpdateDistance(polyLine as IGeometry);

            try
            {
                var construct = (IConstructGeodetic) new Polyline();
                if (construct != null)
                {
                    construct.ConstructGeodesicCircle(Point1, GetLinearUnit(), Distance, esriCurveDensifyMethod.esriCurveDensifyByAngle, 0.01);
                    IDictionary <String, System.Object> circleAttributes = new Dictionary <String, System.Object>();
                    double radiusOrDiameterDistance = 0.0;
                    if (CircleType == CircleFromTypes.Diameter)
                    {
                        radiusOrDiameterDistance = Distance * 2;
                    }
                    else
                    {
                        radiusOrDiameterDistance = Distance;
                    }

                    //Construct a polygon from geodesic polyline
                    var newPoly = PolylineToPolygon((IPolyline)construct);
                    if (newPoly != null)
                    {
                        //Get centroid of polygon
                        var area = (IArea)newPoly;

                        int           roundingFactor = 0;
                        DistanceTypes dtVal          = (DistanceTypes)LineDistanceType;
                        // If Distance Calculator is in use, use the unit from the Rate combobox
                        // to label the circle
                        if (IsDistanceCalcExpanded)
                        {
                            // Select appropriate label and number of decimal places
                            switch (RateUnit)
                            {
                            case DistanceTypes.Feet:
                            case DistanceTypes.Meters:
                            case DistanceTypes.Yards:
                                unitLabel      = RateUnit.ToString();
                                roundingFactor = 0;
                                break;

                            case DistanceTypes.Miles:
                            case DistanceTypes.Kilometers:
                                unitLabel      = RateUnit.ToString();
                                roundingFactor = 2;
                                break;

                            case DistanceTypes.NauticalMiles:
                                var displayValue = new EnumToFriendlyNameConverter();
                                unitLabel      = Convert.ToString(displayValue.Convert(RateUnit, typeof(string), new object(), CultureInfo.CurrentCulture));
                                roundingFactor = 2;
                                break;

                            default:
                                break;
                            }
                        }
                        // Else Distance Calculator not in use, use the unit from the Radius / Diameter combobox
                        // to label the circle
                        else
                        {
                            // Select appropriate number of decimal places
                            switch (LineDistanceType)
                            {
                            case DistanceTypes.Feet:
                            case DistanceTypes.Meters:
                            case DistanceTypes.Yards:
                                unitLabel      = RateUnit.ToString();
                                roundingFactor = 0;
                                break;

                            case DistanceTypes.Miles:
                            case DistanceTypes.Kilometers:
                                unitLabel      = RateUnit.ToString();
                                roundingFactor = 2;
                                break;

                            case DistanceTypes.NauticalMiles:
                                unitLabel      = RateUnit.ToString();
                                roundingFactor = 2;
                                break;

                            default:
                                break;
                            }


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

                        string circleTypeLabel = circleType.ToString();
                        string distanceLabel   = "";
                        // Use the unit from Rate combobox if Distance Calculator is expanded
                        if (IsDistanceCalcExpanded)
                        {
                            radiusOrDiameterDistance = ConvertFromTo(LineDistanceType, RateUnit, radiusOrDiameterDistance);
                            distanceLabel            = (TrimPrecision(radiusOrDiameterDistance, RateUnit, true)).ToString("N" + roundingFactor.ToString());
                        }
                        else
                        {
                            distanceLabel = (TrimPrecision(radiusOrDiameterDistance, LineDistanceType, false)).ToString("N" + roundingFactor.ToString());
                        }

                        //Add text using centroid point
                        this.AddTextToMap(area.LabelPoint, string.Format("{0}:{1} {2}",
                                                                         circleTypeLabel,
                                                                         distanceLabel,
                                                                         StringParser.GetStringValue(dtVal)));
                    }

                    double radiusDistance = radiusOrDiameterDistance;
                    if (CircleType == CircleFromTypes.Diameter)
                    {
                        radiusDistance = radiusOrDiameterDistance / 2;
                    }

                    circleAttributes.Add("radius", radiusDistance);
                    circleAttributes.Add("disttype", CircleType.ToString());
                    circleAttributes.Add("centerx", Point1.X);
                    circleAttributes.Add("centery", Point1.Y);
                    if (IsDistanceCalcExpanded)
                    {
                        circleAttributes.Add("distanceunit", unitLabel.ToString());
                    }
                    else
                    {
                        circleAttributes.Add("distanceunit", unitLabel.ToString());
                    }
                    var color = new RgbColorClass()
                    {
                        Red = 255
                    } as IColor;
                    this.AddGraphicToMap(construct as IGeometry, color, attributes: circleAttributes);
                    Point2    = null;
                    HasPoint2 = false;
                    ResetFeedback();
                }
                return(construct as IGeometry);
            }
            catch (Exception ex)
            {
                System.Diagnostics.Debug.WriteLine(ex.Message);
                return(null);
            }
        }
Beispiel #11
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);
            }
        }
Beispiel #12
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);
                }

                if (Point1.SpatialReference != ArcMap.Document.FocusMap.SpatialReference)
                {
                    Point1.Project(ArcMap.Document.FocusMap.SpatialReference);
                }

                if (Point2.SpatialReference != ArcMap.Document.FocusMap.SpatialReference)
                {
                    Point2.Project(ArcMap.Document.FocusMap.SpatialReference);
                }

                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 || LineAzimuthType == AzimuthTypes.Gradians)
                    {
                        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);
                }

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

                IDictionary <String, System.Object> lineAttributes = new Dictionary <String, System.Object>();
                lineAttributes.Add("distance", Distance);
                lineAttributes.Add("distanceunit", unitLabel.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} {1} {2}: {3}{4}",
                                               Math.Round(Distance, 2).ToString("N2"),
                                               StringParser.GetStringValue(dtVal),
                                               LabelTypes.Angle,
                                               Math.Round(azimuth.Value, 0),
                                               StringParser.GetStringValue(atVal)), (double)Azimuth, LineAzimuthType, false);
                }

                ResetPoints();

                return(construct as IGeometry);
            }
            catch (Exception ex)
            {
                System.Diagnostics.Debug.WriteLine(ex);
                return(null);
            }
        }