Statistics
| Revision:

svn-gvsig-desktop / trunk / extensions / extGeoProcessing / src / com / iver / cit / gvsig / geoprocess / impl / buffer / fmap / BufferGeoprocess.java @ 10626

History | View | Annotate | Download (20.9 KB)

1
/*
2
 * Created on 01-feb-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: BufferGeoprocess.java 10626 2007-03-06 16:55:54Z caballero $
47
 * $Log$
48
 * Revision 1.4  2007-03-06 16:47:58  caballero
49
 * Exceptions
50
 *
51
 * Revision 1.3  2006/07/21 11:04:50  azabala
52
 * Unified createTask and process() methods
53
 *
54
 * Revision 1.2  2006/06/29 07:33:57  fjp
55
 * Cambios ISchemaManager y IFieldManager por terminar
56
 *
57
 * Revision 1.1  2006/06/20 18:20:45  azabala
58
 * first version in cvs
59
 *
60
 * Revision 1.2  2006/06/02 18:20:58  azabala
61
 * cuando el buffer es con dissolve se crea indice espacial para optimizar
62
 *
63
 * Revision 1.1  2006/05/24 21:14:41  azabala
64
 * primera version en cvs despues de refactoring orientado a crear un framework extensible de geoprocessing
65
 *
66
 * Revision 1.14  2006/05/01 19:18:09  azabala
67
 * revisi?n general del buffer (a?adidos anillos concentricos, buffers interiores y exteriores, etc)
68
 *
69
 * Revision 1.13  2006/03/23 21:02:58  azabala
70
 * *** empty log message ***
71
 *
72
 * Revision 1.12  2006/03/17 19:52:31  azabala
73
 * *** empty log message ***
74
 *
75
 * Revision 1.11  2006/03/14 19:35:13  azabala
76
 * *** empty log message ***
77
 *
78
 * Revision 1.10  2006/03/14 18:32:46  fjp
79
 * Cambio con LayerDefinition para que sea compatible con la definici?n de tablas tambi?n.
80
 *
81
 * Revision 1.9  2006/03/07 21:01:33  azabala
82
 * *** empty log message ***
83
 *
84
 * Revision 1.8  2006/03/06 19:48:39  azabala
85
 * *** empty log message ***
86
 *
87
 * Revision 1.7  2006/03/05 19:56:40  azabala
88
 * *** empty log message ***
89
 *
90
 * Revision 1.6  2006/02/17 16:04:50  azabala
91
 * *** empty log message ***
92
 *
93
 * Revision 1.5  2006/02/13 21:13:49  azabala
94
 * *** empty log message ***
95
 *
96
 * Revision 1.4  2006/02/13 18:38:03  azabala
97
 * *** empty log message ***
98
 *
99
 * Revision 1.3  2006/02/13 17:52:45  azabala
100
 * *** empty log message ***
101
 *
102
 * Revision 1.2  2006/02/12 21:02:44  azabala
103
 * *** empty log message ***
104
 *
105
 * Revision 1.1  2006/02/02 19:47:12  azabala
106
 * many refactorings
107
 *
108
 * Revision 1.1  2006/02/01 19:42:04  azabala
109
 * First version in CVS
110
 *
111
 *
112
 */
