Statistics
| Revision:

svn-gvsig-desktop / trunk / extensions / extGeoprocessingExtensions / src / com / iver / cit / gvsig / geoprocess / impl / topology / polygonbuild / fmap / PolygonBuildGeoprocess.java @ 33358

History | View | Annotate | Download (21.1 KB)

1
/*
2
 * Created on 15-dic-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: PolygonBuildGeoprocess.java 21235 2008-06-05 14:08:38Z azabala $
47
 * $Log$
48
 * Revision 1.6  2007-08-13 11:51:09  jmvivo
49
 * *** empty log message ***
50
 *
51
 * Revision 1.5  2007/05/28 15:36:15  jaume
52
 * *** empty log message ***
53
 *
54
 * Revision 1.4  2007/05/15 07:23:25  cesar
55
 * Add the finished method for execution from Event Dispatch Thread
56
 *
57
 * Revision 1.3  2007/03/06 16:48:14  caballero
58
 * Exceptions
59
 *
60
 * Revision 1.2  2006/12/21 17:43:33  azabala
61
 * added filtering of dangling lines by dangle tolerance
62
 *
63
 * Revision 1.1  2006/12/21 17:23:27  azabala
64
 * *** empty log message ***
65
 *
66
 * Revision 1.2  2006/12/19 19:29:50  azabala
67
 * *** empty log message ***
68
 *
69
 * Revision 1.1  2006/12/15 19:06:29  azabala
70
 * scheleton of polygon build
71
 *
72
 *
73
 */
