Revision 20138

View differences:

trunk/libraries/libTopology/src-test/org/gvsig/topology/errorfixes/RemovePseudoNodeFixTest.java
1
/*
2
 * Created on 10-abr-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
*/
49
package org.gvsig.topology.errorfixes;
50

  
51
import java.util.ArrayList;
52
import java.util.List;
53

  
54
import junit.framework.TestCase;
55

  
56
import org.gvsig.exceptions.BaseException;
57
import org.gvsig.topology.SimpleTopologyErrorContainer;
58
import org.gvsig.topology.Topology;
59
import org.gvsig.topology.TopologyError;
60
import org.gvsig.topology.topologyrules.LinesMustNotHavePseudonodes;
61

  
62
import com.hardcode.gdbms.engine.values.Value;
63
import com.hardcode.gdbms.engine.values.ValueFactory;
64
import com.iver.cit.gvsig.fmap.core.DefaultFeature;
65
import com.iver.cit.gvsig.fmap.core.FGeometry;
66
import com.iver.cit.gvsig.fmap.core.FShape;
67
import com.iver.cit.gvsig.fmap.core.IFeature;
68
import com.iver.cit.gvsig.fmap.core.IGeometry;
69
import com.iver.cit.gvsig.fmap.core.ShapeFactory;
70
import com.iver.cit.gvsig.fmap.core.v02.FConverter;
71
import com.iver.cit.gvsig.fmap.drivers.FeatureCollectionMemoryDriver;
72
import com.iver.cit.gvsig.fmap.drivers.FieldDescription;
73
import com.iver.cit.gvsig.fmap.drivers.LayerDefinition;
74
import com.iver.cit.gvsig.fmap.layers.FLyrVect;
75
import com.vividsolutions.jts.geom.Geometry;
76
import com.vividsolutions.jts.geom.GeometryFactory;
77
import com.vividsolutions.jts.io.ParseException;
78
import com.vividsolutions.jts.io.WKTReader;
79

  
80
/**
81
 * Test for remove pseudonode fix.
82
 * @author Alvaro Zabala
83
 *
84
 */
85
public class RemovePseudoNodeFixTest extends TestCase {
86
	GeometryFactory factory = new GeometryFactory();
87
	WKTReader wktReader = new WKTReader(factory);
88
	
89
	
90
	public void tearDown() throws Exception{
91
		super.tearDown();
92
		factory = null;
93
		wktReader = null;
94
		System.gc();
95
	}
96
	
97
	public void test1() throws ParseException, BaseException{
98
		String wkt1 = "LINESTRING (200 80, 240 160, 300 240, 400 240)";
99
		String wkt2 = "LINESTRING (400 240, 440 220, 460 240, 440 280)";
100
		
101
		Geometry g1 = wktReader.read(wkt1);
102
		Geometry g2 = wktReader.read(wkt2);
103
		
104
		IGeometry ig1 = FConverter.jts_to_igeometry(g1);
105
		IGeometry ig2 = FConverter.jts_to_igeometry(g2);
106
		
107
		Value[] values1 = new Value[1];
108
		values1[0] = ValueFactory.createValue(5d);
109
		
110
		Value[] values2 = new Value[1];
111
		values2[0] = ValueFactory.createValue(199d);
112
		
113
		DefaultFeature f1 = new DefaultFeature(ig1, values1, "0");
114
		DefaultFeature f2 = new DefaultFeature(ig2, values2, "1");
115
		
116
		List<IFeature> features = new ArrayList<IFeature>();
117
		features.add(f1);
118
		features.add(f2);
119
		LayerDefinition def = new LayerDefinition(){
120
			public int getShapeType(){
121
				return FShape.LINE;
122
			}	
123
			
124
		};
125
		def.setFieldsDesc(new FieldDescription[]{});
126
		FeatureCollectionMemoryDriver driver = new FeatureCollectionMemoryDriver("", features, def);
127
		FLyrVect lyr = (FLyrVect) com.iver.cit.gvsig.fmap.layers.LayerFactory.
128
											createLayer("",
129
													driver, 
130
													null);
131
		
132
		Topology topo = new Topology(null, null, 0.2d, 0, new SimpleTopologyErrorContainer());
133
		LinesMustNotHavePseudonodes violatedRule = new LinesMustNotHavePseudonodes(topo, lyr, 0.1d);
134
		FGeometry fgeometry =  (FGeometry) ShapeFactory.createPoint2D(400, 240);
135
		TopologyError error = new TopologyError(fgeometry, violatedRule, f1, topo);
136
		
137
		new RemovePseudoNodeFix().fix(error);
138
		
139
	}
140
}

Also available in: Unified diff