Пример #1
0
        /// <summary>
        /// Reads the proj4 parameters and parses out the ones that control the
        /// datum.
        /// </summary>
        /// <param name="parameters"></param>
        /// <remarks>Originally ported from pj_datum_set.c</remarks>
        public void ReadProj4Params(Dictionary <string, string> parameters)
        {
            DatumType = DatumTypes.Unknown;

            /* -------------------------------------------------------------------- */
            /*      Is there a datum definition in the parameters list?  If so,     */
            /*      add the defining values to the parameter list.  Notice that       */
            /*      this will append the ellipse definition as well as the          */
            /*      towgs84= and related parameters.  It should also be pointed     */
            /*      out that the addition is permanent rather than temporary        */
            /*      like most other keyword expansion so that the ellipse           */
            /*      definition will last into the pj_ell_set() function called      */
            /*      after this one.                                                 */
            /* -------------------------------------------------------------------- */

            if (parameters.ContainsKey("datum"))
            {
                AssignStandardDatum(parameters["datum"]);
                // Even though th ellipsoid is set by its known definition, we permit overriding it with a specifically defined ellps parameter
            }

            // ELLIPSOID PARAMETER
            if (parameters.ContainsKey("ellps"))
            {
                Spheroid = new Spheroid(parameters["ellps"]);
            }
            else
            {
                if (parameters.ContainsKey("a"))
                {
                    Spheroid.EquatorialRadius = double.Parse(parameters["a"]);
                }
                if (parameters.ContainsKey("b"))
                {
                    Spheroid.PolarRadius = double.Parse(parameters["b"]);
                }
                if (parameters.ContainsKey("rf"))
                {
                    Spheroid.SetInverseFlattening(double.Parse(parameters["rf"]));
                }
                if (parameters.ContainsKey("R"))
                {
                    Spheroid.EquatorialRadius = double.Parse(parameters["R"]);
                }
            }

            // DATUM PARAMETER
            if (parameters.ContainsKey("nadgrids"))
            {
                _nadGrids  = parameters["nadgrids"].Split(',');
                _datumtype = DatumTypes.GridShift;
            }
            else if (parameters.ContainsKey("towgs84"))
            {
                string[] rawVals = parameters["towgs84"].Split(',');
                _toWGS84 = new double[rawVals.Length];
                for (int i = 0; i < rawVals.Length; i++)
                {
                    _toWGS84[i] = double.Parse(rawVals[i]);
                }
                _datumtype = DatumTypes.Param7;
                if (_toWGS84.Length < 7)
                {
                    _datumtype = DatumTypes.Param3;
                }
                if (_toWGS84[3] == 0.0 && _toWGS84[4] == 0.0 &&
                    _toWGS84[5] == 0.0 && _toWGS84[6] == 0.0)
                {
                    _datumtype = DatumTypes.Param3;
                }
                if (_datumtype == DatumTypes.Param7)
                {
                    // Trnasform from arc seconds to radians
                    _toWGS84[3] *= SecToRad;
                    _toWGS84[4] *= SecToRad;
                    _toWGS84[5] *= SecToRad;
                    // transform from parts per millon to scaling factor
                    _toWGS84[6] = (_toWGS84[6] / 1000000.0) + 1;
                }
            }
        }
