/// <summary>
		/// Uses the default database.
		/// </summary>
		/// <remarks>
		/// The default database must be placed in the working directory. An error occures if the file
		/// cannot be found. The name of the database must be 'EPSG_v61.mcb'.
		/// </remarks>
		/// <returns></returns>
		public static CoordinateTransformationEPSGFactory UseDefaultDatabase()
		{
			string connectionString = @"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=EPSG_v61.mdb";
			OleDbConnection connection = new OleDbConnection(connectionString);
			CoordinateTransformationEPSGFactory factory = new CoordinateTransformationEPSGFactory(connection);
			return factory;
		}
Exemple #2
0
        /// <summary>
        /// Uses the default database.
        /// </summary>
        /// <remarks>
        /// The default database must be placed in the working directory. An error occures if the file
        /// cannot be found. The name of the database must be 'EPSG_v61.mcb'.
        /// </remarks>
        /// <returns></returns>
        public static CoordinateTransformationEPSGFactory UseDefaultDatabase()
        {
            string          connectionString            = @"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=EPSG_v61.mdb";
            OleDbConnection connection                  = new OleDbConnection(connectionString);
            CoordinateTransformationEPSGFactory factory = new CoordinateTransformationEPSGFactory(connection);

            return(factory);
        }
		public void Test1()
		{
			IDbConnection connection = Global.GetEPSGDatabaseConnection();
			_CTfactory = new CoordinateTransformationEPSGFactory(connection);
			_UKNationalGrid1 = _CTfactory.CreateFromTransformationCode("1681");
			_geometryFactory = new GeometryFactory(_pm,4326);
			string wkt = "POINT ( -2.0 49.0 )";
			Assertion.AssertEquals("Point 1",true,Compare(wkt,"POINT (400000 -100000)"));

			wkt = "MULTIPOINT( -2 49, -1 50)";
			Assertion.AssertEquals("Multipoint 1",true,Compare(wkt,"MULTIPOINT (400000 -100000, 471660 11644)"));

			wkt = "MULTIPOINT EMPTY";
			Assertion.AssertEquals("Multipoint 2",true,Compare(wkt,"MULTIPOINT EMPTY"));

			wkt = "LINESTRING(50 31, 54 31, 54 29, 50 29, 50 31 )";
			Assertion.AssertEquals("LineString 1 1",true,Compare(wkt,"LINESTRING (5664915 -615242, 6117479 -308294, 6306392 -569639, 5827846 -873669, 5664915 -615242)"));

			wkt = "POLYGON( ( 50 31, 54 31, 54 29, 50 29, 50 31) )";
			Assertion.AssertEquals("Multipoint 3",true,Compare(wkt,"POLYGON ((5664915 -615242, 6117479 -308294, 6306392 -569639, 5827846 -873669, 5664915 -615242))"));


			//wkt = "POLYGON( ( 1 1, 10 1, 10 10, 1 10, 1 1),(4 4, 5 4, 5 5, 4 5, 4 4 ))";
			//Assertion.AssertEquals("Multipoint 4",true,Compare(wkt,"POLYGON ((733898 -5416388, 1744907 -5414055, 1724214 -4397377, 728899 -4420227, 733898 -5416388), "+
			//"(1067192 -5082521, 1178905 -5081633, 1177832 -4970278, 1066275 -4971386, 1067192 -5082521))"));

			// these tests fail because the strings are too long/ have a CR in the middle of the string. Should really fix this. awc.


			//wkt = "MULTILINESTRING (( 10.05  10.28 , 20.95  20.89 ),( 20.95  20.89, 31.92 21.45)) ";
			//Assertion.AssertEquals("Multipoint 5",false,Compare(wkt,"MULTILINESTRING ((1724213.5597264355 -4397376.6478565233, 2839122.2852214454 -3022771.8465291355), \n  "+ 
			//												"(2839122.2852214454 -3022771.8465291355, 4095081.5366646093 -2776957.6041615554))"));

			//wkt = "MULTIPOLYGON (((10 10, 10 20, 20 20, 20 15 , 10 10), (50 40, 50 50, 60 50, 60 40, 50 40)))";
			//Assertion.AssertEquals("Multipoint 6",true,Compare(wkt,"MULTIPOLYGON (((1724213.5597264355 -4397376.6478565233, 1662268.9948102259 -3270049.5581512651, 2745586.9073599684 -3156174.8212744244, 2817027.1068546474 -3744257.1145197917, 1724213.5597264355 -4397376.6478565233), "+
			//	 "(4882561.4795353347 438327.55639206013, 3970695.8611971624 1430641.0215268317, 4530976.2509158608 2096414.3039089143, 5721871.0214089518 1247465.211354611, 4882561.4795353347 438327.55639206013)))"));

			//wkt = "GEOMETRYCOLLECTION(POINT ( 3 4 ),LINESTRING(50 31, 54 31, 54 29, 50 29, 50 31 ))";
			//Assertion.AssertEquals("Multipoint 7",true,Compare(wkt,"GEOMETRYCOLLECTION (POINT (955682.872367636 -5083270.4404414054),"+
			//											"LINESTRING (-7.5557896002384908 49.766496583001434, -7.555734311078294 49.766499242352, -7.5557322582139372 49.76648133658518, -7.5557875473539609 49.7664786772363, -7.5557896002384908 49.766496583001434))"));

		}	
		public CoordinateTransformationEPSGFactoryTest() 
		{
			IDbConnection connection = Global.GetEPSGDatabaseConnection();
			_CTfactory = new CoordinateTransformationEPSGFactory(connection);
			_CRSfactory = new CoordinateSystemEPSGFactory(connection);
		}
		public void Test2()
		{
			IDbConnection connection = Global.GetEPSGDatabaseConnection();
			PrecisionModel pm = new PrecisionModel(100.0, 0.0, 0.0);
			CoordinateTransformationEPSGFactory CTfactory = new CoordinateTransformationEPSGFactory(connection);
			ICoordinateTransformation UKNationalGrid1 = CTfactory.CreateFromTransformationCode("1681");
			GeometryFactory geometryFactory = new GeometryFactory(pm,4326);

			string wkt = "POINT ( -1 50 )";
			Assertion.AssertEquals("Point 1",true,Compare2(wkt,"POINT (471659.59 11644.49)", geometryFactory, UKNationalGrid1));
			
		}
		/// <summary>
		/// Creates a projected coordinate system using the given code.
		/// </summary>
		/// <param name="code">The EPSG code.</param>
		/// <returns>A IProjectedCoordinateSystem object.</returns>
		public IProjectedCoordinateSystem CreateProjectedCoordinateSystem(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 horizontalDatumCode = reader["DATUM_CODE"].ToString();
			string geographicCRSCode = reader["SOURCE_GEOGCRS_CODE"].ToString();
			string projectionCode = reader["PROJECTION_CONV_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,"Geographic CRC code");
			if (coordRefKind.ToLower() != "projected")
			{
				throw new ArgumentException(String.Format("CRS code {0} is not a projected coordinate system but a {1}.",code,coordRefKind));
			}

			string primeMeridianCode = "";
			IPrimeMeridian primeMeridian = null;
			IHorizontalDatum horizontalDatum= null;
			if (horizontalDatumCode!="")
			{
				horizontalDatum = HorizontalDatum.WGS84;//this.CreateHorizontalDatum( horizontalDatumCode );
				primeMeridianCode = this.CreatePrimeMeridianCodeFromDatum(horizontalDatumCode);
				primeMeridian  = this.CreatePrimeMeridian( primeMeridianCode );
			}

			// we get the information for the axis 
			IAxisInfo[] axisInfos = GetAxisInfo(coordSysCode);
			
			ICoordinateTransformationAuthorityFactory factory = new CoordinateTransformationEPSGFactory(_databaseConnection);

			ICoordinateTransformation mathtransform = factory.CreateFromCoordinateSystemCodes(geographicCRSCode,"");
			string methodOperation = this.GetMethodOperationCodeFromProjectionCode( projectionCode );
			IProjection projection = this.CreateProjection(methodOperation, projectionCode);
			IGeographicCoordinateSystem geographicCoordSystem = this.CreateGeographicCoordinateSystem( geographicCRSCode );
			ILinearUnit linearUnit = LinearUnit.Meters;
			IProjectedCoordinateSystem projectedCoordSys = new ProjectedCoordinateSystem(horizontalDatum, axisInfos,geographicCoordSystem, linearUnit, projection, remarks,datasource,code,coordSysName,"","");
													
			return projectedCoordSys;
		}