Exemplo n.º 1
0
        /// <summary>
        /// The function convertToGeodetic converts UPS (hemisphere, easting,
        /// and northing) coordinates to geodetic (latitude and longitude) coordinates
        /// according to the current ellipsoid parameters.  If any errors occur, an
        /// exception is thrown with a description of the error.
        /// </summary>
        /// <param name="upsCoordinates"></param>
        /// <returns></returns>
        public GeodeticCoordinates convertToGeodetic(UPSCoordinates upsCoordinates)
        {
            /*
             *    hemisphere    : Hemisphere either 'N' or 'S'              (input)
             *    easting       : Easting/X in meters                       (input)
             *    northing      : Northing/Y in meters                      (input)
             *    latitude      : Latitude in radians                       (output)
             *    longitude     : Longitude in radians                      (output)
             */

            string errorStatus = "";

            char   hemisphere = upsCoordinates.getHemisphere();
            double easting    = upsCoordinates.getEasting();
            double northing   = upsCoordinates.getNorthing();

            if ((hemisphere != 'N') && (hemisphere != 'S'))
            {
                errorStatus += ErrorMessages.hemisphere;
            }
            if ((easting < MIN_EAST_NORTH) || (easting > MAX_EAST_NORTH))
            {
                errorStatus += ErrorMessages.easting;
            }
            if ((northing < MIN_EAST_NORTH) || (northing > MAX_EAST_NORTH))
            {
                errorStatus += ErrorMessages.northing;
            }

            //this.UPS_Origin_Latitude = MAX_ORIGIN_LAT;
            //if (hemisphere == 'N')
            //{
            //    UPS_Origin_Latitude = MAX_ORIGIN_LAT;
            //}
            //else if (hemisphere == 'S')
            //{
            //    UPS_Origin_Latitude = -MAX_ORIGIN_LAT;
            //}

            if (errorStatus.Length > 0)
            {
                throw new ArgumentException(errorStatus);
            }

            PolarStereographic  polarStereographic  = new PolarStereographic(this.semiMajorAxis, this.flattening, this.UPS_Origin_Longitude, 0.994, hemisphere, this.UPS_False_Easting, this.UPS_False_Northing);
            GeodeticCoordinates geodeticCoordinates = polarStereographic.convertToGeodetic(new MapProjectionCoordinates(CoordinateType.Enum.polarStereographicStandardParallel, easting, northing));

            double latitude = geodeticCoordinates.latitude;

            if ((latitude < 0) && (latitude >= (MAX_SOUTH_LAT + EPSILON)))
            {
                throw new ArgumentException(ErrorMessages.latitude);
            }
            if ((latitude >= 0) && (latitude < (MIN_NORTH_LAT - EPSILON)))
            {
                throw new ArgumentException(ErrorMessages.latitude);
            }

            return(geodeticCoordinates);
        }
Exemplo n.º 2
0
        /// <summary>
        /// The function convertToGeodetic converts UTM projection (zone,
        /// hemisphere, easting and northing) coordinates to geodetic (latitude
        /// and longitude) coordinates, according to the current ellipsoid
        /// parameters. If any errors occur, an exception is thrown with a description
        /// of the error.
        /// </summary>
        /// <param name="utmCoordinates"></param>
        /// <returns></returns>
        public GeodeticCoordinates convertToGeodetic(UTMCoordinates utmCoordinates)
        {
            /*
             *    zone              : UTM zone                               (input)
             *    hemisphere        : North or South hemisphere              (input)
             *    easting           : Easting (X) in meters                  (input)
             *    northing          : Northing (Y) in meters                 (input)
             *    longitude         : Longitude in radians                   (output)
             *    latitude          : Latitude in radians                    (output)
             */

            double False_Northing = 0;
            string errorStatus    = "";

            int    zone       = (int)utmCoordinates.zone;
            char   hemisphere = utmCoordinates.hemisphere;
            double easting    = utmCoordinates.easting;
            double northing   = utmCoordinates.northing;

            if ((zone < 1) || (zone > 60))
            {
                errorStatus += ErrorMessages.zone;
            }
            if ((hemisphere != 'S') && (hemisphere != 'N'))
            {
                errorStatus += ErrorMessages.hemisphere;
            }
            if ((easting < MIN_EASTING) || (easting > MAX_EASTING))
            {
                errorStatus += ErrorMessages.easting;
            }
            if ((northing < MIN_NORTHING) || (northing > MAX_NORTHING))
            {
                errorStatus += ErrorMessages.northing;
            }

            if (errorStatus.Length > 0)
            {
                throw new ArgumentException(errorStatus);
            }

            TransverseMercator transverseMercator = getTransverseMercator(zone);

            if (hemisphere == 'S')
            {
                False_Northing = 10000000;
            }

            GeodeticCoordinates geodeticCoordinates = transverseMercator.convertToGeodetic(new MapProjectionCoordinates(CoordinateType.Enum.transverseMercator, easting, northing - False_Northing));
            //geodeticCoordinates.setWarningMessage("");

            double latitude = geodeticCoordinates.latitude;

            if ((latitude < (MIN_LAT - EPSILON)) || (latitude >= (MAX_LAT + EPSILON)))
            {   /* latitude out of range */
                throw new ArgumentException(ErrorMessages.northing);
            }

            return(geodeticCoordinates);
        }
