Esempio n. 1
0
 /// <summary>
 /// Combines two coorindate system.
 /// </summary>
 /// <param name="name">The name of the new coordinate system.</param>
 /// <param name="headCS">The first coordinate system.</param>
 /// <param name="tailCS">The second coordinate system.</param>
 /// <returns>An object that implements the ICompoundCoordinateSystem interface.</returns>
 public ICompoundCoordinateSystem CreateCompoundCoordinateSystem(string name, ICoordinateSystem headCS, ICoordinateSystem tailCS)
 {
     if (headCS==null)
     {
         throw new ArgumentNullException("headCS");
     }
     if (tailCS==null)
     {
         throw new ArgumentNullException("tailCS");
     }
     CompoundCoordinateSystem compoundsCS = new CompoundCoordinateSystem(headCS,tailCS,"","","",name,"","");
     return compoundsCS;
 }
Esempio n. 2
0
        /// <summary>
        /// Combines two coorindate system.
        /// </summary>
        /// <param name="name">The name of the new coordinate system.</param>
        /// <param name="headCS">The first coordinate system.</param>
        /// <param name="tailCS">The second coordinate system.</param>
        /// <returns>An object that implements the ICompoundCoordinateSystem interface.</returns>
        public ICompoundCoordinateSystem CreateCompoundCoordinateSystem(string name, ICoordinateSystem headCS, ICoordinateSystem tailCS)
        {
            if (headCS == null)
            {
                throw new ArgumentNullException("headCS");
            }
            if (tailCS == null)
            {
                throw new ArgumentNullException("tailCS");
            }
            CompoundCoordinateSystem compoundsCS = new CompoundCoordinateSystem(headCS, tailCS, "", "", "", name, "", "");

            return(compoundsCS);
        }
        /// <summary>
        /// Creates a 3D coordinate system from a code.
        /// </summary>
        /// <param name="code">The EPSG code.</param>
        /// <returns>An object that implements the ICompoundCoordinateSystem interface.</returns>
        public ICompoundCoordinateSystem CreateCompoundCoordinateSystem(string code)
        {
            if (code == null)
            {
                throw new ArgumentNullException("code");
            }
            string sqlQuery = "SELECT COORD_REF_SYS_NAME, COORD_REF_SYS_CODE, AREA_OF_USE_CODE, " +
                              "	COORD_REF_SYS_KIND, DATUM_CODE, COORD_SYS_CODE, " +
                              "	SOURCE_GEOGCRS_CODE, PROJECTION_CONV_CODE, CMPD_VERTCRS_CODE, CRS_SCOPE, CMPD_HORIZCRS_CODE, DATA_SOURCE, REMARKS " +
                              "FROM  [Coordinate Reference System] " +
                              "WHERE COORD_REF_SYS_CODE = {0}";


            sqlQuery = String.Format(System.Globalization.CultureInfo.InvariantCulture, sqlQuery, code);
            IDataReader reader = Database.ExecuteQuery(_databaseConnection, sqlQuery);

            if (!reader.Read())
            {
                throw new ArgumentException(String.Format("Geographic Coordinate System with a code {0} not found in the CRS table in the EPSG database.", code));
            }


            string coordSysCode      = reader["COORD_SYS_CODE"].ToString().ToLower();
            string coordSysName      = reader["COORD_REF_SYS_NAME"].ToString();
            string name              = reader["COORD_REF_SYS_NAME"].ToString();
            string verticalCRSCode   = reader["CMPD_VERTCRS_CODE"].ToString();
            string horizontalCRSCode = reader["CMPD_HORIZCRS_CODE"].ToString();
            string coordRefKind      = reader["COORD_REF_SYS_KIND"].ToString();
            string remarks           = reader["REMARKS"].ToString();
            string datasource        = reader["DATA_SOURCE"].ToString();      // should always be EPSG??


            Database.CheckOneRow(reader, code, "Copound CRS code");
            if (coordRefKind.ToLower() != "compound")
            {
                throw new ArgumentException(String.Format(System.Globalization.CultureInfo.InvariantCulture, "CRS code {0} is not a projected coordinate system but a {1}.", code, coordRefKind));
            }

            ICoordinateSystem headCRS = this.CreateCoordinateSystem(horizontalCRSCode);
            ICoordinateSystem tailCRS = this.CreateCoordinateSystem(verticalCRSCode);

            ICompoundCoordinateSystem compoundCRS = new CompoundCoordinateSystem(headCRS, tailCRS, remarks, datasource, code, name, "", "");

            return(compoundCRS);
        }
 public void Test_Constructor1()
 {
     ICoordinateSystem headCRS = _factory.CreateProjectedCoordinateSystem("27700");
     ICoordinateSystem tailCRS = _factory.CreateVerticalCoordinateSystem("5701");
     CompoundCoordinateSystem compoundCS = new CompoundCoordinateSystem(headCRS,
         tailCRS,
         "remarks",
         "authority",
         "code",
         "name",
         "alias",
         "abbreviation");
     Assertion.AssertEquals("ctor1.",headCRS,compoundCS.HeadCS);
     Assertion.AssertEquals("ctor2.",tailCRS,compoundCS.TailCS);
     Assertion.AssertEquals("ctor3.","remarks",compoundCS.Remarks);
     Assertion.AssertEquals("ctor3.","authority",compoundCS.Authority);
     Assertion.AssertEquals("ctor3.","code",compoundCS.AuthorityCode);
     Assertion.AssertEquals("ctor3.","name",compoundCS.Name);
     Assertion.AssertEquals("ctor3.","alias",compoundCS.Alias);
     Assertion.AssertEquals("ctor3.","abbreviation",compoundCS.Abbreviation);
 }
		/// <summary>
		/// Creates a 3D coordinate system from a code.
		/// </summary>
		/// <param name="code">The EPSG code.</param>
		/// <returns>An object that implements the ICompoundCoordinateSystem interface.</returns>
		public ICompoundCoordinateSystem CreateCompoundCoordinateSystem(string code)
		{
			if (code==null)
			{
				throw new ArgumentNullException("code");
			}
			string sqlQuery =	"SELECT COORD_REF_SYS_NAME, COORD_REF_SYS_CODE, AREA_OF_USE_CODE, "+
				"	COORD_REF_SYS_KIND, DATUM_CODE, COORD_SYS_CODE, "+
				"	SOURCE_GEOGCRS_CODE, PROJECTION_CONV_CODE, CMPD_VERTCRS_CODE, CRS_SCOPE, CMPD_HORIZCRS_CODE, DATA_SOURCE, REMARKS "+
				"FROM  [Coordinate Reference System] "+
				"WHERE COORD_REF_SYS_CODE = {0}";

			
			sqlQuery = String.Format(sqlQuery,code);
			IDataReader reader = Database.ExecuteQuery(_databaseConnection, sqlQuery);
			if (!reader.Read())
			{
				throw new ArgumentException(String.Format("Geographic Coordinate System with a code {0} not found in the CRS table in the EPSG database.",code));
			}

			
			string coordSysCode = reader["COORD_SYS_CODE"].ToString().ToLower();
			string coordSysName = reader["COORD_REF_SYS_NAME"].ToString();
			string name = reader["COORD_REF_SYS_NAME"].ToString();
			string verticalCRSCode = reader["CMPD_VERTCRS_CODE"].ToString();
			string horizontalCRSCode = reader["CMPD_HORIZCRS_CODE"].ToString();
			string coordRefKind = reader["COORD_REF_SYS_KIND"].ToString();
			string remarks = reader["REMARKS"].ToString();
			string datasource = reader["DATA_SOURCE"].ToString(); // should always be EPSG??


			Database.CheckOneRow(reader,code,"Copound CRS code");
			if (coordRefKind.ToLower() != "compound")
			{
				throw new ArgumentException(String.Format("CRS code {0} is not a projected coordinate system but a {1}.",code,coordRefKind));
			}
		
			ICoordinateSystem   headCRS = this.CreateCoordinateSystem( horizontalCRSCode);
			ICoordinateSystem   tailCRS = this.CreateCoordinateSystem( verticalCRSCode  );									

			ICompoundCoordinateSystem compoundCRS = new CompoundCoordinateSystem(headCRS, tailCRS, remarks, datasource, code, name,"","");
			return compoundCRS;	
		}
        private static ICompoundCoordinateSystem ReadCompoundCoordinateSystem(XmlTextReader reader)
        {
            if (!(reader.NodeType==XmlNodeType.Element &&  reader.Name=="CS_CompoundCoordinateSystem"))
            {
                throw new ParseException(String.Format(System.Globalization.CultureInfo.InvariantCulture, "Expected a ICompoundCoordinateSystem but got a {0} at line {1} col {2}",reader.Name,reader.LineNumber,reader.LinePosition));
            }
            string authority="",authorityCode="",abbreviation="",name="";
            reader.Read();
            ReadInfo(reader, ref authority,ref authorityCode, ref abbreviation, ref name);

            while (reader.NodeType==XmlNodeType.Element && reader.Name=="CS_AxisInfo")
            {
                //IAxisInfo axis = ReadAxisInfo( reader );
                //list.Add(axis);
                reader.Read();
            }
            reader.Read();
            ICoordinateSystem headCS = ReadCoordinateSystem( reader );
            reader.Read();
            reader.Read();
            reader.Read();
            ICoordinateSystem tailCS = ReadCoordinateSystem( reader );
            reader.Read();
            CompoundCoordinateSystem compoundCS = new CompoundCoordinateSystem(headCS,tailCS,"",authority, authorityCode, name, "", abbreviation);
            return compoundCS;
        }
 public void Test_Constructor2()
 {
     ICoordinateSystem headCRS = null;
     ICoordinateSystem tailCRS = _factory.CreateVerticalCoordinateSystem("5701");
     try
     {
         CompoundCoordinateSystem compoundCS = new CompoundCoordinateSystem(headCRS,
             tailCRS,
             "remarks",
             "authority",
             "code",
             "name",
             "alias",
             "abbreviation");
         Assertion.Fail("Argumentexception should be thrown.");
     }
     catch(ArgumentNullException)
     {
     }
 }
        private static ICompoundCoordinateSystem ReadCompoundCoordinateSystem(WktStreamTokenizer tokenizer)
        {
            /*
            COMPD_CS[
            "OSGB36 / British National Grid + ODN",
            PROJCS[]
            VERT_CS[]
            AUTHORITY["EPSG","7405"]
            ]*/

            //TODO add a ReadCoordinateSystem - that determines the correct coordinate system to
            //read. Right now this hard coded for a projected and a vertical coord sys - so the UK
            //national grid works.
            tokenizer.ReadToken("[");
            string name=tokenizer.ReadDoubleQuotedWord();
            tokenizer.ReadToken(",");
            tokenizer.NextToken();
            string headCSCode =  tokenizer.GetStringValue();
            ICoordinateSystem headCS = ReadCoordinateSystem(headCSCode,tokenizer);
            tokenizer.ReadToken(",");
            tokenizer.NextToken();
            string tailCSCode =  tokenizer.GetStringValue();
            ICoordinateSystem tailCS = ReadCoordinateSystem(tailCSCode,tokenizer);
            tokenizer.ReadToken(",");
            string authority="";
            string authorityCode="";
            tokenizer.ReadAuthority(ref authority, ref authorityCode);
            tokenizer.ReadToken("]");
            ICompoundCoordinateSystem compoundCS = new CompoundCoordinateSystem(headCS,tailCS,"",authority,authorityCode,name,"","");
            return compoundCS;
        }