public static IMathTransform CreateCoordinateOperation(IProjection projection, IEllipsoid ellipsoid)
        {
            ParameterList parameterList = new ParameterList();
            for(int i=0; i< projection.NumParameters; i++)
            {
                ProjectionParameter param = projection.GetParameter(i);
                parameterList.Add(param.Name,param.Value);
            }
            parameterList.Add("semi_major",ellipsoid.SemiMajorAxis);
            parameterList.Add("semi_minor",ellipsoid.SemiMinorAxis);

            IMathTransform transform = null;
            switch(projection.Name.ToLower())
            {
                case "mercator":
                    //1SP
                    transform = new MercatorProjection(parameterList);
                    break;
                case "transverse_mercator":
                    transform = new TransverseMercatorProjection(parameterList);
                    break;
                case "albers":
                    transform = new AlbersProjection(parameterList);
                    break;
                case "lambert":
                    transform = new LambertConformalConic2SPProjection(parameterList);
                    break;
                default:
                    throw new NotSupportedException(String.Format(System.Globalization.CultureInfo.InvariantCulture, "Projection {0} is not supported.",projection.AuthorityCode));
            }
            return transform;
        }
 /// <summary>
 /// Returns the inverse of this projection.
 /// </summary>
 /// <returns>IMathTransform that is the reverse of the current projection.</returns>
 public override IMathTransform GetInverse()
 {
     if (_inverse == null)
     {
         _inverse = new TransverseMercatorProjection(this._parameters, !_isInverse);
     }
     return(_inverse);
 }
