Esempio n. 1
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);
        }