|
12 | 12 | *****************************************************************************/ |
13 | 13 |
|
14 | 14 | using System; |
| 15 | +using System.Linq; |
15 | 16 | using OSGeo.OSR; |
16 | 17 |
|
17 | 18 | /** |
|
25 | 26 | /// A C# based sample to make simple transformations. |
26 | 27 | /// </summary> |
27 | 28 | class OSRTransform { |
28 | | - public static void Main(string[] args) { |
29 | | - try |
30 | | - { |
31 | | - /* -------------------------------------------------------------------- */ |
32 | | - /* Initialize srs */ |
33 | | - /* -------------------------------------------------------------------- */ |
34 | | - SpatialReference src = new SpatialReference(""); |
35 | | - src.ImportFromProj4("+proj=latlong +datum=WGS84 +no_defs"); |
36 | | - Console.WriteLine( "SOURCE IsGeographic:" + src.IsGeographic() + " IsProjected:" + src.IsProjected() ); |
37 | | - SpatialReference dst = new SpatialReference(""); |
38 | | - dst.ImportFromProj4("+proj=somerc +lat_0=47.14439372222222 +lon_0=19.04857177777778 +x_0=650000 +y_0=200000 +ellps=GRS67 +units=m +no_defs"); |
39 | | - Console.WriteLine( "DEST IsGeographic:" + dst.IsGeographic() + " IsProjected:" + dst.IsProjected() ); |
40 | | - /* -------------------------------------------------------------------- */ |
41 | | - /* making the transform */ |
42 | | - /* -------------------------------------------------------------------- */ |
43 | | - CoordinateTransformation ct = new CoordinateTransformation(src, dst); |
44 | | - double[] p = new double[3]; |
45 | | - p[0] = 19; p[1] = 47; p[2] = 0; |
46 | | - ct.TransformPoint(p); |
47 | | - Console.WriteLine("x:" + p[0] + " y:" + p[1] + " z:" + p[2]); |
48 | | - ct.TransformPoint(p, 19.2, 47.5, 0); |
49 | | - Console.WriteLine("x:" + p[0] + " y:" + p[1] + " z:" + p[2]); |
50 | | - } |
51 | | - catch (Exception e) |
52 | | - { |
53 | | - Console.WriteLine("Error occurred: " + e.Message); |
54 | | - System.Environment.Exit(-1); |
55 | | - } |
56 | | - } |
| 29 | + public static void Main(string[] args) { |
| 30 | + try |
| 31 | + { |
| 32 | + /* -------------------------------------------------------------------- */ |
| 33 | + /* Initialize srs */ |
| 34 | + /* -------------------------------------------------------------------- */ |
| 35 | + int nvalues; |
| 36 | + int[] confidence_values; |
| 37 | + SpatialReference src = new SpatialReference(""); |
| 38 | + src.ImportFromProj4("+proj=latlong +datum=WGS84 +no_defs"); |
| 39 | + var srName = src.FindMatches(new string[] { "", null }, out nvalues, out confidence_values).FirstOrDefault()?.GetName() ?? "NotFound"; |
| 40 | + Console.WriteLine($"SOURCE Name:'{srName}' IsGeographic:{src. IsGeographic ()} IsProjected:{src.IsProjected()}"); |
| 41 | + SpatialReference dst = new SpatialReference(""); |
| 42 | + dst.ImportFromProj4("+proj=somerc +lat_0=47.14439372222222 +lon_0=19.04857177777778 +x_0=650000 +y_0=200000 +ellps=GRS67 +units=m +no_defs"); |
| 43 | + srName = dst.FindMatches(new string[] { "", null }, out nvalues, out confidence_values).FirstOrDefault()?.GetName() ?? "NotFound"; |
| 44 | + Console.WriteLine($"DEST Name:'{srName}' IsGeographic:{dst.IsGeographic()} IsProjected:{dst.IsProjected()}"); |
| 45 | + /* -------------------------------------------------------------------- */ |
| 46 | + /* making the transform */ |
| 47 | + /* -------------------------------------------------------------------- */ |
| 48 | + CoordinateTransformation ct = new CoordinateTransformation(src, dst); |
| 49 | + double[] p = new double[3]; |
| 50 | + p[0] = 19; p[1] = 47; p[2] = 0; |
| 51 | + ct.TransformPoint(p); |
| 52 | + Console.WriteLine("x:" + p[0] + " y:" + p[1] + " z:" + p[2]); |
| 53 | + ct.TransformPoint(p, 19.2, 47.5, 0); |
| 54 | + Console.WriteLine("x:" + p[0] + " y:" + p[1] + " z:" + p[2]); |
| 55 | + } |
| 56 | + catch (Exception e) |
| 57 | + { |
| 58 | + Console.WriteLine("Error occurred: " + e.Message); |
| 59 | + System.Environment.Exit(-1); |
| 60 | + } |
| 61 | + } |
57 | 62 | } |
0 commit comments