internal DistanceTypes GetDistanceType(int linearUnitFactoryCode)
        {
            DistanceTypes distanceType = DistanceTypes.Meters;

            switch (linearUnitFactoryCode)
            {
            case (int)esriSRUnitType.esriSRUnit_Foot:
                distanceType = DistanceTypes.Feet;
                break;

            case (int)esriSRUnitType.esriSRUnit_Kilometer:
                distanceType = DistanceTypes.Kilometers;
                break;

            case (int)esriSRUnitType.esriSRUnit_Meter:
                distanceType = DistanceTypes.Meters;
                break;

            case (int)esriSRUnitType.esriSRUnit_NauticalMile:
                distanceType = DistanceTypes.NauticalMile;
                break;

            default:
                distanceType = DistanceTypes.Meters;
                break;
            }

            return(distanceType);
        }
        public LinearUnit DeriveUnit(DistanceTypes distType)
        {
            LinearUnit lu = LinearUnit.Meters;

            if (distType == DistanceTypes.Feet)
            {
                lu = LinearUnit.Feet;
            }
            else if (distType == DistanceTypes.Kilometers)
            {
                lu = LinearUnit.Kilometers;
            }
            else if (distType == DistanceTypes.Meters)
            {
                lu = LinearUnit.Meters;
            }
            else if (distType == DistanceTypes.Miles)
            {
                lu = LinearUnit.Miles;
            }
            else if (distType == DistanceTypes.NauticalMiles)
            {
                lu = LinearUnit.NauticalMiles;
            }
            else if (distType == DistanceTypes.Yards)
            {
                lu = LinearUnit.Yards;
            }
            return(lu);
        }
        /// </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 GetLinearDistance(IMap map, double inputDistance, DistanceTypes distanceType)
        {
            if (SelectedSurfaceSpatialRef == null)
            {
                return(inputDistance);
            }

            DistanceTypes distanceTo = DistanceTypes.Meters; // default to meters

            var pcs = SelectedSurfaceSpatialRef as IProjectedCoordinateSystem;

            if (pcs != null)
            {
                // need to convert the offset from the input distance type to the spatial reference linear type
                distanceTo = GetDistanceType(pcs.CoordinateUnit.FactoryCode);
            }
            else
            {
                var gcs = SelectedSurfaceSpatialRef as IGeographicCoordinateSystem;
                if (gcs != null)
                {
                    distanceTo = GetDistanceType(gcs.CoordinateUnit.FactoryCode);
                }
            }

            var result = GetDistanceFromTo(distanceType, distanceTo, inputDistance);

            return(result);
        }
 /// <summary>
 /// Complete constructor
 /// </summary>
 /// <param name="distanceFlag">Flag indicating which norm is used to compute the Hausdorff distance (NORM_L1, NORM_L2).</param>
 /// <param name="rankProp">fractional value (between 0 and 1).</param>
 /// <returns></returns>
 public static HausdorffDistanceExtractor Create(
     DistanceTypes distanceFlag = DistanceTypes.L2, float rankProp = 0.6f)
 {
     IntPtr ptr = NativeMethods.shape_createHausdorffDistanceExtractor(
         (int)distanceFlag, rankProp);
     return new HausdorffDistanceExtractor(ptr);
 }
        internal LinearUnit GetLinearUnit(DistanceTypes dtype)
        {
            LinearUnit result = LinearUnit.Meters;

            switch (dtype)
            {
            case DistanceTypes.Feet:
            case DistanceTypes.SurveyFoot:
                result = LinearUnit.Feet;
                break;

            case DistanceTypes.Kilometers:
                result = LinearUnit.Kilometers;
                break;

            case DistanceTypes.NauticalMile:
                result = LinearUnit.NauticalMiles;
                break;

            case DistanceTypes.Meters:
            default:
                result = LinearUnit.Meters;
                break;
            }
            return(result);
        }
 public double Convert(DistanceTypes typeTarget = DistanceTypes.Best, double rounding = default(double))
 {
     double res = valInMillimeters / System.Convert.ToDouble ((int)typeTarget);
     if (res > (Math.Truncate (res) - rounding) && res < (Math.Truncate (res) + rounding))
         res = Math.Truncate (res);
     return res;
 }
Exemple #7
0
        public static void DistanceTransform(bool negative = false, DistanceTypes distanceType = DistanceTypes.L2, DistanceMaskSize distanceMaskSize = DistanceMaskSize.Mask3)
        {
            Glb.DrawMatAndHist0(Glb.matSrc);

            var matThr = Glb.matSrc.CvtColor(ColorConversionCodes.BGR2GRAY).Threshold(128, 255, ThresholdTypes.Otsu);

            if (negative)
            {
                Cv2.BitwiseNot(matThr, matThr);
            }
            Glb.DrawMatAndHist1(matThr);

            var    matDist      = matThr.DistanceTransform(distanceType, distanceMaskSize);
            var    x1           = matDist.Min();
            var    x2           = matDist.Max();
            float  y1           = 0;
            float  y2           = 255;
            double scale        = (y2 - y1) / (x2 - x1);
            double offset       = (x2 * y1 - x1 * y2) / (x2 - x1);
            var    matDistColor = new Mat();

            matDist.ConvertTo(matDistColor, MatType.CV_8UC1, scale, offset);
            Glb.DrawMatAndHist2(matDistColor);

            matThr.Dispose();
            matDist.Dispose();
            matDistColor.Dispose();
        }
        /// <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);
            }
        }
        /// <summary>
        /// Method to get a z offset distance in the correct units for the map
        /// </summary>
        /// <param name="offset">the input offset</param>
        /// <param name="zFactor">ISurface z factor</param>
        /// <param name="distanceType">the "from" distance unit type</param>
        /// <returns></returns>
        internal double GetOffsetInZUnits(double offset, double zFactor, DistanceTypes distanceType)
        {
            if (SelectedSurfaceSpatialRef == null)
            {
                return(offset);
            }

            double        offsetInMapUnits = 0.0;
            DistanceTypes distanceTo       = DistanceTypes.Meters; // default to meters

            var pcs = SelectedSurfaceSpatialRef as IProjectedCoordinateSystem;

            if (pcs != null)
            {
                // need to convert the offset from the input distance type to the spatial reference linear type
                // then apply the zFactor
                distanceTo = GetDistanceType(pcs.CoordinateUnit.FactoryCode);
            }

            offsetInMapUnits = GetDistanceFromTo(distanceType, distanceTo, offset);

            var result = offsetInMapUnits / zFactor;

            return(result);
        }