Пример #2
0
        /// <summary>
        /// Reads the proj4 parameters and parses out the ones that control the 
        /// datum.
        /// </summary>
        /// <param name="parameters"></param>
        /// <remarks>Originally ported from pj_datum_set.c</remarks>
        public void ReadProj4Params(Dictionary<string, string> parameters)
        {
            DatumType = DatumTypes.Unknown;

            /* -------------------------------------------------------------------- */
            /*      Is there a datum definition in the parameters list?  If so,     */
            /*      add the defining values to the parameter list.  Notice that       */
            /*      this will append the ellipse definition as well as the          */
            /*      towgs84= and related parameters.  It should also be pointed     */
            /*      out that the addition is permanent rather than temporary        */
            /*      like most other keyword expansion so that the ellipse           */
            /*      definition will last into the pj_ell_set() function called      */
            /*      after this one.                                                 */
            /* -------------------------------------------------------------------- */

            if (parameters.ContainsKey("datum"))
            {
                AssignStandardDatum(parameters["datum"]);
                // Even though th ellipsoid is set by its known definition, we permit overriding it with a specifically defined ellps parameter
            }

            // ELLIPSOID PARAMETER
            if (parameters.ContainsKey("ellps"))
            {
                Spheroid = new Spheroid(parameters["ellps"]);
            }
            else
            {
                if (parameters.ContainsKey("a"))
                {
                    Spheroid.EquatorialRadius = double.Parse(parameters["a"]);
                }
                if (parameters.ContainsKey("b"))
                {
                    Spheroid.PolarRadius = double.Parse(parameters["b"]);
                }
                if (parameters.ContainsKey("rf"))
                {
                    Spheroid.SetInverseFlattening(double.Parse(parameters["rf"]));
                }
                if (parameters.ContainsKey("R"))
                {
                    Spheroid.EquatorialRadius = double.Parse(parameters["R"]);
                }

            }

            // DATUM PARAMETER
            if (parameters.ContainsKey("nadgrids"))
            {
                _nadGrids = parameters["nadgrids"].Split(',');
                _datumtype = DatumTypes.GridShift;
            }
            else if (parameters.ContainsKey("towgs84"))
            {
                string[] rawVals = parameters["towgs84"].Split(',');
                _toWGS84 = new double[rawVals.Length];
                for(int i = 0; i < rawVals.Length; i++)
                {
                    _toWGS84[i] = double.Parse(rawVals[i]);
                }
                _datumtype = DatumTypes.Param7;
                if (_toWGS84.Length < 7) _datumtype = DatumTypes.Param3;
                if (_toWGS84[3] == 0.0 && _toWGS84[4] == 0.0 &&
                   _toWGS84[5] == 0.0 && _toWGS84[6] == 0.0) _datumtype = DatumTypes.Param3;
                if(_datumtype == DatumTypes.Param7)
                {
                    // Trnasform from arc seconds to radians
                    _toWGS84[3] *= SecToRad;
                    _toWGS84[4] *= SecToRad;
                    _toWGS84[5] *= SecToRad;
                    // transform from parts per millon to scaling factor
                    _toWGS84[6] = (_toWGS84[6]/1000000.0) + 1;
                }
            }

        }
Пример #3
0
        private void AssignStandardDatum(string datumName)
        {
            string id = datumName.ToLower();

            switch (id)
            {
            case "wgs84":
                _toWGS84     = new double[] { 0, 0, 0 };
                _spheroid    = new Spheroid(Proj4Ellipsoids.WGS_1984);
                _description = "WGS 1984";
                _datumtype   = DatumTypes.WGS84;
                _name        = "D_WGS_1984";
                break;

            case "ggrs87":
                _toWGS84     = new[] { -199.87, 74.79, 246.62 };
                _spheroid    = new Spheroid(Proj4Ellipsoids.GRS_1980);
                _description = "Greek Geodetic Reference System 1987";
                _datumtype   = DatumTypes.Param3;
                break;

            case "nad83":
                _toWGS84     = new double[] { 0, 0, 0 };
                _spheroid    = new Spheroid(Proj4Ellipsoids.GRS_1980);
                _description = "North American Datum 1983";
                _datumtype   = DatumTypes.WGS84;
                break;

            case "nad27":
                _nadGrids    = new[] { "@conus", "@alaska", "@ntv2_0.gsb", "@ntv1_can.dat" };
                _spheroid    = new Spheroid(Proj4Ellipsoids.Clarke_1866);
                _description = "North American Datum 1927";
                _datumtype   = DatumTypes.GridShift;
                break;

            case "potsdam":
                _toWGS84     = new[] { 606.0, 23.0, 413.0 };
                _spheroid    = new Spheroid(Proj4Ellipsoids.Bessel_1841);
                _description = "Potsdam Rauenberg 1950 DHDN";
                _datumtype   = DatumTypes.Param3;
                break;

            case "carthage":
                _toWGS84     = new[] { -263.0, 6, 413 };
                _spheroid    = new Spheroid(Proj4Ellipsoids.ClarkeModified_1880);
                _description = "Carthage 1934 Tunisia";
                _datumtype   = DatumTypes.Param3;
                break;

            case "hermannskogel":
                _toWGS84     = new[] { 653.0, -212.0, 449 };
                _spheroid    = new Spheroid(Proj4Ellipsoids.Bessel_1841);
                _description = "Hermannskogel";
                _datumtype   = DatumTypes.Param3;
                break;

            case "ire65":
                _toWGS84     = new[] { 482.530, -130.569, 564.557, -1.042, -.214, -.631, 8.15 };
                _spheroid    = new Spheroid(Proj4Ellipsoids.AiryModified);
                _description = "Ireland 1965";
                _datumtype   = DatumTypes.Param7;
                break;

            case "nzgd49":
                _toWGS84     = new[] { 59.47, -5.04, 187.44, 0.47, -0.1, 1.024, -4.5993 };
                _spheroid    = new Spheroid(Proj4Ellipsoids.International_1909);
                _description = "New Zealand";
                _datumtype   = DatumTypes.Param7;
                break;

            case "osgb36":
                _toWGS84     = new[] { 446.448, -125.157, 542.060, 0.1502, 0.2470, 0.8421, -20.4894 };
                _spheroid    = new Spheroid(Proj4Ellipsoids.Airy_1830);
                _description = "Airy 1830";
                _datumtype   = DatumTypes.Param7;
                break;
            }
        }