Exemplo n.º 3
0
        /// <summary>
        /// The function convertFromGeodetic converts geodetic (latitude and
        /// longitude) coordinates to UPS (hemisphere, easting, and northing)
        /// coordinates, according to the current ellipsoid parameters.
        /// If any errors occur, an exception is thrown with a description
        /// of the error.
        /// </summary>
        /// <param name="geodeticCoordinates"></param>
        /// <returns></returns>
        public UPSCoordinates convertFromGeodetic(GeodeticCoordinates geodeticCoordinates)
        {
            /*
             *    latitude      : Latitude in radians                       (input)
             *    longitude     : Longitude in radians                      (input)
             *    hemisphere    : Hemisphere either 'N' or 'S'              (output)
             *    easting       : Easting/X in meters                       (output)
             *    northing      : Northing/Y in meters                      (output)
             */

            char   hemisphere;
            string errorStatus = "";

            double longitude = geodeticCoordinates.longitude;
            double latitude  = geodeticCoordinates.latitude;

            if ((latitude < -MAX_LAT) || (latitude > MAX_LAT))
            {   /* latitude out of range */
                errorStatus += ErrorMessages.latitude;
            }
            else if ((latitude < 0) && (latitude >= (MAX_SOUTH_LAT + EPSILON)))
            {
                errorStatus += ErrorMessages.latitude;
            }
            else if ((latitude >= 0) && (latitude < (MIN_NORTH_LAT - EPSILON)))
            {
                errorStatus += ErrorMessages.latitude;
            }
            if ((longitude < -Math.PI) || (longitude > (2 * Math.PI)))
            {  /* longitude out of range */
                errorStatus += ErrorMessages.longitude;
            }

            if (errorStatus.Length > 0)
            {
                throw new ArgumentException(errorStatus);
            }

            if (latitude < 0)
            {
                //this.UPS_Origin_Latitude = -MAX_ORIGIN_LAT;
                hemisphere = 'S';
            }
            else
            {
                //this.UPS_Origin_Latitude = MAX_ORIGIN_LAT;
                hemisphere = 'N';
            }

            PolarStereographic       polarStereographic            = new PolarStereographic(this.semiMajorAxis, this.flattening, this.UPS_Origin_Longitude, 0.994, hemisphere, this.UPS_False_Easting, this.UPS_False_Northing);
            MapProjectionCoordinates polarStereographicCoordinates = polarStereographic.convertFromGeodetic(geodeticCoordinates);

            double easting  = polarStereographicCoordinates.getEasting();
            double northing = polarStereographicCoordinates.getNorthing();

            return(new UPSCoordinates(CoordinateType.Enum.universalPolarStereographic, hemisphere, easting, northing));
        }
        /// <summary>
        /// The function convertFromGeodetic converts geodetic
        /// (latitude and longitude) coordinates to Transverse Mercator projection
        /// (easting and northing) coordinates, according to the current ellipsoid
        /// and Transverse Mercator projection coordinates.  If any errors occur, 
        /// an exception is thrown with a description of the error.
        /// </summary>
        /// <param name="geodeticCoordinates"></param>
        /// <returns></returns>
        public MapProjectionCoordinates convertFromGeodetic(GeodeticCoordinates geodeticCoordinates)
        {
            /*
             *    longitude     : Longitude in radians                        (input)
             *    latitude      : Latitude in radians                         (input)
             *    easting       : Easting/X in meters                         (output)
             *    northing      : Northing/Y in meters                        (output)
             */

            double c1;       /* Cosine of latitude                          */
            double c2;
            double c3;
            double c5;
            double c7;
            double dlam;    /* Delta longitude - Difference in Longitude       */
            double eta1;     /* constant - TranMerc_ebs *c *c                   */
            double eta2;
            double eta3;
            double eta4;
            double s;       /* Sine of latitude                        */
            double sn;      /* Radius of curvature in the prime vertical       */
            double tan1;       /* Tangent of latitude                             */
            double tan2;
            double tan3;
            double tan4;
            double tan5;
            double tan6;
            double t1;      /* Term in coordinate conversion formula - GP to Y */
            double t2;      /* Term in coordinate conversion formula - GP to Y */
            double t3;      /* Term in coordinate conversion formula - GP to Y */
            double t4;      /* Term in coordinate conversion formula - GP to Y */
            double t5;      /* Term in coordinate conversion formula - GP to Y */
            double t6;      /* Term in coordinate conversion formula - GP to Y */
            double t7;      /* Term in coordinate conversion formula - GP to Y */
            double t8;      /* Term in coordinate conversion formula - GP to Y */
            double t9;      /* Term in coordinate conversion formula - GP to Y */
            double temp_Origin;
            double temp_Long;
            string errorStatus = "";

            double longitude = geodeticCoordinates.longitude;
            double latitude = geodeticCoordinates.latitude;

            if ((latitude < -MAX_LAT) || (latitude > MAX_LAT))
            {  /* Latitude out of range */
                errorStatus += ErrorMessages.latitude;
            }
            if (longitude > Math.PI)
            {
                longitude -= (2 * Math.PI);
            }
            if ((longitude < (this.TranMerc_Origin_Long - MAX_DELTA_LONG)) || (longitude > (this.TranMerc_Origin_Long + MAX_DELTA_LONG)))
            {
                if (longitude < 0)
                {
                    temp_Long = longitude + 2 * Math.PI;
                }
                else
                {
                    temp_Long = longitude;
                }
                if (this.TranMerc_Origin_Long < 0)
                {
                    temp_Origin = this.TranMerc_Origin_Long + 2 * Math.PI;
                }
                else
                {
                    temp_Origin = this.TranMerc_Origin_Long;
                }
                //if ((temp_Long < (temp_Origin - MAX_DELTA_LONG)) || (temp_Long > (temp_Origin + MAX_DELTA_LONG)))
                //{
                //    errorStatus += ErrorMessages.longitude;
                //}
            }

            if (errorStatus.Length > 0)
            {

                //throw new ArgumentException(errorStatus);
            }

            /*
             *  Delta Longitude
             */
            dlam = longitude - this.TranMerc_Origin_Long;

            if (Math.Abs(dlam) > Math.PI / 20.0)
            { /* Distortion will result if Longitude is more than 9 degrees from the Central Meridian */
                errorStatus += WarningMessages.longitude;
            }

            if (dlam > Math.PI)
            {
                dlam -= (2 * Math.PI);
            }
            if (dlam < -Math.PI)
            {
                dlam += (2 * Math.PI);
            }
            if (Math.Abs(dlam) < 2.0e-10)
            {
                dlam = 0.0;
            }

            s = Math.Sin(latitude);
            c1 = Math.Cos(latitude);
            c2 = c1 * c1;
            c3 = c2 * c1;
            c5 = c3 * c2;
            c7 = c5 * c2;
            tan1 = Math.Tan(latitude);
            tan2 = tan1 * tan1;
            tan3 = tan2 * tan1;
            tan4 = tan3 * tan1;
            tan5 = tan4 * tan1;
            tan6 = tan5 * tan1;
            eta1 = TranMerc_ebs * c2;
            eta2 = eta1 * eta1;
            eta3 = eta2 * eta1;
            eta4 = eta3 * eta1;

            // radius of curvature in prime vertical
            sn = sphsn(latitude);

            // northing
            t1 = (sphtmd(latitude) - sphtmd(this.TranMerc_Origin_Lat)) * this.TranMerc_Scale_Factor; // True Meridinial Distances, Origin
            t2 = sn * s * c1 * this.TranMerc_Scale_Factor / 2.0;
            t3 = sn * s * c3 * this.TranMerc_Scale_Factor * (5.0 - tan2 + 9.0 * eta1 + 4.0 * eta2) / 24.0;
            t4 = sn * s * c5 * this.TranMerc_Scale_Factor * (61.0 - 58.0 * tan2 + tan4 + 270.0 * eta1 - 330.0 * tan2 * eta1 + 445.0 * eta2 + 324.0 * eta3 - 680.0 * tan2 * eta2 + 88.0 * eta4 - 600.0 * tan2 * eta3 - 192.0 * tan2 * eta4) / 720.0;
            t5 = sn * s * c7 * this.TranMerc_Scale_Factor * (1385.0 - 3111.0 * tan2 + 543.0 * tan4 - tan6) / 40320.0;
            double northing = this.TranMerc_False_Northing + t1 + Math.Pow(dlam, 2.0) * t2 + Math.Pow(dlam, 4.0) * t3 + Math.Pow(dlam, 6.0) * t4 + Math.Pow(dlam, 8.0) * t5;

            // Easting
            t6 = sn * c1 * this.TranMerc_Scale_Factor;
            t7 = sn * c3 * this.TranMerc_Scale_Factor * (1.0 - tan2 + eta1) / 6.0;
            t8 = sn * c5 * this.TranMerc_Scale_Factor * (5.0 - 18.0 * tan2 + tan4 + 14.0 * eta1 - 58.0 * tan2 * eta1 + 13.0 * eta2 + 4.0 * eta3 - 64.0 * tan2 * eta2 - 24.0 * tan2 * eta3) / 120.0;
            t9 = sn * c7 * this.TranMerc_Scale_Factor * (61.0 - 479.0 * tan2 + 179.0 * tan4 - tan6) / 5040.0;
            double easting = this.TranMerc_False_Easting + dlam * t6 + Math.Pow(dlam, 3.0) * t7 + Math.Pow(dlam, 5.0) * t8 + Math.Pow(dlam, 7.0) * t9;

            return new MapProjectionCoordinates(CoordinateType.Enum.transverseMercator, errorStatus, easting, northing);
        }