Exemple #10
0
        /// <summary>
        /// Calculates the distance between two codes. Either 2 Zip Codes or 2 Postal Codes or 1 of each.
        /// </summary>
        /// <param name="Code1">The starting location for the distance calculation</param>
        /// <param name="Code2">The ending location for the distance calculation</param>
        /// <param name="DistanceType">The enumerator value for whether you want the result in miles or KM</param>
        /// <returns>The distance between the two locations in the requested measurement system</returns>
        public static double CalculateDistance(string Code1, string Code2, DistanceTypes DistanceType)
        {
            string strSQL = "";

            DataTable[] dtCodeInfo;
            Double Long1 = 0, Long2 = 0, Lat1 = 0, Lat2 = 0;

            if (DetermineCodeType(Code1) == CodeTypes.ZipCode)
                strSQL += "Select Longitude, Latitude from Adr_ZipCode where Zip_Code = " + Code1;

            else if (DetermineCodeType(Code1) == CodeTypes.PostalCode)
                strSQL += "Select Longitude, Latitude from Adr_PostalCode where Postal_Code = '" + Code1 + "'";

            if (DetermineCodeType(Code2) == CodeTypes.ZipCode)
                strSQL += ";Select Longitude, Latitude from Adr_ZipCode where Zip_Code = " + Code2;

            else if (DetermineCodeType(Code2) == CodeTypes.PostalCode)
                strSQL += ";Select Longitude, Latitude from Adr_PostalCode where Postal_Code = '" + Code2 + "'";

            dtCodeInfo = CareerCruisingWeb.CCLib.Common.DataAccess.GetDataTables(strSQL);
            if (dtCodeInfo[0].Rows.Count > 0)
            {
                Long1 = Convert.ToDouble(dtCodeInfo[0].Rows[0]["Longitude"]);
                Lat1 = Convert.ToDouble(dtCodeInfo[0].Rows[0]["Latitude"]);
            }
            if (dtCodeInfo[1].Rows.Count > 0)
            {
                Long2 = Convert.ToDouble(dtCodeInfo[1].Rows[0]["Longitude"]);
                Lat2 = Convert.ToDouble(dtCodeInfo[1].Rows[0]["Latitude"]);
            }
            return CalculateDistance(Lat1, Long1, Lat2, Long2, DistanceType);
        }
Exemple #11
0
 /// <summary>
 /// Complete constructor
 /// </summary>
 /// <param name="distanceFlag">Flag indicating which norm is used to compute the Hausdorff distance (NORM_L1, NORM_L2).</param>
 /// <param name="rankProp">fractional value (between 0 and 1).</param>
 /// <returns></returns>
 public static HausdorffDistanceExtractor Create(
     DistanceTypes distanceFlag = DistanceTypes.L2, float rankProp = 0.6f)
 {
     NativeMethods.HandleException(
         NativeMethods.shape_createHausdorffDistanceExtractor(
             (int)distanceFlag, rankProp, out var ret));
     return(new HausdorffDistanceExtractor(ret));
 }
        /// <summary>
        /// Complete constructor
        /// </summary>
        /// <param name="distanceFlag">Flag indicating which norm is used to compute the Hausdorff distance (NORM_L1, NORM_L2).</param>
        /// <param name="rankProp">fractional value (between 0 and 1).</param>
        /// <returns></returns>
        public static HausdorffDistanceExtractor Create(
            DistanceTypes distanceFlag = DistanceTypes.L2, float rankProp = 0.6f)
        {
            IntPtr ptr = NativeMethods.shape_createHausdorffDistanceExtractor(
                (int)distanceFlag, rankProp);

            return(new HausdorffDistanceExtractor(ptr));
        }
 public static string BuildClassification(DistanceTypes distanceType)
 {
     return(string.Format(
                CultureInfo.InvariantCulture,
                UnitOfMeasurementFactory.ClassificationTemplate,
                MeasurementTypes.Distance.ToString(),
                distanceType.ToString()));
 }
Exemple #14
0
        private void UpdateDistance(double distance, DistanceTypes fromDistanceType, bool belowLimit)
        {
            Distance = ConvertFromTo(fromDistanceType, LineDistanceType, distance);

            if (belowLimit)
            {
                UpdateFeedbackWithGeoCircle();
            }
        }
        public double Convert(DistanceTypes typeTarget = DistanceTypes.Best, double rounding = default(double))
        {
            double res = valInMillimeters / System.Convert.ToDouble((int)typeTarget);

            if (res > (Math.Truncate(res) - rounding) && res < (Math.Truncate(res) + rounding))
            {
                res = Math.Truncate(res);
            }
            return(res);
        }
 /// <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);
     }
 }
 private void UpdateDistance(double distance, DistanceTypes fromDistanceType)
 {
     if (CircleType == CircleFromTypes.Diameter)
     {
         Distance = ConvertFromTo(fromDistanceType, LineDistanceType, distance) * 2.0;
     }
     else
     {
         Distance = ConvertFromTo(fromDistanceType, LineDistanceType, distance);
     }
     UpdateFeedbackWithGeoCircle();
 }
Exemple #18
0
        internal double ConvertFromTo(DistanceTypes fromType, DistanceTypes toType, double input)
        {
            double result = 0.0;

            var linearUnitFrom = GetLinearUnit(fromType);
            var linearUnitTo   = GetLinearUnit(toType);

            var unit = LinearUnit.CreateLinearUnit(linearUnitFrom.FactoryCode);

            result = unit.ConvertTo(input, linearUnitTo);

            return(result);
        }
        public string Humanize(DistanceTypes typeTarget = DistanceTypes.Best, string format = "{0:G} {1}", double rounding = .07f, CultureInfo cultureInfo = null, int decimals = 1, IDictionary<DistanceTypes, string> abbrMappings = null)
        {
            if (typeTarget == DistanceTypes.Best)
                typeTarget = CalculateBest ();

            var res = Convert (typeTarget, rounding);
            res = Math.Truncate (res * (decimals*10)) / (decimals*10);

            abbrMappings = abbrMappings ?? AbbrMappings;
            string type = "";
            if (abbrMappings.ContainsKey (typeTarget))
                type = abbrMappings [typeTarget];

            return string.Format (cultureInfo ?? CultureInfo.InvariantCulture, format, res, type);
        }
