Revision 10626 trunk/extensions/extGeoProcessing/src/com/iver/cit/gvsig/geoprocess/impl/dissolve/fmap/DissolveGeoprocess.java
DissolveGeoprocess.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 |
... | ... | |
93 | 96 |
|
94 | 97 |
import java.util.Map; |
95 | 98 |
|
99 |
import com.hardcode.gdbms.driver.exceptions.ReadDriverException; |
|
100 |
import com.hardcode.gdbms.driver.exceptions.SchemaEditionException; |
|
96 | 101 |
import com.iver.andami.PluginServices; |
97 |
import com.iver.cit.gvsig.fmap.DriverException; |
|
98 |
import com.iver.cit.gvsig.fmap.drivers.DriverIOException; |
|
99 | 102 |
import com.iver.cit.gvsig.fmap.drivers.ILayerDefinition; |
100 |
import com.iver.cit.gvsig.fmap.edition.EditionException; |
|
101 | 103 |
import com.iver.cit.gvsig.fmap.layers.FLyrVect; |
102 | 104 |
import com.iver.cit.gvsig.geoprocess.core.fmap.AbstractGeoprocess; |
103 | 105 |
import com.iver.cit.gvsig.geoprocess.core.fmap.FeaturePersisterProcessor2; |
... | ... | |
109 | 111 |
import com.iver.utiles.swing.threads.IMonitorableTask; |
110 | 112 |
/** |
111 | 113 |
* Processes each geometry of a polygonal vectorial layer, looking for |
112 |
* its adjacent polygons. If this adjacent polygons has the same specified
|
|
114 |
* its adjacent polygons. If this adjacent polygons has the same specified |
|
113 | 115 |
* field value as processed geometry, this polygons will be dissolved. |
114 |
*
|
|
115 |
*
|
|
116 |
* |
|
117 |
* |
|
116 | 118 |
* @author azabala |
117 | 119 |
* |
118 | 120 |
*/ |
... | ... | |
123 | 125 |
private boolean dissolveOnlySelection; |
124 | 126 |
private ILayerDefinition resultLayerDefinition; |
125 | 127 |
private Map fields_functions; |
126 |
|
|
128 |
|
|
127 | 129 |
//AZABALA |
128 | 130 |
/* |
129 | 131 |
private DissolveVisitor visitor; |
130 | 132 |
*/ |
131 |
private FeatureDissolver visitor;
|
|
132 |
private IDissolveCriteria criteria;
|
|
133 |
private FeatureDissolver visitor; |
|
134 |
private IDissolveCriteria criteria; |
|
133 | 135 |
private int dissolveType = FeatureDissolver.ALPHANUMERIC_DISSOLVE; |
134 |
|
|
135 |
|
|
136 |
|
|
137 |
|
|
138 |
|
|
136 |
|
|
137 |
|
|
138 |
|
|
139 |
|
|
140 |
|
|
139 | 141 |
private boolean dissolveOnlyAdjacents; |
140 |
|
|
141 |
|
|
142 |
|
|
143 |
|
|
142 | 144 |
/** |
143 | 145 |
* Constructor. |
144 |
*
|
|
145 |
* @param inputLayer Layer whose geometries we are
|
|
146 |
* |
|
147 |
* @param inputLayer Layer whose geometries we are |
|
146 | 148 |
* going to dissolve |
147 | 149 |
*/ |
148 | 150 |
public DissolveGeoprocess(FLyrVect inputLayer, String dissolveField) { |
149 | 151 |
setFirstOperand(inputLayer); |
150 | 152 |
this.dissolveField = dissolveField; |
151 | 153 |
} |
152 |
|
|
154 |
|
|
153 | 155 |
public void setFieldsFunctions(Map fieldsFunctions){ |
154 | 156 |
this.fields_functions = fieldsFunctions; |
155 | 157 |
} |
... | ... | |
164 | 166 |
(Boolean) params.get("layer_selection"); |
165 | 167 |
if(onlySelection != null) |
166 | 168 |
dissolveOnlySelection = onlySelection.booleanValue(); |
167 |
|
|
169 |
|
|
168 | 170 |
Boolean onlyAdjacents = |
169 | 171 |
(Boolean) params.get("only_adjacents"); |
170 | 172 |
if(onlyAdjacents != null) |
171 | 173 |
dissolveOnlyAdjacents = onlyAdjacents.booleanValue(); |
172 |
|
|
173 |
|
|
174 |
|
|
175 |
|
|
174 | 176 |
try { |
175 | 177 |
if(dissolveOnlyAdjacents){ |
176 | 178 |
dissolveType = FeatureDissolver.SPATIAL_DISSOLVE; |
177 |
criteria =
|
|
179 |
criteria = |
|
178 | 180 |
new SingleFieldAdjacencyDissolveCriteria(dissolveField, |
179 | 181 |
firstLayer); |
180 |
// visitor = new DissolveVisitor(dissolveField, processor);
|
|
182 |
// visitor = new DissolveVisitor(dissolveField, processor); |
|
181 | 183 |
}else{ |
182 | 184 |
// visitor = new AlphanumericDissolveVisitor(dissolveField, processor); |
183 | 185 |
criteria = new SingleFieldDissolveCriteria(dissolveField, |
184 |
firstLayer);
|
|
186 |
firstLayer); |
|
185 | 187 |
} |
186 | 188 |
} catch (com.hardcode.gdbms.engine.data.driver.DriverException e) { |
187 | 189 |
throw new GeoprocessException("Error preparando la lectura del dissolve field", e); |
188 | 190 |
} |
189 |
|
|
191 |
|
|
190 | 192 |
} |
191 | 193 |
|
192 | 194 |
public void checkPreconditions() throws GeoprocessException { |
193 | 195 |
if (firstLayer == null) |
194 | 196 |
throw new GeoprocessException("Buffer con capa de entrada a null"); |
195 |
if(this.writer == null ||
|
|
197 |
if(this.writer == null || |
|
196 | 198 |
this.schemaManager == null){ |
197 | 199 |
throw new GeoprocessException("Operacion de dissolve sin especificar capa de resultados"); |
198 | 200 |
} |
... | ... | |
200 | 202 |
if(firstLayer.getShapeType() != XTypes.POLYGON |
201 | 203 |
&& firstLayer.getShapeType() != XTypes.MULTI) |
202 | 204 |
throw new GeoprocessException("La capa a disolver debe ser de pol?gonos"); |
203 |
} catch (DriverException e) { |
|
205 |
} catch (ReadDriverException e) {
|
|
204 | 206 |
throw new GeoprocessException("Error intentando verificar el tipo de geometria de la capa a disolver"); |
205 |
}
|
|
207 |
} |
|
206 | 208 |
if(this.dissolveField == null) |
207 | 209 |
throw new GeoprocessException("No se ha proporcionado el campo para dissolver"); |
208 | 210 |
|
... | ... | |
213 | 215 |
try { |
214 | 216 |
FeaturePersisterProcessor2 processor = |
215 | 217 |
new FeaturePersisterProcessor2(writer); |
216 |
|
|
218 |
|
|
217 | 219 |
if(dissolveOnlyAdjacents){ |
218 | 220 |
visitor = new AlphanumericDissolveVisitor(dissolveField, processor); |
219 | 221 |
}else{ |
220 |
visitor = new DissolveVisitor(this.dissolveField, processor);
|
|
222 |
visitor = new DissolveVisitor(this.dissolveField, processor); |
|
221 | 223 |
} |
222 | 224 |
visitor.setDissolvedAttributesInfo(fields_functions); |
223 | 225 |
Strategy strategy = |
... | ... | |
230 | 232 |
}else{ |
231 | 233 |
strategy.process(visitor); |
232 | 234 |
} |
233 |
|
|
234 |
|
|
235 |
|
|
235 |
|
|
236 |
|
|
237 |
|
|
236 | 238 |
} catch (DriverException e) { |
237 | 239 |
throw new GeoprocessException("Error accediendo a los datos durante un dissolve"); |
238 | 240 |
} catch (VisitException e) { |
239 | 241 |
throw new GeoprocessException("Error al procesar los elementos de la capa de entrada durante un dissolve"); |
240 | 242 |
} |
241 |
|
|
243 |
|
|
242 | 244 |
*/ |
243 | 245 |
} |
244 |
|
|
245 |
|
|
246 | 246 |
|
247 |
|
|
248 |
|
|
247 | 249 |
public void cancel() { |
248 | 250 |
try { |
249 | 251 |
schemaManager.removeSchema(""); |
250 |
} catch (EditionException e) { |
|
252 |
} catch (SchemaEditionException e) {
|
|
251 | 253 |
// TODO Auto-generated catch block |
252 | 254 |
e.printStackTrace(); |
253 | 255 |
} |
254 | 256 |
} |
255 |
|
|
257 |
|
|
256 | 258 |
public ILayerDefinition createLayerDefinition() { |
257 | 259 |
if(resultLayerDefinition == null) |
258 | 260 |
resultLayerDefinition = criteria.createLayerDefinition(fields_functions); |
259 | 261 |
return resultLayerDefinition; |
260 | 262 |
} |
261 |
|
|
262 |
|
|
263 | 263 |
|
264 |
|
|
265 |
|
|
264 | 266 |
public IMonitorableTask createTask() { |
265 | 267 |
try { |
266 | 268 |
return new DissolveMonitorableTask(); |
267 |
} catch (DriverIOException e) {
|
|
269 |
} catch (ReadDriverException e) {
|
|
268 | 270 |
return null; |
269 | 271 |
} |
270 | 272 |
} |
271 |
|
|
273 |
|
|
272 | 274 |
/** |
273 | 275 |
* IMonitorableTask that allows to run diff geoprocess in background, |
274 | 276 |
* with cancelation requests. |
275 |
*
|
|
277 |
* |
|
276 | 278 |
* @author azabala |
277 |
*
|
|
279 |
* |
|
278 | 280 |
*/ |
279 | 281 |
class DissolveMonitorableTask implements IMonitorableTask { |
280 | 282 |
private CancellableMonitorable cancelMonitor = null; |
... | ... | |
283 | 285 |
String DISSOLVE_NOTE = PluginServices.getText(this, "Mensaje_procesando_dissolves"); |
284 | 286 |
String OF = PluginServices.getText(this, "De"); |
285 | 287 |
private boolean finished = false; |
286 |
|
|
288 |
|
|
287 | 289 |
FeatureDissolver dissolver = null; |
288 | 290 |
|
289 |
DissolveMonitorableTask() throws DriverIOException {
|
|
291 |
DissolveMonitorableTask() throws ReadDriverException{
|
|
290 | 292 |
initialize(); |
291 | 293 |
} |
292 |
void initialize() throws DriverIOException{
|
|
294 |
void initialize() throws ReadDriverException {
|
|
293 | 295 |
cancelMonitor = createCancelMonitor(); |
294 | 296 |
} |
295 | 297 |
|
296 |
private CancellableMonitorable createCancelMonitor() throws DriverIOException{
|
|
297 |
DefaultCancellableMonitorable monitor = new
|
|
298 |
private CancellableMonitorable createCancelMonitor() throws ReadDriverException{
|
|
299 |
DefaultCancellableMonitorable monitor = new |
|
298 | 300 |
DefaultCancellableMonitorable(); |
299 | 301 |
monitor.setInitialStep(0); |
300 | 302 |
//monitor.setDeterminatedProcess(false); |
301 |
|
|
302 |
|
|
303 |
|
|
304 |
|
|
303 | 305 |
//FIXME: Si solo dissolvemos la seleccion, esto esta mal |
304 | 306 |
monitor.setFinalStep(firstLayer.getSource().getShapeCount()); |
305 | 307 |
monitor.setDeterminatedProcess(true); |
... | ... | |
346 | 348 |
try { |
347 | 349 |
FeaturePersisterProcessor2 processor = |
348 | 350 |
new FeaturePersisterProcessor2(writer); |
349 |
|
|
351 |
|
|
350 | 352 |
dissolver = new |
351 |
FeatureDissolver(processor,
|
|
352 |
firstLayer,
|
|
353 |
FeatureDissolver(processor, |
|
354 |
firstLayer, |
|
353 | 355 |
fields_functions, |
354 | 356 |
criteria, |
355 | 357 |
dissolveType); |
356 | 358 |
dissolver.dissolve(cancelMonitor); |
357 |
|
|
358 |
|
|
359 |
|
|
360 |
|
|
359 | 361 |
// visitor.setDissolvedAttributesInfo(fields_functions); |
360 | 362 |
// Strategy strategy = |
361 | 363 |
// StrategyManager.getStrategy(firstLayer); |
362 |
// visitor.setStrategy(strategy);
|
|
364 |
// visitor.setStrategy(strategy); |
|
363 | 365 |
// if(dissolveOnlySelection){ |
364 | 366 |
// strategy.process(visitor, firstLayer. |
365 | 367 |
// getRecordset(). |
... | ... | |
370 | 372 |
// } |
371 | 373 |
}catch(Exception e){ |
372 | 374 |
e.printStackTrace(); |
373 |
|
|
375 |
|
|
374 | 376 |
} finally{ |
375 | 377 |
finished = true; |
376 | 378 |
} |
Also available in: Unified diff