/// <summary>
        /// Gets information about the parameters for a projection.
        /// </summary>
        /// <param name="projectionConversionCode">The projection code.</param>
        /// <param name="coordOperationMethod">The coordniate operation code.</param>
        /// <returns>IProjectionParameter[] containing information about the parameters.</returns>
        private ProjectionParameter[] GetProjectionParameterInfo(string projectionConversionCode, string coordOperationMethod)
        {
            ParameterList paramsList = GetParameters(projectionConversionCode);            //e, coordOperationMethod);

            ProjectionParameter[] projectionParams = new ProjectionParameter[paramsList.Count];
            int i = 0;

            foreach (string key in paramsList.Keys)
            {
                ProjectionParameter param = new ProjectionParameter(key, paramsList.GetDouble(key));
                projectionParams[i] = param;
                i++;
            }
            return(projectionParams);
        }
Beispiel #2
0
        public void Test_Constructor()
        {
            ProjectionParameter[] paramList = new ProjectionParameter[2];
            paramList[0].Name="test";
            paramList[0].Value=2.2;
            paramList[1].Name="test2";
            paramList[1].Value=2.3;

            Projection projection = new Projection("mercator",paramList,"class","remarks","authority","authoritycode");

            Assertion.AssertEquals("test 1","mercator",projection.Name);
            Assertion.AssertEquals("test 2","class",projection.ClassName);
            Assertion.AssertEquals("test 3",2,projection.NumParameters);
            //Assertion.AssertEquals("test 4a",2.2,projection.get_Parameter(0).Value);
            //Assertion.AssertEquals("test 4b","test",projection.get_Parameter(0).Name);
            //Assertion.AssertEquals("test 5a",2.3,projection.get_Parameter(1).Value);
            //Assertion.AssertEquals("test 5b","test2",projection.get_Parameter(1).Name);
            Assertion.AssertEquals("test 6","remarks",projection.Remarks);
            Assertion.AssertEquals("test 7","authority",projection.Authority);
            Assertion.AssertEquals("Test 8","authoritycode",projection.AuthorityCode);
        }
