root/trunk/gdal/swig/csharp/apps/OSRTransform.cs

Revision 13437, 3.3 kB (checked in by tamas, 1 year ago)

Added standardized copyright headers

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
Line 
1 /******************************************************************************
2  * $Id$
3  *
4  * Name:     OSRTransform.cs
5  * Project:  GDAL CSharp Interface
6  * Purpose:  A sample app to make coordinate transformations.
7  * Author:   Tamas Szekeres, szekerest@gmail.com
8  *
9  ******************************************************************************
10  * Copyright (c) 2007, Tamas Szekeres
11  *
12  * Permission is hereby granted, free of charge, to any person obtaining a
13  * copy of this software and associated documentation files (the "Software"),
14  * to deal in the Software without restriction, including without limitation
15  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
16  * and/or sell copies of the Software, and to permit persons to whom the
17  * Software is furnished to do so, subject to the following conditions:
18  *
19  * The above copyright notice and this permission notice shall be included
20  * in all copies or substantial portions of the Software.
21  *
22  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
23  * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
24  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
25  * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
26  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
27  * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
28  * DEALINGS IN THE SOFTWARE.
29  *****************************************************************************/
30
31 using System;
32 using OSGeo.OSR;
33
34 /**
35  * <p>Title: GDAL C# OSRTransform example.</p>
36  * <p>Description: A sample app to make coordinate transformations.</p>
37  * @author Tamas Szekeres (szekerest@gmail.com)
38  * @version 1.0
39  */
40
41 /// <summary>
42 /// A C# based sample to make simple transformations.
43 /// </summary>
44 class OSRTransform {
45         public static void Main(string[] args) {
46                 try
47                 {
48                         /* -------------------------------------------------------------------- */
49                         /*      Initialize srs                                                  */
50                         /* -------------------------------------------------------------------- */
51                         SpatialReference src = new SpatialReference("");
52                         src.ImportFromProj4("+proj=latlong +datum=WGS84 +no_defs");
53                         Console.WriteLine( "SOURCE IsGeographic:" + src.IsGeographic() + " IsProjected:" + src.IsProjected() );
54                         SpatialReference dst = new SpatialReference("");
55                         dst.ImportFromProj4("+proj=somerc +lat_0=47.14439372222222 +lon_0=19.04857177777778 +x_0=650000 +y_0=200000 +ellps=GRS67 +units=m +no_defs");
56                         Console.WriteLine( "DEST IsGeographic:" + dst.IsGeographic() + " IsProjected:" + dst.IsProjected() );
57                         /* -------------------------------------------------------------------- */
58                         /*      making the transform                                            */
59                         /* -------------------------------------------------------------------- */
60                         CoordinateTransformation ct = new CoordinateTransformation(src, dst);
61                         double[] p = new double[3];
62                         p[0] = 19; p[1] = 47; p[2] = 0;
63                         ct.TransformPoint(p);
64                         Console.WriteLine("x:" + p[0] + " y:" + p[1] + " z:" + p[2]);
65                         ct.TransformPoint(p, 19.2, 47.5, 0);
66                         Console.WriteLine("x:" + p[0] + " y:" + p[1] + " z:" + p[2]);
67                 }
68                 catch (Exception e)
69                 {
70                         Console.WriteLine("Error occurred: " + e.Message);
71                         System.Environment.Exit(-1);
72                 }
73         }
74 }
Note: See TracBrowser for help on using the browser.