/// <summary>
 /// Transform coordinates from one projection system to another
 /// </summary>
 /// <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 void Transform(Projection dst, double[] x, double[] y, double[] z)
 {
     Projection.Transform(this, dst, x, y, z);
 }
 /// <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>
 /// <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 and y arrays don't match</item>
 /// </list>
 /// </exception>
 public static void Transform(Projection src, Projection dst,
                              double[] x, double[] y)
 {
     Projection.Transform(src, dst, x, y, null);
 }
Пример #3
0
    static void Test_Projection_API()
    {
        Projection.SetSearchPath(new string[] {System.Environment.CurrentDirectory});

        using (
        Projection src = new Projection(@"+proj=latlong +datum=NAD27 +nadgrids=conus +nodefs"),
                    dst = new Projection(@"+proj=aea +lat_0=0 +lon_0=-120 +lat_1=34 +lat_2=40.5 +y_0=-4000000 +datum=NAD83 +nodefs"))
        {

            Console.WriteLine("src.Definition = {0}", src.Definition);
            Console.WriteLine("dst.Definition = {0}", dst.Definition);
            Console.WriteLine("src (.ToString()) = {0}", src);
            Console.WriteLine("dst (.ToString()) = {0}", dst);
            Console.WriteLine("latlong.Definition = {0}", dst.GetLatLong().Definition);
            Console.WriteLine("src.IsLatLong = {0}", src.IsLatLong);
            Console.WriteLine("dst.IsLatLong = {0}", dst.IsLatLong);
            Console.WriteLine("src.IsGeoCentric = {0}", src.IsGeoCentric);
            Console.WriteLine("dst.IsGeoCentric = {0}", dst.IsGeoCentric);
            Console.WriteLine("src.GetType() = {0}", src.GetType());

            double[] x = { -116, -117, -118, -119, -120, -121 };
            double[] y = { 34, 35, 36, 37, 38, 39 };
            double[] z = { 0, 10, 20, 30, 40, 50 };

            Console.WriteLine("Original Coordinates:");
            for (int i = 0; i < x.Length; i++)
            {
                Console.WriteLine("\t({0}, {1}, {2})", x[i], y[i], z[i]);
            }

            Console.WriteLine("Trying Projection.Transform(src, dst, x, y)");
            try
            {
                Projection.Transform(src, dst, x, y);
                Console.WriteLine("Transformed Coordinates:");
                for (int i = 0; i < x.Length; i++)
                {
                    Console.WriteLine("\t({0}, {1}, {2})", x[i], y[i], z[i]);
                }
            }
            catch (Exception e)
            {
                Console.Error.WriteLine("Exception: {0}", e.Message);
                return;
            }

            Console.WriteLine("Trying Projection.Transform(dst, src, x, y, z)");
            try
            {
                Projection.Transform(dst, src, x, y, z);
                Console.WriteLine("Original Coordinates ?");
                for (int i = 0; i < x.Length; i++)
                {
                    Console.WriteLine("\t({0}, {1}, {2})", x[i], y[i], z[i]);
                }
            }
            catch (Exception e)
            {
                Console.Error.WriteLine("Exception: {0}", e.Message);
                return;
            }

            Console.WriteLine("Trying src.Transform(dst, x, y, z)");
            try
            {
                src.Transform(dst, x, y, z);
                Console.WriteLine("Transformed Coordinates:");
                for (int i = 0; i < x.Length; i++)
                {
                    Console.WriteLine("\t({0}, {1}, {2})", x[i], y[i], z[i]);
                }
            }
            catch (Exception e)
            {
                Console.Error.WriteLine("Exception: {0}", e.Message);
                return;
            }

            Console.WriteLine("Trying dst.Transform(src, x, y)");
            try
            {
                dst.Transform(src, x, y);
                Console.WriteLine("Original Coordinates ?");
                for (int i = 0; i < x.Length; i++)
                {
                    Console.WriteLine("\t({0}, {1}, {2})", x[i], y[i], z[i]);
                }
            }
            catch (Exception e)
            {
                Console.Error.WriteLine("Exception: {0}", e.Message);
                return;
            }

        }
    }