Exemple #20
0
        /// <summary>Determines the distance between 2 latitude/longitude points</summary>
        /// <param name="latitude1">The latitude of the first point</param>
        /// <param name="longitude1">The longitude of the second point</param>
        /// <param name="latitude2">The latitude of the second point</param>
        /// <param name="longitude2">The longitude of the second point</param>
        /// <param name="DistanceType">The enumerator value for whether you want the result in miles or KM</param>
        /// <returns>The distance between the two points in the requested measurement system</returns>
        public static double CalculateDistance(double latitude1, double longitude1, double latitude2, double longitude2, DistanceTypes DistanceType)
        {
            double ReturnValue = 0;
            double Temp1 = 69.1 * (latitude2 - latitude1);
            double Temp2 = 69.1 * (longitude2 - longitude1) * System.Math.Cos(latitude1 / 57.3);

            double TempInt = System.Math.Sqrt((Temp1 * Temp1) + (Temp2 * Temp2));

            if (DistanceType == DistanceTypes.Miles)
                ReturnValue =  System.Math.Round(TempInt, 2);
            else if (DistanceType == DistanceTypes.Kilometeres)
                ReturnValue = System.Math.Round(TempInt * 1.609344, 2);

            return ReturnValue;
        }
        /// <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;
                    const double DENSIFY_ANGLE_IN_DEGREES = 5.0;
                    construct = polyLine as IConstructGeodetic;
                    construct.ConstructGeodesicCircle(Point1, GetLinearUnit(), radius,
                                                      esriCurveDensifyMethod.esriCurveDensifyByAngle, DENSIFY_ANGLE_IN_DEGREES);
                    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", radius);
                    rrAttributes.Add("distanceunit", lineDistanceType.ToString());
                    rrAttributes.Add("radials", NumberOfRadials);
                    rrAttributes.Add("centerx", Point1.X);
                    rrAttributes.Add("centery", Point1.Y);
                    AddGraphicToMap(construct as IGeometry, 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(construct as IGeometry, String.Format("{0} {1}", radius.ToString(), dtVal.ToString()));
                }

                return(construct as IGeometry);
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex);
                return(null);
            }
        }
        public void RefreshContent()
        {
            //m_Station.Bitmap = new StandardBitmap(new Bitmap(myContact.Picture));

            m_StationName.Text = m_Station.Name;

            DistanceTypes _DistanceType = m_Station.DistanceType;
            string        _DistanceFormat;

            if (_DistanceType == DistanceTypes.Meters)
            {
                _DistanceFormat = "{0} mtrs";
            }
            else
            {
                _DistanceFormat = "{0:0.00} km";
            }

            m_Distance.Text = string.Format(_DistanceFormat,
                                            (_DistanceType == DistanceTypes.Meters ? Convert.ToInt32(m_Station.DistanceToDestination) : m_Station.DistanceToDestination));

            Color _Color;

            if (m_Station.AlertDistance > 0 && m_Station.DistanceToDestination < m_Station.AlertDistance)
            {
                _Color = (m_Station.PerformAlert ? Color.Red : Color.Blue);

                if (null != ParentControl)
                {
                    (ParentControl as ItemsControl).CurrentSelection = m_Station;
                }
            }
            else
            {
                _Color = Color.Green;
            }

            m_Distance.ForeColor = _Color;

            m_StationNumber.Text = m_Station.StationIndex.ToString();

            m_StationAddress.Text = string.Format("Lat:{0}-Long:{1}", m_Station.Latitude, m_Station.Longitude);
        }
        public string Humanize(DistanceTypes typeTarget = DistanceTypes.Best, string format = "{0:G} {1}", double rounding = .07f, CultureInfo cultureInfo = null, int decimals = 1, IDictionary <DistanceTypes, string> abbrMappings = null)
        {
            if (typeTarget == DistanceTypes.Best)
            {
                typeTarget = CalculateBest();
            }

            var res = Convert(typeTarget, rounding);

            res = Math.Truncate(res * (decimals * 10)) / (decimals * 10);

            abbrMappings = abbrMappings ?? AbbrMappings;
            string type = "";

            if (abbrMappings.ContainsKey(typeTarget))
            {
                type = abbrMappings [typeTarget];
            }

            return(string.Format(cultureInfo ?? CultureInfo.InvariantCulture, format, res, type));
        }
Exemple #24
0
        /// <summary>
        /// Gets the linear unit from the esri constants for linear units
        /// </summary>
        /// <returns>ILinearUnit</returns>
        internal ILinearUnit GetLinearUnit(DistanceTypes distanceType)
        {
            int unitType = (int)esriSRUnitType.esriSRUnit_Meter;

            if (srf3 == null)
            {
                Type srType = Type.GetTypeFromProgID("esriGeometry.SpatialReferenceEnvironment");
                srf3 = Activator.CreateInstance(srType) as ISpatialReferenceFactory3;
            }

            switch (distanceType)
            {
            case DistanceTypes.Feet:
                unitType = (int)esriSRUnitType.esriSRUnit_Foot;
                break;

            case DistanceTypes.Kilometers:
                unitType = (int)esriSRUnitType.esriSRUnit_Kilometer;
                break;

            case DistanceTypes.Meters:
                unitType = (int)esriSRUnitType.esriSRUnit_Meter;
                break;

            case DistanceTypes.NauticalMile:
                unitType = (int)esriSRUnitType.esriSRUnit_NauticalMile;
                break;

            case DistanceTypes.SurveyFoot:
                unitType = (int)esriSRUnitType.esriSRUnit_SurveyFoot;
                break;

            default:
                unitType = (int)esriSRUnitType.esriSRUnit_Meter;
                break;
            }

            return(srf3.CreateUnit(unitType) as ILinearUnit);
        }
Exemple #25
0
        private IGeometry CreateRangeRings(double radius)
        {
            IConstructGeodetic construct = null;

            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
            };
            var displayValue = new EnumToFriendlyNameConverter();
            var unitLabel    = Convert.ToString(displayValue.Convert(lineDistanceType, typeof(string), new object(), CultureInfo.CurrentCulture));

            IDictionary <String, System.Object> rrAttributes = new Dictionary <String, System.Object>();

            rrAttributes.Add("rings", NumberOfRings);
            rrAttributes.Add("distance", radius);
            rrAttributes.Add("distanceunit", unitLabel);
            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(), unitLabel));

            return((IGeometry)construct);
        }
        public void SetValue(double value, DistanceTypes type)
        {
            switch (type)
            {
            case DistanceTypes.Meters:
                _value = value;
                break;

            case DistanceTypes.Kilometers:
                _value = value * 1000;
                break;

            case DistanceTypes.Feet:
                _value = value * 0.3048;
                break;

            case DistanceTypes.Inches:
                _value = value * 0.0254;
                break;

            case DistanceTypes.Miles:
                _value = value * 1609.344;
                break;

            case DistanceTypes.Centimeters:
                _value = value * 0.01;
                break;

            case DistanceTypes.Millimeters:
                _value = value * 0.001;
                break;

            case DistanceTypes.Yards:
                _value = value * 0.9144;
                break;
            }
        }