Ejemplo n.º 3
0
        /// <summary>
        /// Given a IProjection and a IEllipsoid, createa a IMathTransform with the required parameters.
        /// </summary>
        /// <param name="projection">The projection information.</param>
        /// <param name="ellipsoid">The ellipsoid to use.</param>
        /// <returns>An object that implements the IMathTransform interface.</returns>
        private IMathTransform CreateCoordinateOperation(IProjection projection, IEllipsoid ellipsoid)
        {
            ParameterList parameterList = new ParameterList();

            for (int i = 0; i < projection.NumParameters; i++)
            {
                ProjectionParameter param = projection.GetParameter(i);
                parameterList.Add(param.Name, param.Value);
            }
            parameterList.Add("semi_major", ellipsoid.SemiMajorAxis);
            parameterList.Add("semi_minor", ellipsoid.SemiMinorAxis);

            IMathTransform transform = null;

            switch (projection.AuthorityCode)
            {
            case "9804":
                //1SP
                transform = new MercatorProjection(parameterList);
                break;

            case "9805":
                //2SP
                transform = new MercatorProjection(parameterList);
                break;

            case "9807":
                transform = new TransverseMercatorProjection(parameterList);
                break;

            case "9633":
                // we should get these parameters from the file - but since we know them....
                ParameterList param = new ParameterList();
                parameterList.Add("latitude_of_natural_origin", 49.0);
                parameterList.Add("longitude_of_natural_origin", -2.0);
                parameterList.Add("scale_factor_at_natural_origin", 0.999601272);
                parameterList.Add("false_easting", 400000.0);
                parameterList.Add("false_northing", -100000.0);
                transform = new MercatorProjection(parameterList);
                break;

            default:
                throw new NotSupportedException(String.Format("Projection {0} is not supported.", projection.AuthorityCode));
            }
            return(transform);
        }
        public static IMathTransform CreateCoordinateOperation(IProjection projection, IEllipsoid ellipsoid)
        {
            ParameterList parameterList = new ParameterList();

            for (int i = 0; i < projection.NumParameters; i++)
            {
                ProjectionParameter param = projection.GetParameter(i);
                parameterList.Add(param.Name, param.Value);
            }
            parameterList.Add("semi_major", ellipsoid.SemiMajorAxis);
            parameterList.Add("semi_minor", ellipsoid.SemiMinorAxis);

            IMathTransform transform = null;

            switch (projection.Name.ToLower())
            {
            case "mercator":
                //1SP
                transform = new MercatorProjection(parameterList);
                break;

            case "transverse_mercator":
                transform = new TransverseMercatorProjection(parameterList);
                break;

            case "albers":
                transform = new AlbersProjection(parameterList);
                break;

            case "lambert":
                transform = new LambertConformalConic2SPProjection(parameterList);
                break;

            default:
                throw new NotSupportedException(String.Format("Projection {0} is not supported.", projection.AuthorityCode));
            }
            return(transform);
        }
        public void Test_Constructor()
        {
            ParameterList parameters = new ParameterList();
            parameters.Add("latitude_of_natural_origin",49.0);
            parameters.Add("longitude_of_natural_origin",-2.0);
            parameters.Add("scale_factor_at_natural_origin",0.999601272);
            parameters.Add("false_easting",400000.0);
            parameters.Add("false_northing",-100000.0);
            parameters.Add("semi_major",6377563.396);
            parameters.Add("semi_minor",6377563.396);

            TransverseMercatorProjection meractor = new TransverseMercatorProjection(parameters);

            double long1 = -2.0;
            double lat1 = 49.0;
            CoordinatePoint pt = new CoordinatePoint();
            pt.Ord = new Double[2];
            pt.Ord.SetValue(long1,0);
            pt.Ord.SetValue(lat1,1);

            CoordinatePoint result1 = meractor.Transform(pt);

            double metersX = (double)result1.Ord[0];
            double metersY = (double)result1.Ord[1];

            Assertion.AssertEquals("Transverse Mercator Transform X","400000",metersX.ToString());
            Assertion.AssertEquals("Transverse Mercator Transform Y","-100000",metersY.ToString());

            CoordinatePoint result2 = meractor.GetInverse().Transform(result1);

            double long2= (double)result2.Ord[0];
            double lat2= (double)result2.Ord[1];

            Assertion.AssertEquals("Transverse Mercator InverseTransformPoint X","-2",long2.ToString());
            Assertion.AssertEquals("TransverseMercator InverseTransformPoint Y","49",lat2.ToString());
        }
        /// <summary>
        /// Given a IProjection and a IEllipsoid, createa a IMathTransform with the required parameters.
        /// </summary>
        /// <param name="projection">The projection information.</param>
        /// <param name="ellipsoid">The ellipsoid to use.</param>
        /// <returns>An object that implements the IMathTransform interface.</returns>
        private IMathTransform CreateCoordinateOperation(IProjection projection, IEllipsoid ellipsoid)
        {
            ParameterList parameterList = new ParameterList();
            for(int i=0; i< projection.NumParameters; i++)
            {
                ProjectionParameter param = projection.GetParameter(i);
                parameterList.Add(param.Name,param.Value);
            }
            parameterList.Add("semi_major",ellipsoid.SemiMajorAxis);
            parameterList.Add("semi_minor",ellipsoid.SemiMinorAxis);

            IMathTransform transform = null;
            switch(projection.AuthorityCode)
            {
                case "9804":
                    //1SP
                    transform = new MercatorProjection(parameterList);
                    break;
                case "9805":
                    //2SP
                    transform = new MercatorProjection(parameterList);
                    break;
                case "9807":
                    transform = new TransverseMercatorProjection(parameterList);
                    break;
                case "9633":
                    // we should get these parameters from the file - but since we know them....
                    ParameterList param = new ParameterList();
                    parameterList.Add("latitude_of_natural_origin",49.0);
                    parameterList.Add("longitude_of_natural_origin",-2.0);
                    parameterList.Add("scale_factor_at_natural_origin",0.999601272);
                    parameterList.Add("false_easting",400000.0);
                    parameterList.Add("false_northing",-100000.0);
                    transform = new MercatorProjection(parameterList);
                    break;
                default:
                    throw new NotSupportedException(String.Format(System.Globalization.CultureInfo.InvariantCulture, "Projection {0} is not supported.",projection.AuthorityCode));
            }
            return transform;
        }
		/// <summary>
		/// 
		/// </summary>
		/// <param name="name">Name to give new object.</param>
		/// <param name="wktProjectionClass">Classification string for projection (e.g. "Transverse_Mercator").</param>
		/// <param name="parameters">Parameters to use for projection. A default set of parameters can
		/// be constructed using classification and initialized
		/// using a chain of SetParameter(...) calls.</param>
		/// <returns>A projection.</returns>
		public IProjection CreateProjection(string name, string wktProjectionClass,  ProjectionParameter[] parameters)
		{	
			if (name==null)
			{
				throw new ArgumentNullException("name");
			}

			ParameterList parameterList = new ParameterList();
			for(int i=0; i< parameters.Length; i++)
			{
				ProjectionParameter param = parameters[i];
				parameterList.Add(param.Name,param.Value);
			}

			IProjection projection= null;
			switch (wktProjectionClass.ToLower())
			{
				case  "transverse_mercator":
					projection = new TransverseMercatorProjection(parameterList);
					break;
				case "mercator":
					projection = new MercatorProjection(parameterList);
					break;
				case "lambert_conformal_conic_2sp":
					projection = new LambertConformalConic2SPProjection(parameterList);
					break;
				case "albers":
					projection = new AlbersProjection(parameterList);
					break;
				default:
					throw new NotImplementedException(String.Format("The {0} projection is not supported",wktProjectionClass));
			}
			return projection;
		}
Ejemplo n.º 8
0
 /// <summary>
 /// Returns the inverse of this projection.
 /// </summary>
 /// <returns>IMathTransform that is the reverse of the current projection.</returns>
 public override IMathTransform GetInverse()
 {
     if (_inverse==null)
     {
         _inverse = new TransverseMercatorProjection(this._parameters, ! _isInverse);
     }
     return _inverse;
 }