コード例 #1
0
        /// <summary>
        /// Takes an initialized LookupTablesHelper instance and a valid Gridsquare and returns a signed Longitude per the table lookup.
        /// LonDirection: If positive, then returned decimal is positive (North); if negative, then returned decimal is negative (South).
        /// </summary>
        /// <param name="lookupTablesHelper"></param>
        /// <param name="Gridsquare"></param>
        /// <param name="LonDirection"></param>
        /// <returns></returns>
        public static decimal GetLonDegrees(LookupTablesHelper lookupTablesHelper, string Gridsquare, out short LonDirection)
        {
            LonDirection = 0;

            if (lookupTablesHelper == null || string.IsNullOrEmpty(Gridsquare) || string.IsNullOrWhiteSpace(Gridsquare))
            {
                return(0m);
            }

            if (lookupTablesHelper.GetTable1G2CLookup.TryGetValue(Gridsquare[0].ToString(currentCulture).ToUpper(currentCulture), out int lonDegreesLookupResult))
            {
                if (Gridsquare[0].ToString(currentCulture).ToUpper(currentCulture) == "I" || lonDegreesLookupResult < 0)
                {
                    LonDirection = -1;
                }
                else if (Gridsquare[0].ToString(currentCulture).ToUpper(currentCulture) == "J" || lonDegreesLookupResult >= 0)
                {
                    LonDirection = 1;
                }
                else
                {
                    return(0m);
                }
            }
            else
            {
                return(0m);
            }

            return(Math.Abs(lonDegreesLookupResult) * LonDirection);
        }
コード例 #2
0
        /// <summary>
        /// Takes an initialized LookupTablesHelper instance and a valid Gridsquare and returns a signed Lattitude per the table lookup.
        /// LatDirection: If positive, then returned decimal is positive (North); if negative, then returned decimal is negative (South).
        /// </summary>
        /// <param name="lookupTablesHelper"></param>
        /// <param name="Gridsquare"></param>
        /// <param name="LatDirection"></param>
        /// <returns></returns>
        public static decimal GetLatDegrees(LookupTablesHelper lookupTablesHelper, string Gridsquare, out short LatDirection)
        {
            LatDirection = 0;

            if (lookupTablesHelper == null || string.IsNullOrEmpty(Gridsquare) || string.IsNullOrWhiteSpace(Gridsquare))
            {
                return(-90m);
            }

            string currentGridsquare = Gridsquare[1].ToString(currentCulture);

            if (lookupTablesHelper.GetTable4G2CLookup.TryGetValue(currentGridsquare.ToUpper(currentCulture), out int latDegreesLookupResult))
            {
                if (currentGridsquare.ToUpper(currentCulture) == "I" || latDegreesLookupResult < 0)
                {
                    LatDirection = -1;
                }
                if (currentGridsquare.ToUpper(currentCulture) == "J" || latDegreesLookupResult > 0)
                {
                    LatDirection = 1;
                }
            }
            else
            {
                LatDirection = 0;
            }

            return(Math.Abs(latDegreesLookupResult) * LatDirection);
        }
コード例 #3
0
        /// <summary>
        /// Takes gridsquare character 5 and uses LookupTableHelper to find and return minutes Longitude.
        /// If greater than one degree Longitude, one degree is removed from minutes and one degree is added to DDMLonDegrees.
        /// DDMLonDegrees is rounded to the nearest 2.5 minutes Longitude and output via adjustedLonDegrees, as an UNSIGNED decimal.
        /// LonDirection is necessary to ensure correct sign is applied at decimal return.
        /// </summary>
        /// <param name="lookupTablesHelper"></param>
        /// <param name="DDMlonDegrees"></param>
        /// <param name="LonDirection"></param>
        /// <param name="Gridsquare"></param>
        /// <param name="adjustedDDMlonDegrees"></param>
        /// <returns></returns>
        public static decimal GetLonMinutes(LookupTablesHelper lookupTablesHelper, decimal DDMlonDegrees, int LonDirection, string Gridsquare, out decimal adjustedDDMlonDegrees)
        {
            adjustedDDMlonDegrees = 0m;
            if (lookupTablesHelper == null || string.IsNullOrEmpty(Gridsquare) || string.IsNullOrWhiteSpace(Gridsquare) || LonDirection == 0)
            {
                return(0.0m);
            }

            decimal testResult = 0.0m;

            if (lookupTablesHelper.GetTable3G2CLookup.TryGetValue(Gridsquare[4].ToString(currentCulture).ToUpper(currentCulture), out decimal lonMinsLookupResult))
            {
                if (LonDirection > 0)
                {
                    if (lonMinsLookupResult < 0)
                    {
                        lonMinsLookupResult += 115;
                    }

                    if (lonMinsLookupResult > 60)
                    {
                        lonMinsLookupResult -= 60;
                        adjustedDDMlonDegrees++;
                    }

                    testResult = lonMinsLookupResult;
                }

                if (LonDirection < 0)
                {
                    if (lonMinsLookupResult < -60)
                    {
                        lonMinsLookupResult += 60;
                        adjustedDDMlonDegrees--;
                    }

                    testResult = lonMinsLookupResult;
                }

                adjustedDDMlonDegrees += DDMlonDegrees;
            }
            else
            {
                return(0m);
            }

            return(Math.Abs(testResult) + LonMinsRound);
        }
コード例 #4
0
        /// <summary>
        /// Takes gridsquare character 6 and uses LookupTableHelper to find and return minutes Latitude.
        /// If greater than one degree Latgitude, one degree is removed from minutes and one degree is added to DDMLatDegrees.
        /// DDMLatDegrees is rounded to the nearest 1.25 minutes Latitude and output via adjustedLatDegrees, as an UNSIGNED decimal.
        /// LatDirection is necessary to ensure correct sign is applied at decimal return.
        /// </summary>
        /// <param name="lookupTablesHelper"></param>
        /// <param name="DDMLatDegrees"></param>
        /// <param name="LatDirection"></param>
        /// <param name="Gridsquare"></param>
        /// <param name="adjustedLatDegrees"></param>
        /// <returns></returns>
        public static decimal GetLatMinutes(LookupTablesHelper lookupTablesHelper, decimal DDMLatDegrees, int LatDirection, string Gridsquare, out decimal adjustedLatDegrees)
        {
            adjustedLatDegrees = 0.0m;

            if (lookupTablesHelper == null || string.IsNullOrEmpty(Gridsquare) || string.IsNullOrWhiteSpace(Gridsquare) || LatDirection == 0)
            {
                return(0.0m);
            }

            if (lookupTablesHelper.GetTable6G2CLookup.TryGetValue(Gridsquare[5].ToString(currentCulture).ToUpper(currentCulture), out decimal latMinsLookupResult))
            {
                if (LatDirection > 0)
                {
                    latMinsLookupResult += 57.5m;

                    if (latMinsLookupResult > 60)
                    {
                        adjustedLatDegrees++;
                        latMinsLookupResult -= 60;
                    }

                    adjustedLatDegrees += DDMLatDegrees;
                }

                if (LatDirection < 0)
                {
                    if (latMinsLookupResult < -60)
                    {
                        adjustedLatDegrees--;
                        latMinsLookupResult += 60;
                    }

                    adjustedLatDegrees -= Math.Abs(DDMLatDegrees);
                }
            }
            else
            {
                return(0m);
            }

            return(Math.Abs(latMinsLookupResult) + LatMinsRound);
        }
コード例 #5
0
 public GridSquareHelper()
 {
     LookupTablesHelper = new LookupTablesHelper();
     LookupTablesHelper.GenerateTableLookups();
 }