Exemple #27
0
 /// <summary>
 /// 
 /// </summary>
 /// <param name="signature1"></param>
 /// <param name="signature2"></param>
 /// <param name="distType"></param>
 /// <param name="cost"></param>
 /// <param name="lowerBound"></param>
 /// <param name="flow"></param>
 /// <returns></returns>
 public static float EMD(InputArray signature1, InputArray signature2,
     DistanceTypes distType, InputArray cost, out float lowerBound, OutputArray flow)
 {
     if (signature1 == null)
         throw new ArgumentNullException(nameof(signature1));
     if (signature2 == null)
         throw new ArgumentNullException(nameof(signature2));
     signature1.ThrowIfDisposed();
     signature2.ThrowIfDisposed();
     float ret = NativeMethods.imgproc_EMD(signature1.CvPtr, signature2.CvPtr, (int)distType, ToPtr(cost), out lowerBound, ToPtr(flow));
     GC.KeepAlive(signature1);
     GC.KeepAlive(signature2);
     GC.KeepAlive(cost);
     if(flow != null)
         flow.Fix();
     return ret;
 }
        /// <summary>
        /// Ugly method to convert to/from different types of distance units
        /// </summary>
        /// <param name="fromType">DistanceTypes</param>
        /// <param name="toType">DistanceTypes</param>
        internal void UpdateDistanceFromTo(DistanceTypes fromType, DistanceTypes toType)
        {
            try
            {
                double length = Distance;

                if (fromType == DistanceTypes.Meters && toType == DistanceTypes.Kilometers)
                    length /= 1000.0;
                else if (fromType == DistanceTypes.Meters && toType == DistanceTypes.Feet)
                    length *= 3.28084;
                else if (fromType == DistanceTypes.Meters && toType == DistanceTypes.SurveyFoot)
                    length *= 3.280833333;
                else if (fromType == DistanceTypes.Meters && toType == DistanceTypes.NauticalMile)
                    length *= 0.000539957;
                else if (fromType == DistanceTypes.Kilometers && toType == DistanceTypes.Meters)
                    length *= 1000.0;
                else if (fromType == DistanceTypes.Kilometers && toType == DistanceTypes.Feet)
                    length *= 3280.84;
                else if (fromType == DistanceTypes.Kilometers && toType == DistanceTypes.SurveyFoot)
                    length *= 3280.833333;
                else if (fromType == DistanceTypes.Kilometers && toType == DistanceTypes.NauticalMile)
                    length *= 0.539957;
                else if (fromType == DistanceTypes.Feet && toType == DistanceTypes.Kilometers)
                    length *= 0.0003048;
                else if (fromType == DistanceTypes.Feet && toType == DistanceTypes.Meters)
                    length *= 0.3048;
                else if (fromType == DistanceTypes.Feet && toType == DistanceTypes.SurveyFoot)
                    length *= 0.999998000004;
                else if (fromType == DistanceTypes.Feet && toType == DistanceTypes.NauticalMile)
                    length *= 0.000164579;
                else if (fromType == DistanceTypes.SurveyFoot && toType == DistanceTypes.Kilometers)
                    length *= 0.0003048006096;
                else if (fromType == DistanceTypes.SurveyFoot && toType == DistanceTypes.Meters)
                    length *= 0.3048006096;
                else if (fromType == DistanceTypes.SurveyFoot && toType == DistanceTypes.Feet)
                    length *= 1.000002;
                else if (fromType == DistanceTypes.SurveyFoot && toType == DistanceTypes.NauticalMile)
                    length *= 0.00016457916285097;
                else if (fromType == DistanceTypes.NauticalMile && toType == DistanceTypes.Kilometers)
                    length *= 1.852001376036;
                else if (fromType == DistanceTypes.NauticalMile && toType == DistanceTypes.Meters)
                    length *= 1852.001376036;
                else if (fromType == DistanceTypes.NauticalMile && toType == DistanceTypes.Feet)
                    length *= 6076.1154855643;
                else if (fromType == DistanceTypes.NauticalMile && toType == DistanceTypes.SurveyFoot)
                    length *= 6076.1033333576;

                Distance = length;
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex);
            }
        }
        /// <summary>
        /// Ugly method to convert to/from different types of distance units
        /// </summary>
        /// <param name="fromType">DistanceTypes</param>
        /// <param name="toType">DistanceTypes</param>
        internal double GetDistanceFromTo(DistanceTypes fromType, DistanceTypes toType, double input)
        {
            double length = input;

            try
            {
                if (fromType == DistanceTypes.Meters && toType == DistanceTypes.Kilometers)
                {
                    length /= 1000.0;
                }
                else if (fromType == DistanceTypes.Meters && toType == DistanceTypes.Feet)
                {
                    length *= 3.28084;
                }
                else if (fromType == DistanceTypes.Meters && toType == DistanceTypes.NauticalMile)
                {
                    length *= 0.000539957;
                }
                else if (fromType == DistanceTypes.Kilometers && toType == DistanceTypes.Meters)
                {
                    length *= 1000.0;
                }
                else if (fromType == DistanceTypes.Kilometers && toType == DistanceTypes.Feet)
                {
                    length *= 3280.84;
                }
                else if (fromType == DistanceTypes.Kilometers && toType == DistanceTypes.NauticalMile)
                {
                    length *= 0.539957;
                }
                else if (fromType == DistanceTypes.Feet && toType == DistanceTypes.Kilometers)
                {
                    length *= 0.0003048;
                }
                else if (fromType == DistanceTypes.Feet && toType == DistanceTypes.Meters)
                {
                    length *= 0.3048;
                }
                else if (fromType == DistanceTypes.Feet && toType == DistanceTypes.NauticalMile)
                {
                    length *= 0.000164579;
                }
                else if (fromType == DistanceTypes.NauticalMile && toType == DistanceTypes.Kilometers)
                {
                    length *= 1.852001376036;
                }
                else if (fromType == DistanceTypes.NauticalMile && toType == DistanceTypes.Meters)
                {
                    length *= 1852.001376036;
                }
                else if (fromType == DistanceTypes.NauticalMile && toType == DistanceTypes.Feet)
                {
                    length *= 6076.1154855643;
                }
            }
            catch (Exception ex)
            {
                System.Diagnostics.Debug.WriteLine(ex.Message);
            }

            return(length);
        }
        /// <summary>
        /// Method to get a z offset distance in the correct units for the map
        /// </summary>
        /// <param name="map">IMap</param>
        /// <param name="offset">the input offset</param>
        /// <param name="zFactor">ISurface z factor</param>
        /// <param name="distanceType">the "from" distance unit type</param>
        /// <returns></returns>
        internal double GetOffsetInZUnits(IMap map, double offset, double zFactor, DistanceTypes distanceType)
        {
            if (map.SpatialReference == null)
                return offset;

            double offsetInMapUnits = 0.0;
            DistanceTypes distanceTo = DistanceTypes.Meters; // default to meters

            var pcs = map.SpatialReference as IProjectedCoordinateSystem;

            if (pcs != null)
            {
                // need to convert the offset from the input distance type to the spatial reference linear type
                // then apply the zFactor
                distanceTo = GetDistanceType(pcs.CoordinateUnit.FactoryCode);
            }

            offsetInMapUnits = GetDistanceFromTo(distanceType, distanceTo, offset);

            var result = offsetInMapUnits / zFactor;

            return result;
        }
 public HumanizedDistance(double valSource, DistanceTypes typeSource = DistanceTypes.Meters)
 {
     this.valInMillimeters = (valSource * (System.Convert.ToDouble ((int)typeSource)));
 }
