Statistics
| Revision:

svn-gvsig-desktop / trunk / libraries / libFMap / src / com / vividsolutions / jts / operation / overlay / SnappingOverlayOperationTest.java @ 9178

History | View | Annotate | Download (5.09 KB)

1
/*
2
 * Created on 03-oct-2006
3
 *
4
 * gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
5
 *
6
 * Copyright (C) 2004 IVER T.I. and Generalitat Valenciana.
7
 *
8
 * This program is free software; you can redistribute it and/or
9
 * modify it under the terms of the GNU General Public License
10
 * as published by the Free Software Foundation; either version 2
11
 * of the License, or (at your option) any later version.
12
 *
13
 * This program is distributed in the hope that it will be useful,
14
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16
 * GNU General Public License for more details.
17
 *
18
 * You should have received a copy of the GNU General Public License
19
 * along with this program; if not, write to the Free Software
20
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307,USA.
21
 *
22
 * For more information, contact:
23
 *
24
 *  Generalitat Valenciana
25
 *   Conselleria d'Infraestructures i Transport
26
 *   Av. Blasco Ib??ez, 50
27
 *   46010 VALENCIA
28
 *   SPAIN
29
 *
30
 *      +34 963862235
31
 *   gvsig@gva.es
32
 *      www.gvsig.gva.es
33
 *
34
 *    or
35
 *
36
 *   IVER T.I. S.A
37
 *   Salamanca 50
38
 *   46005 Valencia
39
 *   Spain
40
 *
41
 *   +34 963163400
42
 *   dac@iver.es
43
 */
44
/* CVS MESSAGES:
45
*
46
* $Id: SnappingOverlayOperationTest.java 9178 2006-12-04 19:30:23Z azabala $
47
* $Log$
48
* Revision 1.1  2006-12-04 19:30:23  azabala
49
* *** empty log message ***
50
*
51
* Revision 1.1  2006/10/19 16:06:48  azabala
52
* *** empty log message ***
53
*
54
* Revision 1.1  2006/10/17 18:25:53  azabala
55
* *** empty log message ***
56
*
57
* Revision 1.3  2006/10/10 18:50:57  azabala
58
* *** empty log message ***
59
*
60
* Revision 1.2  2006/10/09 19:10:56  azabala
61
* First version in CVS
62
*
63
* Revision 1.1  2006/10/05 19:20:57  azabala
64
* first version in cvs
65
*
66
*
67
*/
68
package com.vividsolutions.jts.operation.overlay;
69

    
70
import junit.framework.TestCase;
71

    
72
import com.vividsolutions.jts.geom.Coordinate;
73
import com.vividsolutions.jts.geom.Geometry;
74
import com.vividsolutions.jts.geom.GeometryCollection;
75
import com.vividsolutions.jts.geom.GeometryFactory;
76
import com.vividsolutions.jts.geom.Polygon;
77
import com.vividsolutions.jts.operation.overlay.OverlayOp;
78

    
79

    
80
public class SnappingOverlayOperationTest extends TestCase {
81
        
82
        //test 1
83
        Geometry a,b;
84
        GeometryFactory factory ;
85
        com.vividsolutions.jts.io.WKTReader reader;
86
        
87
        //test 2
88
        Geometry c,d;
89
        
90
        //test 4
91
        Geometry f;
92
        
93
        //test 5
94
        Geometry g, h;
95
        
96
        
97
        //test 6
98
        Geometry pol1, pol2;
99
        
100
        public static void main(String[] args) {
101
        }
102

    
103
        public SnappingOverlayOperationTest(String name) {
104
                super(name);
105
        }
106

    
107
        
108
        protected void setUp() throws Exception {
109
                super.setUp();
110
                factory = new GeometryFactory();
111
                reader = new com.vividsolutions.jts.io.WKTReader(factory);
112
                a = reader.read("LINESTRING(0.001 0.001, 5.001 5.001)");
113
                b = reader.read("LINESTRING(2.1 -3, 0.0 -0.001, -2.22 4.88, 10.0 10.0, 5.002 5.002)");
114
                
115
                c = reader.read("LINESTRING(0 0, 5 0, 10 0.001)");
116
                d = reader.read("LINESTRING(0 0.01, 5 0.002, 10 0.002)");
117
                
118
                f = reader.read("LINESTRING(0 0.11, 5 0.12, 10 0.14)");
119
                
120
                
121
                g = reader.read("LINESTRING(1 0, 3 2)");
122
                h = reader.read("LINESTRING(3.05 2.01, 5 1.25, 0.25 1.75)");
123
                
124
                
125
                pol1 = reader.read("POLYGON((0 0, -5 0, -10 5, 0 10,  10 5, 5 0, 0 0))");
126
                pol2 = reader.read("POLYGON((10.01 0, 5 5, 5 10, 10 10, 10.01 0))");
127
        }
128
        
129
                
130

    
131
        protected void tearDown() throws Exception {
132
                super.tearDown();
133
                factory = null;
134
                reader = null;
135
                a = null;
136
                b = null;
137
        }
138

    
139
        /*
140
         * Test method for 'com.iver.cit.gvsig.fmap.topology.SnappingOverlayOperation.SnappingOverlayOperation(Geometry, Geometry, double)'
141
         */
142
        public void testSnappingOverlayOperation() {
143
                //test 1: dos lineas que intersectan en dos puntos: uno Nodo y otro vertice
144
                Geometry geom = SnappingOverlayOperation.overlayOp(a, b, 
145
                                                                        OverlayOp.INTERSECTION, 0.01);
146
                assertTrue(geom.toString().equals("MULTIPOINT (0.001 0.001, 5.001 5.001)"));
147
                
148
                //test 2: dos lineas paralelas separadas por una distancia inferior a la
149
                //de snap
150
                geom = SnappingOverlayOperation.overlayOp(c, d, 
151
                                OverlayOp.INTERSECTION, 0.1);
152

    
153
                assertTrue(geom.toString().equals("MULTILINESTRING ((0 0, 5 0), (5 0, 10 0.001))"));
154
                
155
                //test 3: identicas l?neas pero reducimos la distancia de snap
156
                geom = SnappingOverlayOperation.overlayOp(c, d, 
157
                                OverlayOp.INTERSECTION, 0.0001);
158
                assertTrue(geom.toString().equals("GEOMETRYCOLLECTION EMPTY"));
159
                
160
                //test 4: identicas l?neas, pero se separan un poco mas
161
                geom = SnappingOverlayOperation.overlayOp(c, f, OverlayOp.INTERSECTION, 0.1);
162
                assertTrue(geom.toString().equals("GEOMETRYCOLLECTION EMPTY"));
163
                
164
                
165
                //test 5: interseccion de dos lineas, la solucion son dos puntos:
166
                //uno con snap y el otro normal. Presentan cambios de orientacion
167
                geom = SnappingOverlayOperation.overlayOp(g, h, OverlayOp.INTERSECTION, 0.1);
168
                assertTrue(geom instanceof GeometryCollection);
169
                assertTrue(geom.toString().equals("MULTIPOINT (2.511904761904762 1.5119047619047619, 3 2)"));
170
                
171
                geom = SnappingOverlayOperation.overlayOp(pol1, 
172
                                                                                                  pol2, 
173
                                                                                        OverlayOp.INTERSECTION, 
174
                                                                                        0.01);
175
                assertTrue(geom instanceof Polygon);
176
                assertTrue(geom.toString().equals("POLYGON ((5 7.5, 10 5, 7.502497502497502 2.5024975024975022, 5 5, 5 7.5))"));
177
                
178

    
179
                
180
                
181
                
182
        }
183

    
184
}
185