Ejemplo n.º 1
0
        /// <summary>
        /// Creates a new instance, based on a 'Maidenhead Locator'.
        /// </summary>
        /// <param name="maidenheadLocator">The 'Maidenhead Locator'.</param>
        /// <param name="positionInRectangle">The position of the geographical coordinates in the locator.</param>
        /// <exception cref="ArgumentException">
        /// If the length of the locator text is null or not an even number.
        /// If the locator text contains invalid characters.
        /// </exception>
        public GeographicalPoint(string maidenheadLocator, PositionInRectangle positionInRectangle)
            : this()
        {
            double latitude;
            double longitude;

            MaidenheadLocator.LatLonFromLoc(maidenheadLocator, positionInRectangle, out latitude, out longitude);

            Latitude  = latitude;
            Longitude = longitude;
        }
Ejemplo n.º 2
0
        /*
         * public static double Lat(string loc)
         * {
         *  double StepB1 = 10;
         *  double StepB2 = StepB1 / 10;
         *  double StepB3 = StepB2 / 24;
         *  double StartB1 = -90;
         *  double StartB2 = 0;
         *  double StartB3 = StepB3 / 2;
         *  try
         *  {
         *      loc = loc.ToUpper();
         *      if ((loc[1] < 'A') || (loc[1] > 'Z') ||
         *          (loc[3] < '0') || (loc[3] > '9') ||
         *          (loc[5] < 'A') || (loc[5] > 'X'))
         *      {
         *          return -360;
         *      }
         *      return StartB1 + StepB1 * (System.Convert.ToInt16(loc[1]) - 0x41) +
         *          StartB2 + StepB2 * (System.Convert.ToInt16(loc[3]) - 0x30) +
         *          StartB3 + StepB3 * (System.Convert.ToInt16(loc[5]) - 0x41);
         *  }
         *  catch
         *  {
         *      // Fehler bei der Breitenberechnung
         *      return -360;
         *  }
         * }
         *
         * public static double Lon(string loc)
         * {
         *  try
         *  {
         *      double StepL1 = 20;
         *      double StepL2 = StepL1 / 10;
         *      double StepL3 = StepL2 / 24;
         *      double StartL1 = -180;
         *      double StartL2 = 0;
         *      double StartL3 = StepL3 / 2;
         *      loc = loc.ToUpper();
         *      if ((loc[0] < 'A') || (loc[0] > 'Z') ||
         *          (loc[2] < '0') || (loc[2] > '9') ||
         *          (loc[4] < 'A') || (loc[4] > 'X'))
         *      {
         *          return -360;
         *      }
         *      return StartL1 + StepL1 * (System.Convert.ToInt16(loc[0]) - 0x41) +
         *          StartL2 + StepL2 * (System.Convert.ToInt16(loc[2]) - 0x30) +
         *          StartL3 + StepL3 * (System.Convert.ToInt16(loc[4]) - 0x41);
         *  }
         *  catch
         *  {
         *      // Fehler bei der Längenberechnung
         *      return -360;
         *  }
         * }
         *
         * public static string Loc(double lat, double lon)
         * {
         *  try
         *  {
         *      double StepB1 = 10;
         *      double StepB2 = StepB1 / 10;
         *      double StepB3 = StepB2 / 24;
         *      double StartB1 = -90;
         *      double StartB2 = 0;
         *      double StartB3 = StepB3 / 2;
         *      double StepL1 = 20;
         *      double StepL2 = StepL1 / 10;
         *      double StepL3 = StepL2 / 24;
         *      double StartL1 = -180;
         *      double StartL2 = 0;
         *      double StartL3 = StepL3 / 2;
         *      int i0, i1, i2, i3, i4, i5;
         *      char S0, S1, S2, S3, S4, S5;
         *      i0 = System.Convert.ToInt32(Math.Floor((lon - StartL1) / StepL1));
         *      S0 = System.Convert.ToChar(i0 + 0x41);
         *      lon = lon - i0 * StepL1 - StartL1;
         *      i2 = System.Convert.ToInt32(Math.Floor((lon - StartL2) / StepL2));
         *      S2 = System.Convert.ToChar(i2 + 0x30);
         *      lon = lon - i2 * StepL2 - StartL2;
         *      i4 = System.Convert.ToInt32((lon - StartL3) / StepL3);
         *      S4 = System.Convert.ToChar(i4 + 0x41);
         *      i1 = System.Convert.ToInt32(Math.Floor((lat - StartB1) / StepB1));
         *      S1 = System.Convert.ToChar(i1 + 0x41);
         *      lat = lat - i1 * StepB1 - StartB1;
         *      i3 = System.Convert.ToInt32(Math.Floor((lat - StartB2) / StepB2));
         *      S3 = System.Convert.ToChar(i3 + 0x30);
         *      lat = lat - i3 * StepB2 - StartB2;
         *      i5 = System.Convert.ToInt32((lat - StartB3) / StepB3);
         *      S5 = System.Convert.ToChar(i5 + 0x41);
         *      string S = System.String.Concat(S0, S1, S2, S3, S4, S5);
         *      return S;
         *  }
         *  catch
         *  {
         *      // Fehler bei der Locatorberechnung
         *      return "";
         *  }
         * }
         *
         */
        public static bool IsPrecise(string loc, double lat, double lon)
        {
            loc = loc.ToUpper();
            double mlat = MaidenheadLocator.LatFromLoc(loc);
            double mlon = MaidenheadLocator.LonFromLoc(loc);
            string mloc = MaidenheadLocator.LocFromLatLon(lat, lon, false, loc.Length);

            if ((loc == mloc) && ((Math.Abs(mlat - lat) > 0.00001) || (mlon - lon) > 0.00001))
            {
                return(true);
            }
            return(false);
        }
