Example #1
0
        /// <summary>
        /// Instantiate a grid by its ordinal number.
        /// </summary>
        /// <param name="projection">The UTM projection this Grid belongs to</param>
        /// <param name="ordinal">The unique ordinal number of the grid</param>
        /// <exception cref="ArgumentOutOfRangeException"></exception>
        public UtmGrid(UtmProjection projection, int ordinal) : this(projection)
        {
            if (ordinal < 0 || ordinal >= NumberOfGrids)
            {
                throw new ArgumentOutOfRangeException(Properties.Resources.INVALID_ORDINAL);
            }

            SetZoneAndBandInConstructor(1 + ordinal / NumberOfBands, ordinal % NumberOfBands);
        }
Example #2
0
        /// <summary>
        /// Initializes a new instance of the <see cref="UtmGrid"/> struct.
        /// </summary>
        /// <param name="projection">The projection.</param>
        /// <exception cref="ArgumentNullException"></exception>
        private UtmGrid(UtmProjection projection)
        {
            // Assign default values
            Projection = projection ?? throw new ArgumentNullException(Properties.Resources.PROJECTION_NULL);
            _origin    = null;
            _mapHeight = 0.0;
            _mapWidth  = 0.0;

            Width  = Xstep;
            Height = Ystep;

            _zone          = 0;
            _band          = 0;
            _llCoordinates = new GlobalCoordinates();
        }
Example #3
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;
                    }
                }
            }
        }
Example #4
0
 /// <summary>
 /// Instantiate a new UTM Grid object
 /// </summary>
 /// <param name="projection">The UTM projection this grid belongs to</param>
 /// <param name="zone">The zone of the grid</param>
 /// <param name="band">The band of the grid</param>
 /// <exception cref="ArgumentOutOfRangeException">Thrown if zone or band are requested</exception>
 /// <exception cref="ArgumentNullException">Thrown if the projection is null</exception>
 public UtmGrid(UtmProjection projection, int zone, char band)
     : this(projection, zone, BandChars.IndexOf(band))
 {
 }
Example #5
0
 /// <summary>
 /// Instantiate a new UTM Grid object
 /// </summary>
 /// <param name="projection">The UTM projection this grid belongs to</param>
 /// <param name="zone">The zone of the grid</param>
 /// <param name="band">The band of the grid</param>
 /// <exception cref="ArgumentOutOfRangeException">Throw if zone or band are invalid</exception>
 /// <exception cref="ArgumentNullException">Thrown if the projection is null</exception>
 public UtmGrid(UtmProjection projection, int zone, int band) : this(projection)
 {
     SetZoneAndBandInConstructor(zone, band);
 }