Revision 10626 trunk/extensions/extGeoProcessing/src/com/iver/cit/gvsig/geoprocess/impl/clip/fmap/ClipVisitor.java
ClipVisitor.java | ||
---|---|---|
45 | 45 |
* |
46 | 46 |
* $Id$ |
47 | 47 |
* $Log$ |
48 |
* Revision 1.2 2006-07-21 09:10:34 azabala |
|
48 |
* Revision 1.3 2007-03-06 16:47:58 caballero |
|
49 |
* Exceptions |
|
50 |
* |
|
51 |
* Revision 1.2 2006/07/21 09:10:34 azabala |
|
49 | 52 |
* fixed bug 608: user doesnt enter any result file to the geoprocess panel |
50 | 53 |
* |
51 | 54 |
* Revision 1.1 2006/06/20 18:20:45 azabala |
... | ... | |
91 | 94 |
*/ |
92 | 95 |
package com.iver.cit.gvsig.geoprocess.impl.clip.fmap; |
93 | 96 |
|
94 |
import com.iver.cit.gvsig.fmap.DriverException; |
|
97 |
import com.hardcode.gdbms.driver.exceptions.ReadDriverException; |
|
98 |
import com.hardcode.gdbms.driver.exceptions.SchemaEditionException; |
|
99 |
import com.iver.cit.gvsig.exceptions.visitors.ProcessVisitorException; |
|
100 |
import com.iver.cit.gvsig.exceptions.visitors.StartVisitorException; |
|
101 |
import com.iver.cit.gvsig.exceptions.visitors.VisitorException; |
|
95 | 102 |
import com.iver.cit.gvsig.fmap.core.IGeometry; |
96 | 103 |
import com.iver.cit.gvsig.fmap.drivers.ITableDefinition; |
97 |
import com.iver.cit.gvsig.fmap.edition.EditionException; |
|
98 | 104 |
import com.iver.cit.gvsig.fmap.edition.ISchemaManager; |
99 | 105 |
import com.iver.cit.gvsig.fmap.edition.IWriter; |
100 | 106 |
import com.iver.cit.gvsig.fmap.layers.FBitSet; |
... | ... | |
103 | 109 |
import com.iver.cit.gvsig.fmap.layers.layerOperations.AlphanumericData; |
104 | 110 |
import com.iver.cit.gvsig.fmap.layers.layerOperations.VectorialData; |
105 | 111 |
import com.iver.cit.gvsig.fmap.operations.strategies.FeatureVisitor; |
106 |
import com.iver.cit.gvsig.fmap.operations.strategies.VisitException; |
|
107 | 112 |
import com.iver.cit.gvsig.geoprocess.core.fmap.FeaturePersisterProcessor; |
108 | 113 |
import com.iver.cit.gvsig.geoprocess.core.util.GeometryUtil; |
109 | 114 |
import com.vividsolutions.jts.geom.Geometry; |
... | ... | |
112 | 117 |
* with the convex hull of another layer. |
113 | 118 |
* If the geometry of the feature analyzed doesnt intersect with the convex |
114 | 119 |
* hull geometry, the clipvisitor will ignore it. |
115 |
*
|
|
120 |
* |
|
116 | 121 |
* It intersects, computes intersection and creates a new feature with |
117 | 122 |
* the same attributes and the new intersection geometry. |
118 | 123 |
* @author azabala |
119 | 124 |
* |
120 | 125 |
*/ |
121 | 126 |
public class ClipVisitor implements FeatureVisitor { |
122 |
|
|
127 |
|
|
123 | 128 |
/** |
124 | 129 |
* Clipping geometry: the convex hull of the |
125 | 130 |
* clipping layer |
... | ... | |
133 | 138 |
* Processes individual clip results |
134 | 139 |
*/ |
135 | 140 |
private FeaturePersisterProcessor resultProcessor; |
136 |
|
|
141 |
|
|
137 | 142 |
/** |
138 | 143 |
* If its different of null manages user selection (discarting any |
139 | 144 |
* feature else) |
... | ... | |
143 | 148 |
* Constructor. It requires clipping geometry. |
144 | 149 |
* @param clippingGeometry |
145 | 150 |
*/ |
146 |
public ClipVisitor(Geometry clippingGeometry,
|
|
151 |
public ClipVisitor(Geometry clippingGeometry, |
|
147 | 152 |
ITableDefinition layerDefinition, |
148 | 153 |
ISchemaManager schemaManager, |
149 | 154 |
IWriter writer){ |
150 |
|
|
155 |
|
|
151 | 156 |
this.clippingConvexHull = clippingGeometry; |
152 |
try { |
|
153 |
this.resultProcessor = new FeaturePersisterProcessor(layerDefinition, |
|
154 |
schemaManager,writer); |
|
155 |
} catch (EditionException e) { |
|
156 |
// TODO Auto-generated catch block |
|
157 |
e.printStackTrace(); |
|
158 |
} |
|
159 |
|
|
157 |
try { |
|
158 |
this.resultProcessor = new FeaturePersisterProcessor(layerDefinition, |
|
159 |
schemaManager,writer); |
|
160 |
} catch (SchemaEditionException e) { |
|
161 |
// TODO Auto-generated catch block |
|
162 |
e.printStackTrace(); |
|
163 |
} catch (VisitorException e) { |
|
164 |
// TODO Auto-generated catch block |
|
165 |
e.printStackTrace(); |
|
166 |
} |
|
167 |
|
|
160 | 168 |
} |
161 |
|
|
169 |
|
|
162 | 170 |
public void setSelection(FBitSet selection){ |
163 | 171 |
this.selection = selection; |
164 | 172 |
} |
165 |
|
|
173 |
|
|
166 | 174 |
/** |
167 | 175 |
* clips feature's geometry with the clipping geometry, preserving |
168 | 176 |
* feature's original attributes. |
169 | 177 |
* If feature's geometry doesnt touch clipping geometry, it will be |
170 | 178 |
* ignored. |
171 | 179 |
*/ |
172 |
public void visit(IGeometry g, int index) throws VisitException { |
|
173 |
|
|
180 |
public void visit(IGeometry g, int index) throws VisitorException, ProcessVisitorException {
|
|
181 |
|
|
174 | 182 |
//TODO METER EL PRINCIPIO Y EL FINAL EN EL VISITOR ABSTRACTO |
175 | 183 |
//AS?, TENDRIAMOS LA GESTI?N TOPOL?GICA EN CADA VISITOR |
176 |
|
|
177 |
|
|
184 |
|
|
185 |
|
|
178 | 186 |
if(g == null) |
179 | 187 |
return; |
180 | 188 |
if(selection != null){ |
... | ... | |
196 | 204 |
* TODO En este caso, la de recorte chequearla al principio |
197 | 205 |
* (cuando se calcula) y solo chequearemos las de entrada |
198 | 206 |
* conforme nos van viniendo. |
199 |
*
|
|
207 |
* |
|
200 | 208 |
* HAY QUE CREAR UN FRAMEWORK DE CORRECCI?N TOPOL?GICA DE |
201 | 209 |
* GEOMETRIAS: |
202 | 210 |
* -Mirando autointersecciones. |
... | ... | |
217 | 225 |
resultProcessor.processJtsGeometry(newGeom, index); |
218 | 226 |
}catch(com.vividsolutions.jts.geom.TopologyException ee){ |
219 | 227 |
ee.printStackTrace(); |
228 |
} catch (ReadDriverException ee) { |
|
229 |
// TODO Auto-generated catch block |
|
230 |
ee.printStackTrace(); |
|
220 | 231 |
}; |
221 |
}//catch |
|
232 |
} catch (ReadDriverException e) { |
|
233 |
// TODO Auto-generated catch block |
|
234 |
e.printStackTrace(); |
|
235 |
} |
|
222 | 236 |
}//if |
223 | 237 |
} |
224 | 238 |
|
225 |
public void stop(FLayer layer) { |
|
239 |
public void stop(FLayer layer) throws VisitorException {
|
|
226 | 240 |
resultProcessor.finish(); |
227 | 241 |
} |
228 | 242 |
|
229 |
public boolean start(FLayer layer) { |
|
243 |
public boolean start(FLayer layer) throws StartVisitorException {
|
|
230 | 244 |
if(layer instanceof AlphanumericData && layer instanceof VectorialData){ |
231 | 245 |
try { |
232 | 246 |
this.recordset = ((AlphanumericData)layer).getRecordset(); |
233 | 247 |
this.resultProcessor.setSelectableDataSource(recordset); |
234 |
} catch (DriverException e) { |
|
235 |
return false;//must we throw an Exception??
|
|
248 |
} catch (ReadDriverException e) {
|
|
249 |
return false; |
|
236 | 250 |
} |
237 | 251 |
return true; |
238 | 252 |
} |
... | ... | |
246 | 260 |
public void setRecordset(SelectableDataSource recordset) { |
247 | 261 |
this.recordset = recordset; |
248 | 262 |
} |
249 |
|
|
263 |
|
|
250 | 264 |
public String getProcessDescription() { |
251 | 265 |
return "Clipping features agaisnt a clip geometry"; |
252 | 266 |
} |
Also available in: Unified diff