Exemplo n.º 5
0
        /// <summary>
        /// The function convertFromGeodetic converts geodetic (latitude and
        /// longitude) coordinates to UTM projection (zone, hemisphere, easting and
        /// northing) coordinates according to the current ellipsoid and UTM zone
        /// zoneOverride parameters.  If any errors occur, an exception is thrown with a description 
        /// of the error.
        /// </summary>
        /// <param name="geodeticCoordinates"></param>
        /// <returns></returns>
        public UTMCoordinates convertFromGeodetic(GeodeticCoordinates geodeticCoordinates)
        {
            /*
             *
             *    longitude         : Longitude in radians                (input)
             *    latitude          : Latitude in radians                 (input)
             *    zone              : UTM zone                            (output)
             *    hemisphere        : North or South hemisphere           (output)
             *    easting           : Easting (X) in meters               (output)
             *    northing          : Northing (Y) in meters              (output)
             */

            long Lat_Degrees;
            long Long_Degrees;
            int temp_zone;
            char hemisphere;
            double False_Northing = 0;
            string errorStatus = "";

            double longitude = geodeticCoordinates.longitude;
            double latitude = geodeticCoordinates.latitude;

            if ((latitude < (MIN_LAT - EPSILON)) || (latitude >= (MAX_LAT + EPSILON)))
            { /* latitude out of range */
                errorStatus += ErrorMessages.latitude;
            }
            if ((longitude < -Math.PI) || (longitude > (2 * Math.PI)))
            { /* longitude out of range */
                errorStatus += ErrorMessages.longitude;
            }

            if (errorStatus.Length > 0)
            {
                throw new ArgumentException(errorStatus);
            }

            if ((latitude > -1.0e-9) && (latitude < 0))
            {
                latitude = 0.0;
            }

            if (longitude < 0)
            {
                longitude += (2 * Math.PI) + 1.0e-10;
            }

            Lat_Degrees = (long)(latitude * 180.0 / Math.PI);
            Long_Degrees = (long)(longitude * 180.0 / Math.PI);

            if (longitude < Math.PI)
            {
                temp_zone = (int)(31 + ((longitude * 180.0 / Math.PI) / 6.0));
            }
            else
            {
                temp_zone = (int)(((longitude * 180.0 / Math.PI) / 6.0) - 29);
            }

            if (temp_zone > 60)
            {
                temp_zone = 1;
            }

            if (zoneOverride > 0)
            {
                if ((temp_zone == 1) && (this.zoneOverride == 60))
                {
                    temp_zone = (int)this.zoneOverride;
                }
                else if ((temp_zone == 60) && (zoneOverride == 1))
                {
                    temp_zone = (int)this.zoneOverride;
                }
                else if (((temp_zone - 1) <= zoneOverride) && (zoneOverride <= (temp_zone + 1)))
                {
                    temp_zone = (int)this.zoneOverride;
                }
                else
                {
                    throw new ArgumentException(ErrorMessages.zoneOverride);
                }
            }

            TransverseMercator transverseMercator = getTransverseMercator(temp_zone);

            if (latitude < 0)
            {
                False_Northing = 10000000.0;
                hemisphere = 'S';
            }
            else
            {
                hemisphere = 'N';
            }

            MapProjectionCoordinates transverseMercatorCoordinates = transverseMercator.convertFromGeodetic(new GeodeticCoordinates(CoordinateType.Enum.geodetic, longitude, latitude));
            double easting = transverseMercatorCoordinates.getEasting();
            double northing = transverseMercatorCoordinates.getNorthing() + False_Northing;

            if ((easting < MIN_EASTING) || (easting > MAX_EASTING))
            {

                throw new ArgumentException(ErrorMessages.easting);
            }

            if ((northing < MIN_NORTHING) || (northing > MAX_NORTHING))
            {
                throw new ArgumentException(ErrorMessages.northing);
            }

            return new UTMCoordinates(CoordinateType.Enum.universalTransverseMercator, temp_zone, hemisphere, easting, northing);
        }
