コード例 #1
0
        private void ConstructGeoCircle()
        {
            if (Point1 == null || double.IsNaN(Distance))
            {
                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;

            maxDistance = Math.Max(maxDistance, Distance);

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

            // 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 = LineDistanceType.ToString(), ringorradial = "Ring"
            };

            CreateRangeRingOrRadialFeature(geom, rangeAttributes);
        }
コード例 #2
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();

            // 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 = LineDistanceType.ToString()
            };

            AddGraphicToMap(Point1, ColorFactory.Instance.GreenRGB, null, true, 5.0);
            AddGraphicToMap(geom, ColorFactory.Instance.GreyRGB, rangeAttributes, true);
        }
コード例 #3
0
        /// <summary>
        /// Method used to draw the rings at the desired interval
        /// Rings are constructed as geodetic circles
        /// </summary>
        private Geometry DrawRings()
        {
            if (Point1 == null || double.IsNaN(Distance))
            {
                return(null);
            }

            double radius = 0.0;

            try
            {
                Geometry geom = null;
                for (int x = 0; x < numberOfRings; x++)
                {
                    // set the current radius
                    radius += Distance;

                    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);

                    // 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 = LineDistanceType.ToString(), ringorradial = "Ring"
                    };

                    CreateRangeRingOrRadialFeature(geom, rangeAttributes);
                }

                return(geom);
            }
            catch (Exception ex)
            {
                System.Diagnostics.Debug.WriteLine(ex);
                return(null);
            }
        }
コード例 #4
0
        private Geometry CreatePolyline()
        {
            if (Point1 == null || Point2 == null)
            {
                return(null);
            }

            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);

                // 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 = LineDistanceType.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);
            }
        }
コード例 #5
0
        private Geometry DrawEllipse()
        {
            if (Point1 == null || double.IsNaN(MajorAxisDistance) || double.IsNaN(MinorAxisDistance))
            {
                return(null);
            }

            try
            {
                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
                EllipseAttributes ellipseAttributes = new EllipseAttributes()
                {
                    mapPoint  = Point1, minorAxis = MinorAxisDistance,
                    majorAxis = MajorAxisDistance, angle = Azimuth,
                    angleunit = AzimuthType.ToString(), centerx = Point1.X,
                    centery   = Point1.Y, distanceunit = LineDistanceType.ToString()
                };

                CreateEllipseFeature(geom, ellipseAttributes);

                return((Geometry)geom);
            }
            catch (Exception ex)
            {
                System.Diagnostics.Debug.WriteLine(ex.Message);
                return(null);
            }
        }
コード例 #6
0
        /// <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);
            }
        }
コード例 #7
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;
            }

            double azimuth      = 0.0;
            double interval     = 360.0 / NumberOfRadials;
            double radialLength = 0.0;

            if (IsInteractive)
            {
                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
                        RangeAttributes rangeAttributes = new RangeAttributes()
                        {
                            mapPoint     = Point1, numRings = NumberOfRings,
                            distance     = radialLength,
                            centerx      = Point1.X, centery = Point1.Y,
                            distanceunit = LineDistanceType.ToString(), ringorradial = "Radial"
                        };

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

                    azimuth += interval;
                }
            }
            catch (Exception ex)
            {
                System.Diagnostics.Debug.WriteLine(ex);
            }
        }
コード例 #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);
            }
        }
コード例 #9
0
        /// <summary>
        /// Create a geodetic circle
        /// </summary>
        private IGeometry CreateCircle()
        {
            if (Point1 == null && Point2 == null)
            {
                return(null);
            }

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

            polyLine.SpatialReference = Point1.SpatialReference;
            var ptCol = polyLine as IPointCollection;

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

            UpdateDistance(polyLine as IGeometry);

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

                    //circleAttributes.Add("radius", dist);
                    //circleAttributes.Add("disttype", CircleType.ToString());
                    //circleAttributes.Add("centerx", Point1.X);
                    //circleAttributes.Add("centery", Point1.Y);
                    //circleAttributes.Add("distanceunit", LineDistanceType.ToString());
                    //var color = new RgbColorClass() { Red = 255 } as IColor;
                    //this.AddGraphicToMap(construct as IGeometry, color, attributes: circleAttributes);

                    //Construct a polygon from geodesic polyline

                    var newPoly = this.PolylineToPolygon((IPolyline)construct);
                    if (newPoly != null)
                    {
                        //Get centroid of polygon
                        var area = newPoly as IArea;


                        string unitLabel      = "";
                        int    roundingFactor = 0;
                        // 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.NauticalMile:
                                unitLabel      = "Nautical Miles";
                                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.NauticalMile:
                                unitLabel      = "Nautical Miles";
                                roundingFactor = 2;
                                break;

                            default:
                                break;
                            }

                            DistanceTypes dtVal = (DistanceTypes)LineDistanceType;
                            unitLabel = dtVal.ToString();
                        }

                        double convertedDistance = Distance;
                        // Distance is storing radius not diameter, so we have to double it to get the correct value
                        // for the label
                        // Only use Diameter when Distance Calculator is not in use
                        if (!IsDistanceCalcExpanded && circleType == CircleFromTypes.Diameter)
                        {
                            convertedDistance *= 2;
                        }

                        string circleTypeLabel = circleType.ToString();
                        string distanceLabel   = "";
                        // Use the unit from Rate combobox if Distance Calculator is expanded
                        if (IsDistanceCalcExpanded)
                        {
                            convertedDistance = ConvertFromTo(LineDistanceType, RateUnit, convertedDistance);
                            distanceLabel     = (TrimPrecision(convertedDistance, RateUnit, true)).ToString("N" + roundingFactor.ToString());
                            // Always label with radius when Distance Calculator is expanded
                            circleTypeLabel = "Radius";
                        }
                        else
                        {
                            distanceLabel = (TrimPrecision(convertedDistance, LineDistanceType, false)).ToString("N" + roundingFactor.ToString());
                        }
                        dist = convertedDistance;
                        //Add text using centroid point
                        this.AddTextToMap(area.Centroid, string.Format("{0}:{1} {2}",
                                                                       circleTypeLabel,
                                                                       distanceLabel,
                                                                       unitLabel));
                    }
                    circleAttributes.Add("radius", dist);
                    circleAttributes.Add("disttype", CircleType.ToString());
                    circleAttributes.Add("centerx", Point1.X);
                    circleAttributes.Add("centery", Point1.Y);
                    if (IsDistanceCalcExpanded)
                    {
                        circleAttributes.Add("distanceunit", RateUnit.ToString());
                    }
                    else
                    {
                        circleAttributes.Add("distanceunit", LineDistanceType.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)
            {
                Console.WriteLine(ex.Message);
                return(null);
            }
        }