Beispiel #1
0
        /// <summary>
        /// The UTM Grid for a given latitude/longitude
        /// </summary>
        /// <param name="projection">The projection to use</param>
        /// <param name="coord">Latitude/Longitude of the location</param>
        /// <exception cref="ArgumentOutOfRangeException"></exception>
        public UtmGrid(UtmProjection projection, GlobalCoordinates coord) : this(projection)
        {
            if (coord.Latitude < projection.MinLatitude || coord.Latitude > projection.MaxLatitude)
            {
                throw new ArgumentOutOfRangeException(Properties.Resources.INVALID_LATITUDE);
            }

            var longitude = MercatorProjection.NormalizeLongitude(coord.Longitude).Degrees + 180.0;
            var latitude  = projection.NormalizeLatitude(coord.Latitude);
            var band      = (int)((latitude - projection.MinLatitude).Degrees / Ystep.Degrees);
            if (band == NumberOfBands)
            {
                var northernLimit = projection.MinLatitude + NumberOfBands * Ystep;
                if (latitude >= northernLimit && latitude <= projection.MaxLatitude)
                {
                    band--;
                }
            }
            var zone = (int)(longitude / Xstep.Degrees) + 1;
            SetZoneAndBandInConstructor(zone, band, true);

            if (_zone == 31 && Band == 'V')
            {
                var delta = coord.Longitude.Degrees - _llCoordinates.Longitude.Degrees - Width.Degrees;
                if (Math.Sign(delta) != -1)
                {
                    Zone = _zone + 1;
                }
            }
            else if (Band == 'X')
            {
                if (_zone == 32 || _zone == 34 || _zone == 36)
                {
                    var delta = coord.Longitude.Degrees - CenterMeridian.Degrees;
                    if (Math.Sign(delta) == -1)
                    {
                        Zone = _zone - 1;
                    }
                    else
                    {
                        Zone = _zone + 1;
                    }
                }
            }
        }