Revision 10626 trunk/extensions/extGeoProcessing/src/com/iver/cit/gvsig/geoprocess/impl/intersection/fmap/IntersectionGeoprocess.java
IntersectionGeoprocess.java | ||
---|---|---|
45 | 45 |
* |
46 | 46 |
* $Id$ |
47 | 47 |
* $Log$ |
48 |
* Revision 1.2 2006-06-29 07:33:57 fjp |
|
48 |
* Revision 1.3 2007-03-06 16:47:58 caballero |
|
49 |
* Exceptions |
|
50 |
* |
|
51 |
* Revision 1.2 2006/06/29 07:33:57 fjp |
|
49 | 52 |
* Cambios ISchemaManager y IFieldManager por terminar |
50 | 53 |
* |
51 | 54 |
* Revision 1.1 2006/06/20 18:20:45 azabala |
... | ... | |
90 | 93 |
|
91 | 94 |
import java.util.Map; |
92 | 95 |
|
93 |
import com.hardcode.gdbms.engine.data.driver.DriverException; |
|
96 |
import com.hardcode.gdbms.driver.exceptions.ReadDriverException; |
|
97 |
import com.hardcode.gdbms.driver.exceptions.SchemaEditionException; |
|
94 | 98 |
import com.iver.andami.PluginServices; |
95 |
import com.iver.cit.gvsig.fmap.drivers.DriverIOException; |
|
99 |
import com.iver.cit.gvsig.exceptions.expansionfile.ExpansionFileReadException; |
|
100 |
import com.iver.cit.gvsig.exceptions.visitors.ProcessVisitorException; |
|
101 |
import com.iver.cit.gvsig.exceptions.visitors.VisitorException; |
|
96 | 102 |
import com.iver.cit.gvsig.fmap.drivers.ILayerDefinition; |
97 |
import com.iver.cit.gvsig.fmap.edition.EditionException; |
|
98 | 103 |
import com.iver.cit.gvsig.fmap.layers.FBitSet; |
99 | 104 |
import com.iver.cit.gvsig.fmap.layers.FLyrVect; |
100 | 105 |
import com.iver.cit.gvsig.fmap.operations.strategies.Strategy; |
101 | 106 |
import com.iver.cit.gvsig.fmap.operations.strategies.StrategyManager; |
102 |
import com.iver.cit.gvsig.fmap.operations.strategies.VisitException; |
|
103 | 107 |
import com.iver.cit.gvsig.geoprocess.core.fmap.AbstractGeoprocess; |
104 | 108 |
import com.iver.cit.gvsig.geoprocess.core.fmap.DefinitionUtils; |
105 | 109 |
import com.iver.cit.gvsig.geoprocess.core.fmap.FeaturePersisterProcessor2; |
... | ... | |
111 | 115 |
import com.iver.utiles.swing.threads.IMonitorableTask; |
112 | 116 |
/** |
113 | 117 |
* Computes intersection between two layers. |
114 |
*
|
|
118 |
* |
|
115 | 119 |
* @author azabala |
116 | 120 |
* |
117 | 121 |
*/ |
118 | 122 |
public class IntersectionGeoprocess extends AbstractGeoprocess |
119 | 123 |
implements IOverlayGeoprocess { |
120 |
|
|
124 |
|
|
121 | 125 |
/** |
122 | 126 |
* overlay layer |
123 | 127 |
*/ |
... | ... | |
137 | 141 |
* flag to only clip with selection of clipping layer |
138 | 142 |
*/ |
139 | 143 |
private boolean onlyClipLayerSelection = false; |
140 |
|
|
144 |
|
|
141 | 145 |
public IntersectionGeoprocess(FLyrVect inputLayer){ |
142 | 146 |
setFirstOperand(inputLayer); |
143 | 147 |
} |
144 |
|
|
148 |
|
|
145 | 149 |
public void setSecondOperand(FLyrVect overlayLayer) { |
146 | 150 |
this.overlayLayer = overlayLayer; |
147 | 151 |
|
... | ... | |
181 | 185 |
throw new GeoprocessException( |
182 | 186 |
"Primera capa de interseccion no es de pol?gonos"); |
183 | 187 |
} |
184 |
if ((overlayLayer.getShapeType() != XTypes.POLYGON) &&
|
|
188 |
if ((overlayLayer.getShapeType() != XTypes.POLYGON) && |
|
185 | 189 |
(overlayLayer.getShapeType() != XTypes.MULTI)) { |
186 | 190 |
throw new GeoprocessException( |
187 | 191 |
"Segunda capa de interseccion no es de pol?gonos"); |
188 | 192 |
} |
189 |
} catch (com.iver.cit.gvsig.fmap.DriverException e) {
|
|
193 |
} catch (ReadDriverException e) {
|
|
190 | 194 |
throw new GeoprocessException( |
191 | 195 |
"Error al tratar de chequear si las capas a intersectar son de pol?gonos"); |
192 | 196 |
} |
... | ... | |
194 | 198 |
} |
195 | 199 |
|
196 | 200 |
public void process() throws GeoprocessException { |
197 |
|
|
201 |
|
|
198 | 202 |
try { |
199 | 203 |
//Prepare the result |
200 | 204 |
this.schemaManager.createSchema(createLayerDefinition()); |
201 | 205 |
writer.preProcess(); |
202 |
Strategy strategy =
|
|
206 |
Strategy strategy = |
|
203 | 207 |
StrategyManager.getStrategy(firstLayer); |
204 |
Strategy overlayStrategy =
|
|
208 |
Strategy overlayStrategy = |
|
205 | 209 |
StrategyManager.getStrategy(overlayLayer); |
206 | 210 |
FeaturePersisterProcessor2 featureProcessor = |
207 | 211 |
new FeaturePersisterProcessor2(writer); |
208 |
IntersectVisitor visitor = new IntersectVisitor(overlayLayer,
|
|
209 |
featureProcessor,
|
|
212 |
IntersectVisitor visitor = new IntersectVisitor(overlayLayer, |
|
213 |
featureProcessor, |
|
210 | 214 |
overlayStrategy, |
211 | 215 |
onlyClipLayerSelection); |
212 | 216 |
if(this.onlyFirstLayerSelection){ |
213 |
strategy.process(visitor,
|
|
217 |
strategy.process(visitor, |
|
214 | 218 |
this.firstLayer.getRecordset().getSelection()); |
215 | 219 |
}else{ |
216 | 220 |
strategy.process(visitor); |
217 | 221 |
} |
218 |
|
|
219 |
} catch (EditionException e) { |
|
220 |
throw new GeoprocessException("Error al crear el esquema/fichero de la nueva capa"); |
|
221 |
} catch (DriverException e) { |
|
222 |
|
|
223 |
} catch (ReadDriverException e) { |
|
222 | 224 |
throw new GeoprocessException("Error de driver al calcular el geoproceso interseccion"); |
223 |
} catch (com.iver.cit.gvsig.fmap.DriverException e) { |
|
225 |
} catch (ProcessVisitorException e) { |
|
226 |
throw new GeoprocessException("Error al procesar el feature de una capa durante el geoproceso interseccion"); |
|
227 |
} catch (ExpansionFileReadException e) { |
|
224 | 228 |
throw new GeoprocessException("Error de driver al calcular el geoproceso interseccion"); |
225 |
} catch (VisitException e) { |
|
226 |
throw new GeoprocessException("Error al procesar el feature de una capa durante el geoproceso interseccion"); |
|
229 |
} catch (VisitorException e) { |
|
230 |
throw new GeoprocessException("Error de driver al calcular el geoproceso interseccion"); |
|
231 |
} catch (SchemaEditionException e) { |
|
232 |
throw new GeoprocessException("Error al crear el esquema/fichero de la nueva capa"); |
|
227 | 233 |
} |
228 |
}
|
|
234 |
} |
|
229 | 235 |
|
230 | 236 |
|
231 | 237 |
public void cancel() { |
232 | 238 |
try { |
233 | 239 |
schemaManager.removeSchema(""); |
234 |
} catch (EditionException e) { |
|
240 |
} catch (SchemaEditionException e) {
|
|
235 | 241 |
// TODO Auto-generated catch block |
236 | 242 |
e.printStackTrace(); |
237 | 243 |
} |
... | ... | |
259 | 265 |
return null; |
260 | 266 |
} |
261 | 267 |
} |
262 |
|
|
268 |
|
|
263 | 269 |
/** |
264 | 270 |
* IMonitorableTask that allows to run intersection geoprocess in background, |
265 | 271 |
* with cancelation requests. |
266 |
*
|
|
272 |
* |
|
267 | 273 |
* @author azabala |
268 |
*
|
|
274 |
* |
|
269 | 275 |
*/ |
270 | 276 |
class IntersectionMonitorableTask implements IMonitorableTask { |
271 | 277 |
private CancellableMonitorable cancelMonitor = null; |
... | ... | |
274 | 280 |
String OF = PluginServices.getText(this, "De"); |
275 | 281 |
private boolean finished = false; |
276 | 282 |
|
277 |
IntersectionMonitorableTask() throws DriverIOException, com.iver.cit.gvsig.fmap.DriverException {
|
|
283 |
IntersectionMonitorableTask() throws ReadDriverException {
|
|
278 | 284 |
initialize(); |
279 | 285 |
} |
280 |
void initialize() throws DriverIOException, com.iver.cit.gvsig.fmap.DriverException {
|
|
286 |
void initialize() throws ReadDriverException {
|
|
281 | 287 |
cancelMonitor = createCancelMonitor(); |
282 | 288 |
} |
283 | 289 |
|
284 |
private CancellableMonitorable createCancelMonitor() |
|
285 |
throws DriverIOException, com.iver.cit.gvsig.fmap.DriverException { |
|
286 |
DefaultCancellableMonitorable monitor = new |
|
290 |
private CancellableMonitorable createCancelMonitor() throws ReadDriverException { |
|
291 |
DefaultCancellableMonitorable monitor = new |
|
287 | 292 |
DefaultCancellableMonitorable(); |
288 | 293 |
monitor.setInitialStep(0); |
289 | 294 |
//Really its undeterminated, but we must to process all |
290 |
//elements of first layer (or selection) we are going to
|
|
295 |
//elements of first layer (or selection) we are going to |
|
291 | 296 |
//consideer determinated |
292 | 297 |
monitor.setDeterminatedProcess(true); |
293 | 298 |
int numSteps = 0; |
... | ... | |
337 | 342 |
//Prepare the result |
338 | 343 |
schemaManager.createSchema(createLayerDefinition()); |
339 | 344 |
writer.preProcess(); |
340 |
Strategy strategy =
|
|
345 |
Strategy strategy = |
|
341 | 346 |
StrategyManager.getStrategy(firstLayer); |
342 |
Strategy overlayStrategy =
|
|
347 |
Strategy overlayStrategy = |
|
343 | 348 |
StrategyManager.getStrategy(overlayLayer); |
344 | 349 |
FeaturePersisterProcessor2 featureProcessor = |
345 | 350 |
new FeaturePersisterProcessor2(writer); |
346 |
IntersectVisitor visitor = new IntersectVisitor(overlayLayer,
|
|
347 |
featureProcessor,
|
|
351 |
IntersectVisitor visitor = new IntersectVisitor(overlayLayer, |
|
352 |
featureProcessor, |
|
348 | 353 |
overlayStrategy, |
349 | 354 |
onlyClipLayerSelection); |
350 |
// AwtIntersectVisitor visitor = new AwtIntersectVisitor(overlayLayer,
|
|
351 |
// featureProcessor,
|
|
355 |
// AwtIntersectVisitor visitor = new AwtIntersectVisitor(overlayLayer, |
|
356 |
// featureProcessor, |
|
352 | 357 |
// overlayStrategy, |
353 | 358 |
// onlyClipLayerSelection); |
354 | 359 |
if(onlyFirstLayerSelection){ |
355 |
strategy.process(visitor,
|
|
360 |
strategy.process(visitor, |
|
356 | 361 |
firstLayer.getRecordset().getSelection(), |
357 | 362 |
cancelMonitor); |
358 | 363 |
}else{ |
359 | 364 |
strategy.process(visitor, cancelMonitor); |
360 | 365 |
} |
361 |
|
|
362 |
} catch (EditionException e) { |
|
363 |
throw new GeoprocessException("Error al crear el esquema/fichero de la nueva capa"); |
|
364 |
} catch (DriverException e) { |
|
366 |
|
|
367 |
} catch (ReadDriverException e) { |
|
365 | 368 |
throw new GeoprocessException("Error de driver al calcular el geoproceso interseccion"); |
366 |
} catch (com.iver.cit.gvsig.fmap.DriverException e) { |
|
369 |
} catch (ProcessVisitorException e) { |
|
370 |
throw new GeoprocessException("Error al procesar el feature de una capa durante el geoproceso interseccion"); |
|
371 |
} catch (ExpansionFileReadException e) { |
|
367 | 372 |
throw new GeoprocessException("Error de driver al calcular el geoproceso interseccion"); |
368 |
} catch (VisitException e) { |
|
369 |
throw new GeoprocessException("Error al procesar el feature de una capa durante el geoproceso interseccion"); |
|
373 |
} catch (VisitorException e) { |
|
374 |
throw new GeoprocessException("Error de driver al calcular el geoproceso interseccion"); |
|
375 |
} catch (SchemaEditionException e) { |
|
376 |
throw new GeoprocessException("Error al crear el esquema/fichero de la nueva capa"); |
|
377 |
|
|
370 | 378 |
}finally{ |
371 | 379 |
finished = true; |
372 | 380 |
} |
Also available in: Unified diff