Exemplo n.º 6
0
        /// <summary>
        /// The function convertFromGeodetic converts geodetic (latitude and
        /// longitude) coordinates to UTM projection (zone, hemisphere, easting and
        /// northing) coordinates according to the current ellipsoid and UTM zone
        /// zoneOverride parameters.  If any errors occur, an exception is thrown with a description
        /// of the error.
        /// </summary>
        /// <param name="geodeticCoordinates"></param>
        /// <returns></returns>
        public UTMCoordinates convertFromGeodetic(GeodeticCoordinates geodeticCoordinates)
        {
            /*
             *
             *    longitude         : Longitude in radians                (input)
             *    latitude          : Latitude in radians                 (input)
             *    zone              : UTM zone                            (output)
             *    hemisphere        : North or South hemisphere           (output)
             *    easting           : Easting (X) in meters               (output)
             *    northing          : Northing (Y) in meters              (output)
             */

            long   Lat_Degrees;
            long   Long_Degrees;
            int    temp_zone;
            char   hemisphere;
            double False_Northing = 0;
            string errorStatus    = "";

            double longitude = geodeticCoordinates.longitude;
            double latitude  = geodeticCoordinates.latitude;

            if ((latitude < (MIN_LAT - EPSILON)) || (latitude >= (MAX_LAT + EPSILON)))
            { /* latitude out of range */
                errorStatus += ErrorMessages.latitude;
            }
            if ((longitude < -Math.PI) || (longitude > (2 * Math.PI)))
            { /* longitude out of range */
                errorStatus += ErrorMessages.longitude;
            }

            if (errorStatus.Length > 0)
            {
                throw new ArgumentException(errorStatus);
            }

            if ((latitude > -1.0e-9) && (latitude < 0))
            {
                latitude = 0.0;
            }

            if (longitude < 0)
            {
                longitude += (2 * Math.PI) + 1.0e-10;
            }

            Lat_Degrees  = (long)(latitude * 180.0 / Math.PI);
            Long_Degrees = (long)(longitude * 180.0 / Math.PI);

            if (longitude < Math.PI)
            {
                temp_zone = (int)(31 + ((longitude * 180.0 / Math.PI) / 6.0));
            }
            else
            {
                temp_zone = (int)(((longitude * 180.0 / Math.PI) / 6.0) - 29);
            }

            if (temp_zone > 60)
            {
                temp_zone = 1;
            }

            if (zoneOverride > 0)
            {
                if ((temp_zone == 1) && (this.zoneOverride == 60))
                {
                    temp_zone = (int)this.zoneOverride;
                }
                else if ((temp_zone == 60) && (zoneOverride == 1))
                {
                    temp_zone = (int)this.zoneOverride;
                }
                else if (((temp_zone - 1) <= zoneOverride) && (zoneOverride <= (temp_zone + 1)))
                {
                    temp_zone = (int)this.zoneOverride;
                }
                else
                {
                    throw new ArgumentException(ErrorMessages.zoneOverride);
                }
            }

            TransverseMercator transverseMercator = getTransverseMercator(temp_zone);

            if (latitude < 0)
            {
                False_Northing = 10000000.0;
                hemisphere     = 'S';
            }
            else
            {
                hemisphere = 'N';
            }

            MapProjectionCoordinates transverseMercatorCoordinates = transverseMercator.convertFromGeodetic(new GeodeticCoordinates(CoordinateType.Enum.geodetic, longitude, latitude));
            double easting  = transverseMercatorCoordinates.getEasting();
            double northing = transverseMercatorCoordinates.getNorthing() + False_Northing;

            if ((easting < MIN_EASTING) || (easting > MAX_EASTING))
            {
                throw new ArgumentException(ErrorMessages.easting);
            }

            if ((northing < MIN_NORTHING) || (northing > MAX_NORTHING))
            {
                throw new ArgumentException(ErrorMessages.northing);
            }

            return(new UTMCoordinates(CoordinateType.Enum.universalTransverseMercator, temp_zone, hemisphere, easting, northing));
        }
        /// <summary>
        /// The function convertFromGeodetic converts geodetic
        /// coordinates (latitude and longitude) to Polar Stereographic coordinates
        /// (easting and northing), according to the current ellipsoid
        /// and Polar Stereographic projection parameters. If any errors occur, 
        /// an exception is thrown with a description of the error.
        /// </summary>
        /// <param name="geodeticCoordinates">Geodetic Coordinates containing Longitude and Latitude, in radians</param>
        /// <returns>Map Projection Coordinates containing easting (X) and Northing (Y), in meters</returns>
        public MapProjectionCoordinates convertFromGeodetic(GeodeticCoordinates geodeticCoordinates)
        {
            double dlam;
            double slat;
            double essin;
            double t;
            double rho;
            double pow_es;
            double easting, northing;
            string errorStatus = "";

            double longitude = geodeticCoordinates.longitude;
            double latitude = geodeticCoordinates.latitude;

            if ((latitude < -PI_OVER_2) || (latitude > PI_OVER_2))
            {   /* latitude out of range */
                errorStatus += ErrorMessages.latitude;
            }
            else if ((latitude < 0) && (Southern_Hemisphere == 0))
            {   /* latitude and Origin Latitude in different hemispheres */
                errorStatus += ErrorMessages.latitude;
            }
            else if ((latitude > 0) && (Southern_Hemisphere == 1))
            {   /* latitude and Origin Latitude in different hemispheres */
                errorStatus += ErrorMessages.latitude;
            }
            if ((longitude < -Math.PI) || (longitude > TWO_PI))
            {  /* longitude out of range */
                errorStatus += ErrorMessages.longitude;
            }

            if (errorStatus.Length > 0)
            {
                throw new ArgumentException(errorStatus);
            }

            if (Math.Abs(Math.Abs(latitude) - PI_OVER_2) < 1.0e-10)
            {
                easting = Polar_False_Easting;
                northing = Polar_False_Northing;
            }
            else
            {
                if (Southern_Hemisphere != 0)
                {
                    longitude *= -1.0;
                    latitude *= -1.0;
                }
                dlam = longitude - this.Polar_Central_Meridian;
                if (dlam > Math.PI)
                {
                    dlam -= TWO_PI;
                }
                if (dlam < -Math.PI)
                {
                    dlam += TWO_PI;
                }
                slat = Math.Sin(latitude);
                essin = es * slat;
                pow_es = polarPow(essin);
                t = Math.Tan(PI_OVER_4 - latitude / 2.0) / pow_es;

                if (Math.Abs(Math.Abs(this.Polar_Standard_Parallel) - PI_OVER_2) > 1.0e-10)
                {
                    rho = this.Polar_a_mc * t / this.Polar_tc;
                }
                else
                {
                    rho = this.two_Polar_a * t / this.Polar_k90;
                }

                if (Southern_Hemisphere != 0)
                {
                    easting = -(rho * Math.Sin(dlam) - this.Polar_False_Easting);
                    northing = rho * Math.Cos(dlam) + this.Polar_False_Northing;
                }
                else
                {
                    easting = rho * Math.Sin(dlam) + this.Polar_False_Easting;
                    northing = -rho * Math.Cos(dlam) + this.Polar_False_Northing;
                }
            }

            return new MapProjectionCoordinates(coordinateType, easting, northing);
        }
