svn-gvsig-desktop / trunk / libraries / libTopology / src / org / gvsig / topology / topologyrules / jtsisvalidrules / PolygonMustNotHaveHoles.java @ 16396
History | View | Annotate | Download (4.11 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.jts.JtsUtil; |
53 |
import org.gvsig.topology.AbstractTopologyRule; |
54 |
import org.gvsig.topology.Messages; |
55 |
import org.gvsig.topology.Topology; |
56 |
import org.gvsig.topology.TopologyError; |
57 |
import org.gvsig.topology.TopologyRuleDefinitionException; |
58 |
import org.gvsig.topology.WrongLyrForTopologyException; |
59 |
|
60 |
import com.hardcode.gdbms.driver.exceptions.ReadDriverException; |
61 |
import com.iver.cit.gvsig.fmap.core.IFeature; |
62 |
import com.iver.cit.gvsig.fmap.layers.FLyrVect; |
63 |
import com.vividsolutions.jts.geom.Geometry; |
64 |
import com.vividsolutions.jts.geom.GeometryCollection; |
65 |
import com.vividsolutions.jts.geom.MultiPolygon; |
66 |
import com.vividsolutions.jts.geom.Polygon; |
67 |
|
68 |
public class PolygonMustNotHaveHoles extends AbstractTopologyRule { |
69 |
|
70 |
public PolygonMustNotHaveHoles(Topology topology, FLyrVect lyr) {
|
71 |
super(topology, lyr);
|
72 |
} |
73 |
|
74 |
public PolygonMustNotHaveHoles(FLyrVect lyr) {
|
75 |
super(lyr);
|
76 |
} |
77 |
|
78 |
public PolygonMustNotHaveHoles(){}
|
79 |
|
80 |
public String getDescription() { |
81 |
return Messages.getText("POLYGON_MUST_NOT_HAVE_DUPLICATED_RINGS"); |
82 |
} |
83 |
|
84 |
public void checkPreconditions() throws TopologyRuleDefinitionException { |
85 |
int shapeType;
|
86 |
try {
|
87 |
shapeType = this.originLyr.getShapeType();
|
88 |
int numDimensions = FGeometryUtil.getDimensions(shapeType);
|
89 |
if (numDimensions != 2) |
90 |
throw new WrongLyrForTopologyException( |
91 |
"MustNotHaveHoles solo aplica sobre capas de dimension 2");
|
92 |
} catch (ReadDriverException e) {
|
93 |
throw new TopologyRuleDefinitionException( |
94 |
"Error al tratar de verificar el tipo de geometria");
|
95 |
} |
96 |
} |
97 |
|
98 |
public void validateFeature(IFeature feature) { |
99 |
Geometry jtsGeo = feature.getGeometry().toJTSGeometry(); |
100 |
if (jtsGeo instanceof Polygon) { |
101 |
Polygon polygon = (Polygon) jtsGeo; |
102 |
if (polygon.getNumInteriorRing() > 0) { |
103 |
createTopologyError(feature); |
104 |
} |
105 |
} else if (jtsGeo instanceof MultiPolygon) { |
106 |
MultiPolygon multiPoly = (MultiPolygon) jtsGeo; |
107 |
for (int i = 0; i < multiPoly.getNumGeometries(); i++) { |
108 |
Polygon polygon = (Polygon) multiPoly.getGeometryN(i); |
109 |
if (polygon.getNumInteriorRing() > 0) { |
110 |
createTopologyError(feature); |
111 |
} |
112 |
} |
113 |
} else if (jtsGeo instanceof GeometryCollection) { |
114 |
MultiPolygon multiPoly = JtsUtil |
115 |
.convertIfPossible((GeometryCollection) jtsGeo); |
116 |
for (int i = 0; i < multiPoly.getNumGeometries(); i++) { |
117 |
Polygon polygon = (Polygon) multiPoly.getGeometryN(i); |
118 |
if (polygon.getNumInteriorRing() > 0) { |
119 |
createTopologyError(feature); |
120 |
} |
121 |
} |
122 |
} |
123 |
} |
124 |
|
125 |
private void createTopologyError(IFeature feature) { |
126 |
IFeature[] features = { feature };
|
127 |
TopologyError error = |
128 |
new TopologyError(feature.getGeometry(), this, features, topology); |
129 |
addTopologyError(error); |
130 |
} |
131 |
} |