Statistics
| Revision:

root / trunk / libraries / libTopology / src / org / gvsig / topology / topologyrules / LyrMustCoversOneGeometry.java @ 24772

History | View | Annotate | Download (4.33 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;
50

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

    
55
import org.gvsig.exceptions.BaseException;
56
import org.gvsig.fmap.core.NewFConverter;
57
import org.gvsig.topology.ITopologyErrorFix;
58
import org.gvsig.topology.Messages;
59
import org.gvsig.topology.Topology;
60
import org.gvsig.topology.TopologyRuleDefinitionException;
61
import org.gvsig.topology.errorfixes.DeleteTopologyErrorFix;
62

    
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.drivers.IFeatureIterator;
66
import com.iver.cit.gvsig.fmap.layers.FLyrVect;
67
import com.vividsolutions.jts.geom.Geometry;
68

    
69
public class LyrMustCoversOneGeometry extends AbstractSpatialPredicateTwoLyrRule {
70

    
71
                static final String RULE_NAME = Messages.getText("must_covers");
72
                
73
                static {
74
                        DEFAULT_ERROR_SYMBOL.setDescription(RULE_NAME);
75
                        automaticErrorFixes.add(new DeleteTopologyErrorFix());
76
                }
77
                
78
                public LyrMustCoversOneGeometry(Topology topology, 
79
                                 FLyrVect originLyr,
80
                                 FLyrVect destinationLyr){
81
                        super(topology, originLyr, destinationLyr);
82
                }
83

    
84

    
85
                public LyrMustCoversOneGeometry(){
86
                        super();
87
                }
88
                
89
                @Override
90
                protected boolean acceptsDestinationGeometryType(int shapeType) {
91
                        return true;
92
                }
93

    
94
                @Override
95
                protected boolean acceptsOriginGeometryType(int shapeType) {
96
                        return true;
97
                }
98
                
99
                @Override
100
                protected void checkWithNeighbourhood(IFeature feature, Rectangle2D extendedBounds, IFeatureIterator neighbourhood) throws BaseException{
101
                        Geometry firstGeometry = NewFConverter.toJtsGeometry(feature.getGeometry());
102
                        boolean isCovered = false;
103
                        List<Geometry> neighboursGeo = new ArrayList<Geometry>();
104
                        while (neighbourhood.hasNext()) {
105
                                IFeature neighbourFeature = neighbourhood.next();
106
                                IGeometry geom2 = neighbourFeature.getGeometry();
107
                                if(acceptsDestinationGeometryType(geom2.getGeometryType())){
108
                                        Rectangle2D rect2 = geom2.getBounds2D();
109
                                        if (extendedBounds.intersects(rect2)) {
110
                                                Geometry jtsGeom2 = NewFConverter.toJtsGeometry(geom2);
111
                                                if(checkSpatialPredicate(feature, firstGeometry, 
112
                                                                                                                        neighbourFeature, jtsGeom2 )){
113
                                                        return;
114
                                                }
115
                                        }//if
116
                                }//if
117
                        }//while
118
                        //at this point, feature doesnt cover any feature of destination layer
119
                        addTopologyError(createTopologyError(firstGeometry, feature, null));
120
                }
121
                
122

    
123
                @Override
124
                protected boolean checkSpatialPredicate(IFeature feature,
125
                                Geometry firstGeometry, IFeature neighbourFeature, Geometry jtsGeom2) {
126
                        return firstGeometry.covers(jtsGeom2);
127
                }
128

    
129
                @Override
130
                public void checkPreconditions() throws TopologyRuleDefinitionException {
131
                }
132

    
133
                @Override
134
                public String getName() {
135
                        return RULE_NAME;
136
                }
137

    
138
                public boolean acceptsDestinationLyr(FLyrVect originLyr) {
139
                        return true;
140
                }
141

    
142
                public boolean acceptsOriginLyr(FLyrVect originLyr) {
143
                        return true;
144
                }
145
                
146
                public ITopologyErrorFix getDefaultFix(){
147
                        return automaticErrorFixes.get(0);
148
                }
149
        }