Beispiel #1
0
        /// <summary>
        /// Reset the location from a string. See <see cref="GeoCoords(string, bool, bool)"/>.
        /// </summary>
        /// <param name="s">1-element, 2-element, or 3-element string representation of the position.</param>
        /// <param name="centerp">governs the interpretation of <see cref="MGRS"/> coordinates.</param>
        /// <param name="longfirst">governs the interpretation of geographic coordinates.</param>
        public void Reset(string s, bool centerp = true, bool longfirst = false)
        {
            var sa = s.Split(" \t\n\v\f\r,".ToCharArray(), StringSplitOptions.RemoveEmptyEntries);

            if (sa.Length == 1)
            {
                int prec;
                (_zone, _northp, _easting, _northing, prec) = MGRS.Reverse(sa[0].AsSpan(), centerp);
                (_lat, _long) = UTMUPS.Reverse(_zone, _northp, _easting, _northing, out _gamma, out _k);
            }
            else if (sa.Length == 2)
            {
                (_lat, _long) = DMS.Decode(sa[0], sa[1], longfirst);
                _long         = AngNormalize(_long);
                (_zone, _northp, _easting, _northing) = UTMUPS.Forward(_lat, _long, out _gamma, out _k);
            }
            else if (sa.Length == 3)
            {
                int zoneind, coordind;
                if (sa[0].Length > 0 && char.IsLetter(sa[0][sa[0].Length - 1]))
                {
                    zoneind  = 0;
                    coordind = 1;
                }
                else if (sa[2].Length > 0 && char.IsLetter(sa[2][sa[2].Length - 1]))
                {
                    zoneind  = 2;
                    coordind = 0;
                }
                else
                {
                    throw new GeographicException("Neither " + sa[0] + " nor " + sa[2]
                                                  + " of the form UTM/UPS Zone + Hemisphere"
                                                  + " (ex: 38n, 09s, n)");
                }

                (_zone, _northp) = UTMUPS.DecodeZone(sa[zoneind].AsSpan());
                for (int i = 0; i < 2; ++i)
                {
                    if (i != 0)
                    {
                        _northing = sa[coordind + i].ParseDouble();
                    }
                    else
                    {
                        _easting = sa[coordind + i].ParseDouble();
                    }
                }

                (_lat, _long) = UTMUPS.Reverse(_zone, _northp, _easting, _northing, out _gamma, out _k);
                FixHemisphere();
            }
            else
            {
                throw new GeographicException("Coordinate requires 1, 2, or 3 elements");
            }
            CopyToAlt();
        }