113
package com.iver.cit.gvsig.geoprocess.impl.buffer.fmap;
114

    
115
import java.io.File;
116
import java.io.IOException;
117
import java.util.Map;
118

    
119
import org.cresques.cts.IProjection;
120

    
121
import com.hardcode.gdbms.driver.exceptions.InitializeDriverException;
122
import com.hardcode.gdbms.driver.exceptions.InitializeWriterException;
123
import com.hardcode.gdbms.driver.exceptions.OpenDriverException;
124
import com.hardcode.gdbms.driver.exceptions.ReadDriverException;
125
import com.hardcode.gdbms.driver.exceptions.SchemaEditionException;
126
import com.hardcode.gdbms.engine.data.driver.DriverException;
127
import com.iver.andami.PluginServices;
128
import com.iver.cit.gvsig.exceptions.expansionfile.ExpansionFileReadException;
129
import com.iver.cit.gvsig.exceptions.layers.LoadLayerException;
130
import com.iver.cit.gvsig.exceptions.visitors.ProcessVisitorException;
131
import com.iver.cit.gvsig.exceptions.visitors.VisitorException;
132
import com.iver.cit.gvsig.fmap.drivers.FieldDescription;
133
import com.iver.cit.gvsig.fmap.drivers.ILayerDefinition;
134
import com.iver.cit.gvsig.fmap.drivers.SHPLayerDefinition;
135
import com.iver.cit.gvsig.fmap.drivers.shp.IndexedShpDriver;
136
import com.iver.cit.gvsig.fmap.edition.writers.shp.ShpWriter;
137
import com.iver.cit.gvsig.fmap.layers.FBitSet;
138
import com.iver.cit.gvsig.fmap.layers.FLyrVect;
139
import com.iver.cit.gvsig.fmap.layers.LayerFactory;
140
import com.iver.cit.gvsig.fmap.operations.strategies.Strategy;
141
import com.iver.cit.gvsig.fmap.operations.strategies.StrategyManager;
142
import com.iver.cit.gvsig.geoprocess.core.fmap.AbstractGeoprocess;
143
import com.iver.cit.gvsig.geoprocess.core.fmap.FeaturePersisterProcessor2;
144
import com.iver.cit.gvsig.geoprocess.core.fmap.GeometryPersisterProcessor;
145
import com.iver.cit.gvsig.geoprocess.core.fmap.GeoprocessException;
146
import com.iver.cit.gvsig.geoprocess.core.fmap.IOneLayerGeoprocess;
147
import com.iver.cit.gvsig.geoprocess.core.fmap.XTypes;
148
import com.iver.cit.gvsig.geoprocess.impl.dissolve.fmap.AdjacencyDissolveVisitor;
149
import com.iver.cit.gvsig.geoprocess.impl.dissolve.fmap.DissolveVisitor;
150
import com.iver.utiles.swing.threads.CancellableMonitorable;
151
import com.iver.utiles.swing.threads.DefaultCancellableMonitorable;
152
import com.iver.utiles.swing.threads.IMonitorableTask;
153

    
154
/**
155
 * Geoprocess that computes a buffer area around each feature's geometry of the
156
 * input layer. <br>
157
 * All the points interior to this buffer area has to be at a distance inferior
158
 * to "buffer distance" to the original geometry. This buffer distance could be
159
 * constant, or it could be a function of the value of a feature attribute.<br>
160
 *
161
 * @author azabala
162
 *
163
 */