Exemplo n.º 8
0
        /// <summary>
        /// Validates that the coordinates are within the proper range.
        /// </summary>
        private void ValidateCoordinates()
        {
            double _PI_OVER_180 = Math.PI / 180d;

            if (Math.Abs(Longitude) > 180)
            {
                throw new ArgumentOutOfRangeException("Longitude", "Longitude must be [-180.0, 180.0]");
            }
            if (Math.Abs(Latitude) > 90)
            {
                throw new ArgumentOutOfRangeException("Latitude", "Longitude must be [-90.0, 90.0]");
            }

            this.geodeticCoordinates = new GeodeticCoordinates(CoordinateType.Enum.geodetic, this.Longitude * _PI_OVER_180, this.Latitude * _PI_OVER_180);
        }
Exemplo n.º 9
0
        /// <summary>
        /// The function convertFromGeodetic converts geodetic (latitude and
        /// longitude) coordinates to UPS (hemisphere, easting, and northing)
        /// coordinates, according to the current ellipsoid parameters. 
        /// If any errors occur, an exception is thrown with a description 
        /// of the error.
        /// </summary>
        /// <param name="geodeticCoordinates"></param>
        /// <returns></returns>
        public UPSCoordinates convertFromGeodetic(GeodeticCoordinates geodeticCoordinates)
        {
            /*
             *    latitude      : Latitude in radians                       (input)
             *    longitude     : Longitude in radians                      (input)
             *    hemisphere    : Hemisphere either 'N' or 'S'              (output)
             *    easting       : Easting/X in meters                       (output)
             *    northing      : Northing/Y in meters                      (output)
             */

            char hemisphere;
            string errorStatus = "";

            double longitude = geodeticCoordinates.longitude;
            double latitude = geodeticCoordinates.latitude;

            if ((latitude < -MAX_LAT) || (latitude > MAX_LAT))
            {   /* latitude out of range */
                errorStatus += ErrorMessages.latitude;
            }
            else if ((latitude < 0) && (latitude >= (MAX_SOUTH_LAT + EPSILON)))
            {
                errorStatus += ErrorMessages.latitude;
            }
            else if ((latitude >= 0) && (latitude < (MIN_NORTH_LAT - EPSILON)))
            {
                errorStatus += ErrorMessages.latitude;
            }
            if ((longitude < -Math.PI) || (longitude > (2 * Math.PI)))
            {  /* longitude out of range */
                errorStatus += ErrorMessages.longitude;
            }

            if (errorStatus.Length > 0)
            {
                throw new ArgumentException(errorStatus);
            }

            if (latitude < 0)
            {
                //this.UPS_Origin_Latitude = -MAX_ORIGIN_LAT;
                hemisphere = 'S';
            }
            else
            {
                //this.UPS_Origin_Latitude = MAX_ORIGIN_LAT;
                hemisphere = 'N';
            }

            PolarStereographic polarStereographic = new PolarStereographic(this.semiMajorAxis, this.flattening, this.UPS_Origin_Longitude, 0.994, hemisphere, this.UPS_False_Easting, this.UPS_False_Northing);
            MapProjectionCoordinates polarStereographicCoordinates = polarStereographic.convertFromGeodetic(geodeticCoordinates);

            double easting = polarStereographicCoordinates.getEasting();
            double northing = polarStereographicCoordinates.getNorthing();

            return new UPSCoordinates(CoordinateType.Enum.universalPolarStereographic, hemisphere, easting, northing);
        }
