root / trunk / libraries / libTopology / src / org / gvsig / topology / topologyrules / LyrMustCrossWith.java @ 24086
History | View | Annotate | Download (4.25 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 |
|
53 |
import org.gvsig.exceptions.BaseException; |
54 |
import org.gvsig.fmap.core.NewFConverter; |
55 |
import org.gvsig.topology.ITopologyErrorFix; |
56 |
import org.gvsig.topology.Messages; |
57 |
import org.gvsig.topology.Topology; |
58 |
import org.gvsig.topology.TopologyRuleDefinitionException; |
59 |
import org.gvsig.topology.errorfixes.DeleteTopologyErrorFix; |
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 |
|
67 |
/**
|
68 |
* Each element of origin layer must cross with at least one element
|
69 |
* of destination layer.
|
70 |
*
|
71 |
*
|
72 |
* @author Alvaro Zabala
|
73 |
*
|
74 |
*/
|
75 |
public class LyrMustCrossWith extends AbstractSpatialPredicateTwoLyrRule { |
76 |
|
77 |
static final String RULE_NAME = Messages.getText("must_cross"); |
78 |
|
79 |
static {
|
80 |
DEFAULT_ERROR_SYMBOL.setDescription(RULE_NAME); |
81 |
automaticErrorFixes.add(new DeleteTopologyErrorFix());
|
82 |
} |
83 |
|
84 |
|
85 |
|
86 |
public LyrMustCrossWith(Topology topology,
|
87 |
FLyrVect originLyr, |
88 |
FLyrVect destinationLyr){ |
89 |
super(topology, originLyr, destinationLyr);
|
90 |
} |
91 |
|
92 |
|
93 |
public LyrMustCrossWith(){
|
94 |
super();
|
95 |
} |
96 |
|
97 |
|
98 |
@Override
|
99 |
protected boolean acceptsDestinationGeometryType(int shapeType) { |
100 |
return true; |
101 |
} |
102 |
|
103 |
@Override
|
104 |
protected boolean acceptsOriginGeometryType(int shapeType) { |
105 |
return true; |
106 |
} |
107 |
|
108 |
@Override
|
109 |
protected void checkWithNeighbourhood(IFeature feature, Rectangle2D extendedBounds, IFeatureIterator neighbourhood) throws BaseException{ |
110 |
Geometry firstGeometry = NewFConverter.toJtsGeometry(feature.getGeometry()); |
111 |
while (neighbourhood.hasNext()) {
|
112 |
IFeature neighbourFeature = neighbourhood.next(); |
113 |
IGeometry geom2 = neighbourFeature.getGeometry(); |
114 |
if(acceptsDestinationGeometryType(geom2.getGeometryType())){
|
115 |
Rectangle2D rect2 = geom2.getBounds2D();
|
116 |
if (extendedBounds.intersects(rect2)) {
|
117 |
Geometry jtsGeom2 = NewFConverter.toJtsGeometry(geom2); |
118 |
if(checkSpatialPredicate(feature, firstGeometry,
|
119 |
neighbourFeature, jtsGeom2 )){ |
120 |
return;
|
121 |
} |
122 |
}//if
|
123 |
}//if
|
124 |
}//while
|
125 |
//at this point, feature doesnt cover any feature of destination layer
|
126 |
addTopologyError(createTopologyError(firstGeometry, feature, null));
|
127 |
} |
128 |
|
129 |
@Override
|
130 |
protected boolean checkSpatialPredicate(IFeature feature, |
131 |
Geometry firstGeometry, IFeature neighbourFeature, Geometry jtsGeom2) { |
132 |
|
133 |
return firstGeometry.crosses(jtsGeom2);
|
134 |
} |
135 |
|
136 |
@Override
|
137 |
public void checkPreconditions() throws TopologyRuleDefinitionException { |
138 |
} |
139 |
|
140 |
@Override
|
141 |
public String getName() { |
142 |
return RULE_NAME;
|
143 |
} |
144 |
|
145 |
public boolean acceptsDestinationLyr(FLyrVect originLyr) { |
146 |
return true; |
147 |
} |
148 |
|
149 |
public boolean acceptsOriginLyr(FLyrVect originLyr) { |
150 |
return true; |
151 |
} |
152 |
|
153 |
public ITopologyErrorFix getDefaultFix(){
|
154 |
return automaticErrorFixes.get(0); |
155 |
} |
156 |
|
157 |
} |