} // end of method

        /// <summary>
        /// This instance method calculates the Great Circle Distance or arclength
        /// between two Geolocation points (city locations) and returns the length
        /// in the prefered unit of measurements as specified by the input LengthTypes
        /// or default to meters.
        /// </summary>
        /// <param name="other">The second Geolocation object (city location)</param>
        /// <param name="lengthType">Unit of Measure (enum LengthTypes), Default: Meters</param>
        /// <returns>Arclength (decimal) between two locations</returns>
        public decimal GreatCircleDistance(Geolocation other, LengthTypes lengthType = LengthTypes.Meters)
        {
            double lat1             = ToRadians((double)Latitude);                         // Location object 1 latitude in radians
            double lat2             = ToRadians((double)other.Latitude);                   // Location object 2 latitude in radians
            double lng1             = ToRadians((double)Longitude);                        // Location object 1 longitude in radians
            double lng2             = ToRadians((double)other.Longitude);                  // Location object 2 longitude in radians
            double latDiff          = lat1 - lat2;                                         // Latitude difference between locations 1 and 2
            double lngDiff          = lng1 - lng2;                                         // Longitude difference between locations 1 and 2
            double sin2Lat          = Math.Pow(Math.Sin(latDiff / 2), 2);                  // Wizard Math
            double sin2Lng          = Math.Pow(Math.Sin(lngDiff / 2), 2);                  // Wizard Math
            double a                = sin2Lat + Math.Cos(lat1) * Math.Cos(lat2) * sin2Lng; // More Wizard Math
            double arcLength        = 2 * Math.Asin(Math.Min(1, Math.Sqrt(a)));            // How the Wizard died of math
            double arcLength_meters = 6371000 * arcLength;                                 // ArchLength in Meters

            // Return arcLength based on Unit of Measurement choice
            switch (lengthType)
            {
            case LengthTypes.Meters:
                return((decimal)arcLength_meters);

            case LengthTypes.Kilometers:
                return((decimal)(arcLength_meters * 0.001));

            case LengthTypes.Feet:
                return((decimal)(arcLength_meters * 3.2808399));

            case LengthTypes.Miles:
                return((decimal)(arcLength_meters * 0.00062137119));
            }

            // Default return of zero
            return(0.0M);
        } // end of GreatCircleDistance method
Ejemplo n.º 2
0
 /// <summary>
 /// Creates a <see cref="Split"/> object.
 /// </summary>
 /// <param name="name">The name of the split.</param>
 /// <param name="length">The length of the split.</param>
 /// <param name="lengthType">Determines whether <paramref name="length"/> contains the age of the node that induced the split or the length of the branch.</param>
 /// <param name="support">The support value of the split.</param>
 public Split(string name, double length, LengthTypes lengthType, double support)
 {
     this.Name       = name;
     this.Length     = length;
     this.Support    = support;
     this.LengthType = lengthType;
 }
Ejemplo n.º 3
0
        //Beginning of: Methods

        #region //Distance()
        //Distance()
        public decimal Distance(City city, LengthTypes lengthType = LengthTypes.Miles)
        {
            decimal result = default;

            result = Location.GreatCircleDistance(city.Location, lengthType);

            return(result);
        }
Ejemplo n.º 4
0
        } // end of method

        /// <summary>
        /// This instance method returns the great circle distance or arc length of two cities
        /// on the globe with coordinate location objects. The method is called on the first city
        /// instance object and used the second city parameter object to determine the arc
        /// distance. The distance is returned in the unit of measured as specified by the
        /// second parameter to the method which is an enum for the units.
        /// </summary>
        /// <param name="city">City type object representing the other city to calculate arc distance between</param>
        /// <param name="lengthType">Enum of Measurement type to return calculation</param>
        /// <returns></returns>
        public decimal Distance(City city, LengthTypes lengthType = LengthTypes.Miles)
        {
            if (city == null)
            {
                return(0.0M);
            }

            return(Location.GreatCircleDistance(city.Location, lengthType));
        } // end of method
Ejemplo n.º 5
0
        private TimeSpan GetTimeSpan()
        {
            int value = (int)Math.Round(ReminderSlider.Value);

            switch (LengthTypes.FindIndex(t => t == LengthType))
            {
            case 2: return(new TimeSpan(ConvertBackDays(value), 0, 0, 0));

            case 1: return(new TimeSpan(value, 0, 0));

            case 0:
            default: return(new TimeSpan(0, value, 0));
            }
        }
Ejemplo n.º 6
0
 /// <summary>
 ///     Constructor.
 /// </summary>
 /// <param name="length" default="512 bytes key">Length of the ke that must be generated.</param>
 public Key(LengthTypes length = LengthTypes.K512)
 {
     LengthType = length;
 }
