Ejemplo n.º 1
0
        /// <summary>
        /// Create a new WGS84 position from a string containing both
        /// latitude and longitude. The string is parsed based on the 
        /// supplied format.
        /// </summary>
        /// <param name="positionString"></param>
        /// <param name="format"></param>
        public WGS84Position(string positionString, WGS84Format format)
            : base(Grid.WGS84)
        {
            if (format == WGS84Format.Degrees)
            {
                positionString = positionString.Trim();
                string[] lat_lon = positionString.Split(' ');
                if (lat_lon.Length == 2)
                {
                    Latitude = double.Parse(lat_lon[0], CultureInfo.InvariantCulture);
                    Longitude = double.Parse(lat_lon[1], CultureInfo.InvariantCulture);
                }
                else
                {
                    throw new FormatException("The position string is invalid");
                }
            }
            else if (format == WGS84Format.DegreesMinutes || format == WGS84Format.DegreesMinutesSeconds)
            {
                int firstValueEndPos = 0;

                if(format== WGS84Format.DegreesMinutes)
                    firstValueEndPos = positionString.IndexOf("'");
                else if(format == WGS84Format.DegreesMinutesSeconds)
                    firstValueEndPos = positionString.IndexOf("\"");

                string lat = positionString.Substring(0, firstValueEndPos + 1).Trim();
                string lon = positionString.Substring(firstValueEndPos + 1).Trim();

                SetLatitudeFromString(lat, format);
                SetLongitudeFromString(lon, format);
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Returns a string representation in the given format
        /// </summary>
        /// <param name="format"></param>
        /// <returns></returns>
        public string LongitudeToString(WGS84Format format)
        {
            switch (format)
            {
            case WGS84Format.DegreesMinutes:
                return(this.ConvToDmString(this.Longitude, 'E', 'W'));

            case WGS84Format.DegreesMinutesSeconds:
                return(this.ConvToDmsString(this.Longitude, 'E', 'W'));

            default:
                return(this.Longitude.ToString(CultureInfo.InvariantCulture));
            }
        }
Ejemplo n.º 3
0
 /// <summary>
 /// Returns a string representation in the given format
 /// </summary>
 /// <param name="format"></param>
 /// <returns></returns>
 public string LongitudeToString(WGS84Format format)
 {
     if (format == WGS84Format.DegreesMinutes)
     {
         return(ConvToDmString(Longitude, 'E', 'W'));
     }
     else if (format == WGS84Format.DegreesMinutesSeconds)
     {
         return(ConvToDmsString(Longitude, 'E', 'W'));
     }
     else
     {
         return(Longitude.ToString());
     }
 }
Ejemplo n.º 4
0
 /// <summary>
 /// Set the longitude value from a string. The string is
 /// parsed based on given format
 /// </summary>
 /// <param name="value">String represenation of a longitude value</param>
 /// <param name="format">Coordinate format in the string</param>
 public void SetLongitudeFromString(string value, WGS84Format format)
 {
     if (format == WGS84Format.DegreesMinutes)
     {
         Longitude = ParseValueFromDmString(value, "W");
     }
     else if (format == WGS84Format.DegreesMinutesSeconds)
     {
         Longitude = ParseValueFromDmsString(value, "W");
     }
     else if (format == WGS84Format.Degrees)
     {
         Longitude = double.Parse(value);
     }
 }
Ejemplo n.º 5
0
        /// <summary>
        /// Set the longitude value from a string. The string is
        /// parsed based on given format
        /// </summary>
        /// <param name="value">String represenation of a longitude value</param>
        /// <param name="format">Coordinate format in the string</param>
        public void SetLongitudeFromString(string value, WGS84Format format)
        {
            switch (format)
            {
            case WGS84Format.DegreesMinutes:
                this.Longitude = this.ParseValueFromDmString(value, 'W');
                break;

            case WGS84Format.DegreesMinutesSeconds:
                this.Longitude = this.ParseValueFromDmsString(value, 'W');
                break;

            case WGS84Format.Degrees:
                this.Longitude = double.Parse(value, CultureInfo.InvariantCulture);
                break;
            }
        }
Ejemplo n.º 6
0
        /// <summary>
        /// Set the latitude value from a string. The string is
        /// parsed based on given format
        /// </summary>
        /// <param name="value">String represenation of a latitude value</param>
        /// <param name="format">Coordinate format in the string</param>
        public void SetLatitudeFromString(string value, WGS84Format format)
        {
            value = value.Trim();

            if (format == WGS84Format.DegreesMinutes)
            {
                Latitude = ParseValueFromDmString(value, "S");
            }
            else if (format == WGS84Format.DegreesMinutesSeconds)
            {
                Latitude = ParseValueFromDmsString(value, "S");
            }
            else if (format == WGS84Format.Degrees)
            {
                Latitude = double.Parse(value);
            }
        }
Ejemplo n.º 7
0
        /// <summary>
        /// Create a new WGS84 position from a string containing both
        /// latitude and longitude. The string is parsed based on the
        /// supplied format.
        /// </summary>
        /// <param name="positionString"></param>
        /// <param name="format"></param>
        public WGS84Position(string positionString, WGS84Format format)
            : base(Grid.WGS84)
        {
            if (format == WGS84Format.Degrees)
            {
                positionString = positionString.Trim();
                string[] latLon = positionString.Split(' ');
                if (latLon.Length == 2)
                {
                    this.Latitude  = double.Parse(latLon[0], CultureInfo.InvariantCulture);
                    this.Longitude = double.Parse(latLon[1], CultureInfo.InvariantCulture);
                }
                else
                {
                    throw new FormatException("The position string is invalid");
                }
            }
            else if (format == WGS84Format.DegreesMinutes || format == WGS84Format.DegreesMinutesSeconds)
            {
                int firstValueEndPos = 0;

                switch (format)
                {
                case WGS84Format.DegreesMinutes:
                    firstValueEndPos = positionString.IndexOf("'", StringComparison.Ordinal);
                    break;

                case WGS84Format.DegreesMinutesSeconds:
                    firstValueEndPos = positionString.IndexOf("\"", StringComparison.Ordinal);
                    break;
                }

                string lat = positionString.Substring(0, firstValueEndPos + 1).Trim();
                string lon = positionString.Substring(firstValueEndPos + 1).Trim();

                this.SetLatitudeFromString(lat, format);
                this.SetLongitudeFromString(lon, format);
            }
        }
Ejemplo n.º 8
0
 /// <summary>
 /// Set the longitude value from a string. The string is
 /// parsed based on given format
 /// </summary>
 /// <param name="value">String represenation of a longitude value</param>
 /// <param name="format">Coordinate format in the string</param>
 public void SetLongitudeFromString(string value, WGS84Format format)
 {
     if (format == WGS84Format.DegreesMinutes)
         Longitude = ParseValueFromDmString(value, "W");
     else if (format == WGS84Format.DegreesMinutesSeconds)
         Longitude = ParseValueFromDmsString(value, "W");
     else if (format == WGS84Format.Degrees)
     {
         Longitude = double.Parse(value);
     }
 }
Ejemplo n.º 9
0
        /// <summary>
        /// Set the latitude value from a string. The string is
        /// parsed based on given format
        /// </summary>
        /// <param name="value">String represenation of a latitude value</param>
        /// <param name="format">Coordinate format in the string</param>
        public void SetLatitudeFromString(string value, WGS84Format format)
        {
            value = value.Trim();

            if(format == WGS84Format.DegreesMinutes)
                Latitude = ParseValueFromDmString(value, "S");
            else if (format == WGS84Format.DegreesMinutesSeconds)
                Latitude = ParseValueFromDmsString(value, "S");
            else if(format == WGS84Format.Degrees)
            {
                Latitude = double.Parse(value);
            }
        }
Ejemplo n.º 10
0
 /// <summary>
 /// Returns a string representation in the given format
 /// </summary>
 /// <param name="format"></param>
 /// <returns></returns>
 public string LongitudeToString(WGS84Format format)
 {
     if (format == WGS84Format.DegreesMinutes)
         return ConvToDmString(Longitude, 'E', 'W');
     else if (format == WGS84Format.DegreesMinutesSeconds)
         return ConvToDmsString(Longitude, 'E', 'W');
     else
         return Longitude.ToString();
 }
 /// <summary>
 /// Set the longitude value from a string. The string is
 /// parsed based on given format
 /// </summary>
 /// <param name="value">String represenation of a longitude value</param>
 /// <param name="format">Coordinate format in the string</param>
 public void SetLongitudeFromString(string value, WGS84Format format)
 {
     switch (format)
     {
         case WGS84Format.DegreesMinutes:
             this.Longitude = this.ParseValueFromDmString(value, 'W');
             break;
         case WGS84Format.DegreesMinutesSeconds:
             this.Longitude = this.ParseValueFromDmsString(value, 'W');
             break;
         case WGS84Format.Degrees:
             this.Longitude = double.Parse(value, CultureInfo.InvariantCulture);
             break;
     }
 }
 /// <summary>
 /// Returns a string representation in the given format
 /// </summary>
 /// <param name="format"></param>
 /// <returns></returns>
 public string LongitudeToString(WGS84Format format)
 {
     switch (format)
     {
         case WGS84Format.DegreesMinutes:
             return this.ConvToDmString(this.Longitude, 'E', 'W');
         case WGS84Format.DegreesMinutesSeconds:
             return this.ConvToDmsString(this.Longitude, 'E', 'W');
         default:
             return this.Longitude.ToString(CultureInfo.InvariantCulture);
     }
 }