Beispiel #1
0
        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);
            Assertion.AssertEquals("test 1","name",horizontalDatum.Name);
            Assertion.AssertEquals("test 2",DatumType.IHD_Geocentric,horizontalDatum.DatumType);
            Assertion.AssertEquals("test 3",ellipsoid,horizontalDatum.Ellipsoid);
            Assertion.AssertEquals("test 4",wgsInfo,horizontalDatum.WGS84Parameters);
        }
        /// <summary>
        /// Creates a horizontal datum from a code.
        /// </summary>
        /// <param name="code">The EPSG code.</param>
        /// <returns>An object that implements the IHorizontalDatum interface.</returns>
        public IHorizontalDatum CreateHorizontalDatum(string code)
        {
            if (code == null)
            {
                throw new ArgumentNullException("code");
            }

            string sqlQuery = "SELECT DATUM_NAME, DATUM_CODE, DATUM_TYPE, ORIGIN_DESCRIPTION, " +
                              "REALIZATION_EPOCH, ELLIPSOID_CODE, PRIME_MERIDIAN_CODE, " +
                              "AREA_OF_USE_CODE, DATUM_SCOPE, REMARKS, DATA_SOURCE, INFORMATION_SOURCE " +
                              "FROM  Datum " +
                              "WHERE DATUM_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("Could not find datum {0}.", code));
            }
            ;
            string datumtype         = reader["DATUM_TYPE"].ToString();
            string ellipsoidCode     = reader["ELLIPSOID_CODE"].ToString();
            string primeMeridianCode = reader["PRIME_MERIDIAN_CODE"].ToString();
            string name       = reader["DATUM_NAME"].ToString();
            string remarks    = reader["REMARKS"].ToString();
            string datasource = reader["DATA_SOURCE"].ToString();            // should always be EPSG?

            Database.CheckOneRow(reader, code, "Horizontal Datum");


            //TODO: need to populate wgsConversionInfo with the right parameters.
            WGS84ConversionInfo wgsConversionInfo = new WGS84ConversionInfo();
            IEllipsoid          ellipsoid         = this.CreateEllipsoid(ellipsoidCode);
            IHorizontalDatum    horizontalDatum   = new HorizontalDatum(name, DatumType.IHD_Geocentric, ellipsoid, wgsConversionInfo, remarks, datasource, code, "", "");

            return(horizontalDatum);
        }
        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 datum from a code.
		/// </summary>
		/// <param name="code">The EPSG code.</param>
		/// <returns>An object that implements the IHorizontalDatum interface.</returns>
		public IHorizontalDatum CreateHorizontalDatum(string code)
		{
			if (code==null)
			{
				throw new ArgumentNullException("code");
			}
			
			string sqlQuery =	"SELECT DATUM_NAME, DATUM_CODE, DATUM_TYPE, ORIGIN_DESCRIPTION, "+ 
				"REALIZATION_EPOCH, ELLIPSOID_CODE, PRIME_MERIDIAN_CODE, "+
				"AREA_OF_USE_CODE, DATUM_SCOPE, REMARKS, DATA_SOURCE, INFORMATION_SOURCE "+
				"FROM  Datum "+
				"WHERE DATUM_CODE={0}";

			sqlQuery = String.Format(sqlQuery,code);
			IDataReader reader = Database.ExecuteQuery(_databaseConnection, sqlQuery);
			if (!reader.Read())
			{
				throw new ArgumentException(String.Format("Could not find datum {0}.",code));
			};
			string datumtype= reader["DATUM_TYPE"].ToString();			
			string ellipsoidCode = reader["ELLIPSOID_CODE"].ToString();
			string primeMeridianCode = reader["PRIME_MERIDIAN_CODE"].ToString();
			string name = reader["DATUM_NAME"].ToString();
			string remarks = reader["REMARKS"].ToString();
			string datasource = reader["DATA_SOURCE"].ToString();// should always be EPSG?

			Database.CheckOneRow(reader, code, "Horizontal Datum");


			//TODO: need to populate wgsConversionInfo with the right parameters. 
			WGS84ConversionInfo wgsConversionInfo = new WGS84ConversionInfo();
			IEllipsoid ellipsoid = this.CreateEllipsoid( ellipsoidCode );
			IHorizontalDatum horizontalDatum = new HorizontalDatum(name, DatumType.IHD_Geocentric, ellipsoid, wgsConversionInfo,remarks,datasource,code,"","");
			return horizontalDatum;
		}
        private static IHorizontalDatum ReadHorizontalDatum(XmlTextReader reader)
        {
            if (!(reader.NodeType==XmlNodeType.Element &&  reader.Name=="CS_HorizontalDatum"))
            {
                throw new ParseException(String.Format(System.Globalization.CultureInfo.InvariantCulture, "Expected a IHorizontalDatum but got a {0} at line {1} col {2}",reader.Name,reader.LineNumber,reader.LinePosition));
            }

            /* <IHorizontalDatum DatumType="1001">
                <IInfo AuthorityCode="6277" Authority="EPSG" Name="OSGB_1936"/>
                <IEllipsoid SemiMajorAxis="6377563.396" SemiMinorAxis="6356256.90923729" InverseFlattening="299.3249646" IvfDefinitive="1">
                    <IInfo AuthorityCode="7001" Authority="EPSG" Name="Airy 1830"/>
                    <ILinearUnit MetersPerUnit="1">
                        <IInfo AuthorityCode="9001" Abbreviation="m" Authority="EPSG" Name="metre"/>
                    </ILinearUnit>
                </IEllipsoid>
                <IWGS84ConversionInfo Dx="375" Dy="-111" Dz="431" Ex="0" Ey="0" Ez="0" Ppm="0"/>
            </IHorizontalDatum>
                    */
            string datumTypeString = reader.GetAttribute("DatumType");
            DatumType datumType = (DatumType)Enum.Parse(typeof(DatumType),datumTypeString,true);
            string authority="",authorityCode="",abbreviation="",name="";
            reader.Read();
            ReadInfo(reader, ref authority,ref authorityCode, ref abbreviation, ref name);
            IEllipsoid ellipsoid = ReadEllipsoid( reader );
            WGS84ConversionInfo wgs84info = ReadWGS84ConversionInfo( reader );
            reader.Read();
            HorizontalDatum horizontalDatum = new HorizontalDatum(name,datumType,ellipsoid, wgs84info,"",authority,authorityCode,"",abbreviation);
            return horizontalDatum;
        }
        private static IHorizontalDatum ReadHorizontalDatum(WktStreamTokenizer tokenizer)
        {
            //DATUM["OSGB 1936",SPHEROID["Airy 1830",6377563.396,299.3249646,AUTHORITY["EPSG","7001"]]TOWGS84[0,0,0,0,0,0,0],AUTHORITY["EPSG","6277"]]

            tokenizer.ReadToken("[");
            string name=tokenizer.ReadDoubleQuotedWord();
            tokenizer.ReadToken(",");
            tokenizer.ReadToken("SPHEROID");
            IEllipsoid ellipsoid = ReadEllipsoid(tokenizer);
            tokenizer.ReadToken("TOWGS84");
            WGS84ConversionInfo wgsInfo = ReadWGS84ConversionInfo(tokenizer);
            tokenizer.ReadToken(",");
            string authority="";
            string authorityCode="";
            tokenizer.ReadAuthority(ref authority, ref authorityCode);
            // make an assumption about the datum type.
            DatumType datumType = DatumType.IHD_Geocentric;
            IHorizontalDatum horizontalDatum = new HorizontalDatum(name,datumType,ellipsoid, wgsInfo,"",authority,authorityCode,"","");
            tokenizer.ReadToken("]");
            return horizontalDatum;
        }