Revision 23035

View differences:

trunk/libraries/libTopology/src/org/gvsig/topology/topologyrules/LineMustNotHavePseudonodes.java
1
/*
2
 * Created on 07-sep-2007
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
 */
50
package org.gvsig.topology.topologyrules;
51

  
52
import java.awt.Color;
53
import java.awt.geom.Rectangle2D;
54
import java.util.ArrayList;
55
import java.util.List;
56

  
57
import org.gvsig.fmap.core.FGeometryUtil;
58
import org.gvsig.fmap.core.NewFConverter;
59
import org.gvsig.jts.JtsUtil;
60
import org.gvsig.jts.SnappingCoordinateMapWithCounter;
61
import org.gvsig.topology.AbstractTopologyRule;
62
import org.gvsig.topology.IRuleWithClusterTolerance;
63
import org.gvsig.topology.ITopologyErrorFix;
64
import org.gvsig.topology.Messages;
65
import org.gvsig.topology.Topology;
66
import org.gvsig.topology.TopologyError;
67
import org.gvsig.topology.TopologyRuleDefinitionException;
68
import org.gvsig.topology.errorfixes.RemovePseudoNodeFix;
69

  
70
import com.hardcode.gdbms.driver.exceptions.ReadDriverException;
71
import com.iver.cit.gvsig.fmap.core.FShape;
72
import com.iver.cit.gvsig.fmap.core.IFeature;
73
import com.iver.cit.gvsig.fmap.core.IGeometry;
74
import com.iver.cit.gvsig.fmap.core.ShapeFactory;
75
import com.iver.cit.gvsig.fmap.core.SymbologyFactory;
76
import com.iver.cit.gvsig.fmap.core.symbols.MultiShapeSymbol;
77
import com.iver.cit.gvsig.fmap.drivers.IFeatureIterator;
78
import com.iver.cit.gvsig.fmap.layers.FLyrVect;
79
import com.iver.cit.gvsig.util.SnappingCoordinateMap;
80
import com.vividsolutions.jts.geom.Coordinate;
81
import com.vividsolutions.jts.geom.Envelope;
82
import com.vividsolutions.jts.geom.Geometry;
83
import com.vividsolutions.jts.geom.GeometryCollection;
84
import com.vividsolutions.jts.geom.LineString;
85
import com.vividsolutions.jts.geom.MultiLineString;
86

  
87
/**
88
 * This rule checks that lines of a line layer dont have pseudonodes ends (a
89
 * point that touchs one only another line). <br>
90
 * If a dangling node is an end point of a line that doesnt touch another line,
91
 * a pseudonode is a point that only touch one line. (we could dissolve these
92
 * two lines).
93
 */
