Exemplo n.º 1
0
 public RuntimeTextTemplateFactory(
     Projection.Projection projection,
     IDiagnosticsCallback diagnosticsCallback,
     IFormatInfo formatInfo)
 {
     if (ReferenceEquals(projection, null))
     {
         throw new ArgumentException(nameof(projection));
     }
     if (ReferenceEquals(diagnosticsCallback, null))
     {
         throw new ArgumentException(nameof(diagnosticsCallback));
     }
     if (ReferenceEquals(diagnosticsCallback, null))
     {
         throw new ArgumentException(nameof(formatInfo));
     }
     m_projection          = projection;
     m_diagnosticsCallback = diagnosticsCallback;
     m_formatInfo          = formatInfo;
 }
Exemplo n.º 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));
        }
Exemplo n.º 3
0
        ///<summary>
        /// Creates a <see cref="Projection"/> initialized from a PROJ.4 argument list.
        ///</summary>
        private Projection.Projection ParseProjection(IDictionary <String, String> parameters, Ellipsoid ellipsoid)
        {
            Projection.Projection projection = null;

            String s;

            if (parameters.TryGetValue(Proj4Keyword.proj, out s))
            {
                projection = registry.GetProjection(s, parameters);
            }

            if (projection == null)
            {
                throw new ArgumentException("Unknown projection: " + s);
            }

            projection.Ellipsoid = ellipsoid;

            // not sure what CSes use this??

            /*
             * s = (String)parameters.TryGetValue( "init" );
             * if ( s != null ) {
             * projection = CreateFromName( s ).getProjection();
             * if ( projection == null )
             *  throw new ProjectionException( "Unknown projection: "+s );
             *      a = projection.getEquatorRadius();
             *      es = projection.getEllipsoid().getEccentricitySquared();
             * }
             */


            //TODO: better error handling for things like bad number syntax.
            // Should be able to report the original param string in the error message
            // Also should the exception be lib specific?  (Say ParseException)

            // Other parameters
            //   projection.ProjectionLatitudeDegrees = 0;
            //   projection.ProjectionLatitude1Degrees = 0;
            //   projection.ProjectionLatitude2Degrees = 0;
            if (parameters.TryGetValue(Proj4Keyword.alpha, out s))
            {
                projection.AlphaDegrees = Double.Parse(s, CultureInfo.InvariantCulture);
            }

            if (parameters.TryGetValue(Proj4Keyword.lonc, out s))
            {
                projection.LonCDegrees = Double.Parse(s, CultureInfo.InvariantCulture);
            }

            if (parameters.TryGetValue(Proj4Keyword.lat_0, out s))
            {
                projection.ProjectionLatitudeDegrees = ParseAngle(s);
            }

            if (parameters.TryGetValue(Proj4Keyword.lon_0, out s))
            {
                projection.ProjectionLongitudeDegrees = ParseAngle(s);
            }

            if (parameters.TryGetValue(Proj4Keyword.lat_1, out s))
            {
                projection.ProjectionLatitude1Degrees = ParseAngle(s);
            }

            if (parameters.TryGetValue(Proj4Keyword.lat_2, out s))
            {
                projection.ProjectionLatitude2Degrees = ParseAngle(s);
            }

            if (parameters.TryGetValue(Proj4Keyword.lat_ts, out s))
            {
                projection.TrueScaleLatitudeDegrees = ParseAngle(s);
            }

            if (parameters.TryGetValue(Proj4Keyword.x_0, out s))
            {
                projection.FalseEasting = Double.Parse(s, CultureInfo.InvariantCulture);
            }

            if (parameters.TryGetValue(Proj4Keyword.y_0, out s))
            {
                projection.FalseNorthing = Double.Parse(s, CultureInfo.InvariantCulture);
            }

            if (!parameters.TryGetValue(Proj4Keyword.k_0, out s))
            {
                if (!parameters.TryGetValue(Proj4Keyword.k, out s))
                {
                    s = null;
                }
            }
            if (s != null)
            {
                projection.ScaleFactor = Double.Parse(s, CultureInfo.InvariantCulture);
            }

            if (parameters.TryGetValue(Proj4Keyword.units, out s))
            {
                Unit unit = Units.Units.FindUnit(s);
                // TODO: report unknown units name as error
                if (unit != null)
                {
                    projection.FromMetres = (1.0 / unit.Value);
                    projection.Unit       = unit;
                }
            }

            if (parameters.TryGetValue(Proj4Keyword.to_meter, out s))
            {
                projection.FromMetres = (1.0 / Double.Parse(s, CultureInfo.InvariantCulture));
            }

            if (parameters.ContainsKey(Proj4Keyword.south))
            {
                projection.SouthernHemisphere = true;
            }

            if (parameters.TryGetValue(Proj4Keyword.pm, out s))
            {
                double pm;
                projection.PrimeMeridian = double.TryParse(s, out pm)
                    ? Meridian.CreateByDegree(pm)
                    : Meridian.CreateByName(s);
            }

            //TODO: implement some of these parameters ?

            // this must be done last, since behaviour depends on other parameters being set (eg +south)
            if (projection is TransverseMercatorProjection)
            {
                if (parameters.TryGetValue("zone", out s))
                {
                    ((TransverseMercatorProjection)projection).UTMZone = int.Parse(s);
                }
            }

            projection.Initialize();

            return(projection);
        }