/// <summary> /// Retrieves the angular type based on the esriSRUnit type /// </summary> /// <param name="angularUnitFactoryCode">factory unit code for the map</param> /// <returns>AngularTypes unit type</returns> private AngularTypes GetAngularType(int angularUnitFactoryCode) { // default to degrees AngularTypes angularType = AngularTypes.DEGREES; switch (angularUnitFactoryCode) { case (int)esriSRUnitType.esriSRUnit_Degree: angularType = AngularTypes.DEGREES; break; case (int)esriSRUnitType.esriSRUnit_Grad: angularType = AngularTypes.GRADS; break; case (int)esriSRUnitType.esriSRUnit_Mil6400: angularType = AngularTypes.MILS; break; default: angularType = AngularTypes.DEGREES; break; } return(angularType); }
/// <summary> /// Method to get an angular distance in the correct units for the map /// </summary> /// <param name="map">IMap</param> /// <param name="inputDistance">the input distance</param> /// <param name="distanceType">the "from" distance unit type</param> /// <returns></returns> private double GetAngularDistance(IMap map, double inputDistance, AngularTypes angularType) { if (SelectedSurfaceSpatialRef == null) { return(inputDistance); } AngularTypes angularDistanceTo = AngularTypes.DEGREES; // default to degrees var gcs = SelectedSurfaceSpatialRef as IGeographicCoordinateSystem; if (gcs != null) { angularDistanceTo = GetAngularType(gcs.CoordinateUnit.FactoryCode); } var result = GetAngularDistanceFromTo(angularType, angularDistanceTo, inputDistance); return(result); }
/// <summary> /// Method to convert to/from different types of angular units /// </summary> /// <param name="fromType">DistanceTypes</param> /// <param name="toType">DistanceTypes</param> private double GetAngularDistanceFromTo(AngularTypes fromType, AngularTypes toType, double input) { double angularDistance = input; try { if (fromType == AngularTypes.DEGREES && toType == AngularTypes.GRADS) { angularDistance *= 1.11111; } else if (fromType == AngularTypes.DEGREES && toType == AngularTypes.MILS) { angularDistance *= 17.777777777778; } else if (fromType == AngularTypes.GRADS && toType == AngularTypes.DEGREES) { angularDistance /= 1.11111; } else if (fromType == AngularTypes.GRADS && toType == AngularTypes.MILS) { angularDistance *= 16; } else if (fromType == AngularTypes.MILS && toType == AngularTypes.DEGREES) { angularDistance /= 17.777777777778; } else if (fromType == AngularTypes.MILS && toType == AngularTypes.GRADS) { angularDistance /= 16; } } catch (Exception ex) { Console.WriteLine(ex); } return(angularDistance); }
// TODO: Move repeated method GetAngularDistanceFromTo to common visibility library /// <summary> /// Method to convert to/from different types of angular units /// </summary> /// <param name="fromType">DistanceTypes</param> /// <param name="toType">DistanceTypes</param> private double GetAngularDistanceFromTo(AngularTypes fromType, AngularTypes toType, double input) { double angularDistance = input; try { if (fromType == AngularTypes.DEGREES && toType == AngularTypes.GRADS) { angularDistance *= 1.11111; } else if (fromType == AngularTypes.DEGREES && toType == AngularTypes.MILS) { angularDistance *= 17.777777777778; } else if (fromType == AngularTypes.GRADS && toType == AngularTypes.DEGREES) { angularDistance /= 1.11111; } else if (fromType == AngularTypes.GRADS && toType == AngularTypes.MILS) { angularDistance *= 16; } else if (fromType == AngularTypes.MILS && toType == AngularTypes.DEGREES) { angularDistance /= 17.777777777778; } else if (fromType == AngularTypes.MILS && toType == AngularTypes.GRADS) { angularDistance /= 16; } } catch (Exception ex) { System.Diagnostics.Debug.WriteLine(ex.Message); } return(Math.Round(angularDistance, 1)); }
/// <summary> /// Method to convert to/from different types of angular units /// </summary> /// <param name="fromType">DistanceTypes</param> /// <param name="toType">DistanceTypes</param> private double GetAngularDistanceFromTo(AngularTypes fromType, AngularTypes toType, double input) { double angularDistance = input; try { if (fromType == AngularTypes.DEGREES && toType == AngularTypes.GRADS) angularDistance *= 1.11111; else if (fromType == AngularTypes.DEGREES && toType == AngularTypes.MILS) angularDistance *= 17.777777777778; else if (fromType == AngularTypes.GRADS && toType == AngularTypes.DEGREES) angularDistance /= 1.11111; else if (fromType == AngularTypes.GRADS && toType == AngularTypes.MILS) angularDistance *= 16; else if (fromType == AngularTypes.MILS && toType == AngularTypes.DEGREES) angularDistance /= 17.777777777778; else if (fromType == AngularTypes.MILS && toType == AngularTypes.GRADS) angularDistance /= 16; } catch (Exception ex) { Console.WriteLine(ex); } return angularDistance; }
/// <summary> /// Method to get an angular distance in the correct units for the map /// </summary> /// <param name="map">IMap</param> /// <param name="inputDistance">the input distance</param> /// <param name="distanceType">the "from" distance unit type</param> /// <returns></returns> private double GetAngularDistance(IMap map, double inputDistance, AngularTypes angularType) { if (map.SpatialReference == null) return inputDistance; AngularTypes angularDistanceTo = AngularTypes.DEGREES; // default to degrees var gcs = map.SpatialReference as IGeographicCoordinateSystem; if (gcs != null) { angularDistanceTo = GetAngularType(gcs.CoordinateUnit.FactoryCode); } var result = GetAngularDistanceFromTo(angularType, angularDistanceTo, inputDistance); return result; }