/// <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 construct = new Polyline() as IConstructGeodetic; if (construct == null) { continue; } 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", radialLength); rrAttributes.Add("distanceunit", lineDistanceType.ToString()); rrAttributes.Add("radials", NumberOfRadials); rrAttributes.Add("centerx", Point1.X); rrAttributes.Add("centery", Point1.Y); construct.ConstructGeodeticLineFromDistance(esriGeodeticType.esriGeodeticTypeLoxodrome, Point1, GetLinearUnit(), radialLength, azimuth, esriCurveDensifyMethod.esriCurveDensifyByDeviation, -1.0); AddGraphicToMap(construct as IGeometry, color, attributes: rrAttributes); azimuth += interval; } } 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) { 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); } }
public static string BuildClassification(DistanceTypes distanceType) { return(string.Format( CultureInfo.InvariantCulture, UnitOfMeasurementFactory.ClassificationTemplate, MeasurementTypes.Distance.ToString(), distanceType.ToString())); }
/// <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); } }
/// <summary> /// Method used to draw the rings at the desired interval /// Rings are constructed as geodetic circles /// </summary> private IGeometry DrawRings() { double radius = 0.0; try { IConstructGeodetic construct = null; for (int x = 0; x < numberOfRings; x++) { // set the current radius radius += Distance; 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 }; IDictionary <String, System.Object> rrAttributes = new Dictionary <String, System.Object>(); rrAttributes.Add("rings", NumberOfRings); rrAttributes.Add("distance", radius); rrAttributes.Add("distanceunit", lineDistanceType.ToString()); 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(), dtVal.ToString())); } return((IGeometry)construct); } catch (Exception ex) { System.Diagnostics.Debug.WriteLine(ex); return(null); } }
/// <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); } }
/// <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); } }
/// <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); } }
/// <summary> /// Create a geodetic circle /// </summary> private IGeometry CreateCircle() { if (Point1 == null && Point2 == null) { return(null); } 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); //var color = new RgbColorClass() { Red = 255 } as IColor; this.AddGraphicToMap(construct as IGeometry); //Construct a polygon from geodesic polyline var newPoly = this.PolylineToPolygon((IPolyline)construct); if (newPoly != null) { //Get centroid of polygon var area = newPoly as IArea; // Ensure we use the correct distance, dependent on whether we are in Radius or Diameter mode string distanceLabel; if (circleType == CircleFromTypes.Radius) { distanceLabel = Math.Round(Distance, 2).ToString("N2"); } else { distanceLabel = Math.Round((Distance * 2), 2).ToString("N2"); } //Add text using centroid point //Use circleType to ensure our label contains either Radius or Diameter dependent on mode DistanceTypes dtVal = (DistanceTypes)LineDistanceType; //Get line distance type this.AddTextToMap(area.Centroid, string.Format("{0}:{1} {2}", circleType, distanceLabel, dtVal.ToString())); } Point2 = null; HasPoint2 = false; ResetFeedback(); } return(construct as IGeometry); } catch (Exception ex) { Console.WriteLine(ex.Message); return(null); } }
/// <summary> /// Method used to draw the rings at the desired interval /// Rings are constructed as geodetic circles /// </summary> private IGeometry DrawRings() { double radius = 0.0; try { IConstructGeodetic construct = null; for (int x = 0; x < numberOfRings; x++) { // set the current radius radius += Distance; var polyLine = new Polyline() as IPolyline; polyLine.SpatialReference = Point1.SpatialReference; construct = polyLine as IConstructGeodetic; construct.ConstructGeodesicCircle(Point1, GetLinearUnit(), radius, esriCurveDensifyMethod.esriCurveDensifyByAngle, 0.001); AddGraphicToMap(construct as IGeometry); // Use negative radius to get the location for the distance label DistanceTypes dtVal = (DistanceTypes)LineDistanceType; construct.ConstructGeodesicCircle(Point1, GetLinearUnit(), -radius, esriCurveDensifyMethod.esriCurveDensifyByAngle, 0.001); this.AddTextToMap(construct as IGeometry, String.Format("{0} {1}", radius.ToString(), dtVal.ToString())); } return(construct as IGeometry); } catch (Exception ex) { Console.WriteLine(ex); return(null); } }