/// <summary> /// Creates a projected coordinate system using a projection object. /// </summary> /// <param name="name">The name of the projected coordinate system.</param> /// <param name="geographicCoordinateSystem">The geographic coordinate system to base this coordinate system on.</param> /// <param name="projection">The projection details.</param> /// <param name="linearUnit">The linear units to use.</param> /// <param name="axis0">The X axis.</param> /// <param name="axis1">The Y aixs.</param> /// <returns>An object the implements the IProjectedCoordinateSystem interface.</returns> public IProjectedCoordinateSystem CreateProjectedCoordinateSystem(string name, IGeographicCoordinateSystem geographicCoordinateSystem, IProjection projection, ILinearUnit linearUnit, IAxisInfo axis0, IAxisInfo axis1) { if (name == null) { throw new ArgumentNullException("name"); } if (geographicCoordinateSystem == null) { throw new ArgumentNullException("geographicCoordinateSystem"); } if (projection == null) { throw new ArgumentNullException("projection"); } if (linearUnit == null) { throw new ArgumentNullException("linearUnit"); } IAxisInfo[] axisInfo = new IAxisInfo[2]; axisInfo[0] = axis0; axisInfo[1] = axis1; ProjectedCoordinateSystem projectedCS = new ProjectedCoordinateSystem(null, axisInfo, geographicCoordinateSystem, linearUnit, projection); return(projectedCS); }
/// <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(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 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(System.Globalization.CultureInfo.InvariantCulture, "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); }
/// <summary> /// Creates a projected coordinate system using a projection object. /// </summary> /// <param name="name">The name of the projected coordinate system.</param> /// <param name="geographicCoordinateSystem">The geographic coordinate system to base this coordinate system on.</param> /// <param name="projection">The projection details.</param> /// <param name="linearUnit">The linear units to use.</param> /// <param name="axis0">The X axis.</param> /// <param name="axis1">The Y aixs.</param> /// <returns>An object the implements the IProjectedCoordinateSystem interface.</returns> public IProjectedCoordinateSystem CreateProjectedCoordinateSystem(string name, IGeographicCoordinateSystem geographicCoordinateSystem, IProjection projection, ILinearUnit linearUnit, IAxisInfo axis0, IAxisInfo axis1) { if (name==null) { throw new ArgumentNullException("name"); } if (geographicCoordinateSystem==null) { throw new ArgumentNullException("geographicCoordinateSystem"); } if (projection==null) { throw new ArgumentNullException("projection"); } if (linearUnit==null) { throw new ArgumentNullException("linearUnit"); } IAxisInfo[] axisInfo = new IAxisInfo[2]; axisInfo[0]=axis0; axisInfo[1]=axis1; ProjectedCoordinateSystem projectedCS = new ProjectedCoordinateSystem(null,axisInfo,geographicCoordinateSystem,linearUnit, projection); return projectedCS; }
/// <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; }
private static IProjectedCoordinateSystem ReadProjectedCoordinateSystem(XmlTextReader reader) { if (!(reader.NodeType==XmlNodeType.Element && reader.Name=="CS_ProjectedCoordinateSystem")) { throw new ParseException(String.Format(System.Globalization.CultureInfo.InvariantCulture, "Expected a IProjectedCoordinateSystem 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); ArrayList list = new ArrayList(); while (reader.NodeType==XmlNodeType.Element && reader.Name=="CS_AxisInfo") { IAxisInfo axis = ReadAxisInfo( reader ); list.Add(axis); reader.Read(); } IAxisInfo[] axisInfos = new IAxisInfo[list.Count]; axisInfos = (IAxisInfo[])list.ToArray(typeof(IAxisInfo)); IGeographicCoordinateSystem geographicCoordinateSystem = ReadGeographicCoordinateSystem( reader ); ILinearUnit linearUnit = ReadLinearUnit( reader ); IProjection projection = ReadProjection( reader ); reader.Read(); //IPrimeMeridian primeMeridian = null; IHorizontalDatum horizontalDatum = null; ProjectedCoordinateSystem projectedCS = new ProjectedCoordinateSystem(horizontalDatum, axisInfos,geographicCoordinateSystem,linearUnit, projection,"",authority,authorityCode, name,"",abbreviation); return projectedCS; }
private static IProjectedCoordinateSystem ReadProjectedCoordinateSystem(WktStreamTokenizer tokenizer) { /* PROJCS[ "OSGB 1936 / British National Grid", GEOGCS[ "OSGB 1936", DATUM[...] PRIMEM[...] AXIS["Geodetic latitude","NORTH"] AXIS["Geodetic longitude","EAST"] AUTHORITY["EPSG","4277"] ], PROJECTION["Transverse Mercator"], PARAMETER["latitude_of_natural_origin",49], PARAMETER["longitude_of_natural_origin",-2], PARAMETER["scale_factor_at_natural_origin",0.999601272], PARAMETER["false_easting",400000], PARAMETER["false_northing",-100000], AXIS["Easting","EAST"], AXIS["Northing","NORTH"], AUTHORITY["EPSG","27700"] ] */ tokenizer.ReadToken("["); string name=tokenizer.ReadDoubleQuotedWord(); tokenizer.ReadToken(","); tokenizer.ReadToken("GEOGCS"); IGeographicCoordinateSystem geographicCS = ReadGeographicCoordinateSystem(tokenizer); tokenizer.ReadToken(","); IProjection projection = ReadProjection(tokenizer); IAxisInfo axis0 = ReadAxisInfo(tokenizer); tokenizer.ReadToken(","); tokenizer.ReadToken("AXIS"); IAxisInfo axis1 = ReadAxisInfo(tokenizer); tokenizer.ReadToken(","); string authority=""; string authorityCode=""; tokenizer.ReadAuthority(ref authority, ref authorityCode); tokenizer.ReadToken("]"); IAxisInfo[] axisArray = new IAxisInfo[2]; axisArray[0]=axis0; axisArray[1]=axis1; ILinearUnit linearUnit = LinearUnit.Meters; IProjectedCoordinateSystem projectedCS = new ProjectedCoordinateSystem(null,axisArray,geographicCS,linearUnit, projection,"",authority,authorityCode,name,"",""); return projectedCS; }