Exemple #32
0
 /// <summary>
 /// Fits line to the set of 3D points using M-estimator algorithm.
 /// The input is vector of 3D points.
 /// </summary>
 /// <param name="distType">Distance used by the M-estimator</param>
 /// <param name="param">Numerical parameter ( C ) for some types of distances. 
 /// If it is 0, an optimal value is chosen.</param>
 /// <param name="reps">Sufficient accuracy for the radius 
 /// (distance between the coordinate origin and the line).</param>
 /// <param name="aeps">Sufficient accuracy for the angle. 
 /// 0.01 would be a good default value for reps and aeps.</param>
 /// <returns>Output line parameters.</returns>
 public Line3D FitLine3D(DistanceTypes distType, double param, double reps, double aeps)
 {
     var line = new MatOfFloat();
     Cv2.FitLine(this, line, distType, param, reps, aeps);
     return new Line3D(line.ToArray());
 }
Exemple #33
0
        /// <summary>
        /// 
        /// </summary>
        /// <param name="signature1"></param>
        /// <param name="signature2"></param>
        /// <param name="distType"></param>
        /// <returns></returns>

        public static float EMD(InputArray signature1, InputArray signature2, DistanceTypes distType)
        {
            float lowerBound;
            return EMD(signature1, signature1, distType, null, out lowerBound, null);
        }
 public Distance(double value, DistanceTypes type)
 {
     SetValue(value, type);
 }
Exemple #35
0
 /// <summary>
 /// builds the discrete Voronoi diagram
 /// </summary>
 /// <param name="src"></param>
 /// <param name="dst"></param>
 /// <param name="labels"></param>
 /// <param name="distanceType"></param>
 /// <param name="maskSize"></param>
 /// <param name="labelType"></param>
 public static void DistanceTransformWithLabels(InputArray src,
                                                OutputArray dst,
                                                OutputArray labels,
                                                DistanceTypes distanceType,
                                                DistanceMaskSize maskSize,
                                                DistanceTransformLabelTypes labelType = DistanceTransformLabelTypes.CComp)
 {
     if (src == null)
         throw new ArgumentNullException(nameof(src));
     if (dst == null)
         throw new ArgumentNullException(nameof(dst));
     if (labels == null)
         throw new ArgumentNullException(nameof(labels));
     src.ThrowIfDisposed();
     dst.ThrowIfNotReady();
     labels.ThrowIfNotReady();
     NativeMethods.imgproc_distanceTransformWithLabels(
         src.CvPtr, dst.CvPtr, labels.CvPtr, (int)distanceType, (int)maskSize, (int)labelType);
     GC.KeepAlive(src);
     dst.Fix();
     labels.Fix();
 }
Exemple #36
0
 /// <summary>
 /// computes the distance transform map
 /// </summary>
 /// <param name="src"></param>
 /// <param name="dst"></param>
 /// <param name="distanceType"></param>
 /// <param name="maskSize"></param>
 public static void DistanceTransform(InputArray src,
                                      OutputArray dst,
                                      DistanceTypes distanceType,
                                      DistanceMaskSize maskSize)
 {
     if (src == null)
         throw new ArgumentNullException(nameof(src));
     if (dst == null)
         throw new ArgumentNullException(nameof(dst));
     src.ThrowIfDisposed();
     dst.ThrowIfNotReady();
     NativeMethods.imgproc_distanceTransform(
         src.CvPtr, dst.CvPtr, (int)distanceType, (int)maskSize);
     GC.KeepAlive(src);
     dst.Fix();
 }
Exemple #37
0
 /// <summary>
 /// Fits line to the set of 2D points using M-estimator algorithm
 /// </summary>
 /// <param name="points">Input vector of 2D or 3D points</param>
 /// <param name="line">Output line parameters. 
 /// In case of 2D fitting, it should be a vector of 4 elements 
 /// (like Vec4f) - (vx, vy, x0, y0), where (vx, vy) is a normalized vector 
 /// collinear to the line and (x0, y0) is a point on the line. 
 /// In case of 3D fitting, it should be a vector of 6 elements 
 /// (like Vec6f) - (vx, vy, vz, x0, y0, z0), where (vx, vy, vz) is a 
 /// normalized vector collinear to the line and (x0, y0, z0) is a point on the line.</param>
 /// <param name="distType">Distance used by the M-estimator</param>
 /// <param name="param">Numerical parameter ( C ) for some types of distances. 
 /// If it is 0, an optimal value is chosen.</param>
 /// <param name="reps">Sufficient accuracy for the radius 
 /// (distance between the coordinate origin and the line).</param>
 /// <param name="aeps">Sufficient accuracy for the angle. 
 /// 0.01 would be a good default value for reps and aeps.</param>
 public static void FitLine(InputArray points, OutputArray line, DistanceTypes distType,
     double param, double reps, double aeps)
 {
     if (points == null)
         throw new ArgumentNullException(nameof(points));
     if (line == null)
         throw new ArgumentNullException(nameof(line));
     points.ThrowIfDisposed();
     line.ThrowIfNotReady();
     NativeMethods.imgproc_fitLine_InputArray(points.CvPtr, line.CvPtr, (int)distType, param, reps, aeps);
     GC.KeepAlive(points);
     line.Fix();
 }
Exemple #38
0
 /// <summary>
 /// Fits line to the set of 3D points using M-estimator algorithm
 /// </summary>
 /// <param name="points">Input vector of 2D or 3D points</param>
 /// <param name="distType">Distance used by the M-estimator</param>
 /// <param name="param">Numerical parameter ( C ) for some types of distances. 
 /// If it is 0, an optimal value is chosen.</param>
 /// <param name="reps">Sufficient accuracy for the radius 
 /// (distance between the coordinate origin and the line).</param>
 /// <param name="aeps">Sufficient accuracy for the angle. 
 /// 0.01 would be a good default value for reps and aeps.</param>
 /// <returns>Output line parameters.</returns>
 public static Line3D FitLine(IEnumerable<Point3f> points, DistanceTypes distType,
     double param, double reps, double aeps)
 {
     if (points == null)
         throw new ArgumentNullException(nameof(points));
     Point3f[] pointsArray = EnumerableEx.ToArray(points);
     float[] line = new float[6];
     NativeMethods.imgproc_fitLine_Point3f(pointsArray, pointsArray.Length, line, (int)distType, param, reps, aeps);
     return new Line3D(line);
 }
        /// <summary>
        /// Gets the linear unit from the esri constants for linear units
        /// </summary>
        /// <returns>ILinearUnit</returns>
        internal ILinearUnit GetLinearUnit(DistanceTypes distanceType)
        {
            int unitType = (int)esriSRUnitType.esriSRUnit_Meter;
            if (srf3 == null)
            {
                Type srType = Type.GetTypeFromProgID("esriGeometry.SpatialReferenceEnvironment");
                srf3 = Activator.CreateInstance(srType) as ISpatialReferenceFactory3;
            }

            switch (distanceType)
            {
                case DistanceTypes.Feet:
                    unitType = (int)esriSRUnitType.esriSRUnit_Foot;
                    break;
                case DistanceTypes.Kilometers:
                    unitType = (int)esriSRUnitType.esriSRUnit_Kilometer;
                    break;
                case DistanceTypes.Meters:
                    unitType = (int)esriSRUnitType.esriSRUnit_Meter;
                    break;
                case DistanceTypes.NauticalMile:
                    unitType = (int)esriSRUnitType.esriSRUnit_NauticalMile;
                    break;
                case DistanceTypes.SurveyFoot:
                    unitType = (int)esriSRUnitType.esriSRUnit_SurveyFoot;
                    break;
                default:
                    unitType = (int)esriSRUnitType.esriSRUnit_Meter;
                    break;
            }

            return srf3.CreateUnit(unitType) as ILinearUnit;
        }