Exemplo n.º 10
0
        /// <summary>
        /// The function convertFromGeodetic converts geodetic
        /// coordinates (latitude and longitude) to Polar Stereographic coordinates
        /// (easting and northing), according to the current ellipsoid
        /// and Polar Stereographic projection parameters. If any errors occur,
        /// an exception is thrown with a description of the error.
        /// </summary>
        /// <param name="geodeticCoordinates">Geodetic Coordinates containing Longitude and Latitude, in radians</param>
        /// <returns>Map Projection Coordinates containing easting (X) and Northing (Y), in meters</returns>
        public MapProjectionCoordinates convertFromGeodetic(GeodeticCoordinates geodeticCoordinates)
        {
            double dlam;
            double slat;
            double essin;
            double t;
            double rho;
            double pow_es;
            double easting, northing;
            string errorStatus = "";

            double longitude = geodeticCoordinates.longitude;
            double latitude  = geodeticCoordinates.latitude;

            if ((latitude < -PI_OVER_2) || (latitude > PI_OVER_2))
            {   /* latitude out of range */
                errorStatus += ErrorMessages.latitude;
            }
            else if ((latitude < 0) && (Southern_Hemisphere == 0))
            {   /* latitude and Origin Latitude in different hemispheres */
                errorStatus += ErrorMessages.latitude;
            }
            else if ((latitude > 0) && (Southern_Hemisphere == 1))
            {   /* latitude and Origin Latitude in different hemispheres */
                errorStatus += ErrorMessages.latitude;
            }
            if ((longitude < -Math.PI) || (longitude > TWO_PI))
            {  /* longitude out of range */
                errorStatus += ErrorMessages.longitude;
            }

            if (errorStatus.Length > 0)
            {
                throw new ArgumentException(errorStatus);
            }

            if (Math.Abs(Math.Abs(latitude) - PI_OVER_2) < 1.0e-10)
            {
                easting  = Polar_False_Easting;
                northing = Polar_False_Northing;
            }
            else
            {
                if (Southern_Hemisphere != 0)
                {
                    longitude *= -1.0;
                    latitude  *= -1.0;
                }
                dlam = longitude - this.Polar_Central_Meridian;
                if (dlam > Math.PI)
                {
                    dlam -= TWO_PI;
                }
                if (dlam < -Math.PI)
                {
                    dlam += TWO_PI;
                }
                slat   = Math.Sin(latitude);
                essin  = es * slat;
                pow_es = polarPow(essin);
                t      = Math.Tan(PI_OVER_4 - latitude / 2.0) / pow_es;

                if (Math.Abs(Math.Abs(this.Polar_Standard_Parallel) - PI_OVER_2) > 1.0e-10)
                {
                    rho = this.Polar_a_mc * t / this.Polar_tc;
                }
                else
                {
                    rho = this.two_Polar_a * t / this.Polar_k90;
                }

                if (Southern_Hemisphere != 0)
                {
                    easting  = -(rho * Math.Sin(dlam) - this.Polar_False_Easting);
                    northing = rho * Math.Cos(dlam) + this.Polar_False_Northing;
                }
                else
                {
                    easting  = rho * Math.Sin(dlam) + this.Polar_False_Easting;
                    northing = -rho *Math.Cos(dlam) + this.Polar_False_Northing;
                }
            }

            return(new MapProjectionCoordinates(coordinateType, easting, northing));
        }