94
public class LineMustNotHavePseudonodes extends AbstractTopologyRule implements
95
		IRuleWithClusterTolerance {
96

  
97
	final static String RULE_NAME = Messages.getText("must_not_have_pseudonodes");
98

  
99
	double clusterTol;
100
	
101
	protected SnappingCoordinateMap pseudoNodesCoordMap = null;
102
	
103
	/**
104
	 * Symbol for topology errors caused by a violation of this rule.
105
	 */
106
	protected MultiShapeSymbol errorSymbol = DEFAULT_ERROR_SYMBOL;
107
	
108
	private static List<ITopologyErrorFix> automaticErrorFixes =
109
		new ArrayList<ITopologyErrorFix>();
110
	static{
111
		automaticErrorFixes.add(new RemovePseudoNodeFix());
112
		
113
	}
114
	
115
	protected static final Color DEFAULT_ERROR_COLOR = Color.PINK;
116
	
117
	
118
	protected static final MultiShapeSymbol DEFAULT_ERROR_SYMBOL = 
119
		(MultiShapeSymbol) SymbologyFactory.createDefaultSymbolByShapeType(FShape.MULTI, 
120
											DEFAULT_ERROR_COLOR);
121
	static{
122
		DEFAULT_ERROR_SYMBOL.setDescription(RULE_NAME);
123
		DEFAULT_ERROR_SYMBOL.setSize(3);
124
	}
125
	
126

  
127
	public LineMustNotHavePseudonodes(Topology topology, FLyrVect originLyr,
128
			double clusterTolerance) {
129
		super(topology, originLyr);
130
		setClusterTolerance(clusterTolerance);
131
		
132

  
133
	}
134

  
135
	public LineMustNotHavePseudonodes() {
136
	}
137

  
138
	public String getName() {
139
		return RULE_NAME;
140
	}
141

  
142
	public void checkPreconditions() throws TopologyRuleDefinitionException {
143
		try {
144
			int shapeType = this.originLyr.getShapeType();
145
			if (FGeometryUtil.getDimensions(shapeType) != 1)
146
				throw new TopologyRuleDefinitionException(
147
						"LineMustNotHavePseudonodes requires a lineal geometry type");
148
		} catch (ReadDriverException e) {
149
			e.printStackTrace();
150
			throw new TopologyRuleDefinitionException(
151
					"Error leyendo el tipo de geometria del driver", e);
152
		}
153
	}
154
	
155
	public void ruleChecked(){
156
		super.ruleChecked();
157
		
158
		this.pseudoNodesCoordMap = new SnappingCoordinateMap(this.clusterTol);
159
	}
160

  
161
	public void validateFeature(IFeature feature) {
162
		IGeometry geom = feature.getGeometry();
163
		int shapeType = geom.getGeometryType();
164
		if (shapeType != FShape.LINE && shapeType != FShape.ARC
165
				&& shapeType != FShape.LINE + FShape.Z)
166
			return;
167

  
168
		Geometry jtsGeom = NewFConverter.toJtsGeometry(geom);
169

  
170
		process(jtsGeom, feature);
171
	}
172

  
173
	protected void process(Geometry geometry, IFeature feature) {
174
		if (geometry instanceof GeometryCollection) {
175
			GeometryCollection geomCol = (GeometryCollection) geometry;
176
			for (int i = 0; i < geomCol.getNumGeometries(); i++) {
177
				Geometry geomI = geomCol.getGeometryN(i);
178
				process(geomI, feature);
179
			}
180
		} else if (geometry instanceof LineString) {
181
			LineString lineString = (LineString) geometry;
182
			Envelope lnEnv = lineString.getEnvelopeInternal();
183
			 
184
			//We try to extend a bit the original envelope to ensure
185
			//recovering geometries in the limit
186
			double minX = lnEnv.getMinX() - 10;
187
			double minY = lnEnv.getMinY() - 10;
188
			double maxX = lnEnv.getMaxX() + 10;
189
			double maxY = lnEnv.getMaxY() + 10;
190

  
191
			Rectangle2D rect = new Rectangle2D.Double(minX, minY, maxX - minX, maxY - minY);
192
			
193
			SnappingCoordinateMapWithCounter coordinateMap = new SnappingCoordinateMapWithCounter(
194
					getClusterTolerance());
195

  
196
			// we consideer  pseudonode a coordinate with degree 2 (it only
197
			// connects two geometries)
198
			Coordinate firstPoint = lineString.getCoordinateN(0);
199
			coordinateMap.put(firstPoint, firstPoint);
200

  
201
			Coordinate lastPoint = lineString.getCoordinateN(lineString
202
					.getNumPoints() - 1);
203
			coordinateMap.put(lastPoint, lastPoint);
204

  
205
			try {
206
				IFeatureIterator neighbours = originLyr.getSource()
207
						.getFeatureIterator(rect, null, null, false);
208
				while (neighbours.hasNext()) {
209
					IFeature neighbourFeature = neighbours.next();
210
					if (neighbourFeature.getID().equalsIgnoreCase(
211
							feature.getID()))
212
						continue;
213
					Geometry geom2 = NewFConverter.toJtsGeometry(neighbourFeature.getGeometry());
214
					ArrayList<LineString> geometriesToProcess = new ArrayList<LineString>();
215
					if (geom2 instanceof LineString) {
216
						geometriesToProcess.add((LineString) geom2);
217
					} else if (geom2 instanceof MultiLineString) {
218
						MultiLineString multiLine = (MultiLineString) geom2;
219
						int numLines = multiLine.getNumGeometries();
220
						for (int i = 0; i < numLines; i++) {
221
							LineString line = (LineString) multiLine
222
									.getGeometryN(i);
223
							geometriesToProcess.add(line);
224
						}
225
					} else if (geom2 instanceof GeometryCollection) {
226
						MultiLineString multiLine = JtsUtil
227
								.convertToMultiLineString((GeometryCollection) geom2);
228
						int numLines = multiLine.getNumGeometries();
229
						for (int i = 0; i < numLines; i++) {
230
							LineString line = (LineString) multiLine
231
									.getGeometryN(i);
232
							geometriesToProcess.add(line);
233
						}
234
					} else {
235
						System.out.println("Encontrado:" + geom2.toString()
236
								+ " en regla de dangles");
237
					}
238

  
239
					int numGeometries = geometriesToProcess.size();
240
					for (int i = 0; i < numGeometries; i++) {
241
						LineString lineString2 = geometriesToProcess.get(i);
242
						Coordinate firstPoint2 = lineString2.getCoordinateN(0);
243
						Coordinate lastPoint2 = lineString2.getCoordinateN(lineString2
244
								.getNumPoints() - 1);
245
						
246
						coordinateMap.put(lastPoint2, lastPoint);
247
						coordinateMap.put(firstPoint2, firstPoint);
248

  
249
					}//for
250

  
251
				}//while
252
				
253
				int firstPointDegree = coordinateMap.getCount(firstPoint);
254
				int lastPointDegree = coordinateMap.getCount(lastPoint);
255
				
256
				if(firstPointDegree == 2){//A pseudonode is a node with degree 2, it only connects two lines
257
					
258
					//we dont add two times the same error
259
					Coordinate existingNode = (Coordinate) pseudoNodesCoordMap.get(firstPoint);
260
					if(existingNode == null){
261
						IGeometry errorGeom = 
262
							ShapeFactory.createPoint2D(firstPoint.x,
263
													   firstPoint.y);
264
					    TopologyError topologyError = 
265
							new TopologyError(errorGeom, 
266
												this, 
267
											 feature,
268
											topology);
269
					    topologyError.setID(errorContainer.getErrorFid());
270
					    addTopologyError(topologyError);
271
					    
272
					    pseudoNodesCoordMap.put(firstPoint, firstPoint);
273
					}
274
				}
275
				
276
				if(lastPointDegree == 2){
277
					Coordinate existingNode = (Coordinate) pseudoNodesCoordMap.get(lastPoint);
278
					if(existingNode == null){
279
						IGeometry errorGeom = 
280
							ShapeFactory.createPoint2D(lastPoint.x,
281
									lastPoint.y);
282
					    TopologyError topologyError = 
283
							new TopologyError(errorGeom, 
284
												this, 
285
											 feature,
286
											topology);
287
					    topologyError.setID(errorContainer.getErrorFid());
288
					    addTopologyError(topologyError);
289
					    
290
					    pseudoNodesCoordMap.put(lastPoint, lastPoint);
291
					}
292
				}
293

  
294
			} catch (ReadDriverException e) {
295
				e.printStackTrace();
296
				return;
297
			}
298
		} else {
299
			System.out.println("Encontrado:" + geometry.toString()
300
					+ " en regla de dangles");
301
		}
302
	}
303

  
304
	public double getClusterTolerance() {
305
		return clusterTol;
306
	}
307

  
308
	public void setClusterTolerance(double clusterTolerance) {
309
		this.clusterTol = clusterTolerance;
310
		pseudoNodesCoordMap = new SnappingCoordinateMap(clusterTolerance);
311
	}
312

  
313
	public boolean acceptsOriginLyr(FLyrVect lyr) {
314
		try {
315
			int shapeType = lyr.getShapeType();
316
			return (FGeometryUtil.getDimensions(shapeType) == 1);
317
		} catch (ReadDriverException e) {
318
			e.printStackTrace();
319
			return false;
320
		}
321
	}
322

  
323
	public List<ITopologyErrorFix> getAutomaticErrorFixes() {
324
		return automaticErrorFixes;
325
	}
326

  
327
	public MultiShapeSymbol getDefaultErrorSymbol() {
328
		return DEFAULT_ERROR_SYMBOL;
329
	}
330

  
331
	public MultiShapeSymbol getErrorSymbol() {
332
		return errorSymbol;
333
	}
334
	
335
	public void setErrorSymbol(MultiShapeSymbol errorSymbol) {
336
		this.errorSymbol = errorSymbol;
337
	}
338

  
339
}
trunk/libraries/libTopology/src/org/gvsig/topology/topologyrules/PointsMustNotOverlap.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.topologyrules;
50

  
51
import java.awt.Color;
52
import java.awt.geom.Rectangle2D;
53
import java.util.ArrayList;
54
import java.util.List;
55

  
56
import org.gvsig.fmap.core.FGeometryUtil;
57
import org.gvsig.fmap.core.NewFConverter;
58
import org.gvsig.jts.JtsUtil;
59
import org.gvsig.topology.ITopologyErrorFix;
60
import org.gvsig.topology.Messages;
61
import org.gvsig.topology.Topology;
62
import org.gvsig.topology.TopologyError;
63
import org.gvsig.topology.TopologyRuleDefinitionException;
64
import org.gvsig.topology.errorfixes.DeleteTopologyErrorFix;
65

  
66
import com.hardcode.gdbms.driver.exceptions.ReadDriverException;
67
import com.iver.cit.gvsig.fmap.core.FShape;
68
import com.iver.cit.gvsig.fmap.core.IFeature;
69
import com.iver.cit.gvsig.fmap.core.IGeometry;
70
import com.iver.cit.gvsig.fmap.core.SymbologyFactory;
71
import com.iver.cit.gvsig.fmap.core.symbols.MultiShapeSymbol;
72
import com.iver.cit.gvsig.fmap.drivers.IFeatureIterator;
73
import com.iver.cit.gvsig.fmap.layers.FLyrVect;
74
import com.vividsolutions.jts.geom.Envelope;
75
import com.vividsolutions.jts.geom.Geometry;
76
import com.vividsolutions.jts.geom.Point;
77

  
78

  
79
/**
80
 * These rule checks that in a point layer there won't be points at a distance
81
 * lower than the cluster tolerance.
82
 * @author Alvaro Zabala
83
 *
84
 */
