/// <summary>
        /// Creates an instance of an TransverseMercatorProjection projection object.
        /// </summary>
        /// <param name="parameters">List of parameters to initialize the projection.</param>
        /// <param name="inverse">Flag indicating wether is a forward/projection (false) or an inverse projection (true).</param>
        /// <remarks>
        /// <list type="bullet">
        /// <listheader><term>Items</term><description>Descriptions</description></listheader>
        /// <item><term>semi_major</term><description>Your Description</description></item>
        /// <item><term>semi_minor</term><description>Your Description</description></item>
        /// <item><term>scale_factor_at_natural_origin</term><description>Your Description</description></item>
        /// <item><term>longitude_of_natural_origin</term><description>Your Description</description></item>
        /// <item><term>latitude_of_natural_origin</term><description>Your Description</description></item>
        /// <item><term>false_easting</term><description>Your Description</description></item>
        /// <item><term>false_northing</term><description>Your Description</description></item>
        /// </list>
        /// </remarks>
        public TransverseMercatorProjection(ParameterList parameters, bool inverse) : base(parameters, inverse)
        {
            double r_maj       = parameters.GetDouble("semi_major");                                     /* major axis			*/
            double r_min       = parameters.GetDouble("semi_minor");                                     /* minor axis			*/
            double scale_fact  = parameters.GetDouble("scale_factor_at_natural_origin");                 /* scale factor			*/
            double center_lon  = Degrees.ToRadians(parameters.GetDouble("longitude_of_natural_origin")); /* center longitude		*/
            double center_lat  = Degrees.ToRadians(parameters.GetDouble("latitude_of_natural_origin"));  /* center latitude		*/
            double false_east  = parameters.GetDouble("false_easting");                                  /* x offset in meters		*/
            double false_north = parameters.GetDouble("false_northing");                                 /* y offset in meters		*/

            double temp;                                                                                 /* temporary variable		*/

            /* Place parameters in static storage for common use
             * -------------------------------------------------*/

            r_major        = r_maj;
            r_minor        = r_min;
            scale_factor   = scale_fact;
            lon_center     = center_lon;
            lat_origin     = center_lat;
            false_northing = false_north;
            false_easting  = false_east;

            temp = r_minor / r_major;
            es   = 1.0 - SQUARE(temp);
            e    = Math.Sqrt(es);
            e0   = e0fn(es);
            e1   = e1fn(es);
            e2   = e2fn(es);
            e3   = e3fn(es);
            ml0  = r_major * mlfn(e0, e1, e2, e3, lat_origin);
            esp  = es / (1.0 - es);
        }
        public override void DegreesToMeters(double lon, double lat, out double x, out double y)
        {
            lon = Degrees.ToRadians(lon);
            lat = Degrees.ToRadians(lat);

            double delta_lon = 0.0;             /* Delta longitude (Given longitude - center    */
            double sin_phi, cos_phi;            /* sin and cos value				*/
            double al, als;                     /* temporary values				*/
            double c, t, tq;                    /* temporary values				*/
            double con, n, ml;                  /* cone constant, small m			*/



            delta_lon = adjust_lon(lon - lon_center);
            sincos(lat, out sin_phi, out cos_phi);


            al  = cos_phi * delta_lon;
            als = SQUARE(al);
            c   = esp * SQUARE(cos_phi);
            tq  = Math.Tan(lat);
            t   = SQUARE(tq);
            con = 1.0 - es * SQUARE(sin_phi);
            n   = r_major / Math.Sqrt(con);
            ml  = r_major * mlfn(e0, e1, e2, e3, lat);

            x = scale_factor * n * al * (1.0 + als / 6.0 * (1.0 - t + c + als / 20.0 *
                                                            (5.0 - 18.0 * t + SQUARE(t) + 72.0 * c - 58.0 * esp))) + false_easting;

            y = scale_factor * (ml - ml0 + n * tq * (als * (0.5 + als / 24.0 *
                                                            (5.0 - t + 9.0 * c + 4.0 * SQUARE(c) + als / 30.0 * (61.0 - 58.0 * t
                                                                                                                 + SQUARE(t) + 600.0 * c - 330.0 * esp))))) + false_northing;

            return;            //(OK);
        }
예제 #3
0
 /// <summary>
 /// Converts a latitude value in degrees to radians.
 /// </summary>
 /// <param name="y">The value in degrees to to radians.</param>
 /// <param name="edge">If true, -90 and +90 are valid, otherwise they are considered out of range.</param>
 /// <returns></returns>
 static protected double LatitudeToRadians(double y, bool edge)
 {
     if (edge ? (y >= Latitude.MinimumValue && y <= Latitude.MaximumValue) : (y > Latitude.MinimumValue && y < Latitude.MaximumValue))
     {
         return(Degrees.ToRadians(y));
     }
     throw new ArgumentOutOfRangeException("x", y, " not a valid latitude in degrees.");
 }
