/// <summary>
        /// Creates a horizontal coordinate system given a code.
        /// </summary>
        /// <param name="code">The EPSG code.</param>
        /// <returns>An object that implements the IHorizontalCoordinateSystem interface.</returns>
        public IHorizontalCoordinateSystem CreateHorizontalCoordinateSystem(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(System.Globalization.CultureInfo.InvariantCulture, "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 datumCode    = reader["DATUM_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, "Coordinate Reference System");
            if (coordRefKind.ToLower() != "horizontal")
            {
                throw new ArgumentException(String.Format(System.Globalization.CultureInfo.InvariantCulture, "CRS code {0} is not a horizontal coordinate system but a {1}.", code, coordRefKind));
            }
            IAxisInfo[]                axisInfos       = GetAxisInfo(coordSysCode);
            IHorizontalDatum           horizontalDatum = this.CreateHorizontalDatum(datumCode);
            HorizontalCoordinateSystem vrs             = new HorizontalCoordinateSystem(horizontalDatum, axisInfos, remarks, datasource, code, name, "", "");

            return(vrs);
        }
        public void Test_Constructor()
        {
            IEllipsoid ellipsoid = new Ellipsoid(20926348,-1.0,294.26068, true,new LinearUnit(1));
            WGS84ConversionInfo wgsInfo = new WGS84ConversionInfo();
            wgsInfo.Dx=1.0;
            HorizontalDatum horizontalDatum = new HorizontalDatum("name",DatumType.IHD_Geocentric,ellipsoid, wgsInfo);

            IAxisInfo[] axisInfos = new IAxisInfo[2];
            axisInfos[0] = AxisInfo.Latitude;
            axisInfos[1] = AxisInfo.Longitude;
            HorizontalCoordinateSystem horzCS = new HorizontalCoordinateSystem(horizontalDatum,axisInfos,"remarks","authority","code","name","alias","abbreviation");

            Assertion.AssertEquals("ctor1.","remarks",horzCS.Remarks);
            Assertion.AssertEquals("ctor2.","authority",horzCS.Authority);
            Assertion.AssertEquals("ctor3.","code",horzCS.AuthorityCode);
            Assertion.AssertEquals("ctor4.","name",horzCS.Name);
            Assertion.AssertEquals("ctor5.","alias",horzCS.Alias);
            Assertion.AssertEquals("ctor6.","abbreviation",horzCS.Abbreviation);

            Assertion.AssertEquals("test 7",horizontalDatum,horzCS.HorizontalDatum);
            //Assertion.AssertEquals("test 8",axisInfos[0],horzCS.GetAxis(0));
            //Assertion.AssertEquals("test 9",axisInfos[1],horzCS.GetAxis(1));
        }
		/// <summary>
		/// Creates a horizontal coordinate system given a code.
		/// </summary>
		/// <param name="code">The EPSG code.</param>
		/// <returns>An object that implements the IHorizontalCoordinateSystem interface.</returns>
		public IHorizontalCoordinateSystem CreateHorizontalCoordinateSystem(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 datumCode = reader["DATUM_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,"Coordinate Reference System");
			if (coordRefKind.ToLower() != "horizontal")
			{
				throw new ArgumentException(String.Format("CRS code {0} is not a horizontal coordinate system but a {1}.",code,coordRefKind));
			}
			IAxisInfo[] axisInfos = GetAxisInfo(coordSysCode);
			IHorizontalDatum horizontalDatum = this.CreateHorizontalDatum(datumCode);
			HorizontalCoordinateSystem vrs = new HorizontalCoordinateSystem(horizontalDatum, axisInfos,remarks,datasource,code,name,"","");
			return vrs;
		}