Ejemplo n.º 7
0
        /// <summary>
        /// 加载选中表的所有列信息
        /// </summary>
        private void ShowSelectedTableColumns()
        {
            var src       = new SFDBSrc(this.FK_SFDBSrc);
            var colTables = src.GetColumns(this.Pub1.GetLBByID("LB_Table").SelectedItemStringVal);

            colTables.Columns.Add("text", typeof(string));

            var    cols = new List <string>();
            string type;
            var    length = 0;

            foreach (DataRow dr in colTables.Rows)
            {
                cols.Add(dr["name"].ToString());
                type   = dr["type"].ToString().ToLower();
                length = int.Parse(dr["length"].ToString());

                dr["text"] = dr["name"] + " (" + (LengthTypes.Contains(type) ?
                                                  (string.Format("{0}{1}", type,
                                                                 (length == -1 || length == 0) ?
                                                                 (MaxTypes.Contains(type) ? "(max)" : "")
                      : string.Format("({0})", length))) : type) + ")";
            }

            //自动判断是否符合规则
            var regColValue    = cols.FirstOrDefault(o => regs[0].Contains(o.ToLower()));
            var regColText     = cols.FirstOrDefault(o => regs[1].Contains(o.ToLower()));
            var regColParentNo = cols.FirstOrDefault(o => regs[2].Contains(o.ToLower()));

            var ddl = this.Pub1.GetDDLByID("DDL_ColValue");

            ddl.Items.Clear();
            ddl.Bind(colTables, "name", "text");

            if (regColValue != null)
            {
                ddl.SetSelectItem(regColValue);
            }

            ddl = this.Pub1.GetDDLByID("DDL_ColText");
            ddl.Items.Clear();
            ddl.Bind(colTables, "name", "text");

            if (regColText != null)
            {
                ddl.SetSelectItem(regColText);
            }

            ddl = this.Pub1.GetDDLByID("DDL_ColParentNo");
            ddl.Items.Clear();
            ddl.Bind(colTables, "name", "text");

            if (regColParentNo != null)
            {
                ddl.SetSelectItem(regColParentNo);
            }

            Pub1.GetTBByID("TB_SelectStatement").Text = string.Empty;
            Pub1.GetDDLByID("DDL_SFTableType").SetSelectItem((regColValue != null && regColText != null &&
                                                              regColParentNo != null)
                                                                  ? "1"
                                                                  : "0");
        }
        public decimal GreatCircleDistance(Geolocation other, LengthTypes lengthType = LengthTypes.Meters)
        {
            #region //Variables
            double        lat1, lat2, lng1, lng2;
            double        latDiff, lngDiff;
            double        sin2Lat, sin2Lng;
            double        a, arcLength;
            decimal?      distance                  = null;
            decimal?      convertedDistance         = null;
            const decimal EarthRadius               = 6371000;
            const decimal KilometersConversionRatio = 0.001M;
            const decimal FeetConversionRatio       = 3.2808399M;
            const decimal MilesConversionRatio      = 0.00062137119M;
            #endregion


            #region                                    //Step1
            /*Convert from degrees to radians*/
            lng1 = ToRadians((double)Longitude);       //The 'x' of city
            lat1 = ToRadians((double)Latitude);        //The 'y' of city

            lng2 = ToRadians((double)other.Longitude); //The 'x' of otherCity
            lat2 = ToRadians((double)other.Latitude);  //The 'y' of otheCity
            #endregion                                 //End of: Step1

            #region                                    //Step2
            /*Calculate for 'latDiff' and 'lngDiff' */
            latDiff = lat1 - lat2;
            lngDiff = lng1 - lng2;
            #endregion//End of: Step2


            #region//Step3
            /*Calculate for sin^2() portion of formula*/
            sin2Lat = Math.Pow(Math.Sin(latDiff / 2), 2);
            sin2Lng = Math.Pow(Math.Sin(lngDiff / 2), 2);

            #endregion //End of: Step3

            #region    //Step4
            /*Calculate 'a' where 'a' is the result of the rest of the terms under the radical*/
            a = sin2Lat + Math.Cos(lat1) * (Math.Cos(lat2)) * sin2Lng;
            #endregion //End of: Step4

            #region    //Step5
            /*Calculate for 'arcLength'*/
            arcLength = 2 * Math.Asin(Math.Min(1, Math.Sqrt(a)));
            #endregion //End of: Step5

            #region    //Step6
            /*Calculate for 'distance'*/
            distance = (decimal)arcLength * (decimal)EarthRadius;
            #endregion //End of: Step6

            #region    //Step7
            if (lengthType == LengthTypes.Meters)
            {
                return((decimal)distance);
            }
            else
            {
                switch (lengthType)
                {
                case LengthTypes.Kilometers:
                    convertedDistance = (decimal)distance * KilometersConversionRatio;
                    break;

                case LengthTypes.Feet:
                    convertedDistance = (decimal)distance * FeetConversionRatio;
                    break;

                case LengthTypes.Miles:
                    convertedDistance = (decimal)distance * MilesConversionRatio;
                    break;
                }
                if (!String.IsNullOrWhiteSpace(convertedDistance.ToString()))
                {
                    distance = (decimal)convertedDistance;
                }
                //Console.WriteLine($"distance: {distance}");
                return((decimal)distance);
            }
            #endregion//End of: Step7
        }