Statistics
| Revision:

svn-gvsig-desktop / trunk / libraries / libTopology / src / org / gvsig / topology / topologyrules / LyrMustBeCoveredByLyr.java @ 24074

History | View | Annotate | Download (4.07 KB)

1 23156 azabala
/*
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.jts.JtsUtil;
58
import org.gvsig.topology.Messages;
59
import org.gvsig.topology.Topology;
60
61
import com.iver.cit.gvsig.fmap.core.IFeature;
62
import com.iver.cit.gvsig.fmap.core.IGeometry;
63
import com.iver.cit.gvsig.fmap.drivers.IFeatureIterator;
64
import com.iver.cit.gvsig.fmap.layers.FLyrVect;
65
import com.vividsolutions.jts.geom.Geometry;
66
import com.vividsolutions.jts.geom.GeometryCollection;
67
import com.vividsolutions.jts.precision.EnhancedPrecisionOp;
68
/**
69
 * All geometries of origin layer must be covered by a group
70
 * of geometries of destination layer
71
 * (it doesnt matter if are covered by one only geometries or a
72
 * group of them)
73
 *
74
 * @author Alvaro Zabala
75
 *
76
 */
77
public class LyrMustBeCoveredByLyr extends LyrMustBeCoveredByOneGeometry {
78
79
        static final String RULE_NAME = Messages.getText("must_be_covered_by_all_lyr");
80
81
        static {
82
                DEFAULT_ERROR_SYMBOL.setDescription(RULE_NAME);
83
        }
84
85
        public LyrMustBeCoveredByLyr(Topology topology,
86
                         FLyrVect originLyr,
87
                         FLyrVect destinationLyr){
88
                super(topology, originLyr, destinationLyr);
89
        }
90
91
92
        public LyrMustBeCoveredByLyr(){
93
                super();
94
        }
95
96
        @Override
97
        protected void checkWithNeighbourhood(IFeature feature, Rectangle2D extendedBounds, IFeatureIterator neighbourhood) throws BaseException{
98
                Geometry firstGeometry = NewFConverter.toJtsGeometry(feature.getGeometry());
99
                List<Geometry> neighboursGeo = new ArrayList<Geometry>();
100
                while (neighbourhood.hasNext()) {
101
                        IFeature neighbourFeature = neighbourhood.next();
102
                        IGeometry geom2 = neighbourFeature.getGeometry();
103
                        if(acceptsDestinationGeometryType(geom2.getGeometryType())){
104
                                Rectangle2D rect2 = geom2.getBounds2D();
105
                                if (extendedBounds.intersects(rect2)) {
106
                                        Geometry jtsGeom2 = NewFConverter.toJtsGeometry(geom2);
107
                                        if(!checkSpatialPredicate(feature, firstGeometry,
108
                                                                                                                neighbourFeature, jtsGeom2 )){
109
                                                neighboursGeo.add(jtsGeom2);
110
                                        }else
111
                                                return;//checks the rule
112
                                }//if
113
                        }//if
114
                }//while
115
                //at this point, feature is not covered by one neighbour feature
116
                //we check for all the neighbourhood
117
                Geometry[] geometries = neighboursGeo.toArray(new Geometry[0]);
118
                GeometryCollection geomCol = JtsUtil.GEOMETRY_FACTORY.createGeometryCollection(geometries);
119
                Geometry buffer = geomCol.buffer(0d);
120
                if(! firstGeometry.coveredBy(buffer)){
121
                        Geometry errorGeo = EnhancedPrecisionOp.difference(firstGeometry, buffer);
122
                        addTopologyError(createTopologyError(errorGeo, feature, null));
123
                }
124
        }
125
126
127
        @Override
128
        public String getName() {
129
                return RULE_NAME;
130
        }
131
}