Beispiel #3
0
        /// <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);
        }
		/// <summary>
		/// Gets information about the parameters for a projection.
		/// </summary>
		/// <param name="projectionConversionCode">The projection code.</param>
		/// <param name="coordOperationMethod">The coordniate operation code.</param>
		/// <returns>IProjectionParameter[] containing information about the parameters.</returns>
		private ProjectionParameter[] GetProjectionParameterInfo(string projectionConversionCode, string coordOperationMethod)
		{
			ParameterList paramsList = GetParameters(projectionConversionCode);//e, coordOperationMethod);
			ProjectionParameter[] projectionParams = new ProjectionParameter[paramsList.Count];
			int i=0;
			foreach(string key in paramsList.Keys)
			{
				ProjectionParameter param = new ProjectionParameter(key,paramsList.GetDouble(key));
				projectionParams[i] = param;
				i++;
			}
			return projectionParams;
		}
		/// <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;
		}
        private static IProjection ReadProjection(XmlTextReader reader)
        {
            if (!(reader.NodeType==XmlNodeType.Element &&  reader.Name=="CS_Projection"))
            {
                throw new ParseException(String.Format(System.Globalization.CultureInfo.InvariantCulture, "Expected a IProjection but got a {0} at line {1} col {2}",reader.Name,reader.LineNumber,reader.LinePosition));
            }
            string className=reader.GetAttribute("ClassName");
            reader.Read();
            string authority="",authorityCode="",abbreviation="",name="";
            ReadInfo(reader, ref authority,ref authorityCode, ref abbreviation, ref name);
            ArrayList list = new ArrayList();
            while (reader.NodeType==XmlNodeType.Element && reader.Name=="CS_ProjectionParameter")
            {
                ProjectionParameter param = ReadProjectionParameter( reader );
                list.Add(param);
                reader.Read();
            }
            ProjectionParameter[] projectionParams = new ProjectionParameter[list.Count];
            projectionParams = (ProjectionParameter[])list.ToArray(typeof(ProjectionParameter));

            Projection projection = new Projection(name,projectionParams,className,"",authority,authorityCode);
            return projection;
        }
 private static ProjectionParameter ReadProjectionParameter(XmlTextReader reader)
 {
     if (!(reader.NodeType==XmlNodeType.Element &&  reader.Name=="CS_ProjectionParameter"))
     {
         throw new ParseException(String.Format(System.Globalization.CultureInfo.InvariantCulture, "Expected a IProjectionParameter but got a {0} at line {1} col {2}",reader.Name,reader.LineNumber,reader.LinePosition));
     }
     string name = reader.GetAttribute("Name");
     string val = reader.GetAttribute("Value");
     ProjectionParameter param = new ProjectionParameter();
     param.Name=name;
     param.Value=Double.Parse( val, System.Globalization.CultureInfo.InvariantCulture );
     return param;
 }
		public void TestCreateProjection3()
		{
			try
			{
				ProjectionParameter[] projectionParams = new ProjectionParameter[1];
				ProjectionParameter param = new ProjectionParameter();
				param.Name="dummy";
				param.Value=2.0;
				projectionParams[0] = param;
				IProjection horizontalDatum = _csFactory.CreateProjection("notexistent","class",projectionParams);
				Assertion.Fail("Should throw a NotImplementedException because the projection does not exist.");
			}
			catch(NotImplementedException)
			{
			}
		}
		public void TestCreateProjection2()
		{
			try
			{
				ProjectionParameter[] projectionParams = new ProjectionParameter[2];
				IProjection horizontalDatum = _csFactory.CreateProjection("mercator","class",projectionParams);
				Assertion.Fail("Should throw a ArgumentException because the params are different lengths.");
			}
			catch(ArgumentException)
			{
			}
		}
		public void TestCreateProjection1()
		{
			try
			{
				ProjectionParameter[] projectionParams = new ProjectionParameter[2];
				IProjection horizontalDatum = _csFactory.CreateProjection(null,"class",projectionParams);
				Assertion.Fail("Should throw a ArgumentNullException.");
			}
			catch(ArgumentNullException)
			{
			}
		}
        private static IProjection ReadProjection(WktStreamTokenizer tokenizer)
        {
            //tokenizer.NextToken();// PROJECTION
            tokenizer.ReadToken("PROJECTION");
            tokenizer.ReadToken("[");//[
            string projectionName=tokenizer.ReadDoubleQuotedWord();
            tokenizer.ReadToken("]");//]
            tokenizer.ReadToken(",");//,
            tokenizer.ReadToken("PARAMETER");
            ParameterList paramList = new ParameterList();
            while (tokenizer.GetStringValue()=="PARAMETER")
            {
                tokenizer.ReadToken("[");
                string paramName = tokenizer.ReadDoubleQuotedWord();
                tokenizer.ReadToken(",");
                tokenizer.NextToken();
                double paramValue = tokenizer.GetNumericValue();
                tokenizer.ReadToken("]");
                tokenizer.ReadToken(",");
                paramList.Add(paramName,paramValue);
                tokenizer.NextToken();
            }

            ProjectionParameter[] paramArray = new ProjectionParameter[paramList.Count];
            int i=0;
            foreach(string key in paramList.Keys)
            {
                ProjectionParameter param= new ProjectionParameter();
                param.Name=key;
                param.Value=(double)paramList[key];
                paramArray[i]=param;
                i++;
            }
            string authority="";
            string authorityCode="";
            IProjection projection = new Projection(projectionName, paramArray,"", "",authority, authorityCode);
            return projection;
        }
Beispiel #12
0
 /// <summary>
 /// Initializes a new instance of the Projection class.
 /// </summary>
 internal Projection(string name, ProjectionParameter[] projectionParameters, string classification, string remarks, string authority, string authorityCode)
     : base(remarks,authority,authorityCode,name,"","")
 {
     _projectionParameters = projectionParameters;
     _classication = classification;
 }