/// <summary>
        /// Creates a transformation between two coordinate systems. (not implemented)
        /// </summary>
        /// <remarks>
        /// This method will examine the coordinate systems in order to construct a transformation between them. This method may fail if no path between the coordinate systems is found, using the normal failing behavior of the DCP (e.g. throwing an exception).
        /// </remarks>
        /// <param name="sourceCoordinateSystem">The source coordinate system.</param>
        /// <param name="targetCoordinateSystem">The target coordinate system.</param>
        /// <returns></returns>
        public ICoordinateTransformation CreateFromCoordinateSystems(ICoordinateSystem sourceCoordinateSystem, ICoordinateSystem targetCoordinateSystem)
        {
            IProjectedCoordinateSystem  projectedCS  = null;
            IGeographicCoordinateSystem geographicCS = null;

            if (sourceCoordinateSystem is IProjectedCoordinateSystem && targetCoordinateSystem is IGeographicCoordinateSystem)
            {
                projectedCS  = (IProjectedCoordinateSystem)sourceCoordinateSystem;
                geographicCS = (IGeographicCoordinateSystem)targetCoordinateSystem;
            }
            else if (targetCoordinateSystem is IProjectedCoordinateSystem && sourceCoordinateSystem is IGeographicCoordinateSystem)
            {
                projectedCS  = (IProjectedCoordinateSystem)targetCoordinateSystem;
                geographicCS = (IGeographicCoordinateSystem)sourceCoordinateSystem;
            }
            if (projectedCS == null || geographicCS == null)
            {
                throw new InvalidOperationException("Need a geographic and a projetced coordinate reference system to make a transform.");
            }
            IMathTransform mathTransform = CreateCoordinateOperation(projectedCS.Projection, projectedCS.GeographicCoordinateSystem.HorizontalDatum.Ellipsoid);

            ICoordinateTransformation coordinateTransformation = new CoordinateTransformation(
                TransformType.Transformation,
                geographicCS,
                projectedCS,
                mathTransform,
                "",
                "",
                "",
                "",
                "", "");

            return(coordinateTransformation);
        }
