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

Revision 13678, 3.4 kB (checked in by tamas, 10 months ago)

Update SVN props

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
Line 
1 /******************************************************************************
2  * $Id$
3  *
4  * Name:     OGRGEOS.cs
5  * Project:  GDAL CSharp Interface
6  * Purpose:  A sample app for testing the OGR GEOS support.
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
33 using OSGeo.OGR;
34
35
36 /**
37
38  * <p>Title: OGR C# GEOS example.</p>
39  * <p>Description: A sample app for testing the OGR GEOS support.</p>
40  * @author Tamas Szekeres (szekerest@gmail.com)
41  * @version 1.0
42  */
43
44
45
46 /// <summary>
47 /// A C# based sample for testing the OGR GEOS support.
48 /// </summary>
49
50 class OGRGEOS {
51        
52         public static void Main(string[] args) {
53         Console.WriteLine("");
54
55         if (TestContains() != 0)
56             System.Environment.Exit(-1);
57         if (TestIntersect() != 0)
58             System.Environment.Exit(-1);
59         }
60
61         private static int TestContains()
62     {
63         Geometry g1 = Geometry.CreateFromWkt( "POLYGON((0 0, 10 10, 10 0, 0 0))" );
64         Geometry g2 = Geometry.CreateFromWkt("POLYGON((-90 -90, -90 90, 190 -90, -90 -90))");
65
66         bool result = g2.Contains( g1 );
67
68         if (result == false)
69         {
70             Console.WriteLine( "Contains: wrong result (got false)" );
71             return -1;
72         }
73
74         result = g1.Contains( g2 );
75
76         if (result != false)
77         {
78             Console.WriteLine( "Contains: wrong result (got false)" );
79             return -1;
80         }
81         Console.WriteLine("Contains test OK");
82         return 0;
83     }
84
85     private static int TestIntersect()
86     {
87         Geometry g1 = Geometry.CreateFromWkt("LINESTRING(0 0, 10 10)");
88         Geometry g2 = Geometry.CreateFromWkt("LINESTRING(10 0, 0 10)");
89
90         bool result = g1.Intersect(g2);
91
92         if (result == false)
93         {
94             Console.WriteLine("Intersect: wrong result (got false)");
95             return -1;
96         }
97
98         g1 = Geometry.CreateFromWkt("LINESTRING(0 0, 10 10)");
99         g2 = Geometry.CreateFromWkt("POLYGON((20 20, 20 30, 30 20, 20 20))");
100
101         result = g1.Intersect(g2);
102
103         if (result == true)
104         {
105             Console.WriteLine("Intersect: wrong result (got true)");
106             return -1;
107         }
108        
109         Console.WriteLine("Intersect test OK");
110         return 0;
111     }
112 }
Note: See TracBrowser for help on using the browser.