Пример #1
0
        /// <summary>
        /// Transform coordinates from one projection system to another
        /// </summary>
        /// <param name="src">The source projection</param>
        /// <param name="dst">The destination projection</param>
        /// <param name="x">The "X" coordinate values.</param>
        /// <param name="y">The "Y" coordinate values.</param>
        /// <param name="z">The "Z" coordinate values.</param>
        /// <exception cref="System.ApplicationException">Thrown when the projection is
        /// not initialized or the transformation failed.  The message will indicate the error.
        /// </exception>
        /// <exception cref="System.ArgumentException">
        /// May be thrown for any of the following reasons:
        /// <list type="bullet">
        /// <item>The "x" array is null</item>
        /// <item>The "y" array is null</item>
        /// <item>The length of the x, y and z (if not null) arrays don't match</item>
        /// </list>
        /// </exception>
        public static void Transform(Projection src, Projection dst,
                                     double[] x, double[] y, double[] z)
        {
            Projection.CheckInitialized(src);
            Projection.CheckInitialized(dst);

            if (x == null)
            {
                throw new ArgumentException("Argument is required", "x");
            }
            if (y == null)
            {
                throw new ArgumentException("Argument is required", "y");
            }
            if (x.Length != y.Length || (z != null && z.Length != x.Length))
            {
                throw new ArgumentException("Coordinate arrays must have the same length");
            }
            if (src.IsLatLong)
            {
                for (int i = 0; i < x.Length; i++)
                {
                    x[i] *= Proj.DEG_TO_RAD;
                    y[i] *= Proj.DEG_TO_RAD;
                }
            }
            int result = Proj.pj_transform(src.prj, dst.prj, x.Length, 1, x, y, z);

            if (result != 0)
            {
                string message = "Tranformation Error";
                int    errno   = GetErrNo();
                if (errno != 0)
                {
                    message = Projection.GetErrorMessage(errno);
                }
                throw new ApplicationException(message);
            }
            if (dst.IsLatLong)
            {
                for (int i = 0; i < x.Length; i++)
                {
                    x[i] *= Proj.RAD_TO_DEG;
                    y[i] *= Proj.RAD_TO_DEG;
                }
            }
        }
 /// <summary>
 /// Instance version checks initialization status.
 /// </summary>
 private void CheckInitialized()
 {
     Projection.CheckInitialized(this);
 }