Exemple #40
0
 /// <summary>
 /// 
 /// </summary>
 /// <param name="signature1"></param>
 /// <param name="signature2"></param>
 /// <param name="distType"></param>
 /// <param name="cost"></param>
 /// <param name="lowerBound"></param>
 /// <returns></returns>
 public static float EMD(InputArray signature1, InputArray signature2,
     DistanceTypes distType, InputArray cost, out float lowerBound)
 {
     return EMD(signature1, signature1, distType, cost, out lowerBound, null);
 }
        private float[,] InitDist(DistanceTypes fromWhat)
        {
            float[,] distArr = new float[width, height];
            switch (fromWhat)
            {
            case DistanceTypes.WATER:

                for (int w = 0; w < width; w++)
                {
                    for (int h = 0; h < height; h++)
                    {
                        float heightFactor = heightmap[w, h] - 1;

                        if (heightFactor < 0)
                        {      // sea
                            distArr[w, h] = 0;
                        }
                        else
                        {      // land
                            distArr[w, h] = float.MaxValue;
                        }
                    }
                }
                break;

            case DistanceTypes.POLES:
                for (int w = 0; w < width; w++)
                {
                    for (int h = 0; h < height; h++)
                    {
                        if (h == 0)
                        {      // topOfTheMap
                            distArr[w, h] = 0;
                        }
                        else
                        {
                            distArr[w, h] = float.MaxValue;
                        }
                    }
                }
                break;

            case DistanceTypes.EQUATOR:

                for (int w = 0; w < width; w++)
                {
                    for (int h = 0; h < height; h++)
                    {
                        if (h == height / 2)
                        {      // equator level
                            distArr[w, h] = 0;
                        }
                        else
                        {
                            distArr[w, h] = float.MaxValue;
                        }
                    }
                }
                break;
            }
            return(distArr);
        }
        private float[,] DistanceFrom(DistanceTypes fromWhat, float heightInfluence)
        {
            float[,] distArr = InitDist(fromWhat);
            float currentDistance = 0;

            Console.WriteLine("Starting distance calculation: " + fromWhat);
            while (currentDistance < Math.Max(width, height))
            {
                for (int w = 0; w < width; w++)
                {
                    for (int h = 0; h < height; h++)
                    {
                        float currHeight = heightmap[w, h];
                        if (distArr[w, h] == float.MaxValue)
                        { //Block could update
                            if (distArr[(w + 1) % width, h] + (heightmap[(w + 1) % width, h] - currHeight) * heightInfluence - currentDistance <= 0 ||
                                distArr[w, (h + 1) % height] + (heightmap[w, (h + 1) % height] - currHeight) * heightInfluence - currentDistance <= 0 ||
                                distArr[(w - 1 + width) % width, h] + (heightmap[(w - 1 + width) % width, h] - currHeight) * heightInfluence - currentDistance <= 0 ||
                                distArr[w, (h - 1 + height) % height] + (heightmap[w, (h - 1 + height) % height] - currHeight) * heightInfluence - currentDistance <= 0)
                            {
                                //System.out.println("In case 1");
                                distArr[w, h] = currentDistance + 1;
                            }
                            else if (
                                distArr[(w + 1) % width, (h + 1) % height] + (heightmap[(w + 1) % width, (h + 1) % height] - currHeight) * heightInfluence - (currentDistance + 0.41421) <= 0 ||
                                distArr[(w - 1 + width) % width, (h + 1) % height] + (heightmap[(w - 1 + width) % width, (h + 1) % height] - currHeight) * heightInfluence - (currentDistance + 0.41421) <= 0 ||
                                distArr[(w + 1) % width, (h - 1 + height) % height] + (heightmap[(w + 1) % width, (h - 1 + height) % height] - currHeight) * heightInfluence - (currentDistance + 0.41421) <= 0 ||
                                distArr[(w - 1 + width) % width, (h - 1 + height) % height] + (heightmap[(w - 1 + width) % width, (h - 1 + height) % height] - currHeight) * heightInfluence - (currentDistance + 0.41421) <= 0)
                            {
                                distArr[w, h] = currentDistance + 1.41421f;
                                //System.out.println("In case 2");
                            }
                        }
                    }
                }
                currentDistance++;
                //System.out.println("I was here " + currentDistance + " times");
            }

            //normalize Array
            float max = 0;

            for (int w = 0; w < width; w++)
            {
                for (int h = 0; h < height; h++)
                {
                    max = distArr[w, h] > max ? distArr[w, h] : max;
                }
            }
            for (int w = 0; w < width; w++)
            {
                for (int h = 0; h < height; h++)
                {
                    distArr[w, h] /= max;
                }
            }

            //invert if necessary
            if (fromWhat == DistanceTypes.EQUATOR)
            {
                for (int w = 0; w < width; w++)
                {
                    for (int h = 0; h < height; h++)
                    {
                        distArr[w, h] = 1 - distArr[w, h];
                    }
                }
            }

            return(distArr);
        }
Exemple #43
0
 /// <summary>
 /// Computes the distance transform map
 /// </summary>
 /// <param name="distanceType"></param>
 /// <param name="maskSize"></param>
 public MatOfFloat DistanceTransform(DistanceTypes distanceType, DistanceMaskSize maskSize)
 {
     var dst = new MatOfFloat();
     Cv2.DistanceTransform(this, dst, distanceType, maskSize);
     return dst;
 }