164
public class BufferGeoprocess extends AbstractGeoprocess implements
165
                IOneLayerGeoprocess {
166

    
167
        /**
168
         * flag that represents buffer computing with one only buffer distance.
169
         */
170
        public static final byte CONSTANT_DISTANCE_STRATEGY = 0;
171

    
172
        /**
173
         * buffer computing with variable buffer distance in function of feature
174
         * attribute value
175
         */
176
        public static final byte ATTRIBUTE_DISTANCE_STRATEGY = 1;
177

    
178

    
179
        /**
180
         * Schema of the result layer
181
         */
182
        private ILayerDefinition resultLayerDefinition;
183

    
184
        /**
185
         * the geoprocess will operate only with selected elements of layer, or with
186
         * all elements.<br>
187
         * By default, it work with all elements.
188
         */
189
        private boolean bufferOnlySelection = false;
190

    
191
        /**
192
         * this flag makes the process to dissolve or not geometries of the result
193
         * layer, to avoid intersections in a polygon layer. By default, is true.<br>
194
         */
195
        private boolean dissolveBuffers = false;
196

    
197
        /**
198
         * Iterates over input layer geometries to compute buffered geometries by
199
         * using a distance buffer function.
200
         */
201
        private BufferVisitor bufferVisitor;
202

    
203
        /**
204
         * Constructor
205
         *
206
         * @param bufferLayer
207
         *            layer to buffer
208
         */
209
        public BufferGeoprocess(FLyrVect bufferLayer) {
210
                setFirstOperand(bufferLayer);
211
        }
212

    
213
        /**
214
         * Sets layer to buffer
215
         */
216
        public void setFirstOperand(FLyrVect bufferLayer) {
217
                this.firstLayer = bufferLayer;
218
        }
219

    
220
        /**
221
         * Sets user entry params to this geoprocess. This params represents user
222
         * preferences (FLayer are not optional params)
223
         */
224
        public void setParameters(Map params) throws GeoprocessException {
225
                Boolean onlySelection = (Boolean) params.get("layer_selection");
226
                if (onlySelection != null)
227
                        bufferOnlySelection = onlySelection.booleanValue();
228

    
229
                Boolean dissolve = (Boolean) params.get("dissolve_buffers");
230
                if (dissolve != null)
231
                        dissolveBuffers = dissolve.booleanValue();
232

    
233
                Byte strategy_flat = (Byte) params.get("strategy_flag");
234
                if (strategy_flat != null
235
                                && strategy_flat.byteValue() == ATTRIBUTE_DISTANCE_STRATEGY) {
236
                        // must check attribute name not null
237
                        String attributeName = (String) params.get("attr_name");
238
                        if (attributeName != null) {
239
                                bufferVisitor = new AttributeBufferVisitor(attributeName);
240
                        } else {
241
                                throw new GeoprocessException(
242
                                                "Buffer por atributo sin nombre de atributo");
243
                        }
244
                } else {
245
                        // default, constant strategy
246
                        // must check distance not null
247
                        Double dist = (Double) params.get("buffer_distance");
248
                        if (dist != null) {
249
                                double distance = dist.doubleValue();
250
                                bufferVisitor = new ConstantDistanceBufferVisitor(distance);
251
                        } else {
252
                                throw new GeoprocessException(
253
                                                "Buffer por dist constante sin distancia");
254
                        }
255
                }// else
256

    
257
                Byte capflag = (Byte) params.get("cap");
258
                if(capflag != null){
259
                        bufferVisitor.setTypeOfCap(capflag.byteValue());
260
                }
261

    
262
                Byte typePolFlag = (Byte) params.get("typePolBuffer");
263
                if(typePolFlag != null){
264
                        bufferVisitor.setTypeOfBuffer(typePolFlag.byteValue());
265
                }
266

    
267
                Integer numRingsFlag = (Integer) params.get("numRings");
268
                if(numRingsFlag != null){
269
                        bufferVisitor.setNumberOfRadialBuffers(numRingsFlag.intValue());
270
                }
271
        }
272

    
273

    
274
        /**
275
         * Checks preconditions to this geoprocess (input layer mustnt be null), etc
276
         */
277
        public void checkPreconditions() throws GeoprocessException {
278
                if (firstLayer == null)
279
                        throw new GeoprocessException("Buffer con capa de entrada a null");
280
                if (this.writer == null || this.schemaManager == null) {
281
                        throw new GeoprocessException(
282
                                        "Operacion de buffer sin especificar capa de resultados");
283
                }
284
        }
285

    
286
        /**
287
         * Computes buffer geoprocess, and saves results in solution layer.
288
         *
289
         */
290
        public void process() throws GeoprocessException {
291
                try {
292
                        createTask().run();
293
                } catch (Exception e) {
294
                        throw new GeoprocessException("Error durante la ejecuci?n del buffer", e);
295
                }
296
        }
297

    
298
        /**
299
         * Creates a temp layer with the file referenced by writer.
300
         * It is useful when you want to dissolve buffers, to avoid working
301
         * with intermediate results in memory.
302
         * @return
303
         * @throws OpenDriverException
304
         * @throws InitializeDriverException
305
         * @throws LoadLayerException
306
         * @throws IOException
307
         * @throws DriverException
308
         */
309
        public FLyrVect createTempLayer() throws OpenDriverException, InitializeDriverException, LoadLayerException {
310
                FLyrVect solution = null;
311
                String fileName = ((ShpWriter) writer).getShpPath();
312
                File file = new File(fileName);
313
                IProjection proj = firstLayer.getProjection();
314
                IndexedShpDriver driver = new IndexedShpDriver();
315
                driver.open(file);
316
                driver.initialize();
317
                solution = (FLyrVect) LayerFactory.createLayer(fileName, driver, file,
318
                                proj);
319
                return solution;
320

    
321
        }
322

    
323
        private void computeAndDissolveBuffer(Strategy strategy,
324
                        CancellableMonitorable cancel) throws InitializeWriterException, SchemaEditionException, DriverException, OpenDriverException, InitializeDriverException, ReadDriverException, LoadLayerException, VisitorException, ExpansionFileReadException  {
325

    
326
                ShpWriter mainWriter = (ShpWriter) writer;
327
                writer = new ShpWriter();
328
                String temp = System.getProperty("java.io.tmpdir") + "/buffer"
329
                                + System.currentTimeMillis() + ".shp";
330
                File newFile = new File(temp);
331
                ((ShpWriter) writer).setFile(newFile);
332
                ((ShpWriter) writer)
333
                                .initialize(resultLayerDefinition);
334
                ((SHPLayerDefinition) resultLayerDefinition).setFile(newFile);
335
                schemaManager.createSchema(resultLayerDefinition);
336
                bufferVisitor.setBufferProcessor(new GeometryPersisterProcessor(
337
                                resultLayerDefinition, schemaManager, writer));
338

    
339
                computeOnlyBuffers(strategy, cancel);
340
                FLyrVect tempLayer = createTempLayer();
341

    
342
                writer = mainWriter;
343
                FeaturePersisterProcessor2 processor = new FeaturePersisterProcessor2(
344
                                writer);
345
                AdjacencyDissolveVisitor dissolveVisitor =
346
                        new AdjacencyDissolveVisitor(null, processor);
347
                Strategy secondPassStrategy = StrategyManager.getStrategy(tempLayer);
348
                dissolveVisitor.setStrategy(secondPassStrategy);
349
long t0 = System.currentTimeMillis();
350
                secondPassStrategy.process(dissolveVisitor, cancel);
351
long t1 = System.currentTimeMillis();
352
System.out.println((t1-t0)+" en dissolver los buffers");
353
        }
354

    
355
        /**
356
         * Computes buffers of input layer, and saves them with the
357
         * actual writer.
358
         * @param strategy
359
         * @param cancel
360
         * @throws ReadDriverException
361
         * @throws EditionException
362
         * @throws DriverException
363
         * @throws ProcessVisitorException
364
         * @throws SchemaEditionException
365
         * @throws ProcessWriterException
366
         * @throws VisitorException
367
         * @throws ExpansionFileReadException
368
         */
369
        private void computeOnlyBuffers(Strategy strategy,
370
                        CancellableMonitorable cancel) throws ReadDriverException, SchemaEditionException, ExpansionFileReadException, VisitorException {
371

    
372
                bufferVisitor.setBufferProcessor(new GeometryPersisterProcessor(
373
                                this.resultLayerDefinition, this.schemaManager, this.writer));
374

    
375
                if (bufferOnlySelection) {
376
                        strategy.process(bufferVisitor, firstLayer.getRecordset()
377
                                        .getSelection(), cancel);
378
                } else {
379
                        strategy.process(bufferVisitor, cancel);
380
                }
381
        }
382

    
383
        /**
384
         * Creates a LayerDefinition in function of:
385
         * a) input layer
386
         * b) user selections
387
         * c) buffer geoprocess itselt operation
388
         *
389
         * Users of this geoprocess may construct a Writer from this LayerDefinition
390
         * (for example, to save to shp ShpWriter needs a File and a LayerDefinition
391
         * -to create this file with the proper schema-)
392
         *
393
         * FIXME
394
         * We cant call this method before setParams(Map params). Launch a exception
395
         *
396
         * ILayerDefinition wont be the same for dissolved buffers layers
397
         *
398
         */
399
        public ILayerDefinition createLayerDefinition() {
400
                // In a buffer geoprocess we only well have a geometry
401
                // and a FID
402
                if (resultLayerDefinition == null) {
403
//                        if(dissolveBuffers){
404
//                                resultLayerDefinition = createDissolvedBuffersDefinition();
405
//                        }else{
406
                                if(bufferVisitor.getTypeOfBuffer() == BufferVisitor.BUFFER_INSIDE_OUTSIDE_POLY){
407
                                        resultLayerDefinition = createPositiveAndNegativeBufferDefinition();
408
                                }else{
409
                                        resultLayerDefinition = createPositiveOrNegativeBufferDefinition();
410
                                }
411
//                        }
412
                }
413
                return resultLayerDefinition;
414
        }
415

    
416
        /**
417
         * Auxilar method to create a layer definition for buffer's process which
418
         * needs to create only internal or external buffers.
419
         * @return
420
         */
421
        protected ILayerDefinition createPositiveOrNegativeBufferDefinition(){
422
                ILayerDefinition resultLayerDefinition = new SHPLayerDefinition();
423
                resultLayerDefinition.setShapeType(XTypes.POLYGON);
424
                FieldDescription[] fields = new FieldDescription[2];
425
                fields[0] = new FieldDescription();
426
                fields[0].setFieldLength(10);
427
                fields[0].setFieldName("FID");
428
                fields[0].setFieldType(XTypes.BIGINT);
429
                fields[1] = new FieldDescription();
430
                fields[1].setFieldLength(10);
431
                fields[1].setFieldDecimalCount(4);
432
                fields[1].setFieldName("DIST");
433
                fields[1].setFieldType(XTypes.DOUBLE);
434
                resultLayerDefinition.setFieldsDesc(fields);
435
                return resultLayerDefinition;
436
        }
437

    
438

    
439
        /**
440
         * Auxilar method to create a layer definition for buffer's process which
441
         * needs to create internal and external buffers.
442
         * @return
443
         */
444
        protected ILayerDefinition createPositiveAndNegativeBufferDefinition(){
445
                ILayerDefinition resultLayerDefinition = new SHPLayerDefinition();
446
                resultLayerDefinition.setShapeType(XTypes.POLYGON);
447
                FieldDescription[] fields = new FieldDescription[3];
448
                fields[0] = new FieldDescription();
449
                fields[0].setFieldLength(10);
450
                fields[0].setFieldName("FID");
451
                fields[0].setFieldType(XTypes.BIGINT);
452
                fields[1] = new FieldDescription();
453
                fields[1].setFieldLength(10);
454
                fields[1].setFieldDecimalCount(4);
455
                fields[1].setFieldName("FROM");
456
                fields[1].setFieldType(XTypes.DOUBLE);
457
                fields[2] = new FieldDescription();
458
                fields[2].setFieldLength(10);
459
                fields[2].setFieldDecimalCount(4);
460
                fields[2].setFieldName("TO");
461
                fields[2].setFieldType(XTypes.DOUBLE);
462

    
463
                resultLayerDefinition.setFieldsDesc(fields);
464
                return resultLayerDefinition;
465
        }
466

    
467
        /**
468
         * Creates a CancelableMonitorable instance to monitor and cancels
469
         * ITask's buffer creation.
470
         * @return
471
         */
472
        private DefaultCancellableMonitorable createCancelMonitor() {
473
                DefaultCancellableMonitorable monitor = new DefaultCancellableMonitorable();
474
                monitor.setInitialStep(0);
475
                if (this.bufferOnlySelection) {
476
                        FBitSet selection = null;
477
                        try {
478
                                selection = firstLayer.getRecordset().getSelection();
479
                        } catch (ReadDriverException e) {
480
                                // TODO Auto-generated catch block
481
                                e.printStackTrace();
482
                        }
483
                        int numSelected = selection.cardinality();
484
                        monitor.setFinalStep(numSelected);
485
                } else {
486
                        try {
487
                                monitor.setFinalStep(firstLayer.getSource().getShapeCount());
488
                        } catch (ReadDriverException e) {
489
                                // TODO Auto-generated catch block
490
                                e.printStackTrace();
491
                        }
492
                }
493
                if (!dissolveBuffers) {
494
                        // if we dont look for adjacents, is a determinated
495
                        // task (we know how many steps we are going to do
496
                        monitor.setDeterminatedProcess(true);
497

    
498
                } else {
499
                        monitor.setDeterminatedProcess(false);
500
                }// if dissolvebuffer
501
                return monitor;
502
        }
503

    
504
        public IMonitorableTask createTask() {
505
                /*
506
                 * Allows to monitor and cancel the task
507
                 */
508
                final CancellableMonitorable cancelMonitor = createCancelMonitor();
509
                /*
510
                 * Main Message for reporting buffer geoprocess
511
                 */
512
                final String message = PluginServices.getText(this, "Mensaje_buffer");
513
                /*
514
                 * Message for report individual step of buffer computation
515
                 */
516
                final String note = PluginServices.getText(this,
517
                                "Mensaje_procesando_buffer");
518
                /*
519
                 * Message for report individual step of dissolving of buffers
520
                 */
521
                final String note2 = PluginServices.getText(this,
522
                "Mensaje_procesando_buffer2");
523
                /*
524
                 * Concatenation string
525
                 */
526
                final String of = PluginServices.getText(this, "De");
527

    
528
                return new IMonitorableTask() {
529
                        private boolean finished = false;
530
                        String currentNote = note;
531

    
532
                        public int getInitialStep() {
533
                                return cancelMonitor.getInitialStep();
534
                        }
535

    
536
                        public int getFinishStep() {
537
                                return cancelMonitor.getFinalStep();
538
                        }
539

    
540
                        public int getCurrentStep() {
541
                                return cancelMonitor.getCurrentStep();
542
                        }
543

    
544
                        public String getStatusMessage() {
545
                                return message;
546
                        }
547

    
548
                        public String getNote() {
549
                                return currentNote + ": " + getCurrentStep() + " " + of + " "
550
                                                + getFinishStep();
551
                        }
552

    
553
                        public void cancel() {
554
                                ((DefaultCancellableMonitorable) cancelMonitor)
555
                                                .setCanceled(true);
556
                                BufferGeoprocess.this.cancel();
557
                        }
558

    
559
                        public void run() {
560

    
561
                                Strategy strategy = StrategyManager.getStrategy(firstLayer);
562
                                resultLayerDefinition = createLayerDefinition();
563
                                try {
564
                                        if (dissolveBuffers) {
565
                                                //computeAndDissolveBuffer(strategy, cancelMonitor);
566
                                                ShpWriter mainWriter = (ShpWriter) writer;
567
                                                writer = new ShpWriter();
568
                                                String temp = System.getProperty("java.io.tmpdir") +
569
                                                                "/buffer" +
570
                                                                System.currentTimeMillis() +
571
                                                                ".shp";
572
                                                File newFile = new File(temp);
573
                                                ((ShpWriter) writer).setFile(newFile);
574
                                                ((ShpWriter) writer).initialize(
575
                                                                resultLayerDefinition);
576
                                                ((SHPLayerDefinition) resultLayerDefinition).setFile(newFile);
577
                                                schemaManager.createSchema(resultLayerDefinition);
578
                                                bufferVisitor.setBufferProcessor(new GeometryPersisterProcessor(
579
                                                                resultLayerDefinition, schemaManager, writer));
580
                                                computeOnlyBuffers(strategy, cancelMonitor);
581
                                                //dissolving buffers
582
                                                currentNote = note2;
583
                                                cancelMonitor.setCurrentStep(0);
584
                                                FLyrVect tempLayer = createTempLayer();
585
                                                tempLayer.createSpatialIndex();
586
                                                cancelMonitor.setFinalStep(tempLayer.getSource().getShapeCount());
587
                                                writer = mainWriter;
588
                                                FeaturePersisterProcessor2 processor = new FeaturePersisterProcessor2(
589
                                                                writer);
590
//                                                AdjacencyDissolveVisitor dissolveVisitor =
591
//                                                        new AdjacencyDissolveVisitor(null, processor);
592
                                                DissolveVisitor dissolveVisitor =
593
                                                        createDissolveVisitor(processor);
594
                                                Strategy secondPassStrategy = StrategyManager.getStrategy(tempLayer);
595
                                                dissolveVisitor.setStrategy(secondPassStrategy);
596
                                long t0 = System.currentTimeMillis();
597
                                                secondPassStrategy.process(dissolveVisitor, cancelMonitor);
598
                                long t1 = System.currentTimeMillis();
599
                                System.out.println((t1-t0)+" en dissolver los buffers");
600
                                        } else {
601
                                                computeOnlyBuffers(strategy, cancelMonitor);
602
                                        }
603
                                        finished = true;
604
                                } catch (Exception e) {
605
                                        e.printStackTrace();
606
                                        finished = true;
607
                                }
608
                        }
609

    
610
                        /**
611
                         * Creates a DissolveVisitor to dissolve computed buffers.
612
                         * If we only computed a ring buffer, dissolve
613
                         * criteria will be adjacency.
614
                         * If we computed many buffers, dissolve criteria will be
615
                         * adjacency and alphanumeric (value of FROM-TO or DISTANCE fields of the
616
                         * buffer geometry)
617
                         * @return
618
                         */
619
                        private DissolveVisitor createDissolveVisitor(FeaturePersisterProcessor2 processor) {
620
                                //int numBuffers = bufferVisitor.getNumberOfRadialBuffers();
621
                                //if(numBuffers == 1){
622
                                        return new AdjacencyDissolveVisitor(null,processor);
623
                                //}
624
                                /*DOCUMENTAR ESTE CASO
625
                                else{
626
                                        //Esto no funciona bien. Para dissolver buffers
627
                                        //con varios rings, da errores topol?gicos.
628

629
                                        //La ?nica soluci?n es calcular 1? la uni?n, luego
630
                                        //y luego los multirings
631

632
                                        if(bufferVisitor.getTypeOfBuffer() == BufferVisitor.BUFFER_INSIDE_OUTSIDE_POLY){
633
                                                return new DissolveVisitor("FROM", processor);
634
                                        }else{
635
                                                return new DissolveVisitor("DIST", processor);
636
                                        }
637
                                }
638
                                */
639
                        }
640

    
641
                        public boolean isDefined() {
642
                                return cancelMonitor.isDeterminatedProcess();
643
                        }
644

    
645
                        public boolean isCanceled() {
646
                                return cancelMonitor.isCanceled();
647
                        }
648

    
649
                        public boolean isFinished() {
650
                                return finished;
651
                        }
652
                };
653
        }
654
}