74
package com.iver.cit.gvsig.geoprocess.impl.topology.polygonbuild.fmap;
75

    
76
import java.awt.Color;
77
import java.io.File;
78
import java.util.ArrayList;
79
import java.util.Collection;
80
import java.util.HashMap;
81
import java.util.Iterator;
82
import java.util.List;
83
import java.util.Map;
84

    
85
import com.hardcode.gdbms.driver.exceptions.InitializeWriterException;
86
import com.hardcode.gdbms.driver.exceptions.ReadDriverException;
87
import com.hardcode.gdbms.driver.exceptions.SchemaEditionException;
88
import com.hardcode.gdbms.engine.values.Value;
89
import com.hardcode.gdbms.engine.values.ValueFactory;
90
import com.iver.andami.PluginServices;
91
import com.iver.cit.gvsig.exceptions.expansionfile.ExpansionFileReadException;
92
import com.iver.cit.gvsig.exceptions.visitors.StopVisitorException;
93
import com.iver.cit.gvsig.exceptions.visitors.StopWriterVisitorException;
94
import com.iver.cit.gvsig.exceptions.visitors.VisitorException;
95
import com.iver.cit.gvsig.fmap.MapContext;
96
import com.iver.cit.gvsig.fmap.core.DefaultFeature;
97
import com.iver.cit.gvsig.fmap.core.FPoint2D;
98
import com.iver.cit.gvsig.fmap.core.FShape;
99
import com.iver.cit.gvsig.fmap.core.IGeometry;
100
import com.iver.cit.gvsig.fmap.core.ShapeFactory;
101
import com.iver.cit.gvsig.fmap.core.SymbologyFactory;
102
import com.iver.cit.gvsig.fmap.core.symbols.ILineSymbol;
103
import com.iver.cit.gvsig.fmap.core.symbols.ISymbol;
104
import com.iver.cit.gvsig.fmap.core.symbols.SimpleMarkerSymbol;
105
import com.iver.cit.gvsig.fmap.core.v02.FConverter;
106
import com.iver.cit.gvsig.fmap.drivers.DriverIOException;
107
import com.iver.cit.gvsig.fmap.drivers.FieldDescription;
108
import com.iver.cit.gvsig.fmap.drivers.ILayerDefinition;
109
import com.iver.cit.gvsig.fmap.drivers.SHPLayerDefinition;
110
import com.iver.cit.gvsig.fmap.edition.IWriter;
111
import com.iver.cit.gvsig.fmap.edition.ShpSchemaManager;
112
import com.iver.cit.gvsig.fmap.edition.writers.shp.ShpWriter;
113
import com.iver.cit.gvsig.fmap.layers.FBitSet;
114
import com.iver.cit.gvsig.fmap.layers.FLayer;
115
import com.iver.cit.gvsig.fmap.layers.FLayers;
116
import com.iver.cit.gvsig.fmap.layers.FLyrVect;
117
import com.iver.cit.gvsig.fmap.layers.ReadableVectorial;
118
import com.iver.cit.gvsig.fmap.rendering.SingleSymbolLegend;
119
import com.iver.cit.gvsig.geoprocess.core.fmap.AbstractGeoprocess;
120
import com.iver.cit.gvsig.geoprocess.core.fmap.FeaturePersisterProcessor2;
121
import com.iver.cit.gvsig.geoprocess.core.fmap.GeoprocessException;
122
import com.iver.cit.gvsig.geoprocess.core.fmap.XTypes;
123
import com.iver.cit.gvsig.project.documents.view.gui.View;
124
import com.iver.cit.gvsig.topology.NodeError;
125
import com.iver.utiles.swing.threads.AbstractMonitorableTask;
126
import com.iver.utiles.swing.threads.IMonitorableTask;
127
import com.vividsolutions.jts.geom.Coordinate;
128
import com.vividsolutions.jts.geom.CoordinateArrays;
129
import com.vividsolutions.jts.geom.Geometry;
130
import com.vividsolutions.jts.geom.GeometryFactory;
131
import com.vividsolutions.jts.geom.util.LinearComponentExtracter;
132
import com.vividsolutions.jts.operation.polygonize.Polygonizer;
133
import com.vividsolutions.jts.planargraph.NodeMap;
134

    
135
public class PolygonBuildGeoprocess extends AbstractGeoprocess {
136

    
137
        private static final SimpleMarkerSymbol symNodeError =(SimpleMarkerSymbol) SymbologyFactory.createDefaultSymbolByShapeType(FShape.POINT, Color.RED);
138
        private static final ILineSymbol symDangle = (ILineSymbol) SymbologyFactory.createDefaultSymbolByShapeType(FShape.LINE, Color.RED);
139
        private static final ILineSymbol symCutEdge = (ILineSymbol)SymbologyFactory.createDefaultSymbolByShapeType(FShape.LINE, Color.BLUE);
140
        private static final ILineSymbol symInvalidRing = (ILineSymbol)SymbologyFactory.createDefaultSymbolByShapeType(FShape.LINE, Color.YELLOW);
141
        static{
142
                symNodeError.setSize(10);
143
                symNodeError.setStyle(SimpleMarkerSymbol.SQUARE_STYLE);
144
                symNodeError.setOutlined(true);
145
                symNodeError.setOutlineColor(Color.RED);
146
        }
147
        /**
148
         * Static counter to add like a suffix to the error's layer names
149
         * */
150
        private static int numOcurrences = 0;
151

    
152
        // USER PARAMS
153
        private boolean onlyFirstLayerSelection = false;
154

    
155
        private boolean computeCleanBefore = false;
156

    
157
        private boolean applySnapTolerance = false;
158
        private double snapTolerance;
159

    
160
        private boolean applyDangleTolerance = false;
161
        private double dangleTolerance;
162

    
163
        private boolean addGroupOfLyrs = false;
164

    
165
        private GeometryFactory fact = new GeometryFactory();
166

    
167
        /**
168
         * Relates an IWriter with the symbol of the layer
169
         * (for error layers)
170
         * */
171
        private HashMap writer2sym = new HashMap();
172

    
173
        /**
174
         * Processes features (writing them in a persistent data store)
175
         */
176
        FeaturePersisterProcessor2 processor;
177

    
178
        /**
179
         * It saves all temporal writers (to save error geometries)
180
         * */
181
        ArrayList tempWriters = new ArrayList();
182

    
183
        /**
184
         * Schema of the result layer
185
         */
186
        ILayerDefinition resultLayerDefinition;
187

    
188

    
189
        public PolygonBuildGeoprocess(FLyrVect inputLayer) {
190
                this.firstLayer = inputLayer;
191
        }
192

    
193
        public void setParameters(Map params) throws GeoprocessException {
194
                Boolean firstLayerSelection = (Boolean) params
195
                                .get("firstlayerselection");
196
                if (firstLayerSelection != null)
197
                        this.onlyFirstLayerSelection = firstLayerSelection.booleanValue();
198

    
199
                Boolean applySnap = (Boolean) params.get("applysnaptol");
200
                if (applySnap != null)
201
                        this.applySnapTolerance = applySnap.booleanValue();
202
                Double snapTol = (Double) params.get("snaptolerance");
203
                if (snapTol != null)
204
                        this.snapTolerance = snapTol.doubleValue();
205

    
206
                Boolean applyDange = (Boolean) params.get("applydangletol");
207
                if (applyDange != null)
208
                        this.applyDangleTolerance = applyDange.booleanValue();
209

    
210
                Double dangleTol = (Double) params.get("dangletolerance");
211
                if (dangleTol != null)
212
                        this.dangleTolerance = dangleTol.doubleValue();
213

    
214
                Boolean cleanBefore = (Boolean) params.get("computeclean");
215
                if (cleanBefore != null)
216
                        this.computeCleanBefore = cleanBefore.booleanValue();
217

    
218
                Boolean groupOfLyrs = (Boolean) params.get("addgroupoflyrs");
219
                if (groupOfLyrs != null)
220
                        this.addGroupOfLyrs = groupOfLyrs.booleanValue();
221

    
222
        }
223

    
224
        public void checkPreconditions() throws GeoprocessException {
225
                if (firstLayer == null)
226
                        throw new GeoprocessException(
227
                                        "POLIGON BUILD: capa de entrada a null");
228
                if (this.writer == null || this.schemaManager == null) {
229
                        throw new GeoprocessException(
230
                                        "Operacion de BUILD de pol?gonos sin especificar capa de resultados");
231
                }
232
                try {
233
                        if (firstLayer.getSource().getShapeCount() == 0) {
234
                                throw new GeoprocessException("Capa de entrada vacia");
235
                        }
236
                } catch (ReadDriverException e) {
237
                        throw new GeoprocessException(
238
                                        "Error al verificar si la capa est? vac?a");
239
                }
240
        }
241

    
242
        // TODO Move this stuff to AbstractGeoprocess
243
        public void process() throws GeoprocessException {
244
                try {
245
                        createTask().run();
246
                } catch (Exception e) {
247
                        throw new GeoprocessException("Error al ejecutar el geoproceso");
248
                }
249
        }
250

    
251
        /**
252
         *
253
         * Creates the schema (ILayerDefinition) of the result layer which will have
254
         * all the polygons resulting from the BUILD
255
         */
256
        public ILayerDefinition createLayerDefinition() {
257
                if (resultLayerDefinition == null) {
258
                        resultLayerDefinition = getLayerDefinition();
259
                }
260
                return resultLayerDefinition;
261
        }
262

    
263
        /**
264
         * Utility method to create schemas for all kind of layers this
265
         * geoprocess could create (polygons, and error layers -dangles, etc-)
266
         *
267
         * */
268
        private ILayerDefinition getLayerDefinition(){
269
                SHPLayerDefinition definition = new SHPLayerDefinition();
270
                definition.setShapeType(XTypes.POLYGON);
271
                FieldDescription[] fields = new FieldDescription[1];
272
                fields[0] = new FieldDescription();
273
                fields[0].setFieldLength(10);
274
                fields[0].setFieldName("FID");
275
                fields[0].setFieldType(XTypes.BIGINT);
276
                definition.setFieldsDesc(fields);
277
            return definition;
278
        }
279

    
280
        public IMonitorableTask createTask() {
281
                return new PolygonBuildTask();
282
        }
283

    
284

    
285
        class PolygonBuildTask extends AbstractMonitorableTask {
286

    
287
                PolygonBuildTask() {
288
                        setInitialStep(0);
289
                        int additionalSteps = 2;
290
                        try {
291
                                if (onlyFirstLayerSelection) {
292
                                        int numSelected = firstLayer.getRecordset().getSelection()
293
                                                        .cardinality();
294
                                        setFinalStep(numSelected + additionalSteps);
295
                                } else {
296
                                        int numShapes = firstLayer.getSource().getShapeCount();
297
                                        setFinalStep(numShapes + additionalSteps);
298
                                }// else
299
                        } catch (ReadDriverException e) {
300
                                // TODO Auto-generated catch block
301
                                e.printStackTrace();
302
                        }
303
                        setDeterminatedProcess(true);
304
                        setStatusMessage(PluginServices.getText(this,
305
                                        "PolygonBuild._Progress_Message"));
306

    
307
                }
308

    
309
                /**
310
                 * Verifies cancelation events, and return a boolean flag if processes
311
                 * must be stopped for this cancelations events.
312
                 *
313
                 * @param cancel
314
                 * @param va
315
                 * @param visitor
316
                 * @return
317
                 * @throws DriverIOException
318
                 */
319

    
320
                // TODO Move all this stuff and remove
321
                boolean verifyCancelation(ReadableVectorial va) {
322
                        if (isCanceled()) {
323
                                try {
324
                                        va.stop();
325
                                } finally {
326
                                        return true;
327
                                }
328
                        }
329
                        return false;
330
                }
331

    
332
                /**
333
                 * Processes the record "record" of the given vectorial data source
334
                 * (ReadableVectorial) to extract linear components with "lineFilter".
335
                 * (Previous step necessary to polygonize a linear layer).
336
                 *
337
                 * If user has choosen add to the toc a group of layers (with
338
                 * topological errors, pseudonodes, dangles, etc) this method computes
339
                 * pseudonodes also.
340
                 * @throws StopWriterVisitorException
341
                 */
342
                void process(ReadableVectorial va,
343
                                FeaturePersisterProcessor2 processor,
344
                                LinearComponentExtracter lineFilter,
345
                                NodeMap nodeMap,
346
                                int record) throws ReadDriverException, StopVisitorException {
347

    
348
                        if (verifyCancelation(va)) {
349
                                processor.finish();
350
                                return;
351
                        }
352
                        reportStep();
353
                        IGeometry g;
354
                        try {
355
                                g = va.getShape(record);
356
                        } catch (ExpansionFileReadException e) {
357
                                throw new ReadDriverException(va.getDriver().getName(),e);
358
                        }
359
                        if(g == null)
360
                                return;
361
                        Geometry jtsGeom = g.toJTSGeometry();
362
                        jtsGeom.apply(lineFilter);
363

    
364
                        // In parallel to the line filtering, if nodeMap != null we
365
                        // look for pseudonodes
366
                        if(nodeMap != null){
367
                                Coordinate[] coords = jtsGeom.getCoordinates();
368
                            if (jtsGeom.isEmpty())
369
                                    return;
370
                            Coordinate[] linePts = CoordinateArrays.
371
                                                    removeRepeatedPoints(coords);
372
                            Coordinate startPt = linePts[0];
373
                            Coordinate endPt = linePts[linePts.length - 1];
374

    
375
                            NodeError nStart = (NodeError) nodeMap.find(startPt);
376
                            NodeError nEnd = (NodeError) nodeMap.find(endPt);
377
                            if (nStart == null)
378
                            {
379
                                    nStart = new NodeError(startPt);
380
                                    nodeMap.add(nStart);
381
                            }else
382
                                    nStart.setOccurrences(nStart.getOccurrences()+1);
383
                            
384
                            if (nEnd == null)
385
                            {
386
                                    nEnd = new NodeError(endPt);
387
                                    nodeMap.add(nEnd);
388
                            }
389
                            else
390
                                    nEnd.setOccurrences(nEnd.getOccurrences()+1);
391
                        }// if nodeMap
392
                }
393

    
394

    
395

    
396
                public void run() throws Exception {
397
                        processor = new FeaturePersisterProcessor2(writer);
398
                        Polygonizer polygonizer = new Polygonizer();
399
                        try {
400
                                processor.start();
401
                                ReadableVectorial va = firstLayer.getSource();
402
                                va.start();
403

    
404
                                List linesList = new ArrayList();
405
                                LinearComponentExtracter lineFilter = new LinearComponentExtracter(
406
                                                linesList);
407

    
408
                                NodeMap nodeMap = null;
409
                                if(addGroupOfLyrs)
410
                                        nodeMap = new NodeMap();
411
                                if (onlyFirstLayerSelection) {
412
                                        FBitSet selection = firstLayer.getRecordset()
413
                                                        .getSelection();
414
                                        for (int i = selection.nextSetBit(0); i >= 0; i = selection
415
                                                        .nextSetBit(i + 1)) {
416
                                                process(va, processor, lineFilter, nodeMap, i);
417
                                        }
418
                                } else {
419
                                        for (int i = 0; i < va.getShapeCount(); i++) {// for each
420
                                                process(va, processor, lineFilter, nodeMap, i);
421
                                        }// for
422
                                }// if selection
423
                                va.stop();
424

    
425
                                // here lineList has all the linear elements
426
                                if (computeCleanBefore) {
427
                                        linesList = cleanLines(linesList);
428
                                }
429
                                for (Iterator i = linesList.iterator(); i.hasNext(); ) {
430
                                      Geometry g = (Geometry) i.next();
431
                                      polygonizer.add(g);
432
                                }
433

    
434
                                reportStep();
435

    
436
                                // First we save polygons from build
437
                                List polygons = (List) polygonizer.getPolygons();
438
                                for(int i = 0; i < polygons.size(); i++){
439
                                        Geometry geom = (Geometry) polygons.get(i);
440
                                        Value[] values = new Value[1];
441
                                        values[0] = ValueFactory.createValue(i);
442
                                        IGeometry igeom = FConverter.jts_to_igeometry(geom);
443
                                        DefaultFeature feature = new
444
                                                DefaultFeature(igeom, values, (i+""));
445
                                        processor.processFeature(feature);
446
                                }
447
                                processor.finish();
448

    
449
                                reportStep();
450
                                if(addGroupOfLyrs){
451
                                        Collection cutEdgesLines = (List) polygonizer.getCutEdges();
452
                                        Collection danglingLines = polygonizer.getDangles();
453
                                        Collection invalidRingLines = (List) polygonizer.getInvalidRingLines();
454
                                        List nodeErrors = new ArrayList();
455
                                        // Obtain pseudonodes
456
                                        // (we look for nodes of valency 1)
457
                                        Iterator it = nodeMap.iterator();
458
                                        while (it.hasNext()){
459
                                                NodeError node = (NodeError) it.next();
460
                                                if (node.getOccurrences() == 1){
461
                                                        FPoint2D p = FConverter.coordinate2FPoint2D(
462
                                                                        node.getCoordinate());
463
                                                        IGeometry gAux = ShapeFactory.createPoint2D(p);
464
                                                        nodeErrors.add(gAux.toJTSGeometry());
465
                                                }// if
466
                                        }// while
467

    
468
                                        
469
                                        String fileName = ((ShpWriter)writer).getShpPath();
470
                                        String layerName = null;
471
                                        int fileNameStart = fileName.lastIndexOf(File.separator) + 1;
472
                                        if(fileNameStart == -1)
473
                                                fileNameStart = 0;
474
                                        layerName = fileName.substring(fileNameStart, fileName.length());
475
                                        if(layerName.endsWith(".shp"))
476
                                                layerName = layerName.substring(0, layerName.length() - 4);
477
                                        
478
                                        if(cutEdgesLines != null){
479
                                                if(cutEdgesLines.size() > 0)
480
                                                        writeCutEdgeLines(cutEdgesLines, layerName);
481
                                        }
482

    
483
                                        if(danglingLines != null){
484
                                                //check to filter dangling lines by length
485
                                                if(applyDangleTolerance){
486
                                                        ArrayList filteredDangles = new ArrayList();
487
                                                        Iterator iterator = danglingLines.iterator();
488
                                                        while(iterator.hasNext()){
489
                                                                Geometry geom = (Geometry) iterator.next();
490
                                                                if(geom.getLength() >= dangleTolerance)
491
                                                                        filteredDangles.add(geom);
492
                                                        }//while
493
                                                        danglingLines = filteredDangles;
494
                                                }
495
                                                if(danglingLines.size() > 0)
496
                                                        writeDanglingLines(danglingLines, layerName);
497
                                        }
498

    
499
                                        if(invalidRingLines != null){
500
                                                if(invalidRingLines.size() > 0)
501
                                                        writeInvalidRingLines(invalidRingLines, layerName);
502
                                        }
503

    
504
                                        if(nodeErrors != null){
505
                                                if(nodeErrors.size() > 0)
506
                                                        writeNodeErrors(nodeErrors, layerName);
507
                                        }
508
                                }// if addGroupOfLayers
509
                        } catch (ReadDriverException e) {
510
                                e.printStackTrace();
511
                        }
512
                }
513

    
514
                public String getNote() {
515
                        String buildText = PluginServices.getText(this,
516
                                        "Generando_topologia_de_poligonos");
517
                        String of = PluginServices.getText(this, "de");
518
                        return buildText + " " + getCurrentStep() + " " + of + " "
519
                                        + getFinishStep();
520
                }
521

    
522
                public void cancel() {
523
                        setCanceled(true);
524
                        PolygonBuildGeoprocess.this.cancel();
525
                }
526

    
527
                /* (non-Javadoc)
528
                 * @see com.iver.utiles.swing.threads.IMonitorableTask#finished()
529
                 */
530
                public void finished() {
531
                        // TODO Auto-generated method stub
532

    
533
                }
534

    
535
        }// PolygonBuildTask
536

    
537
        /**
538
         * This method apply a topology clean to the list of lines.
539
         *
540
         * This clean is made in memory (against LineCleanGeoprocess, that makes
541
         * this clean without memory consumption).
542
         *
543
         */
544
        // TODO Move this method to a JTS Utility class
545
        List cleanLines(List lines) {
546
                Geometry linesGeom = fact.createMultiLineString(GeometryFactory
547
                                .toLineStringArray(lines));
548
                Geometry empty = fact.createMultiLineString(null);
549
                Geometry noded = linesGeom.union(empty);
550
                List nodedList = new ArrayList();
551
                nodedList.add(noded);
552
                return nodedList;
553
        }
554

    
555

    
556
        void writeGeometriesInMemory(Collection geometries, int geometryType, ISymbol symbol, String fileName) throws InitializeWriterException, SchemaEditionException, VisitorException {
557

    
558
                ShpWriter writer = new ShpWriter();
559
                File newFile = new File(fileName);
560
                writer.setFile(newFile);
561
                SHPLayerDefinition schema = (SHPLayerDefinition) getLayerDefinition();
562
                schema.setShapeType(geometryType);
563
                writer.initialize(schema);
564
                schema.setFile(newFile);
565
                ShpSchemaManager schemaManager =
566
                        new ShpSchemaManager(newFile.getAbsolutePath());
567
                schemaManager.createSchema(schema);
568
                FeaturePersisterProcessor2 tempProcessor = new
569
                        FeaturePersisterProcessor2(writer);
570
                tempProcessor = new FeaturePersisterProcessor2(writer);
571
                tempProcessor.start();
572
                Iterator it = geometries.iterator();
573
                int i = 0;
574
                while(it.hasNext()){
575
                        Geometry geom = (Geometry) it.next();
576
                        Value[] values = new Value[1];
577
                        values[0] = ValueFactory.createValue(i);
578
                        IGeometry igeom = FConverter.jts_to_igeometry(geom);
579
                        DefaultFeature feature = new
580
                                DefaultFeature(igeom, values, (i+""));
581
                        tempProcessor.processFeature(feature);
582
                        i++;
583
                }
584
                tempProcessor.finish();
585
                //We save the information to recover these layers after
586
                //(to add them to the toc)
587
                tempWriters.add(writer);
588

    
589
                //saves the symbol specified for this writer, to use it
590
                //when we will add the layer derived of the writer to the TOC
591
                writer2sym.put(writer, symbol);
592
        }
593

    
594

    
595

    
596
        void writeCutEdgeLines(Collection cutEdgeLines, String layerName) throws InitializeWriterException, SchemaEditionException, VisitorException{
597
                String temp = System.getProperty("java.io.tmpdir")         + layerName +
598
                "_cutEdgeLines" +
599
                (numOcurrences++)+
600
                ".shp";
601
                writeGeometriesInMemory(cutEdgeLines, XTypes.LINE, symCutEdge, temp);
602
        }
603

    
604

    
605
        void writeDanglingLines(Collection danglingLines, String layerName) throws InitializeWriterException, SchemaEditionException, VisitorException{
606
                String temp = System.getProperty("java.io.tmpdir")  + layerName +
607
                "_danglingLines" +
608
                (numOcurrences++)+
609
                ".shp";
610
                writeGeometriesInMemory(danglingLines, XTypes.LINE, symDangle, temp);
611
        }
612

    
613
        void writeInvalidRingLines(Collection invalidRingLines, String layerName) throws InitializeWriterException, SchemaEditionException, VisitorException{
614
                String temp = System.getProperty("java.io.tmpdir")  + layerName +
615
                "_invalidRing" +
616
                (numOcurrences++)+
617
                ".shp";
618
                writeGeometriesInMemory(invalidRingLines, XTypes.LINE,symInvalidRing, temp);
619
        }
620

    
621
        void writeNodeErrors(Collection nodeErrors, String layerName) throws InitializeWriterException, SchemaEditionException, VisitorException{
622
                String temp = System.getProperty("java.io.tmpdir") + layerName +
623
                "_pseudonodes" +
624
                (numOcurrences++)+
625
                ".shp";
626
                writeGeometriesInMemory(nodeErrors, XTypes.POINT,symNodeError, temp);
627
        }
628

    
629

    
630
        public FLayer getResult() throws GeoprocessException {
631
                if(! addGroupOfLyrs){
632
                        // user choose in GUI not to load errors in TOC
633
                        return super.getResult();
634
                }else{
635
                        if(tempWriters.size() == 0)
636
                                return super.getResult();
637
                        IWriter[] writers = new IWriter[tempWriters.size()];
638
                        tempWriters.toArray(writers);
639

    
640
                        MapContext map = ((View)PluginServices.getMDIManager().
641
                                 getActiveWindow()).getModel().getMapContext();
642
                        FLayers solution = new FLayers();//(map,map.getLayers());
643
                        solution.setMapContext(map);
644
                        solution.setParentLayer(map.getLayers());
645
                        solution.setName("Build");
646
                        solution.addLayer(super.getResult());
647
                        for(int i = 0; i < writers.length; i++){
648
                                FLyrVect layer = (FLyrVect) createLayerFrom(writers[i]);
649
                                ISymbol symbol = (ISymbol) writer2sym.get(writers[i]);
650
                                try {
651
                                        layer.setLegend(new SingleSymbolLegend(symbol));
652
                                } catch (Exception e) {
653
                                        throw new GeoprocessException("Error al crear la leyenda de una de las capas resultado", e);
654
                                }
655
                                solution.addLayer(layer);
656
                        }
657
                        return solution;
658
                }//else
659
        }
660
}