85
public class PointsMustNotOverlap extends PolygonMustNotOverlap{
86
	
87
	static final String RULE_NAME = Messages.getText("points_must_not_overlap");
88

  
89
	private static List<ITopologyErrorFix> automaticErrorFixes = new ArrayList<ITopologyErrorFix>();
90
	static {
91
		automaticErrorFixes.add(new DeleteTopologyErrorFix());
92
	}
93

  
94
	private static final Color DEFAULT_ERROR_COLOR = Color.CYAN;
95

  
96
	private static final MultiShapeSymbol DEFAULT_ERROR_SYMBOL = 
97
		(MultiShapeSymbol) SymbologyFactory.createDefaultSymbolByShapeType(FShape.MULTI, DEFAULT_ERROR_COLOR);
98
	static {
99
		DEFAULT_ERROR_SYMBOL.setDescription(RULE_NAME);
100
		DEFAULT_ERROR_SYMBOL.setSize(5);
101
	}
102

  
103
	private MultiShapeSymbol errorSymbol = DEFAULT_ERROR_SYMBOL;
104

  
105
	/**
106
	 * Constructor
107
	 * 
108
	 * @param topology
109
	 *            Topology which owns this rule
110
	 * @param originLyr
111
	 * @param destinationLyr
112
	 * @param clusterTolerance
113
	 */
114
	public PointsMustNotOverlap(Topology topology, FLyrVect originLyr, double clusterTolerance) {
115
		super(topology, originLyr, clusterTolerance);
116
	}
117

  
118
	public PointsMustNotOverlap() {
119
		super();
120
	}
121

  
122
	public String getName() {
123
		return RULE_NAME;
124
	}
125

  
126
	public void checkPreconditions() throws TopologyRuleDefinitionException {
127
		try {
128
			int shapeType = this.originLyr.getShapeType();
129
			if (FGeometryUtil.getDimensions(shapeType) != 0)
130
				throw new TopologyRuleDefinitionException(
131
						"PointsMustNotOverlap requires a point geometry type");
132
		} catch (ReadDriverException e) {
133
			e.printStackTrace();
134
			throw new TopologyRuleDefinitionException(
135
					"Error leyendo el tipo de geometria del driver", e);
136
		}
137
	}
138

  
139
	public void validateFeature(IFeature feature) {
140
		IGeometry geom = feature.getGeometry();
141
		int shapeType = geom.getGeometryType();
142
		int numDimensions = FGeometryUtil.getDimensions(shapeType);
143
		if(numDimensions != 0)
144
			return;
145
		process(geom, feature);
146
	}
147

  
148
	
149
	
150
	
151
	protected void process(IGeometry geometry, IFeature feature) {
152
		Geometry jtsGeom = NewFConverter.toJtsGeometry(geometry);
153
		Point[] points = JtsUtil.extractPoints(jtsGeom);
154
		for (int i = 0; i < points.length; i++) {
155

  
156
			Point point = points[i];
157
			Envelope env1 = point.getEnvelopeInternal();
158

  
159
			// We try to extend a bit the original envelope to ensure
160
			// recovering geometries in the limit
161

  
162
			double delta = getClusterTolerance() + 10;
163
			double minX = env1.getMinX() - delta;
164
			double minY = env1.getMinY() - delta;
165
			double maxX = env1.getMaxX() + delta;
166
			double maxY = env1.getMaxY() + delta;
167

  
168
			Rectangle2D rect = new Rectangle2D.Double(minX, 
169
													  minY, 
170
													  maxX - minX,
171
													  maxY - minY);
172

  
173
			try {
174
				IFeatureIterator neighbours = 
175
					originLyr.getSource().getFeatureIterator(rect, null, null, false);
176
				while (neighbours.hasNext()) {
177
					IFeature neighbourFeature = neighbours.next();
178
					if (neighbourFeature.getID().equalsIgnoreCase(feature.getID()))
179
						continue;
180

  
181
					IGeometry geom2 = neighbourFeature.getGeometry();
182
					Rectangle2D rect2 = geom2.getBounds2D();
183
					if (rect.intersects(rect2)) {
184
						Geometry jts2 = NewFConverter.toJtsGeometry(geom2);
185
						Point[] geometriesToProcess = JtsUtil.extractPoints(jts2);
186

  
187
						for (int j = 0; j < geometriesToProcess.length; j++) {
188
							Point point2 = geometriesToProcess[j];
189
							if (point2.getCoordinate().distance(point.getCoordinate()) <= getClusterTolerance() ) {
190
								ComputedTopologyError errorEntry = new ComputedTopologyError();
191
								errorEntry.firstFeature = feature.getID();
192
								errorEntry.secondFeature = neighbourFeature.getID();
193

  
194
								if (this.errorEntries.get(errorEntry) == null) {
195
									IGeometry errorGeom = NewFConverter.toFMap(point);
196
									TopologyError topologyError = new TopologyError(errorGeom, 
197
																errorContainer.getErrorFid(), 
198
																this,
199
																feature, 
200
																neighbourFeature, 
201
																topology);
202
									addTopologyError(topologyError);
203
									errorEntries.put(errorEntry, errorEntry);
204
								}// if
205
							}// if
206
						}// for
207
					}// if
208
				}// while
209

  
210
			} catch (ReadDriverException e) {
211
				e.printStackTrace();
212
				return;
213
			}
214

  
215
		}
216
	}
217

  
218

  
219
	public boolean acceptsOriginLyr(FLyrVect lyr) {
220
		try {
221
			int shapeType = lyr.getShapeType();
222
			return (FGeometryUtil.getDimensions(shapeType) == 0);
223
		} catch (ReadDriverException e) {
224
			e.printStackTrace();
225
			return false;
226
		}
227
	}
228

  
229
	public List<ITopologyErrorFix> getAutomaticErrorFixes() {
230
		return automaticErrorFixes;
231
	}
232

  
233
	public MultiShapeSymbol getDefaultErrorSymbol() {
234
		return DEFAULT_ERROR_SYMBOL;
235
	}
236

  
237
	public MultiShapeSymbol getErrorSymbol() {
238
		return errorSymbol;
239
	}
240

  
241
	public void setErrorSymbol(MultiShapeSymbol errorSymbol) {
242
		this.errorSymbol = errorSymbol;
243
	}
244

  
245
}
trunk/libraries/libTopology/src/org/gvsig/topology/topologyrules/PolygonMustNotHaveGaps.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.topologyrules;
50

  
51
import java.awt.Color;
52
import java.awt.geom.Rectangle2D;
53
import java.util.ArrayList;
54
import java.util.List;
55

  
56
import org.gvsig.fmap.core.FGeometryUtil;
57
import org.gvsig.fmap.core.NewFConverter;
58
import org.gvsig.jts.JtsUtil;
59
import org.gvsig.topology.AbstractTopologyRule;
60
import org.gvsig.topology.IRuleWithClusterTolerance;
61
import org.gvsig.topology.ITopologyErrorFix;
62
import org.gvsig.topology.Messages;
63
import org.gvsig.topology.Topology;
64
import org.gvsig.topology.TopologyError;
65
import org.gvsig.topology.TopologyRuleDefinitionException;
66
import org.gvsig.topology.errorfixes.CreateFeatureOverlapPolygonFix;
67

  
68
import com.hardcode.gdbms.driver.exceptions.ReadDriverException;
69
import com.iver.cit.gvsig.fmap.core.FShape;
70
import com.iver.cit.gvsig.fmap.core.IFeature;
71
import com.iver.cit.gvsig.fmap.core.IGeometry;
72
import com.iver.cit.gvsig.fmap.core.SymbologyFactory;
73
import com.iver.cit.gvsig.fmap.core.symbols.MultiShapeSymbol;
74
import com.iver.cit.gvsig.fmap.layers.FLyrVect;
75
import com.iver.utiles.swing.threads.CancellableProgressTask;
76
import com.vividsolutions.jts.geom.Geometry;
77
import com.vividsolutions.jts.geom.LinearRing;
78
import com.vividsolutions.jts.geom.Polygon;
79

  
80
public class PolygonMustNotHaveGaps extends AbstractTopologyRule implements
81
		IRuleWithClusterTolerance {
82

  
83
	private double clusterTolerance;
84

  
85
	static final String RULE_NAME = Messages.getText("must_not_have_gaps");
86

  
87
	private static List<ITopologyErrorFix> automaticErrorFixes = new ArrayList<ITopologyErrorFix>();
88
	static{
89
		automaticErrorFixes.add(new CreateFeatureOverlapPolygonFix());
90
	}
91
	
92
	private static final Color DEFAULT_ERROR_COLOR = Color.RED;
93

  
94
	private static final MultiShapeSymbol DEFAULT_ERROR_SYMBOL = (MultiShapeSymbol) SymbologyFactory
95
			.createDefaultSymbolByShapeType(FShape.MULTI, DEFAULT_ERROR_COLOR);
96
	static {
97
		DEFAULT_ERROR_SYMBOL.setDescription(RULE_NAME);
98
	}
99

  
100
	private MultiShapeSymbol errorSymbol = DEFAULT_ERROR_SYMBOL;
101
	
102
	
103
	private List<Geometry> geometries;
104

  
105
	/**
106
	 * Constructor
107
	 * 
108
	 * @param topology
109
	 *            Topology which owns this rule
110
	 * @param originLyr
111
	 * @param destinationLyr
112
	 * @param clusterTolerance
113
	 */
114
	public PolygonMustNotHaveGaps(Topology topology, FLyrVect originLyr,
115
			double clusterTolerance) {
116
		super(topology, originLyr);
117
		setClusterTolerance(clusterTolerance);
118
		geometries = new ArrayList<Geometry>();
119
	}
120
	
121
	public PolygonMustNotHaveGaps(){
122
		geometries = new ArrayList<Geometry>();
123
	}
124

  
125
	public String getName() {
126
		return RULE_NAME;
127
	}
128

  
129
	public void checkPreconditions() throws TopologyRuleDefinitionException {
130
		try {
131
			int shapeType = this.originLyr.getShapeType();
132
			if (FGeometryUtil.getDimensions(shapeType) != 2)
133
				throw new TopologyRuleDefinitionException(
134
						"PolygonMustNotOverlap requires a polygonal geometry type");
135
		} catch (ReadDriverException e) {
136
			e.printStackTrace();
137
			throw new TopologyRuleDefinitionException(
138
					"Error leyendo el tipo de geometria del driver", e);
139
		}
140
	}
141
	
142
	
143
	public void checkRule(CancellableProgressTask progressMonitor){
144
		super.checkRule(progressMonitor);
145
		findGaps();
146
	}
147
	
148
	private void findGaps(){
149
		if(geometries.size() > 0){
150
			Geometry union = JtsUtil.GEOMETRY_FACTORY.
151
							createGeometryCollection(geometries.toArray(new Geometry[0])).
152
							buffer(0d);
153
			Polygon[] polygons = JtsUtil.extractPolygons(union);
154
			for (int i = 0; i < polygons.length; i++) {
155
				Polygon polygon = polygons[i];
156
				int numberOfGaps = polygon.getNumInteriorRing();
157
				for(int j = 0; j < numberOfGaps; j++){
158
					LinearRing gap = (LinearRing) polygon.getInteriorRingN(j);
159
					Polygon gapPoly = JtsUtil.GEOMETRY_FACTORY.createPolygon(gap, null);
160
					IGeometry errorGeometry = NewFConverter.toFMap(gapPoly);
161
					TopologyError error = new TopologyError(errorGeometry, this, null, getTopology());
162
					addTopologyError(error);
163
				}
164
			}
165
		}
166
	}
167
	 
168
	public  void checkRule(CancellableProgressTask progressMonitor, Rectangle2D rect){
169
		super.checkRule(progressMonitor, rect);
170
		findGaps();
171
	}
172
	
173

  
174
	public void validateFeature(IFeature feature) {
175
		IGeometry geom = feature.getGeometry();
176
		int shapeType = geom.getGeometryType();
177
		if (shapeType != FShape.CIRCLE && shapeType != FShape.ELLIPSE
178
				&& shapeType != FShape.MULTI && shapeType != FShape.POLYGON)
179
			return;
180
		geometries.add(NewFConverter.toJtsGeometry(geom));
181
	}
182

  
183
	
184

  
185
	public double getClusterTolerance() {
186
		return clusterTolerance;
187
	}
188

  
189
	public void setClusterTolerance(double clusterTolerance) {
190
		this.clusterTolerance = clusterTolerance;
191
	}
192

  
193
	public boolean acceptsOriginLyr(FLyrVect lyr) {
194
		try {
195
			int shapeType = lyr.getShapeType();
196
			return (FGeometryUtil.getDimensions(shapeType) == 2);
197
		} catch (ReadDriverException e) {
198
			e.printStackTrace();
199
			return false;
200
		}
201
	}
202

  
203
	public List<ITopologyErrorFix> getAutomaticErrorFixes() {
204
		return automaticErrorFixes;
205
	}
206

  
207
	public MultiShapeSymbol getDefaultErrorSymbol() {
208
		return DEFAULT_ERROR_SYMBOL;
209
	}
210

  
211
	public MultiShapeSymbol getErrorSymbol() {
212
		return errorSymbol;
213
	}
214

  
215
	public void setErrorSymbol(MultiShapeSymbol errorSymbol) {
216
		this.errorSymbol = errorSymbol;
217
	}
218

  
219
}
trunk/libraries/libTopology/src/org/gvsig/topology/topologyrules/LineMustNotHaveDangles2.java
53 53
import java.util.ArrayList;
54 54
import java.util.List;
55 55

  
56
import org.gvsig.fmap.core.NewFConverter;
56 57
import org.gvsig.jts.JtsUtil;
57 58
import org.gvsig.jts.SnappingCoordinateMapWithCounter;
58 59
import org.gvsig.topology.ITopologyErrorFix;
......
68 69
import com.iver.cit.gvsig.fmap.core.IGeometry;
69 70
import com.iver.cit.gvsig.fmap.core.ShapeFactory;
70 71
import com.iver.cit.gvsig.fmap.core.SymbologyFactory;
71
import com.iver.cit.gvsig.fmap.core.symbols.IMarkerSymbol;
72
import com.iver.cit.gvsig.fmap.core.symbols.ISymbol;
72
import com.iver.cit.gvsig.fmap.core.symbols.MultiShapeSymbol;
73 73
import com.iver.cit.gvsig.fmap.drivers.IFeatureIterator;
74 74
import com.iver.cit.gvsig.fmap.layers.FLyrVect;
75 75
import com.vividsolutions.jts.geom.Coordinate;
......
80 80
import com.vividsolutions.jts.geom.MultiLineString;
81 81

  
82 82

  
83
public class LineMustNotHaveDangles2 extends LinesMustNotHavePseudonodes {
83
public class LineMustNotHaveDangles2 extends LineMustNotHavePseudonodes {
84 84
	final static String RULE_NAME = Messages.getText("must_not_have_dangles");
85 85
	
86 86
	/**
87 87
	 * Symbol for topology errors caused by a violation of this rule.
88 88
	 */
89
	private ISymbol errorSymbol = DEFAULT_ERROR_SYMBOL;
89
	private MultiShapeSymbol errorSymbol = DEFAULT_ERROR_SYMBOL;
90 90
	
91 91
	
92 92
	private static List<ITopologyErrorFix> automaticErrorFixes =
......
100 100
	private static final Color DEFAULT_ERROR_COLOR = Color.RED;
101 101
	
102 102
	
103
	private static final IMarkerSymbol DEFAULT_ERROR_SYMBOL = 
104
		(IMarkerSymbol) SymbologyFactory.createDefaultSymbolByShapeType(FShape.POINT, 
103
	private static final MultiShapeSymbol DEFAULT_ERROR_SYMBOL = 
104
		(MultiShapeSymbol) SymbologyFactory.createDefaultSymbolByShapeType(FShape.MULTI, 
105 105
											DEFAULT_ERROR_COLOR);
106 106
	static{
107 107
		DEFAULT_ERROR_SYMBOL.setDescription(RULE_NAME);
......
166 166
					if (neighbourFeature.getID().equalsIgnoreCase(
167 167
							feature.getID()))
168 168
						continue;
169
					Geometry geom2 = neighbourFeature.getGeometry()
170
							.toJTSGeometry();
169
					Geometry geom2 = NewFConverter.toJtsGeometry(neighbourFeature.getGeometry());
171 170
					ArrayList<LineString> geometriesToProcess = new ArrayList<LineString>();
172 171
					if (geom2 instanceof LineString) {
173 172
						geometriesToProcess.add((LineString) geom2);
......
260 259
		return automaticErrorFixes;
261 260
	}
262 261

  
263
	public ISymbol getDefaultErrorSymbol() {
262
	public MultiShapeSymbol getDefaultErrorSymbol() {
264 263
		return DEFAULT_ERROR_SYMBOL;
265 264
	}
266 265

  
267
	public ISymbol getErrorSymbol() {
266
	public MultiShapeSymbol getErrorSymbol() {
268 267
		return errorSymbol;
269 268
	}
270 269
	
271
	public void setErrorSymbol(ISymbol errorSymbol) {
270
	public void setErrorSymbol(MultiShapeSymbol errorSymbol) {
272 271
		this.errorSymbol = errorSymbol;
273 272
	}
274 273
}
trunk/libraries/libTopology/src/org/gvsig/topology/topologyrules/MustBeLargerThanClusterTolerance.java
54 54
import java.util.List;
55 55

  
56 56
import org.gvsig.fmap.core.FGeometryUtil;
57
import org.gvsig.fmap.core.NewFConverter;
57 58
import org.gvsig.jts.GeometryCollapsedException;
58 59
import org.gvsig.jts.GeometrySnapper;
59 60
import org.gvsig.topology.AbstractTopologyRule;
......
70 71
import com.iver.cit.gvsig.fmap.core.IFeature;
71 72
import com.iver.cit.gvsig.fmap.core.IGeometry;
72 73
import com.iver.cit.gvsig.fmap.core.SymbologyFactory;
73
import com.iver.cit.gvsig.fmap.core.symbols.ISymbol;
74 74
import com.iver.cit.gvsig.fmap.core.symbols.MultiShapeSymbol;
75 75
import com.iver.cit.gvsig.fmap.layers.FLyrVect;
76 76
import com.iver.utiles.XMLEntity;
......
130 130
	/**
131 131
	 * Symbol for topology errors caused by a violation of this rule.
132 132
	 */
133
	private ISymbol errorSymbol = DEFAULT_ERROR_SYMBOL;
133
	private MultiShapeSymbol errorSymbol = DEFAULT_ERROR_SYMBOL;
134 134
	
135 135
	
136 136
	
......
169 169
	 */
170 170
	public void validateFeature(IFeature feature) {
171 171
		IGeometry geometry = feature.getGeometry();
172
		Geometry jtsGeometry = geometry.toJTSGeometry();
172
		Geometry jtsGeometry = NewFConverter.toJtsGeometry(geometry);
173 173
		try{
174 174
			geometrySnapper.snap(jtsGeometry);
175 175
		}catch(GeometryCollapsedException e){
......
215 215
		return MustBeLargerThanClusterTolerance.errorFixes;
216 216
	}
217 217

  
218
	public ISymbol getDefaultErrorSymbol() {
218
	public MultiShapeSymbol getDefaultErrorSymbol() {
219 219
		return DEFAULT_ERROR_SYMBOL;
220 220
	}
221 221

  
222
	public ISymbol getErrorSymbol() {
222
	public MultiShapeSymbol getErrorSymbol() {
223 223
		return errorSymbol;
224 224
	}
225 225

  
226
	public void setErrorSymbol(ISymbol errorSymbol) {
226
	public void setErrorSymbol(MultiShapeSymbol errorSymbol) {
227 227
		this.errorSymbol = errorSymbol;
228 228
	}
229 229
}
trunk/libraries/libTopology/src/org/gvsig/topology/topologyrules/PolygonMustNotOverlapWith.java
48 48
*/
49 49
package org.gvsig.topology.topologyrules;
50 50

  
51
import java.awt.Color;
51 52
import java.awt.geom.Rectangle2D;
52 53
import java.util.ArrayList;
54
import java.util.List;
53 55

  
54 56
import org.gvsig.fmap.core.FGeometryUtil;
57
import org.gvsig.fmap.core.NewFConverter;
55 58
import org.gvsig.jts.JtsUtil;
59
import org.gvsig.topology.ITopologyErrorFix;
56 60
import org.gvsig.topology.ITwoLyrRule;
57 61
import org.gvsig.topology.Messages;
58 62
import org.gvsig.topology.Topology;
59 63
import org.gvsig.topology.TopologyError;
64
import org.gvsig.topology.errorfixes.MergeOverlapWithPolygonFix;
65
import org.gvsig.topology.errorfixes.SubstractOverlapPolygonWithFix;
60 66

  
61 67
import com.hardcode.gdbms.driver.exceptions.ReadDriverException;
68
import com.iver.cit.gvsig.fmap.core.FShape;
62 69
import com.iver.cit.gvsig.fmap.core.IFeature;
63 70
import com.iver.cit.gvsig.fmap.core.IGeometry;
64
import com.iver.cit.gvsig.fmap.core.v02.FConverter;
71
import com.iver.cit.gvsig.fmap.core.SymbologyFactory;
72
import com.iver.cit.gvsig.fmap.core.symbols.MultiShapeSymbol;
65 73
import com.iver.cit.gvsig.fmap.drivers.IFeatureIterator;
66 74
import com.iver.cit.gvsig.fmap.layers.FLyrVect;
67 75
import com.vividsolutions.jts.geom.Envelope;
68 76
import com.vividsolutions.jts.geom.Geometry;
69
import com.vividsolutions.jts.geom.GeometryCollection;
70
import com.vividsolutions.jts.geom.MultiPolygon;
71 77
import com.vividsolutions.jts.geom.Polygon;
72 78
import com.vividsolutions.jts.precision.EnhancedPrecisionOp;
73 79

  
......
78 84
 * @author Alvaro Zabala
79 85
 *
80 86
 */
81
public class PolygonMustNotOverlapWith extends PolygonsMustNotOverlap 
87
public class PolygonMustNotOverlapWith extends PolygonMustNotOverlap 
82 88
										implements ITwoLyrRule{
83
	String ruleName = Messages.getText("must_not_overlap_with");
89
	final static String RULE_NAME = Messages.getText("must_not_overlap_with");
84 90
	
85 91
	FLyrVect destinationLyr;
86 92
	
93
	private static List<ITopologyErrorFix> automaticErrorFixes = new ArrayList<ITopologyErrorFix>();
94
	static {
95
		automaticErrorFixes.add(new SubstractOverlapPolygonWithFix());
96
		automaticErrorFixes.add(new MergeOverlapWithPolygonFix());
97
	}
98

  
99
	private static final Color DEFAULT_ERROR_COLOR = Color.BLUE;
100

  
101
	private static final MultiShapeSymbol DEFAULT_ERROR_SYMBOL = (MultiShapeSymbol) SymbologyFactory
102
			.createDefaultSymbolByShapeType(FShape.MULTI, DEFAULT_ERROR_COLOR);
103
	static {
104
		DEFAULT_ERROR_SYMBOL.setDescription(RULE_NAME);
105
	}
106

  
107
	private MultiShapeSymbol errorSymbol = DEFAULT_ERROR_SYMBOL;
108
	
109
	
110
	
87 111
	/**
88 112
	 * Constructor.
89 113
	 * 
......
104 128
		
105 129
	}
106 130
	
107
	protected void process(Geometry geometry, IFeature feature) {
108
		if (geometry instanceof GeometryCollection) {
109
			GeometryCollection geomCol = (GeometryCollection) geometry;
110
			for (int i = 0; i < geomCol.getNumGeometries(); i++) {
111
				Geometry geomI = geomCol.getGeometryN(i);
112
				process(geomI, feature);
113
			}
114
		} else if (geometry instanceof Polygon) {
115
			Polygon polygon = (Polygon) geometry;
131
	@Override
132
	public String getName() {
133
		return RULE_NAME;
134
	}
135
	
136
	@Override
137
	public List<ITopologyErrorFix> getAutomaticErrorFixes() {
138
		return automaticErrorFixes;
139
	}
140
	
141
	@Override
142
	protected void process(IGeometry geometry, IFeature feature) {
143
		Geometry jtsGeom = NewFConverter.toJtsGeometry(geometry);
144
		Polygon[] polygons = JtsUtil.extractPolygons(jtsGeom);
145
		for (int i = 0; i < polygons.length; i++) {
146
			Polygon polygon = polygons[i];
116 147
			Envelope env1 = polygon.getEnvelopeInternal();
117 148

  
118 149
			// We try to extend a bit the original envelope to ensure
......
133 164
													getFeatureIterator(rect, null, null, false);
134 165
				while (neighbours.hasNext()) {
135 166
					IFeature neighbourFeature = neighbours.next();
136
					if (neighbourFeature.getID().equalsIgnoreCase(
137
							feature.getID()))
138
						continue;
139

  
140 167
					IGeometry geom2 = neighbourFeature.getGeometry();
141 168
					Rectangle2D rect2 = geom2.getBounds2D();
142 169
					if (rect.intersects(rect2)) {
143
						
144
						Geometry jts2 = geom2.toJTSGeometry();
145
						ArrayList<Polygon> geometriesToProcess = new ArrayList<Polygon>();
146
						
147
						if (jts2 instanceof Polygon) {
148
							geometriesToProcess.add((Polygon) jts2);
149
						} else if (jts2 instanceof MultiPolygon) {
150
							MultiPolygon multiPolygon = (MultiPolygon) jts2;
151
							int numLines = multiPolygon.getNumGeometries();
152
							for (int i = 0; i < numLines; i++) {
153
								Polygon polygon2 = (Polygon) multiPolygon
154
										.getGeometryN(i);
155
								geometriesToProcess.add(polygon2);
156
							}
157
						} else if (jts2 instanceof GeometryCollection) {
158
							MultiPolygon multiPoly = JtsUtil
159
									.convertToMultiPolygon((GeometryCollection) jts2);
160
							int numPolys = multiPoly.getNumGeometries();
161
							for (int i = 0; i < numPolys; i++) {
162
								Polygon line = (Polygon) multiPoly
163
										.getGeometryN(i);
164
								geometriesToProcess.add(line);
165
							}
166
						} else {
167
							System.out.println("Encontrado:" + jts2.toString()
168
									+ " en regla PolygonsMustNotOverlap");
169
						}
170

  
171
						int numGeometries = geometriesToProcess.size();
172
						for (int i = 0; i < numGeometries; i++) {
173
							Polygon poly2 = geometriesToProcess.get(i);
174
								if(poly2.overlaps(polygon)){
175
									ComputedTopologyError errorEntry = 
176
										new ComputedTopologyError();
177
									errorEntry.firstFeature = feature.getID();
178
									errorEntry.secondFeature = neighbourFeature.getID();
179
									
180
									if(this.errorEntries.get(errorEntry) == null){
170
						Geometry jts2 = NewFConverter.toJtsGeometry(geom2);
171
						Polygon[] polygons2 = JtsUtil.extractPolygons(jts2);
172
						int numGeometries = polygons2.length;
173
						for (int j = 0; j < numGeometries; j++) {
174
							Polygon poly2 = polygons2[j];
175
							if (poly2.overlaps(polygon) || poly2.covers(polygon) || polygon.covers(poly2)) {
181 176
										Geometry errorGeomJts = EnhancedPrecisionOp.intersection(poly2, polygon);
182
										IGeometry errorGeom = FConverter.jts_to_igeometry(errorGeomJts);
183
										TopologyError topologyError = 
184
											new TopologyError(errorGeom, 
185
														errorContainer.getErrorFid(), 
186
														this,  
187
														feature, 
188
														neighbourFeature, 
189
														topology );
190
										addTopologyError(topologyError);
191
										
192
										errorEntries.put(errorEntry, errorEntry);
193
									}//if
177
										Polygon[] overlappingPolygons = JtsUtil.extractPolygons(errorGeomJts);
178
										if(overlappingPolygons.length > 0){
179
											errorGeomJts = JtsUtil.GEOMETRY_FACTORY.createGeometryCollection(overlappingPolygons);
180
											IGeometry errorGeom = NewFConverter.toFMap(errorGeomJts);
181
											TopologyError topologyError = 
182
												new TopologyError(errorGeom, 
183
															errorContainer.getErrorFid(), 
184
															this,  
185
															feature, 
186
															neighbourFeature, 
187
															topology );
188
											addTopologyError(topologyError);
189
										}
194 190
								}//if
195 191
						}// for
196 192
					}//if
......
200 196
				e.printStackTrace();
201 197
				return;
202 198
			}
203
		} else {
204
			System.out.println("Encontrado:" + geometry.toString()
205
					+ " en regla de dangles");
206
		}
199
		}//for polygons
207 200
	}
208 201

  
209 202

  
203
//	public List<ITopologyErrorFix> getAutomaticErrorFixes() {
204
//		return automaticErrorFixes;
205
//	}
206
	
210 207
	public boolean acceptsDestinationLyr(FLyrVect destLyr) {
211 208
		try {
212 209
			int shapeType = destLyr.getShapeType();
......
226 223
	public void setDestinationLyr(FLyrVect destinationLyr) {
227 224
		this.destinationLyr = destinationLyr;
228 225
	}
226
	
227
	public MultiShapeSymbol getDefaultErrorSymbol() {
228
		return DEFAULT_ERROR_SYMBOL;
229
	}
230

  
231
	public MultiShapeSymbol getErrorSymbol() {
232
		return errorSymbol;
233
	}
234

  
235
	public void setErrorSymbol(MultiShapeSymbol errorSymbol) {
236
		this.errorSymbol = errorSymbol;
237
	}
229 238
}
trunk/libraries/libTopology/src/org/gvsig/topology/topologyrules/jtsisvalidrules/PolygonMustNotHaveDuplicatedRings.java
53 53
import java.util.List;
54 54

  
55 55
import org.gvsig.fmap.core.FGeometryUtil;
56
import org.gvsig.fmap.core.NewFConverter;
56 57
import org.gvsig.jts.JtsUtil;
57 58
import org.gvsig.topology.AbstractTopologyRule;
58 59
import org.gvsig.topology.ITopologyErrorFix;
......
66 67
import com.iver.cit.gvsig.fmap.core.IFeature;
67 68
import com.iver.cit.gvsig.fmap.core.IGeometry;
68 69
import com.iver.cit.gvsig.fmap.core.SymbologyFactory;
69
import com.iver.cit.gvsig.fmap.core.symbols.ILineSymbol;
70
import com.iver.cit.gvsig.fmap.core.symbols.ISymbol;
71
import com.iver.cit.gvsig.fmap.core.v02.FConverter;
70
import com.iver.cit.gvsig.fmap.core.symbols.MultiShapeSymbol;
72 71
import com.iver.cit.gvsig.fmap.layers.FLyrVect;
73 72
import com.iver.utiles.XMLEntity;
74 73
import com.vividsolutions.jts.geom.Geometry;
......
85 84
 */
86 85
public class PolygonMustNotHaveDuplicatedRings extends AbstractTopologyRule {
87 86
	
88
	private ISymbol errorSymbol = DEFAULT_ERROR_SYMBOL;
87
	private MultiShapeSymbol errorSymbol = DEFAULT_ERROR_SYMBOL;
89 88
	
90 89
	private static String RULE_NAME = Messages.getText("POLYGON_MUST_NOT_HAVE_DUPLICATED_RINGS");
91 90
	
......
95 94
	private static final Color DEFAULT_ERROR_COLOR = Color.RED;
96 95
	
97 96
	
98
	private static final ILineSymbol DEFAULT_ERROR_SYMBOL = 
99
		(ILineSymbol) SymbologyFactory.createDefaultSymbolByShapeType(FShape.LINE, 
97
	private static final MultiShapeSymbol DEFAULT_ERROR_SYMBOL = 
98
		(MultiShapeSymbol) SymbologyFactory.createDefaultSymbolByShapeType(FShape.MULTI, 
100 99
											DEFAULT_ERROR_COLOR);
101 100
	static{
102 101
		DEFAULT_ERROR_SYMBOL.setDescription(RULE_NAME);
......
161 160
		for(int i = 0; i < numHoles; i++){
162 161
			LineString hole = polygon.getInteriorRingN(i);
163 162
			if(shell.equalsExact(hole, snapTolerance)){
164
				IGeometry geometry = FConverter.jts_to_igeometry(hole);
163
				IGeometry geometry = NewFConverter.toFMap(hole);
165 164
				AbstractTopologyRule violatedRule = null;
166 165
				if(this.parentRule != null)
167 166
					violatedRule = parentRule;
......
180 179
					continue;
181 180
				LineString hole2 = polygon.getInteriorRingN(j);
182 181
				if(hole.equalsExact(hole2)){
183
					IGeometry geometry = FConverter.jts_to_igeometry(hole);
182
					IGeometry geometry = NewFConverter.toFMap(hole);
184 183
					AbstractTopologyRule violatedRule = null;
185 184
					if(this.parentRule != null)
186 185
						violatedRule = parentRule;
......
231 230
		return automaticErrorFixes;
232 231
	}
233 232

  
234
	public ISymbol getDefaultErrorSymbol() {
233
	public MultiShapeSymbol getDefaultErrorSymbol() {
235 234
		return DEFAULT_ERROR_SYMBOL;
236 235
	}
237 236

  
238
	public ISymbol getErrorSymbol() {
237
	public MultiShapeSymbol getErrorSymbol() {
239 238
		return errorSymbol;
240 239
	}
241 240
}
trunk/libraries/libTopology/src/org/gvsig/topology/topologyrules/jtsisvalidrules/PolygonMustNotHaveSelfIntersectedRings.java
53 53
import java.util.List;
54 54

  
55 55
import org.gvsig.fmap.core.FGeometryUtil;
56
import org.gvsig.fmap.core.NewFConverter;
56 57
import org.gvsig.jts.JtsUtil;
57 58
import org.gvsig.jts.SnapLineStringSelfIntersectionChecker;
58 59
import org.gvsig.topology.AbstractTopologyRule;
......
69 70
import com.iver.cit.gvsig.fmap.core.FShape;
70 71
import com.iver.cit.gvsig.fmap.core.IFeature;
71 72
import com.iver.cit.gvsig.fmap.core.SymbologyFactory;
72
import com.iver.cit.gvsig.fmap.core.symbols.IMarkerSymbol;
73
import com.iver.cit.gvsig.fmap.core.symbols.ISymbol;
73
import com.iver.cit.gvsig.fmap.core.symbols.MultiShapeSymbol;
74 74
import com.iver.cit.gvsig.fmap.layers.FLyrVect;
75 75
import com.iver.utiles.XMLEntity;
76 76
import com.vividsolutions.jts.geom.Coordinate;
......
86 86
	/**
87 87
	 * Symbol for topology errors caused by a violation of this rule.
88 88
	 */
89
	private ISymbol errorSymbol = DEFAULT_ERROR_SYMBOL;
89
	private MultiShapeSymbol errorSymbol = DEFAULT_ERROR_SYMBOL;
90 90
	
91 91
	
92 92
	private static List<ITopologyErrorFix> automaticErrorFixes =
......
100 100
	private static final Color DEFAULT_ERROR_COLOR = Color.RED;
101 101
	
102 102
	
103
	private static final IMarkerSymbol DEFAULT_ERROR_SYMBOL = 
104
		(IMarkerSymbol) SymbologyFactory.createDefaultSymbolByShapeType(FShape.POINT, 
103
	private static final MultiShapeSymbol DEFAULT_ERROR_SYMBOL = 
104
		(MultiShapeSymbol) SymbologyFactory.createDefaultSymbolByShapeType(FShape.MULTI, 
105 105
											DEFAULT_ERROR_COLOR);
106 106
	static{
107 107
		DEFAULT_ERROR_SYMBOL.setDescription(RULE_NAME);
......
141 141
	}
142 142

  
143 143
	public void validateFeature(IFeature feature) {
144
		Geometry jtsGeo = feature.getGeometry().toJTSGeometry();
144
		Geometry jtsGeo = NewFConverter.toJtsGeometry(feature.getGeometry());
145 145
		if (jtsGeo instanceof Polygon) {
146 146
			Polygon polygon = (Polygon) jtsGeo;
147 147
			checkPolygon(polygon, feature);
......
241 241
		return automaticErrorFixes;
242 242
	}
243 243

  
244
	public ISymbol getDefaultErrorSymbol() {
244
	public MultiShapeSymbol getDefaultErrorSymbol() {
245 245
		return DEFAULT_ERROR_SYMBOL;
246 246
	}
247 247

  
248
	public ISymbol getErrorSymbol() {
248
	public MultiShapeSymbol getErrorSymbol() {
249 249
		return errorSymbol;
250 250
	}
251 251
}
trunk/libraries/libTopology/src/org/gvsig/topology/topologyrules/jtsisvalidrules/PolygonHolesMustBeInShell.java
53 53
import java.util.List;
54 54

  
55 55
import org.gvsig.fmap.core.FGeometryUtil;
56
import org.gvsig.fmap.core.NewFConverter;
56 57
import org.gvsig.jts.JtsUtil;
57 58
import org.gvsig.topology.AbstractTopologyRule;
58 59
import org.gvsig.topology.ITopologyErrorFix;
......
66 67
import com.iver.cit.gvsig.fmap.core.IFeature;
67 68
import com.iver.cit.gvsig.fmap.core.IGeometry;
68 69
import com.iver.cit.gvsig.fmap.core.SymbologyFactory;
69
import com.iver.cit.gvsig.fmap.core.symbols.IFillSymbol;
70
import com.iver.cit.gvsig.fmap.core.symbols.ISymbol;
71
import com.iver.cit.gvsig.fmap.core.v02.FConverter;
70
import com.iver.cit.gvsig.fmap.core.symbols.MultiShapeSymbol;
72 71
import com.iver.cit.gvsig.fmap.layers.FLyrVect;
73 72
import com.iver.utiles.XMLEntity;
74 73
import com.vividsolutions.jts.algorithm.PointInRing;
......
98 97
	
99 98
	private static final Color DEFAULT_ERROR_COLOR = Color.BLACK;
100 99

  
101
	private static final IFillSymbol DEFAULT_ERROR_SYMBOL = 
102
		(IFillSymbol) SymbologyFactory.createDefaultSymbolByShapeType(FShape.POLYGON, 
100
	private static final MultiShapeSymbol DEFAULT_ERROR_SYMBOL = 
101
		(MultiShapeSymbol) SymbologyFactory.createDefaultSymbolByShapeType(FShape.MULTI, 
103 102
																DEFAULT_ERROR_COLOR);
104 103
	static {
105 104
		DEFAULT_ERROR_SYMBOL.setDescription(RULE_NAME);
......
107 106

  
108 107

  
109 108

  
110
	private ISymbol errorSymbol;
109
	private MultiShapeSymbol errorSymbol;
111 110
	
112 111
	private double snapTolerance;
113 112
	
......
244 243
			
245 244
			Polygon holeAsPoly = JtsUtil.GEOMETRY_FACTORY.createPolygon(hole, null);
246 245
			Geometry errorGeometry = EnhancedPrecisionOp.difference(shellAsPoly, holeAsPoly);
247
			IGeometry errorGeo = FConverter.jts_to_igeometry(errorGeometry);
246
			IGeometry errorGeo = NewFConverter.toFMap(errorGeometry);
248 247
			AbstractTopologyRule violatedRule = null;
249 248
			if(this.parentRule != null)
250 249
				violatedRule = parentRule;
......
317 316
		return automaticErrorFixes;
318 317
	}
319 318

  
320
	public ISymbol getDefaultErrorSymbol() {
319
	public MultiShapeSymbol getDefaultErrorSymbol() {
321 320
		return DEFAULT_ERROR_SYMBOL;
322 321
	}
323 322

  
324
	public ISymbol getErrorSymbol() {
323
	public MultiShapeSymbol getErrorSymbol() {
325 324
		return errorSymbol;
326 325
	}
327 326
}
trunk/libraries/libTopology/src/org/gvsig/topology/topologyrules/jtsisvalidrules/PolygonHolesMustNotBeNested.java
55 55
import java.util.List;
56 56

  
57 57
import org.gvsig.fmap.core.FGeometryUtil;
58
import org.gvsig.fmap.core.NewFConverter;
58 59
import org.gvsig.jts.JtsUtil;
59 60
import org.gvsig.topology.AbstractTopologyRule;
60 61
import org.gvsig.topology.ITopologyErrorFix;
......
68 69
import com.iver.cit.gvsig.fmap.core.IFeature;
69 70
import com.iver.cit.gvsig.fmap.core.IGeometry;
70 71
import com.iver.cit.gvsig.fmap.core.SymbologyFactory;
71
import com.iver.cit.gvsig.fmap.core.symbols.IFillSymbol;
72
import com.iver.cit.gvsig.fmap.core.symbols.ISymbol;
72
import com.iver.cit.gvsig.fmap.core.symbols.MultiShapeSymbol;
73 73
import com.iver.cit.gvsig.fmap.layers.FLyrVect;
74 74
import com.vividsolutions.jts.algorithms.SnapCGAlgorithms;
75 75
import com.vividsolutions.jts.geom.Coordinate;
......
90 90

  
91 91
	private static final Color DEFAULT_ERROR_COLOR = Color.BLACK;
92 92

  
93
	private static final IFillSymbol DEFAULT_ERROR_SYMBOL = (IFillSymbol) SymbologyFactory
94
			.createDefaultSymbolByShapeType(FShape.POLYGON, DEFAULT_ERROR_COLOR);
93
	private static final MultiShapeSymbol DEFAULT_ERROR_SYMBOL = (MultiShapeSymbol) SymbologyFactory
94
			.createDefaultSymbolByShapeType(FShape.MULTI, DEFAULT_ERROR_COLOR);
95 95
	static {
96 96
		DEFAULT_ERROR_SYMBOL.setDescription(RULE_NAME);
97 97
	}
98 98

  
99
	private ISymbol errorSymbol;
99
	private MultiShapeSymbol errorSymbol;
100 100

  
101 101
	private JtsValidRule parentRule;
102 102

  
......
131 131
	}
132 132

  
133 133
	public void validateFeature(IFeature feature) {
134
		Geometry jtsGeo = FGeometryUtil.toJtsPolygon((FShape) feature
134
		Geometry jtsGeo = NewFConverter.toJtsPolygon((FShape) feature
135 135
				.getGeometry().getInternalShape());
136 136
		if (jtsGeo instanceof Polygon) {
137 137
			checkHoles((Polygon) jtsGeo, new GeometryGraph(0, jtsGeo), feature);
......
299 299
		return automaticErrorFixes;
300 300
	}
301 301

  
302
	public ISymbol getDefaultErrorSymbol() {
302
	public MultiShapeSymbol getDefaultErrorSymbol() {
303 303
		return DEFAULT_ERROR_SYMBOL;
304 304
	}
305 305

  
306
	public ISymbol getErrorSymbol() {
306
	public MultiShapeSymbol getErrorSymbol() {
307 307
		return errorSymbol;
308 308
	}
309 309
}
trunk/libraries/libTopology/src/org/gvsig/topology/topologyrules/PolygonMustNotOverlap.java
1
/*
2
 * Created on 07-sep-2007
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:
... This diff was truncated because it exceeds the maximum size that can be displayed.

Also available in: Unified diff