Exemplo n.º 11
0
        /// <summary>
        /// The function convertFromGeodetic converts Geodetic (latitude and
        /// longitude) coordinates to an MGRS coordinate string, according to the
        /// current ellipsoid parameters.  If any errors occur, an exception
        /// is thrown with a description of the error.
        /// </summary>
        /// <param name="geodeticCoordinates">Geodetic Coordinates</param>
        /// <param name="precision">Precision level of MGRS string (0 to 5)</param>
        /// <returns>MGRS Coordinates</returns>
        public MGRSorUSNGCoordinates convertFromGeodetic(GeodeticCoordinates geodeticCoordinates, long precision)
        {
            MGRSorUSNGCoordinates mgrsorUSNGCoordinates = new MGRSorUSNGCoordinates();
            string errorStatus = "";

            double latitude = geodeticCoordinates.latitude;
            double longitude = geodeticCoordinates.longitude;

            if ((latitude < -PI_OVER_2) || (latitude > PI_OVER_2))
            { /* latitude out of range */
                errorStatus = ErrorMessages.latitude;
            }
            if ((longitude < -Math.PI) || (longitude > (2 * Math.PI)))
            { /* longitude out of range */
                errorStatus = ErrorMessages.longitude;
            }
            if ((precision < 0) || (precision > MAX_PRECISION))
            {
                errorStatus = ErrorMessages.precision;
            }

            if (errorStatus.Length > 0)
            {
                throw new ArgumentException(errorStatus);
            }

            // If the latitude is within the valid mgrs non polar range [-80, 84),
            // convert to mgrs using the utm path, otherwise convert to mgrs using the ups path
            if ((latitude >= MIN_MGRS_NON_POLAR_LAT) && (latitude < MAX_MGRS_NON_POLAR_LAT))
            {
                mgrsorUSNGCoordinates = fromUTM(utm.convertFromGeodetic(geodeticCoordinates), longitude, latitude, precision);
            }
            else
            {
                mgrsorUSNGCoordinates = fromUPS(ups.convertFromGeodetic(geodeticCoordinates), precision);
            }

            return mgrsorUSNGCoordinates;
        }