예제 #2
0
        /// <summary>
        /// Creates a transformation from coordinate system codes.
        /// </summary>
        /// <param name="sourceCRSCode">EPSG code of the first coordinate reference system.</param>
        /// <param name="targetCRSCode">EPSG code of the second coordinate reference system.</param>
        /// <returns>An object that implements the ICoordinateTransformation interface.</returns>
        public ICoordinateTransformation CreateFromCoordinateSystemCodes(string sourceCRSCode, string targetCRSCode)
        {
            ICoordinateSystem sourceCRS = null;
            ICoordinateSystem targetCRS = null;

            if (sourceCRSCode != "")
            {
                sourceCRS = _coordSystemFactory.CreateCoordinateSystem(sourceCRSCode);
            }
            if (targetCRSCode != "")
            {
                targetCRS = _coordSystemFactory.CreateCoordinateSystem(targetCRSCode);
            }

            IEllipsoid     ellipsoid     = Ellipsoid.WGS84Test;
            IMathTransform mathTransform = null;

            if (sourceCRS is IProjectedCoordinateSystem)
            {
                IProjectedCoordinateSystem projectedCS = (IProjectedCoordinateSystem)sourceCRS;
                ellipsoid     = projectedCS.GeographicCoordinateSystem.HorizontalDatum.Ellipsoid;
                mathTransform = CreateCoordinateOperation(projectedCS.Projection, ellipsoid);
            }

            string areaOfUseDescription = "";
            string authority            = "";
            string code    = "";
            string remarks = "";
            string name    = "";

            ICoordinateTransformation coordinateTransformation = new CoordinateTransformation(
                TransformType.Transformation,
                targetCRS,
                sourceCRS,
                mathTransform,
                code,
                authority,
                name,
                areaOfUseDescription,
                remarks, "");

            return(coordinateTransformation);
        }
        /// <summary>
        /// Creates a transformation from a single transformation code.
        /// </summary>
        /// <remarks>
        /// The ‘Authority’ and ‘AuthorityCode’ values of the created object will be set to the authority of this object, and the code supplied by the client, respectively.  The other metadata values may or may not be set.
        /// </remarks>
        /// <param name="code">The EPSG code of the transformation to create.</param>
        /// <returns>An object that implements the ICoordinateTransformation interface.</returns>
        public ICoordinateTransformation CreateFromTransformationCode(string code)
        {
            string sqlQuery="SELECT	SOURCE_CRS_CODE, TARGET_CRS_CODE, COORD_OP_NAME, COORD_OP_SCOPE, COORD_OP_METHOD_CODE, "+
                            "		REMARKS, INFORMATION_SOURCE, DATA_SOURCE, AREA_OF_USE_CODE, COORD_OP_TYPE "+
                            "FROM	Coordinate_Operation "+
                            "WHERE COORD_OP_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, "Coord Operation code of {0} is not found.",code));
            }
            string sourceCSCode = reader["SOURCE_CRS_CODE"].ToString();
            string targetCSCode = reader["TARGET_CRS_CODE"].ToString();
            string coordOpMethod = reader["COORD_OP_METHOD_CODE"].ToString();
            string areaOfUseCode=reader["AREA_OF_USE_CODE"].ToString();
            string authority=reader["DATA_SOURCE"].ToString();
            string name=reader["COORD_OP_NAME"].ToString();
            string remarks = reader["REMARKS"].ToString();
            string coordOpType = reader["COORD_OP_TYPE"].ToString().ToLower();

            Database.CheckOneRow(reader, code, "CreateFromTransformationCode");

            string areaOfUseDescription = this.GetAreaOfUse(areaOfUseCode);

            ICoordinateSystem sourceCS = null;
            ICoordinateSystem targetCS  = null;
            IMathTransform mathTransform = null;
            if (coordOpType=="transformation")
            {
                if (sourceCSCode=="" || targetCSCode=="")
                {
                    throw new InvalidOperationException(String.Format(System.Globalization.CultureInfo.InvariantCulture, "Coordinate operation {0} which is a transformation does not have a source or target coordinate system.",code));
                }
                // create the coordinate systems. Use this helper method. The
                // helper first determines if the coordinate system is a projected or geographic coordinate system
                // and then creates the right one.
                sourceCS = _coordSystemFactory.CreateCoordinateSystem( sourceCSCode );
                targetCS = _coordSystemFactory.CreateCoordinateSystem( targetCSCode );

                // use the WGS84 ellipsoid if an ellipsoid is not defined.
                IEllipsoid ellipsoid = Ellipsoid.WGS84Test;
                if (sourceCS is IProjectedCoordinateSystem)
                {
                    IProjectedCoordinateSystem projectedCS = (IProjectedCoordinateSystem)sourceCS;
                    ellipsoid = projectedCS.GeographicCoordinateSystem.HorizontalDatum.Ellipsoid;
                    IProjection projection = projectedCS.Projection;

                    //mathTransform = CreateCoordinateOperation(code, coordOpMethod, ellipsoid);
                    mathTransform = CreateCoordinateOperation( projection, ellipsoid);
                }

            }
            else if (coordOpType=="conversion")
            {
                // not sure what to do here.
                throw new NotImplementedException("Coordinate operation 'conversion' has not been implemented.");
                // use the the WGS84 ellipsoid as a default.
                //mathTransform = CreateCoordinateOperation(code, coordOpMethod, Ellipsoid.WGS84Test);
            }
            else if (coordOpType=="concatenated operation")
            {
                throw new NotImplementedException("concatenated operation have not been implemented.");
            }

            ICoordinateTransformation coordinateTransformation = new CoordinateTransformation(
                            TransformType.Transformation,
                            targetCS,
                            sourceCS,
                            mathTransform,
                            code,
                            authority,
                            name,
                            areaOfUseDescription,
                            remarks,"");

            return coordinateTransformation;
        }
        /// <summary>
        /// Creates a transformation from coordinate system codes.
        /// </summary>
        /// <param name="sourceCRSCode">EPSG code of the first coordinate reference system.</param>
        /// <param name="targetCRSCode">EPSG code of the second coordinate reference system.</param>
        /// <returns>An object that implements the ICoordinateTransformation interface.</returns>
        public ICoordinateTransformation CreateFromCoordinateSystemCodes(string sourceCRSCode, string targetCRSCode)
        {
            ICoordinateSystem sourceCRS = null;
            ICoordinateSystem targetCRS  = null;
            if (sourceCRSCode!="")
            {
                sourceCRS = _coordSystemFactory.CreateCoordinateSystem(sourceCRSCode);
            }
            if (targetCRSCode!="")
            {
                targetCRS = _coordSystemFactory.CreateCoordinateSystem(targetCRSCode);
            }

            IEllipsoid ellipsoid = Ellipsoid.WGS84Test;
            IMathTransform mathTransform = null;
            if (sourceCRS is IProjectedCoordinateSystem)
            {
                IProjectedCoordinateSystem projectedCS = (IProjectedCoordinateSystem)sourceCRS;
                ellipsoid = projectedCS.GeographicCoordinateSystem.HorizontalDatum.Ellipsoid;
                mathTransform = CreateCoordinateOperation(projectedCS.Projection,ellipsoid);
            }

            string areaOfUseDescription="";
            string authority="";
            string code="";
            string remarks="";
            string name="";

            ICoordinateTransformation coordinateTransformation = new CoordinateTransformation(
                TransformType.Transformation,
                targetCRS,
                sourceCRS,
                mathTransform,
                code,
                authority,
                name,
                areaOfUseDescription,
                remarks,"");

            return coordinateTransformation;
        }
        /// <summary>
        /// Creates a transformation between two coordinate systems. (not implemented) 
        /// </summary>
        /// <remarks>
        /// This method will examine the coordinate systems in order to construct a transformation between them. This method may fail if no path between the coordinate systems is found, using the normal failing behavior of the DCP (e.g. throwing an exception).
        /// </remarks>
        /// <param name="sourceCoordinateSystem">The source coordinate system.</param>
        /// <param name="targetCoordinateSystem">The target coordinate system.</param>
        /// <returns></returns>
        public ICoordinateTransformation CreateFromCoordinateSystems(ICoordinateSystem sourceCoordinateSystem, ICoordinateSystem targetCoordinateSystem)
        {
            IProjectedCoordinateSystem projectedCS =  null;
            IGeographicCoordinateSystem geographicCS = null;

            if (sourceCoordinateSystem is IProjectedCoordinateSystem && targetCoordinateSystem is IGeographicCoordinateSystem)
            {
                projectedCS = (IProjectedCoordinateSystem)sourceCoordinateSystem;
                geographicCS = (IGeographicCoordinateSystem)targetCoordinateSystem;
            }
            else if (targetCoordinateSystem is IProjectedCoordinateSystem && sourceCoordinateSystem is IGeographicCoordinateSystem)
            {
                projectedCS = (IProjectedCoordinateSystem)targetCoordinateSystem;
                geographicCS = (IGeographicCoordinateSystem)sourceCoordinateSystem;
            }
            if (projectedCS==null || geographicCS==null)
            {
                throw new InvalidOperationException("Need a geographic and a projetced coordinate reference system to make a transform.");
            }
            IMathTransform mathTransform =	CreateCoordinateOperation( projectedCS.Projection, projectedCS.GeographicCoordinateSystem.HorizontalDatum.Ellipsoid);

            ICoordinateTransformation coordinateTransformation = new CoordinateTransformation(
                TransformType.Transformation,
                geographicCS,
                projectedCS,
                mathTransform,
                "",
                "",
                "",
                "",
                "","");
            return coordinateTransformation;
        }
