Ejemplo n.º 1
0
        /// <summary>
        /// Creates a new lambert projection.
        /// </summary>
        /// <param name="name"></param>
        /// <param name="ellipsoid"></param>
        /// <param name="standard_parallel_1"></param>
        /// <param name="standard_parallel_2"></param>
        /// <param name="latitude_origin_1"></param>
        /// <param name="longitude_origin_2"></param>
        /// <param name="x_origin"></param>
        /// <param name="y_origin"></param>
        protected LambertProjectionBase(string name,
            LambertEllipsoid ellipsoid,
            double standard_parallel_1,
            double standard_parallel_2,
            double latitude_origin_1,
            double longitude_origin_2,
            double x_origin,
            double y_origin)
        {
            _name = name;
            _ellipsoid = ellipsoid;

            _standard_parallel_1 = standard_parallel_1;
            Radian temp = new Degree(_standard_parallel_1);
            _standard_parallel_1_radians = temp.Value;

            _standard_parallel_2 = standard_parallel_2;
            temp = new Degree(_standard_parallel_2);
            _standard_parallel_2_radians = temp.Value;

            _latitude_origin = latitude_origin_1;
            temp = new Degree(_latitude_origin);
            _latitude_origin_radians = temp.Value;

            _longitude_origin = longitude_origin_2;
            temp = new Degree(_longitude_origin);
            _longitude_origin_radians = temp.Value;

            _x_origin = x_origin;
            _y_origin = y_origin;

            // calculate common calculation intermidiates.
            _m_1 = (System.Math.Cos(_standard_parallel_1_radians) /
                System.Math.Sqrt((1.0 - _ellipsoid.Eccentricity * _ellipsoid.Eccentricity *
                System.Math.Pow(System.Math.Sin(_standard_parallel_1_radians), 2.0))));

            _m_2 = (System.Math.Cos(_standard_parallel_2_radians) /
                System.Math.Sqrt((1 - _ellipsoid.Eccentricity * _ellipsoid.Eccentricity *
                System.Math.Pow(System.Math.Sin(_standard_parallel_2_radians), 2.0))));

            _t_0 = (System.Math.Tan(System.Math.PI / 4.0 - _latitude_origin_radians / 2.0) /
                System.Math.Pow(((1 - _ellipsoid.Eccentricity * System.Math.Sin(_latitude_origin_radians)) /
                (1 + _ellipsoid.Eccentricity * System.Math.Sin(_latitude_origin_radians))), _ellipsoid.Eccentricity / 2.0));

            _t_1 = (System.Math.Tan(System.Math.PI / 4.0 - _standard_parallel_1_radians / 2.0) /
                System.Math.Pow(((1 - _ellipsoid.Eccentricity * System.Math.Sin(_standard_parallel_1_radians)) /
                (1 + _ellipsoid.Eccentricity * System.Math.Sin(_standard_parallel_1_radians))), _ellipsoid.Eccentricity / 2.0));

            _t_2 = (System.Math.Tan(System.Math.PI / 4.0 - _standard_parallel_2_radians / 2.0) /
                System.Math.Pow(((1 - _ellipsoid.Eccentricity * System.Math.Sin(_standard_parallel_2_radians)) /
                (1 + _ellipsoid.Eccentricity * System.Math.Sin(_standard_parallel_2_radians))), _ellipsoid.Eccentricity / 2.0));

            _n = ((System.Math.Log(_m_1) - System.Math.Log(_m_2))
                / (System.Math.Log(_t_1) - System.Math.Log(_t_2)));

            _g = _m_1 / (_n * System.Math.Pow(_t_1, _n));

            _r_0 = _ellipsoid.SemiMajorAxis * _g * System.Math.Pow(System.Math.Abs(_t_0), _n);
        }
Ejemplo n.º 2
0
        public TileRange GetTileToLoadFor(GeoCoordinateBox bbox,
            int zoom)
        {
            int n = (int)System.Math.Floor(System.Math.Pow(2, zoom));

            Radian rad = new Degree(bbox.MaxLat);

            int x_tile_min = (int)(((bbox.MinLon + 180.0f) / 360.0f) * (double)n);
            int y_tile_min = (int)(
                (1.0f - (System.Math.Log(System.Math.Tan(rad.Value) + (1.0f / System.Math.Cos(rad.Value))))
                / System.Math.PI) / 2f * (double)n);

            rad = new Degree(bbox.MinLat);
            int x_tile_max = (int)(((bbox.MaxLon + 180.0f) / 360.0f) * (double)n);
            int y_tile_max = (int)(
                (1.0f - (System.Math.Log(System.Math.Tan(rad.Value) + (1.0f / System.Math.Cos(rad.Value))))
                / System.Math.PI) / 2f * (double)n);

            TileRange range = new TileRange();
            range.XMax = x_tile_max;
            range.XMin = x_tile_min;
            range.YMax = y_tile_max;
            range.YMin = y_tile_min;
            return range;
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Returns the tile at the given location at the given zoom.
        /// </summary>
        /// <param name="location"></param>
        /// <param name="zoom"></param>
        /// <returns></returns>
        public static Tile CreateAroundLocation(GeoCoordinate location, int zoom)
        {
            int n = (int)System.Math.Floor(System.Math.Pow(2, zoom));

            Radian rad = new Degree(location.Latitude);

            int x = (int)(((location.Longitude + 180.0f) / 360.0f) * (double)n);
            int y = (int)(
                (1.0f - (System.Math.Log(System.Math.Tan(rad.Value) + (1.0f / System.Math.Cos(rad.Value))))
                / System.Math.PI) / 2f * (double)n);

            return new Tile(x, y, zoom);
        }