root / trunk / libraries / libTopology / src / org / gvsig / topology / topologyrules / jtsisvalidrules / IGeometryMustBeClosed.java @ 18065
History | View | Annotate | Download (4.16 KB)
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.jtsisvalidrules; |
50 |
|
51 |
import org.gvsig.fmap.core.FGeometryUtil; |
52 |
import org.gvsig.topology.AbstractTopologyRule; |
53 |
import org.gvsig.topology.Messages; |
54 |
import org.gvsig.topology.Topology; |
55 |
import org.gvsig.topology.TopologyError; |
56 |
import org.gvsig.topology.TopologyRuleDefinitionException; |
57 |
|
58 |
import com.hardcode.gdbms.driver.exceptions.ReadDriverException; |
59 |
import com.iver.cit.gvsig.fmap.core.FShape; |
60 |
import com.iver.cit.gvsig.fmap.core.IFeature; |
61 |
import com.iver.cit.gvsig.fmap.core.IGeometry; |
62 |
import com.iver.cit.gvsig.fmap.layers.FLyrVect; |
63 |
import com.iver.utiles.XMLEntity; |
64 |
|
65 |
/**
|
66 |
* This rule checks if an FMap geometry is closed, always applying a
|
67 |
* given snap tolerance.
|
68 |
*
|
69 |
* To check multigeometries and multipart geometries, we follow the
|
70 |
* next guideline:
|
71 |
*
|
72 |
* a) if geometry is multipart or multigeometry, to be closed all parts must be closed.
|
73 |
* b) point geometries are not closed.
|
74 |
*
|
75 |
* @author Alvaro Zabala
|
76 |
*
|
77 |
*/
|
78 |
public class IGeometryMustBeClosed extends AbstractTopologyRule { |
79 |
|
80 |
public static final String RULE_NAME = |
81 |
Messages.getText("LINEAR_RING_MUST_BE_CLOSED");
|
82 |
|
83 |
private double snapTolerance; |
84 |
|
85 |
|
86 |
public IGeometryMustBeClosed(Topology topology, FLyrVect originLyr, double snapTolerance) { |
87 |
super(topology, originLyr);
|
88 |
this.snapTolerance = snapTolerance;
|
89 |
} |
90 |
|
91 |
public IGeometryMustBeClosed(){}
|
92 |
|
93 |
public IGeometryMustBeClosed(FLyrVect originLyr, double snapTolerance) { |
94 |
this(null, originLyr, snapTolerance); |
95 |
} |
96 |
|
97 |
public String getDescription() { |
98 |
return RULE_NAME;
|
99 |
} |
100 |
|
101 |
public void checkPreconditions() throws TopologyRuleDefinitionException { |
102 |
try {
|
103 |
int shapeType = this.originLyr.getShapeType(); |
104 |
if(shapeType == FShape.POINT ||
|
105 |
shapeType == FShape.MULTIPOINT || |
106 |
shapeType == FShape.TEXT) |
107 |
throw new TopologyRuleDefinitionException(); |
108 |
} catch (ReadDriverException e) {
|
109 |
e.printStackTrace(); |
110 |
throw new TopologyRuleDefinitionException("Error leyendo el tipo de geometria del driver",e); |
111 |
} |
112 |
} |
113 |
|
114 |
public void validateFeature(IFeature feature) { |
115 |
IGeometry geometry = feature.getGeometry(); |
116 |
if(! FGeometryUtil.isClosed(geometry, snapTolerance)){
|
117 |
IGeometry errorGeometry = FGeometryUtil. |
118 |
getGeometryToClose(geometry, snapTolerance); |
119 |
addTopologyError(feature, errorGeometry); |
120 |
} |
121 |
} |
122 |
|
123 |
|
124 |
private void addTopologyError(IFeature errorFeature, IGeometry errorGeometry) { |
125 |
TopologyError error = |
126 |
new TopologyError(errorGeometry, this, errorFeature, topology); |
127 |
addTopologyError(error); |
128 |
} |
129 |
|
130 |
public XMLEntity getXMLEntity(){
|
131 |
XMLEntity xml = super.getXMLEntity();
|
132 |
xml.putProperty("snapTolerance", snapTolerance);
|
133 |
return xml;
|
134 |
} |
135 |
|
136 |
public void setXMLEntity(XMLEntity xml){ |
137 |
super.setXMLEntity(xml);
|
138 |
|
139 |
if(xml.contains("snapTolerance")){ |
140 |
snapTolerance = xml.getDoubleProperty("snapTolerance");
|
141 |
} |
142 |
} |
143 |
|
144 |
} |