svn-gvsig-desktop / trunk / libraries / libTopology / src / org / gvsig / topology / topologyrules / MustBeLargerThanClusterTolerance.java @ 16256
History | View | Annotate | Download (4.75 KB)
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 org.gvsig.jts.GeometryCollapsedException; |
53 |
import org.gvsig.jts.GeometrySnapper; |
54 |
import org.gvsig.topology.AbstractTopologyRule; |
55 |
import org.gvsig.topology.IOneLyrRule; |
56 |
import org.gvsig.topology.Messages; |
57 |
import org.gvsig.topology.Topology; |
58 |
import org.gvsig.topology.TopologyError; |
59 |
import org.gvsig.topology.TopologyRuleDefinitionException; |
60 |
|
61 |
import com.hardcode.gdbms.driver.exceptions.ReadDriverException; |
62 |
import com.iver.cit.gvsig.fmap.core.FShape; |
63 |
import com.iver.cit.gvsig.fmap.core.IFeature; |
64 |
import com.iver.cit.gvsig.fmap.core.IGeometry; |
65 |
import com.iver.cit.gvsig.fmap.layers.FLyrVect; |
66 |
import com.iver.utiles.XMLEntity; |
67 |
import com.vividsolutions.jts.geom.Geometry; |
68 |
|
69 |
|
70 |
/**
|
71 |
* For lines o polygons. The lenght of a line or the perimeter
|
72 |
* of a polygon must be larger than the cluster tolerance.
|
73 |
*
|
74 |
* Two consecutives points at a distance lower than cluster tolerance must be
|
75 |
* deleted.
|
76 |
*
|
77 |
*
|
78 |
* @author azabala
|
79 |
*/
|
80 |
public class MustBeLargerThanClusterTolerance extends AbstractTopologyRule implements IOneLyrRule { |
81 |
|
82 |
//TODO Test that internazionalization are running well
|
83 |
static final String ruleName = Messages.getText("must_be_larger_than_cluster_tolerance"); |
84 |
|
85 |
/**
|
86 |
* Cluster tolerance to check.
|
87 |
*/
|
88 |
private double clusterTolerance; |
89 |
|
90 |
/**
|
91 |
* Snapper to check coords proximity of a given geometry
|
92 |
*/
|
93 |
private GeometrySnapper geometrySnapper;
|
94 |
|
95 |
|
96 |
|
97 |
public MustBeLargerThanClusterTolerance(Topology topology, FLyrVect originLyr, double clusterTolerance){ |
98 |
super(topology, originLyr);
|
99 |
setClusterTolerance(clusterTolerance); |
100 |
} |
101 |
|
102 |
public MustBeLargerThanClusterTolerance(FLyrVect originLyr, double clusterTolerance){ |
103 |
this(null, originLyr, clusterTolerance); |
104 |
} |
105 |
|
106 |
|
107 |
public String getName() { |
108 |
return ruleName;
|
109 |
} |
110 |
|
111 |
|
112 |
public void checkPreconditions() throws TopologyRuleDefinitionException { |
113 |
//This rule doesnt apply to Point or MultiPoint vectorial layers.
|
114 |
try {
|
115 |
int shapeType = this.originLyr.getShapeType(); |
116 |
if( (shapeType == FShape.POINT) || (shapeType == FShape.MULTIPOINT) || (shapeType == FShape.TEXT))
|
117 |
throw new TopologyRuleDefinitionException(); |
118 |
} catch (ReadDriverException e) {
|
119 |
e.printStackTrace(); |
120 |
throw new TopologyRuleDefinitionException("Error leyendo el tipo de geometria del driver",e); |
121 |
} |
122 |
} |
123 |
|
124 |
/**
|
125 |
* Validates this rule with a feature of the origin layer
|
126 |
* @param feature feature of the origin layer this rule is checking
|
127 |
*/
|
128 |
public void validateFeature(IFeature feature) { |
129 |
IGeometry geometry = feature.getGeometry(); |
130 |
Geometry jtsGeometry = geometry.toJTSGeometry(); |
131 |
try{
|
132 |
geometrySnapper.snap(jtsGeometry); |
133 |
}catch(GeometryCollapsedException e){
|
134 |
IFeature[] errorFeatures = {feature};
|
135 |
//use an ErrorFactory
|
136 |
TopologyError topologyError = new TopologyError(geometry, this, errorFeatures); |
137 |
topologyError.setID(errorContainer.getErrorFid()); |
138 |
addTopologyError(topologyError); |
139 |
} |
140 |
} |
141 |
|
142 |
public double getClusterTolerance() { |
143 |
return clusterTolerance;
|
144 |
} |
145 |
|
146 |
public void setClusterTolerance(double clusterTolerance) { |
147 |
this.clusterTolerance = clusterTolerance;
|
148 |
this.geometrySnapper = new GeometrySnapper(clusterTolerance); |
149 |
} |
150 |
|
151 |
public XMLEntity getXMLEntity(){
|
152 |
XMLEntity xml = super.getXMLEntity();
|
153 |
xml.putProperty("className", getClassName());
|
154 |
xml.putProperty("clusterTolerance", this.clusterTolerance); |
155 |
return xml;
|
156 |
} |
157 |
|
158 |
public void setXMLEntity(XMLEntity xml){ |
159 |
super.setXMLEntity(xml);
|
160 |
if(xml.contains("clusterTolerance")){ |
161 |
setClusterTolerance(xml.getDoubleProperty("clusterTolerance"));
|
162 |
} |
163 |
} |
164 |
} |
165 |
|