Ejemplo n.º 3
0
 protected override void OnValidating(CancelEventArgs e)
 {
     base.OnValidating(e);
     if (!String.IsNullOrEmpty(Text))
     {
         // check if text is a valid Maidenhead Locator
         if (MaidenheadLocator.Check(Text))
         {
             ForeColor = OriginalForeColor;
             BackColor = OriginalBackColor;
         }
         else
         {
             base.ForeColor = ErrorForeColor;
             base.BackColor = ErrorBackColor;
             e.Cancel       = true;
         }
     }
 }
Ejemplo n.º 4
0
 protected override void OnTextUpdate(EventArgs e)
 {
     base.OnTextUpdate(e);
     // set the location value
     if (MaidenheadLocator.Check(this.Text))
     {
         if (this.Text.Length >= 6)
         {
             GeoLocation = MaidenheadLocator.GPointFromLoc(this.Text);
         }
         else
         {
             geolocation = MaidenheadLocator.GPointFromLoc(this.Text);
         }
     }
     else
     {
         GeoLocation = null;
     }
     itemchanged     = false;
     locationchanged = false;
 }
Ejemplo n.º 5
0
 public static double Bearing(string myloc, string loc)
 {
     return(Bearing(MaidenheadLocator.LatFromLoc(myloc), MaidenheadLocator.LonFromLoc(myloc), MaidenheadLocator.LatFromLoc(loc), MaidenheadLocator.LonFromLoc(loc)));
 }
Ejemplo n.º 6
0
 public static double Distance(string myloc, string loc)
 {
     return(Distance(MaidenheadLocator.LatFromLoc(myloc), MaidenheadLocator.LonFromLoc(myloc), MaidenheadLocator.LatFromLoc(loc), MaidenheadLocator.LonFromLoc(loc)));
 }
Ejemplo n.º 7
0
        /// <summary>
        /// Converts the geographical coordinates to a 'Maidenhead Locator'.
        /// </summary>
        /// <param name="smallLettersForSubsquares">If true: generate small (if false: big) letters for 'Subsquares', 'Subsubsquare', etc.</param>
        /// <param name="precision">The precision for conversion, must be &gt;=1 and &lt;=10.</param>
        /// <returns>The 'Maidenhead Locator'.</returns>
        /// <exception cref="ArgumentException">If the latitude or longitude exceeds its allowed interval.</exception>
        public string GetMaidenheadLocator(bool smallLettersForSubsquares, int precision)
        {
            string result = MaidenheadLocator.LocFromLatLon(Latitude, Longitude, smallLettersForSubsquares, precision);

            return(result);
        }