/// <summary> /// Get the currently selected geodetic type /// </summary> /// <returns>esriGeodeticType</returns> internal esriGeodeticType GetEsriGeodeticType() { esriGeodeticType type = esriGeodeticType.esriGeodeticTypeGeodesic; switch (LineType) { case LineTypes.Geodesic: type = esriGeodeticType.esriGeodeticTypeGeodesic; break; case LineTypes.GreatElliptic: type = esriGeodeticType.esriGeodeticTypeGreatElliptic; break; case LineTypes.Loxodrome: type = esriGeodeticType.esriGeodeticTypeLoxodrome; break; default: type = esriGeodeticType.esriGeodeticTypeGeodesic; break; } return(type); }
private double GetAreas(IEnumerable <IPolygon> polygons, esriGeodeticType geodeticType) { double area = 0; ILinearUnit linearUnit = ((IProjectedCoordinateSystem)_lv95).CoordinateUnit; foreach (IPolygon clone in polygons) { // NOTE uncomment to run on 10.1+ //area = ((IAreaGeodetic) clone).AreaGeodetic[geodeticType, linearUnit]; } return(area); }
/// <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> /// 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); } }