private void UpdateFeedbackWithGeoCircle() { if (Point1 == null || Distance <= 0) { return; } var construct = (IConstructGeodetic) new Polyline(); ClearTempGraphics(); IDictionary <String, System.Object> circleAttributes = new Dictionary <String, System.Object>(); if (HasPoint1) { IDictionary <String, System.Object> ptAttributes = new Dictionary <String, System.Object>(); ptAttributes.Add("X", Point1.X); ptAttributes.Add("Y", Point1.Y); circleAttributes.Add("centerx", Point1.X); circleAttributes.Add("centery", Point1.Y); // Re-add the point as it was cleared by ClearTempGraphics() but we still want to see it AddGraphicToMap(Point1, new RgbColor() { Green = 255 } as IColor, true, attributes: ptAttributes); circleAttributes.Add("radius", Distance); circleAttributes.Add("disttype", CircleType.ToString()); construct.ConstructGeodesicCircle(Point1, GetLinearUnit(), Distance, esriCurveDensifyMethod.esriCurveDensifyByAngle, 0.45); Point2 = ((IPolyline)construct).ToPoint; var color = new RgbColorClass() as IColor; this.AddGraphicToMap((IGeometry)construct, color, true, rasterOpCode: esriRasterOpCode.esriROPNotXOrPen, attributes: circleAttributes); } }
/// <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); }
/// <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); } }
/// <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); } }