Exemplo n.º 12
0
        /// <summary>
        /// The function convertFromGeodetic converts geodetic
        /// (latitude and longitude) coordinates to Transverse Mercator projection
        /// (easting and northing) coordinates, according to the current ellipsoid
        /// and Transverse Mercator projection coordinates.  If any errors occur,
        /// an exception is thrown with a description of the error.
        /// </summary>
        /// <param name="geodeticCoordinates"></param>
        /// <returns></returns>
        public MapProjectionCoordinates convertFromGeodetic(GeodeticCoordinates geodeticCoordinates)
        {
            /*
             *    longitude     : Longitude in radians                        (input)
             *    latitude      : Latitude in radians                         (input)
             *    easting       : Easting/X in meters                         (output)
             *    northing      : Northing/Y in meters                        (output)
             */

            double c1;       /* Cosine of latitude                          */
            double c2;
            double c3;
            double c5;
            double c7;
            double dlam;    /* Delta longitude - Difference in Longitude       */
            double eta1;    /* constant - TranMerc_ebs *c *c                   */
            double eta2;
            double eta3;
            double eta4;
            double s;       /* Sine of latitude                        */
            double sn;      /* Radius of curvature in the prime vertical       */
            double tan1;    /* Tangent of latitude                             */
            double tan2;
            double tan3;
            double tan4;
            double tan5;
            double tan6;
            double t1;      /* Term in coordinate conversion formula - GP to Y */
            double t2;      /* Term in coordinate conversion formula - GP to Y */
            double t3;      /* Term in coordinate conversion formula - GP to Y */
            double t4;      /* Term in coordinate conversion formula - GP to Y */
            double t5;      /* Term in coordinate conversion formula - GP to Y */
            double t6;      /* Term in coordinate conversion formula - GP to Y */
            double t7;      /* Term in coordinate conversion formula - GP to Y */
            double t8;      /* Term in coordinate conversion formula - GP to Y */
            double t9;      /* Term in coordinate conversion formula - GP to Y */
            double temp_Origin;
            double temp_Long;
            string errorStatus = "";

            double longitude = geodeticCoordinates.longitude;
            double latitude  = geodeticCoordinates.latitude;

            if ((latitude < -MAX_LAT) || (latitude > MAX_LAT))
            {  /* Latitude out of range */
                errorStatus += ErrorMessages.latitude;
            }
            if (longitude > Math.PI)
            {
                longitude -= (2 * Math.PI);
            }
            if ((longitude < (this.TranMerc_Origin_Long - MAX_DELTA_LONG)) || (longitude > (this.TranMerc_Origin_Long + MAX_DELTA_LONG)))
            {
                if (longitude < 0)
                {
                    temp_Long = longitude + 2 * Math.PI;
                }
                else
                {
                    temp_Long = longitude;
                }
                if (this.TranMerc_Origin_Long < 0)
                {
                    temp_Origin = this.TranMerc_Origin_Long + 2 * Math.PI;
                }
                else
                {
                    temp_Origin = this.TranMerc_Origin_Long;
                }
                //if ((temp_Long < (temp_Origin - MAX_DELTA_LONG)) || (temp_Long > (temp_Origin + MAX_DELTA_LONG)))
                //{
                //    errorStatus += ErrorMessages.longitude;
                //}
            }

            if (errorStatus.Length > 0)
            {
                //throw new ArgumentException(errorStatus);
            }

            /*
             *  Delta Longitude
             */
            dlam = longitude - this.TranMerc_Origin_Long;

            if (Math.Abs(dlam) > Math.PI / 20.0)
            { /* Distortion will result if Longitude is more than 9 degrees from the Central Meridian */
                errorStatus += WarningMessages.longitude;
            }

            if (dlam > Math.PI)
            {
                dlam -= (2 * Math.PI);
            }
            if (dlam < -Math.PI)
            {
                dlam += (2 * Math.PI);
            }
            if (Math.Abs(dlam) < 2.0e-10)
            {
                dlam = 0.0;
            }

            s    = Math.Sin(latitude);
            c1   = Math.Cos(latitude);
            c2   = c1 * c1;
            c3   = c2 * c1;
            c5   = c3 * c2;
            c7   = c5 * c2;
            tan1 = Math.Tan(latitude);
            tan2 = tan1 * tan1;
            tan3 = tan2 * tan1;
            tan4 = tan3 * tan1;
            tan5 = tan4 * tan1;
            tan6 = tan5 * tan1;
            eta1 = TranMerc_ebs * c2;
            eta2 = eta1 * eta1;
            eta3 = eta2 * eta1;
            eta4 = eta3 * eta1;

            // radius of curvature in prime vertical
            sn = sphsn(latitude);

            // northing
            t1 = (sphtmd(latitude) - sphtmd(this.TranMerc_Origin_Lat)) * this.TranMerc_Scale_Factor; // True Meridinial Distances, Origin
            t2 = sn * s * c1 * this.TranMerc_Scale_Factor / 2.0;
            t3 = sn * s * c3 * this.TranMerc_Scale_Factor * (5.0 - tan2 + 9.0 * eta1 + 4.0 * eta2) / 24.0;
            t4 = sn * s * c5 * this.TranMerc_Scale_Factor * (61.0 - 58.0 * tan2 + tan4 + 270.0 * eta1 - 330.0 * tan2 * eta1 + 445.0 * eta2 + 324.0 * eta3 - 680.0 * tan2 * eta2 + 88.0 * eta4 - 600.0 * tan2 * eta3 - 192.0 * tan2 * eta4) / 720.0;
            t5 = sn * s * c7 * this.TranMerc_Scale_Factor * (1385.0 - 3111.0 * tan2 + 543.0 * tan4 - tan6) / 40320.0;
            double northing = this.TranMerc_False_Northing + t1 + Math.Pow(dlam, 2.0) * t2 + Math.Pow(dlam, 4.0) * t3 + Math.Pow(dlam, 6.0) * t4 + Math.Pow(dlam, 8.0) * t5;

            // Easting
            t6 = sn * c1 * this.TranMerc_Scale_Factor;
            t7 = sn * c3 * this.TranMerc_Scale_Factor * (1.0 - tan2 + eta1) / 6.0;
            t8 = sn * c5 * this.TranMerc_Scale_Factor * (5.0 - 18.0 * tan2 + tan4 + 14.0 * eta1 - 58.0 * tan2 * eta1 + 13.0 * eta2 + 4.0 * eta3 - 64.0 * tan2 * eta2 - 24.0 * tan2 * eta3) / 120.0;
            t9 = sn * c7 * this.TranMerc_Scale_Factor * (61.0 - 479.0 * tan2 + 179.0 * tan4 - tan6) / 5040.0;
            double easting = this.TranMerc_False_Easting + dlam * t6 + Math.Pow(dlam, 3.0) * t7 + Math.Pow(dlam, 5.0) * t8 + Math.Pow(dlam, 7.0) * t9;

            return(new MapProjectionCoordinates(CoordinateType.Enum.transverseMercator, errorStatus, easting, northing));
        }