예제 #1
0
        private void ParseDatum(IDictionary <String, String> parameters, DatumParameters datumParam)
        {
            String towgs84;

            if (parameters.TryGetValue(Proj4Keyword.towgs84, out towgs84))
            {
                double[] datumConvparameters = ParseToWGS84(towgs84);
                datumParam.SetDatumTransform(datumConvparameters);
            }

            String code;

            if (parameters.TryGetValue(Proj4Keyword.datum, out code))
            {
                Datum.Datum datum = registry.GetDatum(code);
                if (datum == null)
                {
                    throw new ArgumentException("Unknown datum: " + code);
                }
                datumParam.Datum = datum;
            }

            string grids;

            if (parameters.TryGetValue(Proj4Keyword.nadgrids, out grids))
            {
                datumParam.SetNadGrids(grids);
            }
        }
예제 #2
0
        public CoordinateReferenceSystem Parse(String name, String[] args)
        {
            if (args == null)
            {
                return(null);
            }

            IDictionary <String, String> parameters = CreateParameterMap(args);

            Proj4Keyword.CheckUnsupported(parameters.Keys);
            DatumParameters datumParam = new DatumParameters();

            ParseDatum(parameters, datumParam);
            ParseEllipsoid(parameters, datumParam);
            Datum.Datum datum     = datumParam.Datum;
            Ellipsoid   ellipsoid = datum.Ellipsoid;

            // TODO: this makes a difference - why?
            // which is better?
            //    Ellipsoid ellipsoid = datumParam.getEllipsoid();
            Projection.Projection proj = ParseProjection(parameters, ellipsoid);
            return(new CoordinateReferenceSystem(name, args, datum, proj));
        }
예제 #3
0
 /**
  * Parse ellipsoid modifiers.
  *
  * @param parameters
  * @param datumParam
  */
 private static void ParseEllipsoidModifiers(IDictionary <String, String> parameters, DatumParameters datumParam)
 {
     /**
      * Modifiers are mutually exclusive, so when one is detected method returns
      */
     if (parameters.ContainsKey(Proj4Keyword.R_A))
     {
         datumParam.setR_A();
         return;
     }
 }
예제 #4
0
        private void ParseEllipsoid(IDictionary <String, String> parameters, DatumParameters datumParam)
        {
            double b = 0;
            String s;

            /*
             * // not supported by PROJ4 s = (String) parameters.TryGetValue(Proj4Param.R); if (s !=
             * null) a = Double.parseDouble(s);
             */

            String code;

            if (parameters.TryGetValue(Proj4Keyword.ellps, out code))
            {
                Ellipsoid ellipsoid = registry.GetEllipsoid(code);
                if (ellipsoid == null)
                {
                    throw new ArgumentException("Unknown ellipsoid: " + code);
                }
                datumParam.Ellipsoid = ellipsoid;
            }

            /*
             * Explicit parameters override ellps and datum settings
             */
            if (parameters.TryGetValue(Proj4Keyword.a, out s))
            {
                double a = Double.Parse(s, CultureInfo.InvariantCulture);
                datumParam.EquatorRadius = a;
            }

            if (parameters.TryGetValue(Proj4Keyword.es, out s))
            {
                double es = Double.Parse(s, CultureInfo.InvariantCulture);
                datumParam.EccentricitySquared = es;
            }

            if (parameters.TryGetValue(Proj4Keyword.rf, out s))
            {
                double rf = Double.Parse(s, CultureInfo.InvariantCulture);
                datumParam.SetRF(rf);
            }

            if (parameters.TryGetValue(Proj4Keyword.f, out s))
            {
                double f = Double.Parse(s, CultureInfo.InvariantCulture);
                datumParam.SetF(f);
            }

            if (parameters.TryGetValue(Proj4Keyword.b, out s))
            {
                b = Double.Parse(s, CultureInfo.InvariantCulture);
                datumParam.SetB(b);
            }

            if (b == 0)
            {
                b = datumParam.EquatorRadius * Math.Sqrt(1.0 - datumParam.EccentricitySquared);
            }

            ParseEllipsoidModifiers(parameters, datumParam);

            /*
             * // None of these appear to be supported by PROJ4 ??
             *
             * s = (String)
             * parameters.TryGetValue(Proj4Param.R_A); if (s != null && Boolean.getBoolean(s)) { a *=
             * 1. - es * (SIXTH + es * (RA4 + es * RA6)); } else { s = (String)
             * parameters.TryGetValue(Proj4Param.R_V); if (s != null && Boolean.getBoolean(s)) { a *=
             * 1. - es * (SIXTH + es * (RV4 + es * RV6)); } else { s = (String)
             * parameters.TryGetValue(Proj4Param.R_a); if (s != null && Boolean.getBoolean(s)) { a =
             * .5 * (a + b); } else { s = (String) parameters.TryGetValue(Proj4Param.R_g); if (s !=
             * null && Boolean.getBoolean(s)) { a = Math.sqrt(a * b); } else { s =
             * (String) parameters.TryGetValue(Proj4Param.R_h); if (s != null &&
             * Boolean.getBoolean(s)) { a = 2. * a * b / (a + b); es = 0.; } else { s =
             * (String) parameters.TryGetValue(Proj4Param.R_lat_a); if (s != null) { double tmp =
             * Math.sin(ParseAngle(s)); if (Math.abs(tmp) > MapMath.HALFPI) throw new
             * ProjectionException("-11"); tmp = 1. - es * tmp * tmp; a *= .5 * (1. - es +
             * tmp) / (tmp * Math.sqrt(tmp)); es = 0.; } else { s = (String)
             * parameters.TryGetValue(Proj4Param.R_lat_g); if (s != null) { double tmp =
             * Math.sin(ParseAngle(s)); if (Math.abs(tmp) > MapMath.HALFPI) throw new
             * ProjectionException("-11"); tmp = 1. - es * tmp * tmp; a *= Math.sqrt(1. -
             * es) / tmp; es = 0.; } } } } } } } }
             */
        }