Revision 13233

View differences:

trunk/libraries/libFMap/src-test/com/vividsolutions/jts/operation/overlay/SnappingOverlayOperationTest.java
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$
47
* $Log$
48
* Revision 1.1  2007-08-22 07:54:39  cesar
49
* Move tests to src-test
50
*
51
* Revision 1.2  2007/03/06 17:08:59  caballero
52
* Exceptions
53
*
54
* Revision 1.1  2006/12/04 19:30:23  azabala
55
* *** empty log message ***
56
*
57
* Revision 1.1  2006/10/19 16:06:48  azabala
58
* *** empty log message ***
59
*
60
* Revision 1.1  2006/10/17 18:25:53  azabala
61
* *** empty log message ***
62
*
63
* Revision 1.3  2006/10/10 18:50:57  azabala
64
* *** empty log message ***
65
*
66
* Revision 1.2  2006/10/09 19:10:56  azabala
67
* First version in CVS
68
*
69
* Revision 1.1  2006/10/05 19:20:57  azabala
70
* first version in cvs
71
*
72
*
73
*/
74
package com.vividsolutions.jts.operation.overlay;
75

  
76
import junit.framework.TestCase;
77

  
78
import com.vividsolutions.jts.geom.Geometry;
79
import com.vividsolutions.jts.geom.GeometryCollection;
80
import com.vividsolutions.jts.geom.GeometryFactory;
81
import com.vividsolutions.jts.geom.Polygon;
82

  
83

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

  
107
	public SnappingOverlayOperationTest(String name) {
108
		super(name);
109
	}
110

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

  
135
	protected void tearDown() throws Exception {
136
		super.tearDown();
137
		factory = null;
138
		reader = null;
139
		a = null;
140
		b = null;
141
	}
142

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

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

  
183
		
184
		
185
		
186
	}
187

  
188
}
189

  
0 190

  
trunk/libraries/libFMap/src-test/com/vividsolutions/jts/operation/JtsTests.java
1
package com.vividsolutions.jts.operation;
2

  
3

  
4
import junit.framework.Test;
5
import junit.framework.TestSuite;
6

  
7
import com.vividsolutions.jts.operation.overlay.SnappingOverlayOperationTest;
8

  
9
public class JtsTests {
10

  
11
	public static Test suite() {
12
		TestSuite suite = new TestSuite(
13
				"Test for com.iver.cit.gvsig.fmap.topology");
14
		//$JUnit-BEGIN$
15
		suite.addTestSuite(SnappingOverlayOperationTest.class);
16
		//$JUnit-END$
17
		return suite;
18
	}
19

  
20
}
21

  
0 22

  
trunk/libraries/libFMap/src/com/vividsolutions/jts/operation/JtsTests.java
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$
47
* $Log$
48
* Revision 1.2  2007-03-06 17:08:57  caballero
49
* Exceptions
50
*
51
* Revision 1.1  2006/12/04 19:30:23  azabala
52
* *** empty log message ***
53
*
54
* Revision 1.2  2006/10/19 16:06:48  azabala
55
* *** empty log message ***
56
*
57
* Revision 1.1  2006/10/17 18:25:53  azabala
58
* *** empty log message ***
59
*
60
* Revision 1.1  2006/10/05 19:20:57  azabala
61
* first version in cvs
62
*
63
*
64
*/
65
package com.vividsolutions.jts.operation;
66

  
67
import junit.framework.Test;
68
import junit.framework.TestSuite;
69

  
70
import com.vividsolutions.jts.operation.overlay.SnappingOverlayOperationTest;
71

  
72
public class JtsTests {
73

  
74
	public static Test suite() {
75
		TestSuite suite = new TestSuite(
76
				"Test for com.iver.cit.gvsig.fmap.topology");
77
		//$JUnit-BEGIN$
78
		suite.addTestSuite(SnappingOverlayOperationTest.class);
79
		//$JUnit-END$
80
		return suite;
81
	}
82

  
83
}
84

  
trunk/libraries/libFMap/src/com/vividsolutions/jts/operation/overlay/SnappingOverlayOperationTest.java
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$
47
* $Log$
48
* Revision 1.2  2007-03-06 17:08:59  caballero
49
* Exceptions
50
*
51
* Revision 1.1  2006/12/04 19:30:23  azabala
52
* *** empty log message ***
53
*
54
* Revision 1.1  2006/10/19 16:06:48  azabala
55
* *** empty log message ***
56
*
57
* Revision 1.1  2006/10/17 18:25:53  azabala
58
* *** empty log message ***
59
*
60
* Revision 1.3  2006/10/10 18:50:57  azabala
61
* *** empty log message ***
62
*
63
* Revision 1.2  2006/10/09 19:10:56  azabala
64
* First version in CVS
65
*
66
* Revision 1.1  2006/10/05 19:20:57  azabala
67
* first version in cvs
68
*
69
*
70
*/
71
package com.vividsolutions.jts.operation.overlay;
72

  
73
import junit.framework.TestCase;
74

  
75
import com.vividsolutions.jts.geom.Geometry;
76
import com.vividsolutions.jts.geom.GeometryCollection;
77
import com.vividsolutions.jts.geom.GeometryFactory;
78
import com.vividsolutions.jts.geom.Polygon;
79

  
80

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

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

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

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

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

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

  
180
		
181
		
182
		
183
	}
184

  
185
}
186

  

Also available in: Unified diff