Пример #4
0
 private void AssignStandardDatum(string datumName)
 {
     string id = datumName.ToLower();
     switch (id)
     {
         case "wgs84":
             _toWGS84 = new double[] { 0, 0, 0 };
             _spheroid = new Spheroid(Proj4Ellipsoids.WGS_1984);
             _description = "WGS 1984";
             _datumtype = DatumTypes.WGS84;
             break;
         case "ggrs87":
             _toWGS84 = new[] { -199.87, 74.79, 246.62 };
             _spheroid = new Spheroid(Proj4Ellipsoids.GRS_1980);
             _description = "Greek Geodetic Reference System 1987";
             _datumtype = DatumTypes.Param3;
             break;
         case "nad83":
             _toWGS84 = new double[] { 0, 0, 0 };
             _spheroid = new Spheroid(Proj4Ellipsoids.GRS_1980);
             _description = "North American Datum 1983";
             _datumtype = DatumTypes.WGS84;
             break;
         case "nad27":
             _nadGrids = new[] { "@conus", "@alaska", "@ntv2_0.gsb", "@ntv1_can.dat" };
             _spheroid = new Spheroid(Proj4Ellipsoids.Clarke_1866);
             _description = "North American Datum 1927";
             _datumtype = DatumTypes.GridShift;
             break;
         case "potsdam":
             _toWGS84 = new[] { 606.0, 23.0, 413.0 };
             _spheroid = new Spheroid(Proj4Ellipsoids.Bessel_1841);
             _description = "Potsdam Rauenberg 1950 DHDN";
             _datumtype = DatumTypes.Param3;
             break;
         case "carthage":
             _toWGS84 = new[] { -263.0, 6, 413 };
             _spheroid = new Spheroid(Proj4Ellipsoids.ClarkeModified_1880);
             _description = "Carthage 1934 Tunisia";
             _datumtype = DatumTypes.Param3;
             break;
         case "hermannskogel":
             _toWGS84 = new[] { 653.0, -212.0, 449 };
             _spheroid = new Spheroid(Proj4Ellipsoids.Bessel_1841);
             _description = "Hermannskogel";
             _datumtype = DatumTypes.Param3;
             break;
         case "ire65":
             _toWGS84 = new[] { 482.530, -130.569, 564.557, -1.042, -.214, -.631, 8.15 };
             _spheroid = new Spheroid(Proj4Ellipsoids.AiryModified);
             _description = "Ireland 1965";
             _datumtype = DatumTypes.Param7;
             break;
         case "nzgd49":
             _toWGS84 = new[] { 59.47, -5.04, 187.44, 0.47, -0.1, 1.024, -4.5993 };
             _spheroid = new Spheroid(Proj4Ellipsoids.International_1909);
             _description = "New Zealand";
             _datumtype = DatumTypes.Param7;
             break;
         case "osgb36":
             _toWGS84 = new[] { 446.448, -125.157, 542.060, 0.1502, 0.2470, 0.8421, -20.4894 };
             _spheroid = new Spheroid(Proj4Ellipsoids.Airy_1830);
             _description = "Airy 1830";
             _datumtype = DatumTypes.Param7;
             break;
     }
 }