Exemple #1
0
 public void Test_Constructor1()
 {
     ICoordinateSystemFactory csFactory = new CoordinateSystemFactory();
     IEllipsoid ellipsoid = new Ellipsoid(20926348,-1.0,294.26068,true, new LinearUnit(1));
     Assertion.AssertEquals("ctor. 2 ",20926348.0,ellipsoid.SemiMajorAxis);
     Assertion.AssertEquals("ctor. 3 ",20855233.000877455, ellipsoid.SemiMinorAxis);
 }
        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);
        }
        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 an ellipsoid given a code.
		/// </summary>
		/// <param name="code">The EPSG code.</param>
		/// <returns>An object that implements the IEllipsoid interface.</returns>
		public IEllipsoid CreateEllipsoid(string code)
		{
			if (code==null)
			{
				throw new ArgumentNullException("code");
			}
			string sqlQuery =	"SELECT "+
				"	ELLIPSOID_CODE, ELLIPSOID_NAME, SEMI_MAJOR_AXIS, UOM_CODE, "+
				"	SEMI_MINOR_AXIS, INV_FLATTENING, ELLIPSOID_SHAPE, DATA_SOURCE,  "+
				"	REMARKS "+
				"FROM Ellipsoid "+
				"WHERE ELLIPSOID_CODE={0}";

			sqlQuery = String.Format(sqlQuery, code);
			IDataReader reader = Database.ExecuteQuery(_databaseConnection, sqlQuery);
			IEllipsoid ellipsoid = null;
			bool recordFound = reader.Read();
			if (!recordFound)
			{
				throw new ArgumentOutOfRangeException(String.Format("Ellipsoid with a code of '{0}' was not found in the database.",code));
			}

			int semiMinorAxisIndex = reader.GetOrdinal("SEMI_MINOR_AXIS");
			int inverseFlatteningIndex = reader.GetOrdinal("INV_FLATTENING");
			string ellipsoidName = reader["ELLIPSOID_NAME"].ToString();
			double semiMajorAxis = (double)reader["SEMI_MAJOR_AXIS"];
			string unitsOfMearureCode = reader["UOM_CODE"].ToString();
			string datasource = reader["DATA_SOURCE"].ToString();
			bool ellipsoidShape = (bool)reader["ELLIPSOID_SHAPE"];
			string remarks = reader["REMARKS"].ToString();
			
			if (reader.IsDBNull(semiMinorAxisIndex))
			{
				double inverseFlattening = (double)reader["INV_FLATTENING"];
				Database.CheckOneRow(reader, code, "Ellipsoid");
				ILinearUnit linearUnit = CreateLinearUnit(unitsOfMearureCode);
				ellipsoid = new Ellipsoid(semiMajorAxis,0.0,inverseFlattening,true,linearUnit, remarks,datasource,code,ellipsoidName,"","");
			} 
			else if  (reader.IsDBNull(inverseFlatteningIndex))
			{
				double semiMinorAxis = (double)reader["SEMI_MINOR_AXIS"];
				Database.CheckOneRow(reader, code, "Ellipsoid");
				ILinearUnit linearUnit = CreateLinearUnit(unitsOfMearureCode);
				ellipsoid = new Ellipsoid(semiMajorAxis,semiMinorAxis, 0.0,false, linearUnit, remarks,datasource,code,ellipsoidName,"","");
			}
			return ellipsoid;
		}
 private static IEllipsoid ReadEllipsoid(XmlTextReader reader)
 {
     /*
      * <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>
                 */
     if (!(reader.NodeType==XmlNodeType.Element &&  reader.Name=="CS_Ellipsoid"))
     {
         throw new ParseException(String.Format(System.Globalization.CultureInfo.InvariantCulture, "Expected a CS_Ellipsoid but got a {0} at line {1} col {2}",reader.Name,reader.LineNumber,reader.LinePosition));
     }
     double semiMajor = XmlConvert.ToDouble(reader.GetAttribute("SemiMajorAxis"));
     double semiMinor = XmlConvert.ToDouble(reader.GetAttribute("SemiMinorAxis"));
     double inverseFlattening = XmlConvert.ToDouble(reader.GetAttribute("InverseFlattening"));
     bool ivfDefinitive=false;
     if (reader.GetAttribute("IvfDefinitive")=="1")
     {
         ivfDefinitive=true;
     }
     string authority="",authorityCode="",abbreviation="",name="";
     reader.Read();
     ReadInfo(reader, ref authority,ref authorityCode, ref abbreviation, ref name);
     //reader.Read();
     ILinearUnit linearUnit = ReadLinearUnit( reader );
     reader.Read();
     Ellipsoid ellipsoid = new Ellipsoid(semiMajor, semiMinor, inverseFlattening,ivfDefinitive,
                                         linearUnit,"",authority,authorityCode,name,"",abbreviation);
     return ellipsoid;
 }
        private static IEllipsoid ReadEllipsoid(WktStreamTokenizer tokenizer)
        {
            //SPHEROID["Airy 1830",6377563.396,299.3249646,AUTHORITY["EPSG","7001"]]
            tokenizer.ReadToken("[");
            string name=tokenizer.ReadDoubleQuotedWord();
            tokenizer.ReadToken(",");
            tokenizer.NextToken();
            double majorAxis = tokenizer.GetNumericValue();
            tokenizer.ReadToken(",");
            tokenizer.NextToken();
            double e = tokenizer.GetNumericValue();
            tokenizer.ReadToken(",");

            string authority="";
            string authorityCode="";
            tokenizer.ReadAuthority(ref authority, ref authorityCode);
            tokenizer.ReadToken("]");
            IEllipsoid ellipsoid = new Ellipsoid(majorAxis,0.0,e,true,LinearUnit.Meters,"",authority,authorityCode,name,"","");
            return ellipsoid;
        }