예제 #6
0
        /// <summary>
        /// Creates a transformation from a single transformation code.
        /// </summary>
        /// <remarks>
        /// The ‘Authority’ and ‘AuthorityCode’ values of the created object will be set to the authority of this object, and the code supplied by the client, respectively.  The other metadata values may or may not be set.
        /// </remarks>
        /// <param name="code">The EPSG code of the transformation to create.</param>
        /// <returns>An object that implements the ICoordinateTransformation interface.</returns>
        public ICoordinateTransformation CreateFromTransformationCode(string code)
        {
            string sqlQuery = "SELECT	SOURCE_CRS_CODE, TARGET_CRS_CODE, COORD_OP_NAME, COORD_OP_SCOPE, COORD_OP_METHOD_CODE, "+
                              "		REMARKS, INFORMATION_SOURCE, DATA_SOURCE, AREA_OF_USE_CODE, COORD_OP_TYPE "+
                              "FROM	Coordinate_Operation " +
                              "WHERE COORD_OP_CODE={0}";

            sqlQuery = String.Format(sqlQuery, code);
            IDataReader reader = Database.ExecuteQuery(_databaseConnection, sqlQuery);

            if (!reader.Read())
            {
                throw new ArgumentException(String.Format("Coord Operation code of {0} is not found.", code));
            }
            string sourceCSCode  = reader["SOURCE_CRS_CODE"].ToString();
            string targetCSCode  = reader["TARGET_CRS_CODE"].ToString();
            string coordOpMethod = reader["COORD_OP_METHOD_CODE"].ToString();
            string areaOfUseCode = reader["AREA_OF_USE_CODE"].ToString();
            string authority     = reader["DATA_SOURCE"].ToString();
            string name          = reader["COORD_OP_NAME"].ToString();
            string remarks       = reader["REMARKS"].ToString();
            string coordOpType   = reader["COORD_OP_TYPE"].ToString().ToLower();

            Database.CheckOneRow(reader, code, "CreateFromTransformationCode");

            string areaOfUseDescription = this.GetAreaOfUse(areaOfUseCode);

            ICoordinateSystem sourceCS      = null;
            ICoordinateSystem targetCS      = null;
            IMathTransform    mathTransform = null;

            if (coordOpType == "transformation")
            {
                if (sourceCSCode == "" || targetCSCode == "")
                {
                    throw new InvalidOperationException(String.Format("Coordinate operation {0} which is a transformation does not have a source or target coordinate system.", code));
                }
                // create the coordinate systems. Use this helper method. The
                // helper first determines if the coordinate system is a projected or geographic coordinate system
                // and then creates the right one.
                sourceCS = _coordSystemFactory.CreateCoordinateSystem(sourceCSCode);
                targetCS = _coordSystemFactory.CreateCoordinateSystem(targetCSCode);

                // use the WGS84 ellipsoid if an ellipsoid is not defined.
                IEllipsoid ellipsoid = Ellipsoid.WGS84Test;
                if (sourceCS is IProjectedCoordinateSystem)
                {
                    IProjectedCoordinateSystem projectedCS = (IProjectedCoordinateSystem)sourceCS;
                    ellipsoid = projectedCS.GeographicCoordinateSystem.HorizontalDatum.Ellipsoid;
                    IProjection projection = projectedCS.Projection;

                    //mathTransform = CreateCoordinateOperation(code, coordOpMethod, ellipsoid);
                    mathTransform = CreateCoordinateOperation(projection, ellipsoid);
                }
            }
            else if (coordOpType == "conversion")
            {
                // not sure what to do here.
                throw new NotImplementedException("Coordinate operation 'conversion' has not been implemented.");
                // use the the WGS84 ellipsoid as a default.
                //mathTransform = CreateCoordinateOperation(code, coordOpMethod, Ellipsoid.WGS84Test);
            }
            else if (coordOpType == "concatenated operation")
            {
                throw new NotImplementedException("concatenated operation have not been implemented.");
            }

            ICoordinateTransformation coordinateTransformation = new CoordinateTransformation(
                TransformType.Transformation,
                targetCS,
                sourceCS,
                mathTransform,
                code,
                authority,
                name,
                areaOfUseDescription,
                remarks, "");

            return(coordinateTransformation);
        }