Exemple #44
0
 private void UpdateDistance(double distance, DistanceTypes fromDistanceType)
 {
     Distance = distance;
     UpdateDistanceFromTo(fromDistanceType, LineDistanceType);
     UpdateFeedbackWithGeoCircle();
 }
        //internal DistanceTypes GetDistanceType(int linearUnitFactoryCode)
        //{
        //    DistanceTypes distanceType = DistanceTypes.Meters;
        //    switch (linearUnitFactoryCode)
        //    {
        //        case (int)esriSRUnitType.esriSRUnit_Foot:
        //            distanceType = DistanceTypes.Feet;
        //            break;
        //        case (int)esriSRUnitType.esriSRUnit_Kilometer:
        //            distanceType = DistanceTypes.Kilometers;
        //            break;
        //        case (int)esriSRUnitType.esriSRUnit_Meter:
        //            distanceType = DistanceTypes.Meters;
        //            break;
        //        case (int)esriSRUnitType.esriSRUnit_NauticalMile:
        //            distanceType = DistanceTypes.NauticalMile;
        //            break;
        //        case (int)esriSRUnitType.esriSRUnit_SurveyFoot:
        //            distanceType = DistanceTypes.SurveyFoot;
        //            break;
        //        default:
        //            distanceType = DistanceTypes.Meters;
        //            break;
        //    }

        //    return distanceType;
        //}

        //internal ISpatialReferenceFactory3 srf3 = null;
        //internal ILinearUnit GetLinearUnit()
        //{
        //    return GetLinearUnit(LineDistanceType);
        //}
        /// <summary>
        /// Gets the linear unit from the esri constants for linear units
        /// </summary>
        /// <returns>ILinearUnit</returns>
        //internal ILinearUnit GetLinearUnit(DistanceTypes distanceType)
        //{
        //    int unitType = (int)esriSRUnitType.esriSRUnit_Meter;
        //    if (srf3 == null)
        //    {
        //        Type srType = Type.GetTypeFromProgID("esriGeometry.SpatialReferenceEnvironment");
        //        srf3 = Activator.CreateInstance(srType) as ISpatialReferenceFactory3;
        //    }

        //    switch (distanceType)
        //    {
        //        case DistanceTypes.Feet:
        //            unitType = (int)esriSRUnitType.esriSRUnit_Foot;
        //            break;
        //        case DistanceTypes.Kilometers:
        //            unitType = (int)esriSRUnitType.esriSRUnit_Kilometer;
        //            break;
        //        case DistanceTypes.Meters:
        //            unitType = (int)esriSRUnitType.esriSRUnit_Meter;
        //            break;
        //        case DistanceTypes.NauticalMile:
        //            unitType = (int)esriSRUnitType.esriSRUnit_NauticalMile;
        //            break;
        //        case DistanceTypes.SurveyFoot:
        //            unitType = (int)esriSRUnitType.esriSRUnit_SurveyFoot;
        //            break;
        //        default:
        //            unitType = (int)esriSRUnitType.esriSRUnit_Meter;
        //            break;
        //    }

        //    return srf3.CreateUnit(unitType) as ILinearUnit;
        //}

        //private void UpdateDistanceFromTo(DistanceTypes fromType, DistanceTypes toType)
        //{
        //    Distance = GetDistanceFromTo(fromType, toType, Distance);
        //}

        /// <summary>
        /// Ugly method to convert to/from different types of distance units
        /// </summary>
        /// <param name="fromType">DistanceTypes</param>
        /// <param name="toType">DistanceTypes</param>
        internal double GetDistanceFromTo(DistanceTypes fromType, DistanceTypes toType, double input)
        {
            double length = input;

            try
            {
                if (fromType == DistanceTypes.Meters && toType == DistanceTypes.Kilometers)
                {
                    length /= 1000.0;
                }
                else if (fromType == DistanceTypes.Meters && toType == DistanceTypes.Feet)
                {
                    length *= 3.28084;
                }
                else if (fromType == DistanceTypes.Meters && toType == DistanceTypes.SurveyFoot)
                {
                    length *= 3.280833333;
                }
                else if (fromType == DistanceTypes.Meters && toType == DistanceTypes.NauticalMile)
                {
                    length *= 0.000539957;
                }
                else if (fromType == DistanceTypes.Kilometers && toType == DistanceTypes.Meters)
                {
                    length *= 1000.0;
                }
                else if (fromType == DistanceTypes.Kilometers && toType == DistanceTypes.Feet)
                {
                    length *= 3280.84;
                }
                else if (fromType == DistanceTypes.Kilometers && toType == DistanceTypes.SurveyFoot)
                {
                    length *= 3280.833333;
                }
                else if (fromType == DistanceTypes.Kilometers && toType == DistanceTypes.NauticalMile)
                {
                    length *= 0.539957;
                }
                else if (fromType == DistanceTypes.Feet && toType == DistanceTypes.Kilometers)
                {
                    length *= 0.0003048;
                }
                else if (fromType == DistanceTypes.Feet && toType == DistanceTypes.Meters)
                {
                    length *= 0.3048;
                }
                else if (fromType == DistanceTypes.Feet && toType == DistanceTypes.SurveyFoot)
                {
                    length *= 0.999998000004;
                }
                else if (fromType == DistanceTypes.Feet && toType == DistanceTypes.NauticalMile)
                {
                    length *= 0.000164579;
                }
                else if (fromType == DistanceTypes.SurveyFoot && toType == DistanceTypes.Kilometers)
                {
                    length *= 0.0003048006096;
                }
                else if (fromType == DistanceTypes.SurveyFoot && toType == DistanceTypes.Meters)
                {
                    length *= 0.3048006096;
                }
                else if (fromType == DistanceTypes.SurveyFoot && toType == DistanceTypes.Feet)
                {
                    length *= 1.000002;
                }
                else if (fromType == DistanceTypes.SurveyFoot && toType == DistanceTypes.NauticalMile)
                {
                    length *= 0.00016457916285097;
                }
                else if (fromType == DistanceTypes.NauticalMile && toType == DistanceTypes.Kilometers)
                {
                    length *= 1.852001376036;
                }
                else if (fromType == DistanceTypes.NauticalMile && toType == DistanceTypes.Meters)
                {
                    length *= 1852.001376036;
                }
                else if (fromType == DistanceTypes.NauticalMile && toType == DistanceTypes.Feet)
                {
                    length *= 6076.1154855643;
                }
                else if (fromType == DistanceTypes.NauticalMile && toType == DistanceTypes.SurveyFoot)
                {
                    length *= 6076.1033333576;
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex);
            }

            return(length);
        }
 private void UpdateDistance(double distance, DistanceTypes fromDistanceType)
 {
     Distance = distance;
     UpdateDistanceFromTo(fromDistanceType, LineDistanceType);
     UpdateFeedbackWithGeoCircle();
 }
    public UnitOfMeasurement CreateDistanceUnitOfMeasurement(DistanceTypes distanceType, string name, double value)
    {
        string classification = BuildClassification(distanceType);

        return(this.factory.Create(classification, name, value));
    }
        private void CheckStation()
        {
            Logger.Log("CheckStation - Start");

            double _AlertDistance = m_Options.AlertDistance;

            foreach (Station _Station in m_ItemsControl.Items)
            {
                //m_Latitude = 48.323644;
                //m_Longitude = 10.050087;

                //Have to check dinamically of any changes made on the options dialog
                var _StationChanges = from _StationChange in m_Options.GetStations()
                                      where _StationChange.StationID == _Station.StationID
                                      select _StationChange;

                if (null != _StationChanges.SingleOrDefault())
                {
                    _Station.PerformAlert = _StationChanges.SingleOrDefault().PerformAlert;
                }
                else
                {
                    _Station.PerformAlert = false;
                }

                _Station.RefreshDistanceTo(m_Latitude, m_Longitude);
                _Station.AlertDistance = _AlertDistance;

                m_ItemsControl.Items.GetContentPresenter(_Station).RefreshContent();

                Application.DoEvents();

                if (_Station.PerformAlert && _AlertDistance > 0 && _Station.DistanceToDestination < _AlertDistance)
                {
                    if (m_Options.SmsActive && !m_SMSSent)
                    {
                        //TODO : Calculate speed without GPS information, only with distance.
                        //if (m_GpsPosition.SpeedValid)
                        //{
                        //    _EstimatedTime = Utils.ETAString(", estaria llegando en {0} {1}", Utils.EstimatedTimeOfArrival(m_GpsPosition.Speed, _Distance));
                        //}

                        //TODO : Multilanguage
                        DistanceTypes _DistanceType       = _Station.DistanceType;
                        string        _DistanceTypeFormat = "I'm {0:0.00} km from {1}";
                        if (_DistanceType == DistanceTypes.Meters)
                        {
                            _DistanceTypeFormat = "I'm {0:0.00} meters from {1}";
                        }

                        string _SMSMessage = string.Format(_DistanceTypeFormat,
                                                           (_DistanceType == DistanceTypes.Meters ? Convert.ToInt32(_Station.DistanceToDestination) : _Station.DistanceToDestination),
                                                           _Station.Name);

                        SendSMS(_SMSMessage);
                    }

                    Logger.Log("Video Power on");

                    //Power on the device if stand by
                    if (NativeMethods.GetVideoPowerState() != NativeMethods.VideoPowerState.VideoPowerOn)
                    {
                        NativeMethods.SetVideoPowerState(NativeMethods.VideoPowerState.VideoPowerOn);
                    }

                    //Doesnt matter if the Ringer is on/off,
                    //when off it will vibrates when on will do both.
                    Vibrate.PlaySync(150, 150, 150, 150);
                    Vibrate.PlaySnd();

                    Logger.Log("Vibrate and Sound played");
                }
            }

            NativeMethods.PowerPolicyNotify(NativeMethods.PPNMessage.PPN_UNATTENDEDMODE, 0);

            Logger.Log("CheckStation - Finished");

            //string _Message = string.Empty;
            //string _EstimatedTime = string.Empty;
            //Color _Color = Color.Green;
            //double _Distance = 0;
            //double _AlertInstance = m_Options.GetAlert();
            //bool _Alert = false;

            //try
            //{
            //    Station _Station = m_Options.GetStation();
            //    if (null != _Station)
            //    {
            //        //TEST
            //        //_Station.Latitude = 48.323644;
            //        //_Station.Longitude = 10.050087;

            //        txtStatus.Text = string.Format("{0} Lat:{1}-Long:{2} <-> Current Lat:{3}-Lon:{4}", _Station.Name, _Station.Latitude, _Station.Longitude, m_Latitude, m_Longitude);

            //        _Distance = _Station.DistanceTo(m_Latitude, m_Longitude);

            //        if (_AlertInstance > 0 && _Distance < _AlertInstance)
            //        {
            //            _Color = Color.Red;
            //            _Alert = true;
            //        }

            //        //if (m_GpsPosition.SpeedValid)
            //        //{
            //        //    _EstimatedTime = Utils.ETAString("ETA: {0} {1}", Utils.EstimatedTimeOfArrival(m_GpsPosition.Speed, _Distance));
            //        //}

            //        //"{0} in {1:0.00} km. {2}"
            //        _Message = string.Format("{0} in {1:0.00} km", _Station.Name, _Distance/*, _EstimatedTime*/);
            //    }
            //    else
            //    {
            //        txtStatus.Text = "Station cannot be found";
            //    }
            //}
            //catch (Exception ex)
            //{
            //    _Color = Color.Red;
            //    _Message = ex.Message;
            //}

            //lblAlert.ForeColor = _Color;
            //lblAlert.Text = _Message;

            //if (_Alert)
            //{
            //    //TODO : Recheck this option.
            //    //if (chkSendSMS.Checked && !m_SMSSent)
            //    //{
            //    //    if (m_GpsPosition.SpeedValid)
            //    //    {
            //    //        _EstimatedTime = Utils.ETAString(", estaria llegando en {0} {1}", Utils.EstimatedTimeOfArrival(m_GpsPosition.Speed, _Distance));
            //    //    }

            //    //    //TODO : Multilanguage
            //    //    string _DistanceType = (((_Distance * 1000) < 1000) ? "metros" : "km");
            //    //    string _SMSMessage = string.Format("Estoy a {0} {1} de {2}", _Distance, _DistanceType, _Station, _EstimatedTime);
            //    //    SendSMS(_SMSMessage);
            //    //}

            //    //Doesnt matter if the Ringer is on/off,
            //    //when off it will vibrates when on will do both.
            //    //m_Vibrate.Play();
            //    //Application.DoEvents();
            //    //m_Vibrate.Play();
            //    //Application.DoEvents();
            //    //m_Vibrate.Play();

            //    Vibrate.PlaySync(300, 300, 300, 300);
            //    Vibrate.PlaySnd();
            //}
        }
 private void UpdateDistanceFromTo(DistanceTypes fromType, DistanceTypes toType)
 {
     Distance = GetDistanceFromTo(fromType, toType, Distance);
 }
 internal LinearUnit GetLinearUnit(DistanceTypes dtype)
 {
     LinearUnit result = LinearUnit.Meters;
     switch(dtype)
     {
         case DistanceTypes.Feet:
         case DistanceTypes.SurveyFoot:
             result = LinearUnit.Feet;
             break;
         case DistanceTypes.Kilometers:
             result = LinearUnit.Kilometers;
             break;
         case DistanceTypes.NauticalMile:
             result = LinearUnit.NauticalMiles;
             break;
         case DistanceTypes.Meters:
         default:
             result = LinearUnit.Meters;
             break;
     }
     return result;
 }
        /// <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>
        /// <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 GetLinearDistance(IMap map, double inputDistance, DistanceTypes distanceType)
        {
            if (map.SpatialReference == null)
                return inputDistance;

            DistanceTypes distanceTo = DistanceTypes.Meters; // default to meters

            var pcs = map.SpatialReference as IProjectedCoordinateSystem;

            if (pcs != null)
            {
                // need to convert the offset from the input distance type to the spatial reference linear type
                distanceTo = GetDistanceType(pcs.CoordinateUnit.FactoryCode);
            }
            else
            {
                var gcs = map.SpatialReference as IGeographicCoordinateSystem;
                if (gcs != null)
                {
                    distanceTo = GetDistanceType(gcs.CoordinateUnit.FactoryCode);

                }
            }

            var result = GetDistanceFromTo(distanceType, distanceTo, inputDistance);

            return result;
        }