예제 #4
0
 /// <summary>
 /// Converts a longitude value in degrees to radians.
 /// </summary>
 /// <param name="x">The value in degrees to convert to radians.</param>
 /// <param name="edge">If true, -180 and +180 are valid, otherwise they are considered out of range.</param>
 /// <returns></returns>
 static protected double LongitudeToRadians(double x, bool edge)
 {
     if (edge ? (x >= Longitude.MinimumValue && x <= Longitude.MaximumValue) : (x > Longitude.MinimumValue && x < Longitude.MaximumValue))
     {
         return(Degrees.ToRadians(x));
     }
     throw new ArgumentOutOfRangeException("x", x, " not a valid longitude in degrees.");
 }
예제 #5
0
        public static Coordinate GetEndCoordinate(Coordinate startCoordinate, double distance, double bearing)
        {
            double lat1 = Degrees.ToRadians(startCoordinate.Y);
            double lon1 = Degrees.ToRadians(startCoordinate.X);
            double brng = Degrees.ToRadians(bearing);
            // Simplification
            double lat2 = Math.Asin(Math.Sin(lat1) * Math.Cos(distance / EarthRadiusAvg) + Math.Cos(lat1) * Math.Sin(distance / EarthRadiusAvg) * Math.Cos(brng));
            double lon2 = lon1 + Math.Atan2(Math.Sin(brng) * Math.Sin(distance / EarthRadiusAvg) * Math.Cos(lat1), Math.Cos(distance / EarthRadiusAvg) - Math.Sin(lat1) * Math.Sin(lat2));

            return(new Coordinate(Radians.ToDegrees(lon2), Radians.ToDegrees(lat2)));
        }
예제 #6
0
        private IGeometry ClipLinealGeomToViewExtents(MapViewport map, IGeometry geom)
        {
            if (map.MapTransform.IsIdentity)
            {
                var lineClipping = new CohenSutherlandLineClipping(map.Envelope.MinX, map.Envelope.MinY,
                                                                   map.Envelope.MaxX, map.Envelope.MaxY);

                if (geom is ILineString)
                {
                    return(lineClipping.ClipLineString(geom as ILineString));
                }

                if (geom is IMultiLineString)
                {
                    return(lineClipping.ClipLineString(geom as IMultiLineString));
                }
            }
            else
            {
                var clipPolygon = new Polygon(new LinearRing(new[]
                {
                    new Coordinate(map.Center.X - map.Zoom * .5, map.Center.Y - map.MapHeight * .5),
                    new Coordinate(map.Center.X - map.Zoom * .5, map.Center.Y + map.MapHeight * .5),
                    new Coordinate(map.Center.X + map.Zoom * .5, map.Center.Y + map.MapHeight * .5),
                    new Coordinate(map.Center.X + map.Zoom * .5, map.Center.Y - map.MapHeight * .5),
                    new Coordinate(map.Center.X - map.Zoom * .5, map.Center.Y - map.MapHeight * .5)
                }
                                                             ));

                var at = AffineTransformation.RotationInstance(
                    Degrees.ToRadians(map.MapTransformRotation), map.Center.X, map.Center.Y);

                clipPolygon = (Polygon)at.Transform(clipPolygon);

                if (geom is ILineString)
                {
                    return(clipPolygon.Intersection(geom as ILineString));
                }

                if (geom is IMultiLineString)
                {
                    return(clipPolygon.Intersection(geom as IMultiLineString));
                }
            }

            return(null);
        }
예제 #7
0
        /// <summary>
        /// Initializes a new instance of the MapAround.CoordinateSystems.Transformations.Gnomonic.
        /// </summary>
        /// <param name="centerLongitude">Longitude of projection center in degrees</param>
        /// <param name="centerLatitude">Latitude of projection center in degrees</param>
        public Gnomonic(double centerLongitude, double centerLatitude)
            : this(false)
        {
            _center =
                UnitSphere.LatLonToGeocentric(
                    Degrees.ToRadians(centerLatitude),
                    Degrees.ToRadians(centerLongitude));

            double[] center = { _center.X, _center.Y, _center.Z };
            double[] vector = new double[3];

            int k = getMinEntryIndex(center);
            int j = (k + 2) % 3;
            int i = (j + 2) % 3;

            vector[i] = -center[j];
            vector[j] = center[i];
            vector[k] = 0;

            _xAxis = (new Vector3(vector[0], vector[1], vector[2])).Unitize();
            _yAxis = _center.CrossProduct(_xAxis);
        }
예제 #8
0
        private double[] apply(double[] p)
        {
            double[] result = new double[p.Length];

            int delta = 2;

            if (p.Length % 3 == 0)
            {
                delta = 3;
            }

            for (int i = 0; i < p.Length / 2; i += delta)
            {
                if (delta == 3)
                {
                    result[i + 2] = p[i + 2];
                }

                Vector3 vector =
                    UnitSphere.LatLonToGeocentric(
                        Degrees.ToRadians(p[i + 1]),
                        Degrees.ToRadians(p[i]));

                double r = vector * _center;

                if (r < 1e-8)
                {
                    throw new ApplicationException();
                }

                vector = vector / r;

                result[i]     = vector * _xAxis;
                result[i + 1] = vector * _yAxis;
            }

            return(result);
        }
예제 #9
0
 public static double DegreesToRadians(double degrees)
 {
     return(Degrees.ToRadians(degrees));
 }