Statistics
| Revision:

svn-gvsig-desktop / branches / v2_0_0_prep / libraries / libFMap_mapcontext / src / org / gvsig / fmap / mapcontext / layers / vectorial / FLyrVect.java @ 26778

History | View | Annotate | Download (59.1 KB)

1
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
2
 *
3
 * Copyright (C) 2004 IVER T.I. and Generalitat Valenciana.
4
 *
5
 * This program is free software; you can redistribute it and/or
6
 * modify it under the terms of the GNU General Public License
7
 * as published by the Free Software Foundation; either version 2
8
 * of the License, or (at your option) any later version.
9
 *
10
 * This program is distributed in the hope that it will be useful,
11
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13
 * GNU General Public License for more details.
14
 *
15
 * You should have received a copy of the GNU General Public License
16
 * along with this program; if not, write to the Free Software
17
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307,USA.
18
 *
19
 * For more information, contact:
20
 *
21
 *  Generalitat Valenciana
22
 *   Conselleria d'Infraestructures i Transport
23
 *   Av. Blasco Ib??ez, 50
24
 *   46010 VALENCIA
25
 *   SPAIN
26
 *
27
 *      +34 963862235
28
 *   gvsig@gva.es
29
 *      www.gvsig.gva.es
30
 *
31
 *    or
32
 *
33
 *   IVER T.I. S.A
34
 *   Salamanca 50
35
 *   46005 Valencia
36
 *   Spain
37
 *
38
 *   +34 963163400
39
 *   dac@iver.es
40
 */
41
package org.gvsig.fmap.mapcontext.layers.vectorial;
42

    
43
import java.awt.Graphics2D;
44
import java.awt.Point;
45
import java.awt.geom.AffineTransform;
46
import java.awt.geom.Point2D;
47
import java.awt.image.BufferedImage;
48
import java.net.URI;
49
import java.util.Iterator;
50
import java.util.Set;
51
import java.util.TreeSet;
52

    
53
import javax.print.attribute.PrintRequestAttributeSet;
54
import javax.print.attribute.standard.PrintQuality;
55

    
56
import org.cresques.cts.ICoordTrans;
57
import org.gvsig.fmap.dal.DALLocator;
58
import org.gvsig.fmap.dal.DataManager;
59
import org.gvsig.fmap.dal.DataStore;
60
import org.gvsig.fmap.dal.DataStoreParameters;
61
import org.gvsig.fmap.dal.exception.DataException;
62
import org.gvsig.fmap.dal.exception.ReadException;
63
import org.gvsig.fmap.dal.feature.Feature;
64
import org.gvsig.fmap.dal.feature.FeatureAttributeDescriptor;
65
import org.gvsig.fmap.dal.feature.FeatureQuery;
66
import org.gvsig.fmap.dal.feature.FeatureSelection;
67
import org.gvsig.fmap.dal.feature.FeatureSet;
68
import org.gvsig.fmap.dal.feature.FeatureStore;
69
import org.gvsig.fmap.dal.feature.FeatureStoreNotification;
70
import org.gvsig.fmap.dal.feature.FeatureType;
71
import org.gvsig.fmap.geom.Geometry;
72
import org.gvsig.fmap.geom.GeometryLocator;
73
import org.gvsig.fmap.geom.operation.DrawInts;
74
import org.gvsig.fmap.geom.operation.DrawOperationContext;
75
import org.gvsig.fmap.geom.operation.GeometryOperationException;
76
import org.gvsig.fmap.geom.operation.GeometryOperationNotSupportedException;
77
import org.gvsig.fmap.geom.primitive.DefaultEnvelope;
78
import org.gvsig.fmap.geom.primitive.Envelope;
79
import org.gvsig.fmap.mapcontext.MapContext;
80
import org.gvsig.fmap.mapcontext.ViewPort;
81
import org.gvsig.fmap.mapcontext.exceptions.LegendLayerException;
82
import org.gvsig.fmap.mapcontext.exceptions.LoadLayerException;
83
import org.gvsig.fmap.mapcontext.exceptions.ReloadLayerException;
84
import org.gvsig.fmap.mapcontext.exceptions.StartEditionLayerException;
85
import org.gvsig.fmap.mapcontext.exceptions.XMLLayerException;
86
import org.gvsig.fmap.mapcontext.layers.AbstractLinkProperties;
87
import org.gvsig.fmap.mapcontext.layers.FLayer;
88
import org.gvsig.fmap.mapcontext.layers.FLyrDefault;
89
import org.gvsig.fmap.mapcontext.layers.LayerEvent;
90
import org.gvsig.fmap.mapcontext.layers.SpatialCache;
91
import org.gvsig.fmap.mapcontext.layers.operations.ClassifiableVectorial;
92
import org.gvsig.fmap.mapcontext.layers.operations.ILabelable;
93
import org.gvsig.fmap.mapcontext.layers.operations.InfoByPoint;
94
import org.gvsig.fmap.mapcontext.layers.operations.SingleLayer;
95
import org.gvsig.fmap.mapcontext.layers.operations.VectorialXMLItem;
96
import org.gvsig.fmap.mapcontext.layers.operations.XMLItem;
97
import org.gvsig.fmap.mapcontext.rendering.legend.IClassifiedVectorLegend;
98
import org.gvsig.fmap.mapcontext.rendering.legend.ILegend;
99
import org.gvsig.fmap.mapcontext.rendering.legend.IVectorLegend;
100
import org.gvsig.fmap.mapcontext.rendering.legend.LegendFactory;
101
import org.gvsig.fmap.mapcontext.rendering.legend.SingleSymbolLegend;
102
import org.gvsig.fmap.mapcontext.rendering.legend.SymbolLegendEvent;
103
import org.gvsig.fmap.mapcontext.rendering.legend.XMLLegendException;
104
import org.gvsig.fmap.mapcontext.rendering.legend.ZSort;
105
import org.gvsig.fmap.mapcontext.rendering.legend.events.LegendChangedEvent;
106
import org.gvsig.fmap.mapcontext.rendering.legend.events.LegendClearEvent;
107
import org.gvsig.fmap.mapcontext.rendering.legend.events.LegendContentsChangedListener;
108
import org.gvsig.fmap.mapcontext.rendering.legend.styling.AttrInTableLabelingStrategy;
109
import org.gvsig.fmap.mapcontext.rendering.legend.styling.ILabelingStrategy;
110
import org.gvsig.fmap.mapcontext.rendering.legend.styling.LabelingFactory;
111
import org.gvsig.fmap.mapcontext.rendering.symbols.CartographicSupport;
112
import org.gvsig.fmap.mapcontext.rendering.symbols.FSymbol;
113
import org.gvsig.fmap.mapcontext.rendering.symbols.IMultiLayerSymbol;
114
import org.gvsig.fmap.mapcontext.rendering.symbols.ISymbol;
115
import org.gvsig.tools.ToolsLocator;
116
import org.gvsig.tools.dynobject.exception.DynMethodException;
117
import org.gvsig.tools.dynobject.exception.DynMethodNotSupportedException;
118
import org.gvsig.tools.exception.BaseException;
119
import org.gvsig.tools.observer.Observable;
120
import org.gvsig.tools.observer.Observer;
121
import org.gvsig.tools.persistence.PersistenceException;
122
import org.gvsig.tools.persistence.PersistentState;
123
import org.gvsig.tools.persistence.xmlentity.XMLEntityManager;
124
import org.gvsig.tools.persistence.xmlentity.XMLEntityState;
125
import org.gvsig.tools.task.Cancellable;
126
import org.slf4j.LoggerFactory;
127

    
128
import com.iver.utiles.NotExistInXMLEntity;
129
import com.iver.utiles.XMLEntity;
130
import com.iver.utiles.XMLException;
131

    
132
/**
133
 * Capa b?sica Vectorial.
134
 *
135
 * @author Fernando Gonz?lez Cort?s
136
 */
137

    
138
// TODO Cuando no sea para pruebas debe no ser public
139
public class FLyrVect extends FLyrDefault implements ILabelable, InfoByPoint,
140
ClassifiableVectorial, SingleLayer, LegendContentsChangedListener,
141
Observer {
142
        final static private org.slf4j.Logger logger = LoggerFactory.getLogger(FLyrVect.class);
143
        /** Leyenda de la capa vectorial */
144
        private IVectorLegend legend;
145
        private int typeShape = -1;
146
        private FeatureStore featureStore=null;
147
        private SpatialCache spatialCache = new SpatialCache();
148
        private boolean spatialCacheEnabled = false;
149

    
150
        /**
151
         * An implementation of gvSIG spatial index
152
         */
153
        //    protected ISpatialIndex spatialIndex = null;
154
        private boolean bHasJoin = false;
155
        private XMLEntity orgXMLEntity = null;
156
        private XMLEntity loadSelection = null;
157
        private IVectorLegend loadLegend = null;
158

    
159
        //Lo a?ado. Caracter?sticas de HyperEnlace (LINK)
160
        private FLyrVectLinkProperties linkProperties=new FLyrVectLinkProperties();
161

    
162
        /**
163
         * Devuelve el VectorialAdapater de la capa.
164
         *
165
         * @return VectorialAdapter.
166
         */
167
        public DataStore getDataStore() {
168
                if (!this.isAvailable()) {
169
                        return null;
170
                }
171
                return featureStore;
172
        }
173

    
174
        /**
175
         * If we use a persistent spatial index associated with this layer, and the
176
         * index is not intrisic to the layer (for example spatial databases) this
177
         * method looks for existent spatial index, and loads it.
178
         *
179
         */
180
        //    private void loadSpatialIndex() {
181
        //        //FIXME: Al abrir el indice en fichero...
182
        //        //?C?mo lo liberamos? un metodo Layer.shutdown()
183
        //
184
        //
185
        //        ReadableVectorial source = getSource();
186
        //        //REVISAR QUE PASA CON LOS DRIVERS DXF, DGN, etc.
187
        //        //PUES SON VECTORIALFILEADAPTER
188
        //        if (!(source instanceof VectorialFileAdapter)) {
189
        //            // we are not interested in db adapters
190
        //            return;
191
        //        }
192
        //        VectorialDriver driver = source.getDriver();
193
        //        if (!(driver instanceof BoundedShapes)) {
194
        //            // we dont spatially index layers that are not bounded
195
        //            return;
196
        //        }
197
        //        File file = ((VectorialFileAdapter) source).getFile();
198
        //        String fileName = file.getAbsolutePath();
199
        //        File sptFile = new File(fileName + ".qix");
200
        //        if (!sptFile.exists() || (!(sptFile.length() > 0))) {
201
        //            // before to exit, look for it in temp path
202
        //            String tempPath = System.getProperty("java.io.tmpdir");
203
        //            fileName = tempPath + File.separator + sptFile.getName();
204
        //            sptFile = new File(fileName);
205
        //            // it doesnt exists, must to create
206
        //            if (!sptFile.exists() || (!(sptFile.length() > 0))) {
207
        //                return;
208
        //            }// if
209
        //        }// if
210
        //
211
        //        try {
212
        //            source.start();
213
        //            spatialIndex = new QuadtreeGt2(FileUtils.getFileWithoutExtension(sptFile),
214
        //                    "NM", source.getFullExtent(), source.getShapeCount(), false);
215
        //            source.setSpatialIndex(spatialIndex);
216
        //        } catch (SpatialIndexException e) {
217
        //            spatialIndex = null;
218
        //            e.printStackTrace();
219
        //            return;
220
        //        } catch (ReadDriverException e) {
221
        //            spatialIndex = null;
222
        //            e.printStackTrace();
223
        //            return;
224
        //        }
225
        //
226
        //    }
227

    
228
        /**
229
         * Checks if it has associated an external spatial index
230
         * (an spatial index file).
231
         *
232
         * It looks for it in main file path, or in temp system path.
233
         * If main file is rivers.shp, it looks for a file called
234
         * rivers.shp.qix.
235

236
         * @return
237
         */
238
        //    public boolean isExternallySpatiallyIndexed() {
239
        //        /*
240
        //         * FIXME (AZABALA): Independizar del tipo de fichero de ?ndice
241
        //          * con el que se trabaje (ahora mismo considera la extension .qix,
242
        //         * pero esto depender? del tipo de ?ndice)
243
        //         * */
244
        //        ReadableVectorial source = getSource();
245
        //        if (!(source instanceof VectorialFileAdapter)) {
246
        //            // we are not interested in db adapters.
247
        //            // think in non spatial dbs, like HSQLDB
248
        //            return false;
249
        //        }
250
        //        File file = ((VectorialFileAdapter) source).getFile();
251
        //        String fileName = file.getAbsolutePath();
252
        //        File sptFile = new File(fileName + ".qix");
253
        //        if (!sptFile.exists() || (!(sptFile.length() > 0))) {
254
        //            // before to exit, look for it in temp path
255
        //            // it doesnt exists, must to create
256
        //            String tempPath = System.getProperty("java.io.tmpdir");
257
        //            fileName = tempPath + File.separator + sptFile.getName();
258
        //            sptFile = new File(fileName);
259
        //            if (!sptFile.exists() || (!(sptFile.length() > 0))) {
260
        //                return false;
261
        //            }// if
262
        //        }// if
263
        //        return true;
264
        //    }
265
        /**
266
         * Inserta el VectorialAdapter a la capa.
267
         *
268
         * @param va
269
         *            VectorialAdapter.
270
         *
271
         * @deprecated esto deber?a se ser protected
272
         */
273
          public void setDataStore(DataStore dataStore) throws LoadLayerException {
274
                if (this.featureStore != null && this.featureStore != dataStore){
275
                        this.featureStore.deleteObserver(this);
276
                }
277

    
278
                featureStore = (FeatureStore)dataStore;
279

    
280
                ILegend legend = null;
281
                try {
282
                        legend = (ILegend) dataStore.invokeDynMethod("defaultLegend", null);
283

    
284
                } catch (DynMethodNotSupportedException e1) {
285
                        try {
286
                                legend = LegendFactory.createSingleSymbolLegend(this
287
                                                .getShapeType());
288
                        } catch (ReadException e) {
289
                                throw new LoadLayerException(this.getName(), e);
290
                        }
291

    
292
                } catch (DynMethodException e1) {
293
                        throw new LoadLayerException(this.getName(), e1);
294
                }
295
                this.setLegend((IVectorLegend) legend);
296

    
297

    
298

    
299

    
300
                ILabelingStrategy labeler = null;
301
                try {
302
                        labeler = (ILabelingStrategy) dataStore.invokeDynMethod(
303
                                        "defaultLabelingStrategy", null);
304
                } catch (DynMethodNotSupportedException e1) {
305
                        labeler = null;
306
                } catch (DynMethodException e1) {
307
                        throw new LoadLayerException(this.getName(), e1);
308
                }
309

    
310
                if (labeler != null) {
311
                        try {
312
                                labeler.setLayer(this);
313
                        } catch (ReadException e) {
314
                                throw new LoadLayerException(this.getName(), e);
315
                        }
316
                        this.setLabelingStrategy(labeler);
317
                        this.setIsLabeled(true); // TODO: ac? no s'hauria de detectar si t? etiquetes?????
318
                }
319

    
320
                this.delegate(dataStore);
321

    
322
                dataStore.addObserver(this);
323

    
324
                // azabala: we check if this layer could have a file spatial index
325
                // and load it if it exists
326
                //        loadSpatialIndex();
327
        }
328

    
329
        public Envelope getFullEnvelope() throws ReadException {
330
                Envelope rAux;
331
                try {
332
                        rAux = getFeatureStore().getEnvelope();
333
                } catch (BaseException e) {
334
                        throw new ReadException(getName(),e);
335
                }
336

    
337
                //Esto es para cuando se crea una capa nueva con el fullExtent de ancho y alto 0.
338
                if (rAux == null || rAux.getMaximum(0)-rAux.getMinimum(0)==0 && rAux.getMaximum(1)-rAux.getMinimum(1)==0) {
339
                        rAux=new DefaultEnvelope(2,new double[]{0,0},new double[]{100,100});
340
                }
341
                // Si existe reproyecci?n, reproyectar el extent
342
                ICoordTrans ct = getCoordTrans();
343
                if (ct != null) {
344
                        Point2D pt1 = new Point2D.Double(rAux.getMinimum(0), rAux.getMinimum(1));
345
                        Point2D pt2 = new Point2D.Double(rAux.getMaximum(0), rAux.getMaximum(1));
346
                        pt1 = ct.convert(pt1, null);
347
                        pt2 = ct.convert(pt2, null);
348
                        rAux = new DefaultEnvelope(2,new double[]{pt1.getX(),pt1.getY()},new double[]{pt2.getX(),pt2.getY()});//new Rectangle2D.Double();
349
                }
350
                return rAux;
351

    
352
        }
353

    
354
        /**
355
         * Draws using IFeatureIterator. This method will replace the old draw(...) one.
356
         * @autor jaume dominguez faus - jaume.dominguez@iver.es
357
         * @param image
358
         * @param g
359
         * @param viewPort
360
         * @param cancel
361
         * @param scale
362
         * @throws ReadDriverException
363
         */
364
        public void draw(BufferedImage image, Graphics2D g, ViewPort viewPort,
365
                        Cancellable cancel, double scale) throws ReadException {
366
                if (!this.isWithinScale(scale)) {
367
                        return;
368
                }
369
                if (cancel.isCanceled()) {
370
                        return;
371
                }
372
                boolean containsAll = false;
373
                Envelope viewPortEnvelope =viewPort.getAdjustedExtent();
374
                Envelope viewPortEnvelopeInMyProj = viewPortEnvelope;
375
                Envelope viewPortEnvelopeInMyProj2 = viewPortEnvelope;
376
                // FIXME
377
                if (this.getCoordTrans() != null) {
378
                        ICoordTrans myCt = getCoordTrans().getPDest().getCT(
379
                                        getCoordTrans().getPOrig());
380
                        viewPortEnvelopeInMyProj = viewPortEnvelope
381
                                        .convert(myCt);
382
                        viewPortEnvelopeInMyProj2 = viewPortEnvelopeInMyProj
383
                                        .convert(getCoordTrans());
384

    
385

    
386
                }
387
                System.out.println("=XX viewPortEnvelope["
388
                                + viewPortEnvelope.getLowerCorner()[0]
389
                                + "," + viewPortEnvelope.getLowerCorner()[1] + "] ["
390
                                + viewPortEnvelope.getUpperCorner()[0] + ","
391
                                + viewPortEnvelope.getUpperCorner()[1] + "]");
392

    
393
                System.out.println("=XX viewPortEnvelopeInMyProj["
394
                                + viewPortEnvelopeInMyProj.getLowerCorner()[0] + ","
395
                                + viewPortEnvelopeInMyProj.getLowerCorner()[1] + "] ["
396
                                + viewPortEnvelopeInMyProj.getUpperCorner()[0] + ","
397
                                + viewPortEnvelopeInMyProj.getUpperCorner()[1] + "]");
398

    
399
                System.out.println("=XX viewPortEnvelopeInMyProj2["
400
                                + viewPortEnvelopeInMyProj2.getLowerCorner()[0] + ","
401
                                + viewPortEnvelopeInMyProj2.getLowerCorner()[1] + "] ["
402
                                + viewPortEnvelopeInMyProj2.getUpperCorner()[0] + ","
403
                                + viewPortEnvelopeInMyProj2.getUpperCorner()[1] + "]");
404

    
405

    
406
                Envelope myEnvelope = this.getFullEnvelope();
407

    
408
                System.out.println("=XX myEnvelope[" + myEnvelope.getLowerCorner()[0]
409
                                + "," + myEnvelope.getLowerCorner()[1] + "] ["
410
                                + myEnvelope.getUpperCorner()[0] + ","
411
                                + myEnvelope.getUpperCorner()[1] + "]");
412

    
413

    
414
                Envelope rAux = null;
415
                try {
416
                        rAux = getFeatureStore().getEnvelope();
417
                } catch (DataException e1) {
418
                        e1.printStackTrace();
419
                }
420

    
421
                if (rAux != null) {
422
                System.out.println("=XX DSEnv [" + rAux.getLowerCorner()[0] + ","
423
                                + rAux.getLowerCorner()[1] + "] [" + rAux.getUpperCorner()[0]
424
                                + "," + rAux.getUpperCorner()[1] + "]");
425
                }
426

    
427
                if (!viewPortEnvelope.contains(myEnvelope)){
428
                        if (!viewPortEnvelope.intersects(myEnvelope)){
429
                                return;
430
                        }
431
                } else {
432
                        containsAll = true;
433
                }
434
                System.out.println("=XX containsAll=" + containsAll);
435
                double dpi = MapContext.getScreenDPI();
436
                DrawOperationContext doc=new DrawOperationContext();
437
                doc.setViewPort(viewPort);
438
                doc.setScale(scale);
439
                doc.setCancellable(cancel);
440
                doc.setDPI(dpi);
441
                boolean bDrawShapes = true;
442
                if (legend instanceof SingleSymbolLegend) {
443
                        bDrawShapes = legend.getDefaultSymbol().isShapeVisible();
444
                }
445
                Point2D offset = viewPort.getOffset();
446

    
447
                if (bDrawShapes) {
448
                        if (cancel.isCanceled()) {
449
                                return;
450
                        }
451
                        boolean cacheFeatures = isSpatialCacheEnabled();
452
                        SpatialCache cache = null;
453
                        if (cacheFeatures) {
454
                                getSpatialCache().clearAll();
455
                                cache = getSpatialCache();
456
                        }
457

    
458
                        try {
459

    
460
                                FeatureSelection selection = this.featureStore
461
                                .getFeatureSelection();
462

    
463
                                FeatureStore featureStore=getFeatureStore();
464
                                String[] fieldNames=null;
465
                                if (legend instanceof IClassifiedVectorLegend){
466
                                        String[] classified=((IClassifiedVectorLegend)legend).getClassifyingFieldNames();
467
                                        fieldNames=new String[classified.length+1];
468
                                        fieldNames[0]=featureStore.getDefaultFeatureType().getDefaultGeometryAttributeName();
469
                                        for (int i = 1; i < fieldNames.length; i++) {
470
                                                fieldNames[i]=classified[i-1];
471
                                        }
472

    
473
                                }else{
474
                                        fieldNames=new String[]{featureStore.getDefaultFeatureType().getDefaultGeometryAttributeName()};
475
                                }
476
                                FeatureSet featureSet=null;
477
                                FeatureQuery featureQuery=featureStore.createFeatureQuery();
478
                                featureQuery.setScale(scale);
479
                                featureQuery.setAttributeNames(fieldNames);
480
                                if (!containsAll) {
481
                                        InEnvelopeEvaluator iee = new InEnvelopeEvaluator(
482
                                                        viewPortEnvelopeInMyProj, getProjection(),
483
                                                        featureStore.getDefaultFeatureType(),
484
                                                        featureStore.getDefaultFeatureType().getDefaultGeometryAttributeName());
485
                                        featureQuery.setFilter(iee);
486

    
487
                                }
488
                                featureSet = featureStore.getFeatureSet(featureQuery);
489
                                Iterator it = featureSet.fastIterator();
490

    
491
                                ZSort zSort = ((IVectorLegend) getLegend()).getZSort();
492

    
493
                                boolean bSymbolLevelError = false;
494

    
495
                                // if layer has map levels it will use a ZSort
496
                                boolean useZSort = zSort != null && zSort.isUsingZSort();
497

    
498
                                // -- visual FX stuff
499
                                long time = System.currentTimeMillis();
500
                                BufferedImage virtualBim;
501
                                Graphics2D virtualGraphics;
502

    
503
                                if (cancel.isCanceled()) {
504
                                        return;
505
                                }
506

    
507
                                // render temporary map each screenRefreshRate milliseconds;
508
                                int screenRefreshDelay = (int) ((1D/MapContext.getDrawFrameRate())*3*1000);
509
                                BufferedImage[] imageLevels = null;
510
                                Graphics2D[] graphics = null;
511
                                if (useZSort) {
512
                                        imageLevels = new BufferedImage[zSort.getLevelCount()];
513
                                        graphics = new Graphics2D[imageLevels.length];
514
                                        for (int i = 0; !cancel.isCanceled() && i < imageLevels.length; i++) {
515
                                                imageLevels[i] = new BufferedImage(image.getWidth(), image.getHeight(), image.getType());
516
                                                graphics[i] = imageLevels[i].createGraphics();
517
                                                graphics[i].setTransform(g.getTransform());
518
                                                graphics[i].setRenderingHints(g.getRenderingHints());
519
                                        }
520
                                }
521
                                // -- end visual FX stuff
522

    
523
                                // FIXME geometry reproject temporaly patch
524
                                // FeatureAttributeDescriptor attrGeom =
525
                                // featureStore.getDefaultFeatureType().getAttributeDescriptor(featureStore.getDefaultFeatureType().getDefaultGeometryAttributeIndex());
526
                                // ICoordTrans myct = null;
527
                                // if (!viewPort.getProjection().equals(attrGeom.getSRS())) {
528
                                // myct = viewPort.getProjection().getCT(attrGeom.getSRS());
529
                                // }
530

    
531

    
532
                                // Iteration over each feature
533
                                while (it.hasNext()) {
534
                                        if (cancel.isCanceled()) {
535
                                                return;
536
                                        }
537
                                        Feature feat = (Feature) it.next();
538

    
539
                                        Geometry geom = feat.getDefaultGeometry();
540
                                        System.out.println("*" + geom.getBounds());
541

    
542
                                        if (this.getCoordTrans() != null) {
543
                                                geom = geom.cloneGeometry();
544
                                                geom.reProject(this.getCoordTrans());
545
                                                System.out.println("**" + geom.getBounds());
546
                                        }
547

    
548
                                        if (cacheFeatures) {
549
                                                if (cache.getMaxFeatures() >= cache.size()) {
550
                                                        // already reprojected
551
                                                        cache.insert(geom.getEnvelope(), geom);
552
                                                }
553
                                        }
554

    
555
                                        // retrieve the symbol associated to such feature
556
                                        ISymbol sym = legend.getSymbolByFeature(feat);
557
                                        if (selection.isSelected(feat)) {
558
                                                sym=sym.getSymbolForSelection();
559
                                        }
560
                                        if (sym == null) {
561
                                                continue;
562
                                        }
563

    
564
                                        // Check if this symbol is sized with CartographicSupport
565
                                        CartographicSupport csSym = null;
566
                                        int symbolType = sym.getSymbolType();
567
                                        boolean bDrawCartographicSupport = false;
568

    
569
                                        if (   symbolType == Geometry.TYPES.POINT
570
                                                        || symbolType == Geometry.TYPES.CURVE
571
                                                        || sym instanceof CartographicSupport) {
572

    
573
                                                // patch
574
                                                if (!sym.getClass().equals(FSymbol.class)) {
575
                                                        csSym = (CartographicSupport) sym;
576
                                                        bDrawCartographicSupport = (csSym.getUnit() != -1);
577
                                                }
578
                                        }
579

    
580
                                        int x = -1;
581
                                        int y = -1;
582
                                        int[] xyCoords = new int[2];
583

    
584
                                        // Check if size is a pixel
585
                                        boolean onePoint = bDrawCartographicSupport ?
586
                                                        isOnePoint(g.getTransform(), viewPort, MapContext.getScreenDPI(), csSym, geom, xyCoords) :
587
                                                                isOnePoint(g.getTransform(), viewPort, geom, xyCoords);
588

    
589
                                                        // Avoid out of bounds exceptions
590
                                                        if (onePoint) {
591
                                                                x = xyCoords[0];
592
                                                                y = xyCoords[1];
593
                                                                if (x<0 || y<0 || x>= viewPort.getImageWidth() || y>=viewPort.getImageHeight()) {
594
                                                                        continue;
595
                                                                }
596
                                                        }
597

    
598
                                                        if (cancel.isCanceled()) {
599
                                                                return;
600
                                                        }
601

    
602
                                                        if (useZSort) {
603
                                                                // Check if this symbol is a multilayer
604
                                                                int[] symLevels = zSort.getLevels(sym);
605
                                                                if (sym instanceof IMultiLayerSymbol) {
606
                                                                        // if so, treat each of its layers as a single symbol
607
                                                                        // in its corresponding map level
608
                                                                        IMultiLayerSymbol mlSym = (IMultiLayerSymbol) sym;
609
                                                                        for (int i = 0; !cancel.isCanceled() && i < mlSym.getLayerCount(); i++) {
610
                                                                                ISymbol mySym = mlSym.getLayer(i);
611
                                                                                int symbolLevel = 0;
612
                                                                                if (symLevels != null) {
613
                                                                                        symbolLevel = symLevels[i];
614
                                                                                } else {
615
                                                                                        /* an error occured when managing symbol levels
616
                                                                                         * some of the legend changed events regarding the
617
                                                                                         * symbols did not finish satisfactory and the legend
618
                                                                                         * is now inconsistent. For this drawing, it will finish
619
                                                                                         * as it was at the bottom (level 0) but, when done, the
620
                                                                                         * ZSort will be reset to avoid app crashes. This is
621
                                                                                         * a bug that has to be fixed.
622
                                                                                         */
623
                                                                                        bSymbolLevelError = true;
624
                                                                                }
625

    
626
                                                                                if (onePoint) {
627
                                                                                        if (x<0 || y<0 || x>= imageLevels[symbolLevel].getWidth() || y>=imageLevels[symbolLevel].getHeight()) {
628
                                                                                                continue;
629
                                                                                        }
630
                                                                                        imageLevels[symbolLevel].setRGB(x, y, mySym.getOnePointRgb());
631
                                                                                } else {
632
                                                                                        if (!bDrawCartographicSupport) {
633
                                                                                                doc.setGraphics(graphics[symbolLevel]);
634
                                                                                                doc.setSymbol(mySym);
635
                                                                                                geom.invokeOperation(DrawInts.CODE,doc);
636
                                                                                        } else {
637
                                                                                                doc.setGraphics(graphics[symbolLevel]);
638
                                                                                                doc.setSymbol(mySym);
639
                                                                                                geom.invokeOperation(DrawInts.CODE,doc);
640
                                                                                        }
641
                                                                                }
642
                                                                        }
643
                                                                } else {
644
                                                                        // else, just draw the symbol in its level
645
                                                                        int symbolLevel = 0;
646
                                                                        if (symLevels != null) {
647
                                                                                symbolLevel=symLevels[0];
648
                                                                        }
649
                                                                        if (!bDrawCartographicSupport) {
650
                                                                                doc.setGraphics(graphics[symbolLevel]);
651
                                                                                doc.setSymbol(sym);
652
                                                                                geom.invokeOperation(DrawInts.CODE,doc);
653
                                                                        } else {
654
                                                                                doc.setGraphics(graphics[symbolLevel]);
655
                                                                                doc.setSymbol((ISymbol)csSym);
656
                                                                                geom.invokeOperation(DrawInts.CODE,doc);
657
                                                                        }
658
                                                                }
659

    
660
                                                                // -- visual FX stuff
661
                                                                // Cuando el offset!=0 se est? dibujando sobre el Layout y por tanto no tiene que ejecutar el siguiente c?digo.
662
                                                                if (offset.getX()==0 && offset.getY()==0) {
663
                                                                        if ((System.currentTimeMillis() - time) > screenRefreshDelay) {
664
                                                                                virtualBim = new BufferedImage(image.getWidth(),image.getHeight(),BufferedImage.TYPE_INT_ARGB);
665
                                                                                virtualGraphics = virtualBim.createGraphics();
666
                                                                                virtualGraphics.drawImage(image,0,0, null);
667
                                                                                for (int i = 0; !cancel.isCanceled() && i < imageLevels.length; i++) {
668
                                                                                        virtualGraphics.drawImage(imageLevels[i],0,0, null);
669
                                                                                }
670
                                                                                g.clearRect(0, 0, image.getWidth(), image.getHeight());
671
                                                                                g.drawImage(virtualBim, 0, 0, null);
672
                                                                                time = System.currentTimeMillis();
673
                                                                        }
674
                                                                        // -- end visual FX stuff
675
                                                                }
676

    
677
                                                        } else {
678
                                                                // no ZSort, so there is only a map level, symbols are
679
                                                                // just drawn.
680
                                                                if (onePoint) {
681
                                                                        if (x<0 || y<0 || x>= image.getWidth() || y>=image.getHeight()) {
682
                                                                                continue;
683
                                                                        }
684
                                                                        image.setRGB(x, y, sym.getOnePointRgb());
685
                                                                } else {
686

    
687
                                                                        if (!bDrawCartographicSupport) {
688
                                                                                doc.setGraphics(g);
689
                                                                                doc.setSymbol(sym);
690
                                                                                geom.invokeOperation(DrawInts.CODE,doc);
691
                                                                        } else {
692
                                                                                doc.setGraphics(g);
693
                                                                                doc.setSymbol((ISymbol)csSym);
694
                                                                                geom.invokeOperation(DrawInts.CODE,doc);
695
                                                                        }
696
                                                                }
697
                                                        }
698
                                }
699

    
700
                                if (useZSort) {
701
                                        g.drawImage(image, 0, 0, null);
702
                                        g.translate(offset.getX(), offset.getY());
703
                                        for (int i = 0; !cancel.isCanceled() && i < imageLevels.length; i++) {
704
                                                g.drawImage(imageLevels[i],0,0, null);
705
                                                imageLevels[i] = null;
706
                                                graphics[i] = null;
707
                                        }
708
                                        g.translate(-offset.getX(), -offset.getY());
709
                                        imageLevels = null;
710
                                        graphics = null;
711
                                }
712
                                //                            it.closeIterator();
713
                                it=null;
714
                                featureSet.dispose();
715

    
716
                                if (bSymbolLevelError) {
717
                                        ((IVectorLegend) getLegend()).setZSort(null);
718
                                }
719

    
720
                        } catch (ReadException e) {
721
                                this.setVisible(false);
722
                                this.setActive(false);
723
                                throw e;
724
                        } catch (GeometryOperationNotSupportedException e) {
725
                                this.setVisible(false);
726
                                this.setActive(false);
727
                                throw new ReadException(getName(),e);
728
                        } catch (GeometryOperationException e) {
729
                                this.setVisible(false);
730
                                this.setActive(false);
731
                                throw new ReadException(getName(),e);
732
                        } catch (BaseException e) {
733
                                this.setVisible(false);
734
                                this.setActive(false);
735
                                throw new ReadException(getName(),e);
736
                        }
737

    
738

    
739
                }
740
        }
741
        public void print(Graphics2D g, ViewPort viewPort, Cancellable cancel,
742
                        double scale, PrintRequestAttributeSet properties) throws ReadException {
743
                // TEST METHOD
744
                boolean bDrawShapes = true;
745
                if (legend instanceof SingleSymbolLegend) {
746
                        bDrawShapes = legend.getDefaultSymbol().isShapeVisible();
747
                }
748
                if (bDrawShapes) {
749
                        try {
750
                                double dpi = 72;
751

    
752
                                PrintQuality resolution=(PrintQuality)properties.get(PrintQuality.class);
753
                                if (resolution.equals(PrintQuality.NORMAL)){
754
                                        dpi = 300;
755
                                } else if (resolution.equals(PrintQuality.HIGH)){
756
                                        dpi = 600;
757
                                } else if (resolution.equals(PrintQuality.DRAFT)){
758
                                        dpi = 72;
759
                                }
760
                                ZSort zSort = ((IVectorLegend) getLegend()).getZSort();
761

    
762
                                // if layer has map levels it will use a ZSort
763
                                boolean useZSort = zSort != null && zSort.isUsingZSort();
764

    
765

    
766
                                int mapLevelCount = (useZSort) ? zSort.getLevelCount() : 1;
767
                                for (int mapPass = 0; mapPass < mapLevelCount; mapPass++) {
768
                                        // Get the iterator over the visible features
769
                                        FeatureStore featureStore=getFeatureStore();
770
                                        // Get the iterator over the visible features
771
                                        //                                String featureFilter = null;
772
                                        //
773
                                        //                                if (!viewPort.getAdjustedExtent().contains((Envelope)featureStore.getMetadata().get("extent"))) {
774
                                        //                                            featureFilter=this.getDataStoreFilterForGeomerty(
775
                                        //                                                    viewPort.getAdjustedExtent().getGeometry(),
776
                                        //                                                    featureStore.getDefaultFeatureType().getDefaultGeometryAttributeName(),
777
                                        //                                                    null);
778
                                        //                                    }
779
                                        String[] fieldNames=null;
780
                                        if (legend instanceof IClassifiedVectorLegend){
781
                                                String[] classified=((IClassifiedVectorLegend)legend).getClassifyingFieldNames();
782
                                                fieldNames=new String[classified.length+1];
783
                                                fieldNames[0]=featureStore.getDefaultFeatureType().getDefaultGeometryAttributeName();
784
                                                for (int i = 1; i < fieldNames.length; i++) {
785
                                                        fieldNames[i]=classified[i-1];
786
                                                }
787

    
788
                                        }else{
789
                                                fieldNames=new String[]{featureStore.getDefaultFeatureType().getDefaultGeometryAttributeName()};
790
                                        }
791

    
792

    
793
                                        FeatureSet featureCollection=null;
794
                                        FeatureQuery featureQuery=featureStore.createFeatureQuery();
795
                                        featureQuery.setAttributeNames(fieldNames);
796
                                        featureQuery.setScale(scale);
797
                                        //                                ??SQLJEPEvaluator evaluator=new SQLJEPEvaluator(featureFilter);
798
                                        InEnvelopeEvaluator iee=new InEnvelopeEvaluator(viewPort.getAdjustedExtent(),viewPort.getProjection(),featureStore.getDefaultFeatureType(),featureStore.getDefaultFeatureType().getDefaultGeometryAttributeName());
799
                                        featureQuery.setFilter(iee);
800
                                        featureCollection = featureStore.getFeatureSet(featureQuery);                               Iterator it = featureCollection.iterator();
801

    
802
                                        // Iteration over each feature
803
                                        while ( !cancel.isCanceled() && it.hasNext()) {
804
                                                Feature feat = (Feature)it.next();
805
                                                Geometry geom = feat.getDefaultGeometry();
806

    
807
                                                // retreive the symbol associated to such feature
808
                                                ISymbol sym = legend.getSymbolByFeature(feat);
809

    
810
                                                if (useZSort) {
811
                                                        int[] symLevels = zSort.getLevels(sym);
812
                                                        if(symLevels != null){
813

    
814
                                                                // Check if this symbol is a multilayer
815
                                                                if (sym instanceof IMultiLayerSymbol) {
816
                                                                        // if so, get the layer corresponding to the current
817
                                                                        // level. If none, continue to next iteration
818
                                                                        IMultiLayerSymbol mlSym = (IMultiLayerSymbol) sym;
819
                                                                        for (int i = 0; i < mlSym.getLayerCount(); i++) {
820
                                                                                ISymbol mySym = mlSym.getLayer(i);
821
                                                                                if (symLevels[i] == mapPass) {
822
                                                                                        sym = mySym;
823
                                                                                        break;
824
                                                                                }
825
                                                                                System.out.println("avoided layer "+i+"of symbol '"+mlSym.getDescription()+"' (pass "+mapPass+")");
826
                                                                        }
827

    
828
                                                                        if (sym == null) {
829
                                                                                continue;
830
                                                                        }
831
                                                                } else {
832
                                                                        // else, just draw the symbol in its level
833
                                                                        if (symLevels[0] != mapPass) {
834
                                                                                System.out.println("avoided single layer symbol '"+sym.getDescription()+"' (pass "+mapPass+")");
835
                                                                                continue;
836
                                                                        }
837
                                                                }
838
                                                        }
839
                                                }
840

    
841
                                                // Check if this symbol is sized with CartographicSupport
842
                                                CartographicSupport csSym = null;
843
                                                int symbolType = sym.getSymbolType();
844
                                                boolean bDrawCartographicSupport = false;
845

    
846
                                                if (   symbolType == Geometry.TYPES.POINT
847
                                                                || symbolType == Geometry.TYPES.CURVE
848
                                                                || sym instanceof CartographicSupport) {
849

    
850
                                                        csSym = (CartographicSupport) sym;
851
                                                        bDrawCartographicSupport = (csSym.getUnit() != -1);
852
                                                }
853

    
854
                                                System.err.println("passada "+mapPass+" pinte s?mboll "+sym.getDescription());
855

    
856
                                                if (!bDrawCartographicSupport) {
857
                                                        DrawOperationContext doc=new DrawOperationContext();
858
                                                        doc.setGraphics(g);
859
                                                        doc.setViewPort(viewPort);
860
                                                        doc.setSymbol(sym);
861
                                                        doc.setCancellable(cancel);
862
                                                        geom.invokeOperation(DrawInts.CODE,doc);
863
                                                } else {
864
                                                        DrawOperationContext doc=new DrawOperationContext();
865
                                                        doc.setGraphics(g);
866
                                                        doc.setViewPort(viewPort);
867
                                                        doc.setSymbol((ISymbol)csSym);
868
                                                        doc.setCancellable(cancel);
869
                                                        doc.setDPI(dpi);
870
                                                        geom.invokeOperation(DrawInts.CODE,doc);
871
                                                }
872
                                        }
873
                                        it=null;
874
                                        featureCollection.dispose();
875
                                }
876
                        } catch (ReadException e) {
877
                                this.setVisible(false);
878
                                this.setActive(false);
879
                                throw e;
880
                        } catch (GeometryOperationNotSupportedException e) {
881
                                this.setVisible(false);
882
                                this.setActive(false);
883
                                throw new ReadException(getName(),e);
884
                        } catch (GeometryOperationException e) {
885
                                this.setVisible(false);
886
                                this.setActive(false);
887
                                throw new ReadException(getName(),e);
888
                        } catch (BaseException e) {
889
                                this.setVisible(false);
890
                                this.setActive(false);
891
                                throw new ReadException(getName(),e);
892
                        }
893
                }
894
        }
895

    
896
        /**
897
         * <p>
898
         * Creates an spatial index associated to this layer.
899
         * The spatial index will used
900
         * the native projection of the layer, so if the layer is reprojected, it will
901
         * be ignored.
902
         * </p>
903
         * @param cancelMonitor instance of CancellableMonitorable that allows
904
         * to monitor progress of spatial index creation, and cancel the process
905
         */
906
        //    public void createSpatialIndex(CancellableMonitorable cancelMonitor){
907
        //         // FJP: ESTO HABR? QUE CAMBIARLO. PARA LAS CAPAS SECUENCIALES, TENDREMOS
908
        //        // QUE ACCEDER CON UN WHILE NEXT. (O mejorar lo de los FeatureVisitor
909
        //        // para que acepten recorrer sin geometria, solo con rectangulos.
910
        //
911
        //        //If this vectorial layer is based in a spatial database, the spatial
912
        //        //index is already implicit. We only will index file drivers
913
        //        ReadableVectorial va = getSource();
914
        //        //We must think in non spatial databases, like HSQLDB
915
        //        if(!(va instanceof VectorialFileAdapter)){
916
        //            return;
917
        //        }
918
        //        if (!(va.getDriver() instanceof BoundedShapes)) {
919
        //            return;
920
        //        }
921
        //        File file = ((VectorialFileAdapter) va).getFile();
922
        //        String fileName = file.getAbsolutePath();
923
        //        ISpatialIndex localCopy = null;
924
        //        try {
925
        //            va.start();
926
        //            localCopy = new QuadtreeGt2(fileName, "NM", va.getFullExtent(),
927
        //                    va.getShapeCount(), true);
928
        //
929
        //        } catch (SpatialIndexException e1) {
930
        //            // Probably we dont have writing permissions
931
        //            String directoryName = System.getProperty("java.io.tmpdir");
932
        //            File newFile = new File(directoryName +
933
        //                    File.separator +
934
        //                    file.getName());
935
        //            String newFileName = newFile.getName();
936
        //            try {
937
        //                localCopy = new QuadtreeGt2(newFileName, "NM", va.getFullExtent(),
938
        //                        va.getShapeCount(), true);
939
        //            } catch (SpatialIndexException e) {
940
        //                // if we cant build a file based spatial index, we'll build
941
        //                // a pure memory spatial index
942
        //                localCopy = new QuadtreeJts();
943
        //            } catch (ReadException e) {
944
        //                localCopy = new QuadtreeJts();
945
        //            }
946
        //
947
        //        } catch(Exception e){
948
        //            e.printStackTrace();
949
        //        }//try
950
        //        BoundedShapes shapeBounds = (BoundedShapes) va.getDriver();
951
        //        try {
952
        //            for (int i=0; i < va.getShapeCount(); i++)
953
        //            {
954
        //                if(cancelMonitor != null){
955
        //                    if(cancelMonitor.isCanceled())
956
        //                        return;
957
        //                    cancelMonitor.reportStep();
958
        //                }
959
        //                Rectangle2D r = shapeBounds.getShapeBounds(i);
960
        //                if(r != null)
961
        //                    localCopy.insert(r, i);
962
        //            } // for
963
        //            va.stop();
964
        //            if(localCopy instanceof IPersistentSpatialIndex)
965
        //                ((IPersistentSpatialIndex) localCopy).flush();
966
        //            spatialIndex = localCopy;
967
        //            //vectorial adapter needs a reference to the spatial index, to solve
968
        //            //request for feature iteration based in spatial queries
969
        //            source.setSpatialIndex(spatialIndex);
970
        //        } catch (ReadException e) {
971
        //            // TODO Auto-generated catch block
972
        //            e.printStackTrace();
973
        //        }
974
        //    }
975

    
976
        //    public void createSpatialIndex() {
977
        //        createSpatialIndex(null);
978
        //    }
979

    
980

    
981
        public void setLegend(IVectorLegend r) throws LegendLayerException {
982
                if (this.legend == r){
983
                        return;
984
                }
985
                if (this.legend != null && this.legend.equals(r)){
986
                        return;
987
                }
988
                IVectorLegend oldLegend = legend;
989
                legend = r;
990
                try {
991
                        legend.setFeatureStore(getFeatureStore());
992
                } catch (ReadException e1) {
993
                        throw new LegendLayerException(getName(),e1);
994
                } catch (DataException e) {
995
                        throw new LegendLayerException(getName(),e);
996
                } finally{
997
                        this.updateDrawVersion();
998
                }
999

    
1000
                if (oldLegend != null) {
1001
                        oldLegend.removeLegendListener(this);
1002
                }
1003
                if (legend != null) {
1004
                        legend.addLegendListener(this);
1005
                }
1006

    
1007
                LegendChangedEvent e = LegendChangedEvent.createLegendChangedEvent(
1008
                                oldLegend, legend);
1009
                callLegendChanged(e);
1010
        }
1011

    
1012
        /**
1013
         * Devuelve la Leyenda de la capa.
1014
         *
1015
         * @return Leyenda.
1016
         */
1017
        public ILegend getLegend() {
1018
                return legend;
1019
        }
1020

    
1021
        /**
1022
         * Devuelve el tipo de shape que contiene la capa.
1023
         *
1024
         * @return tipo de shape.
1025
         *
1026
         * @throws ReadException
1027
         */
1028
        public int getShapeType() throws ReadException {
1029
                if (typeShape == -1) {
1030
                        FeatureType featureType;
1031
                        try {
1032
                                featureType = (((FeatureStore)getDataStore()).getDefaultFeatureType());
1033
                        } catch (DataException e) {
1034
                                throw new ReadException(getName(),e);
1035
                        }
1036
                        int indexGeom=featureType.getDefaultGeometryAttributeIndex();
1037
                        typeShape=featureType.getAttributeDescriptor(indexGeom).getGeometryType();
1038
                }
1039
                return typeShape;
1040
        }
1041

    
1042
        public XMLEntity getXMLEntity() throws XMLException {
1043

    
1044
                if (!this.isAvailable() && this.orgXMLEntity != null) {
1045
                        return this.orgXMLEntity;
1046
                }
1047
                XMLEntity xml = super.getXMLEntity();
1048
                if (getLegend()!=null){
1049
                        XMLEntity xmlLegend=getLegend().getXMLEntity();
1050
                        xmlLegend.putProperty("tagName","legend");
1051
                        xml.addChild(xmlLegend);
1052
                }
1053
                try {
1054
                        PersistentState stateFeatureStore=getFeatureStore().getState();
1055
                        stateFeatureStore.set("tagName","featureStore");
1056
                        xml.addChild(((XMLEntityState)stateFeatureStore).getXMLEntity());
1057
                } catch (ReadException e) {
1058
                        throw new XMLLayerException(getName(),e);
1059
                } catch (PersistenceException e) {
1060
                        throw new XMLLayerException(getName(),e);
1061
                }
1062
                // properties from ILabelable
1063
                xml.putProperty("isLabeled", isLabeled);
1064
                if (strategy != null) {
1065
                        XMLEntity strategyXML = strategy.getXMLEntity();
1066
                        strategyXML.putProperty("tagName", "labelingStrategy");
1067
                        xml.addChild(strategy.getXMLEntity());
1068
                }
1069
                xml.addChild(getLinkProperties().getXMLEntity());
1070
                return xml;
1071
        }
1072
        /*
1073
         * @see com.iver.cit.gvsig.fmap.layers.FLyrDefault#setXMLEntity(com.iver.utiles.XMLEntity)
1074
         */
1075
        public void setXMLEntity(XMLEntity xml) throws XMLException {
1076
                try {
1077
                        super.setXMLEntity(xml);
1078
                        XMLEntity legendXML = xml.firstChild("tagName","legend");
1079
                        IVectorLegend leg = LegendFactory.createFromXML(legendXML);
1080
                        /* (jaume) begin patch;
1081
                         * for backward compatibility purposes. Since gvSIG v1.1 labeling is
1082
                         * no longer managed by the Legend but by the ILabelingStrategy. The
1083
                         * following allows restoring older projects' labelings.
1084
                         */
1085
                        if (legendXML.contains("labelFieldName")) {
1086
                                String labelTextField = legendXML.getStringProperty("labelFieldName");
1087
                                if (labelTextField != null) {
1088
                                        AttrInTableLabelingStrategy labeling = new AttrInTableLabelingStrategy();
1089
                                        labeling.setLayer(this);
1090
                                        labeling.setTextField(legendXML.getStringProperty("labelFieldName"));
1091
                                        labeling.setHeightField(legendXML.getStringProperty("labelHeightFieldName"));
1092
                                        labeling.setRotationField(legendXML.getStringProperty("labelRotationFieldName"));
1093
                                        this.setLabelingStrategy(labeling);
1094
                                        this.setIsLabeled(true);
1095
                                }
1096
                        }
1097
                        //            PersistentState persistentState=new XMLEntityState(new XMLEntityManager());
1098
                        XMLEntity xmlStore=xml.firstChild("tagName","featureStore");
1099
                        XMLEntityManager xmlManger = new XMLEntityManager();
1100
                        PersistentState state = xmlManger.createState(xmlStore);
1101
                        DataStore store = (DataStore) ToolsLocator.getPersistenceManager().create(state);
1102
                        //            persistentState.createState(xmlStore);
1103

    
1104
                        //            DataManager dm=DALLocator.getDataManager();
1105

    
1106
                        this.setDataStore(store);
1107
                        /* end patch */
1108
                        try {
1109
                                setLegend(leg);
1110
                        } catch (LegendLayerException e) {
1111
                                throw new XMLLegendException(e);
1112
                        }
1113
                        // set properties for ILabelable
1114

    
1115
                        if (xml.contains("isLabeled")
1116
                                        && xml.getBooleanProperty(("isLabeled"))) {
1117
                                XMLEntity labelingXML = xml.firstChild("tagName", "labelingStrategy");
1118
                                if (labelingXML != null){
1119

    
1120
                                        isLabeled = true;
1121
                                        try {
1122
                                                this.strategy = LabelingFactory.createStrategyFromXML(labelingXML, this);
1123
                                        } catch (NotExistInXMLEntity neXMLEX) {
1124
                                                // no strategy was set, just continue;
1125
                                                logger.warn("Reached what should be unreachable code");
1126
                                        }
1127
                                } else {
1128
                                        isLabeled = false;
1129
                                }
1130
                        } else {
1131
                                isLabeled = false;
1132
                        }
1133
                        XMLEntity xmlLinkProperties=xml.firstChild("typeChild","linkProperties");
1134
                        if (xmlLinkProperties != null){
1135
                                getLinkProperties().setXMLEntity(xmlLinkProperties);
1136
                        }
1137
                } catch (Exception e) {
1138
                        e.printStackTrace();
1139
                        this.setAvailable(false);
1140
                        this.orgXMLEntity = xml;
1141

    
1142
                }
1143
                //
1144

    
1145
        }
1146

    
1147
        public void setXMLEntityNew(XMLEntity xml) throws XMLException {
1148
                //        try {
1149
                //            super.setXMLEntity(xml);
1150
                //
1151
                //            XMLEntity legendXML = xml.getChild(0);
1152
                //            IVectorLegend leg = LegendFactory.createFromXML(legendXML);
1153
                //            /* (jaume) begin patch;
1154
                //             * for backward compatibility purposes. Since gvSIG v1.1 labeling is
1155
                //             * no longer managed by the Legend but by the ILabelingStrategy. The
1156
                //             * following allows restoring older projects' labelings.
1157
                //             */
1158
                //            if (legendXML.contains("labelFieldHeight")) {
1159
                //                AttrInTableLabelingStrategy labeling = new AttrInTableLabelingStrategy();
1160
                //                labeling.setLayer(this);
1161
                //                labeling.setTextField(legendXML.getStringProperty("labelFieldHeight"));
1162
                //                labeling.setRotationField(legendXML.getStringProperty("labelFieldRotation"));
1163
                //                this.setLabelingStrategy(labeling);
1164
                //                this.setIsLabeled(true);
1165
                //              }
1166
                //            /* end patch */
1167
                //            try {
1168
                //                getRecordset().getSelectionSupport().setXMLEntity(xml.getChild(1));
1169
                //
1170
                //                this.setLoadSelection(xml.getChild(1));
1171
                //            } catch (ReadException e1) {
1172
                //                this.setAvailable(false);
1173
                //                throw new XMLException(e1);
1174
                //            }
1175
                //            // Si tiene una uni?n, lo marcamos para que no se cree la leyenda hasta
1176
                //            // el final
1177
                //            // de la lectura del proyecto
1178
                //            if (xml.contains("hasJoin")) {
1179
                //                setIsJoined(true);
1180
                //                PostProcessSupport.addToPostProcess(this, "setLegend", leg, 1);
1181
                //            } else {
1182
                //                this.setLoadLegend(leg);
1183
                //            }
1184
                //
1185
                //        } catch (XMLException e) {
1186
                //            this.setAvailable(false);
1187
                //            this.orgXMLEntity = xml;
1188
                //        } catch (Exception e) {
1189
                //            this.setAvailable(false);
1190
                //            this.orgXMLEntity = xml;
1191
                //        }
1192

    
1193

    
1194
        }
1195

    
1196

    
1197
        /**
1198
         * Sobreimplementaci?n del m?todo toString para que las bases de datos
1199
         * identifiquen la capa.
1200
         *
1201
         * @return DOCUMENT ME!
1202
         */
1203
        public String toString() {
1204
                /*
1205
                 * Se usa internamente para que la parte de datos identifique de forma
1206
                 * un?voca las tablas
1207
                 */
1208
                String ret = super.toString();
1209

    
1210
                return "layer" + ret.substring(ret.indexOf('@') + 1);
1211
        }
1212

    
1213
        public boolean isJoined() {
1214
                return bHasJoin;
1215
        }
1216

    
1217
        /**
1218
         * Returns if a layer is spatially indexed
1219
         *
1220
         * @return if this layer has the ability to proces spatial queries without
1221
         *         secuential scans.
1222
         */
1223
        //    public boolean isSpatiallyIndexed() {
1224
        //        ReadableVectorial source = getSource();
1225
        //        if (source instanceof ISpatialDB)
1226
        //            return true;
1227
        //
1228
        ////FIXME azabala
1229
        ///*
1230
        // * Esto es muy dudoso, y puede cambiar.
1231
        // * Estoy diciendo que las que no son fichero o no son
1232
        // * BoundedShapes estan indexadas. Esto es mentira, pero
1233
        // * as? quien pregunte no querr? generar el indice.
1234
        // * Esta por ver si interesa generar el indice para capas
1235
        // * HSQLDB, WFS, etc.
1236
        // */
1237
        //        if(!(source instanceof VectorialFileAdapter)){
1238
        //            return true;
1239
        //        }
1240
        //        if (!(source.getDriver() instanceof BoundedShapes)) {
1241
        //            return true;
1242
        //        }
1243
        //
1244
        //        if (getISpatialIndex() != null)
1245
        //            return true;
1246
        //        return false;
1247
        //    }
1248

    
1249
        public void setIsJoined(boolean hasJoin) {
1250
                bHasJoin = hasJoin;
1251
        }
1252

    
1253
        //    /**
1254
        //     * @return Returns the spatialIndex.
1255
        //     */
1256
        //    public ISpatialIndex getISpatialIndex() {
1257
        //        return spatialIndex;
1258
        //    }
1259
        //    /**
1260
        //     * Sets the spatial index. This could be useful if, for some
1261
        //     * reasons, you want to work with a distinct spatial index
1262
        //     * (for example, a spatial index which could makes nearest
1263
        //     * neighbour querys)
1264
        //     * @param spatialIndex
1265
        //     */
1266
        //    public void setISpatialIndex(ISpatialIndex spatialIndex){
1267
        //        this.spatialIndex = spatialIndex;
1268
        //    }
1269

    
1270
        public void setEditing(boolean b) throws StartEditionLayerException {
1271
                super.setEditing(b);
1272
                if (b){
1273
                        try {
1274
                                getFeatureStore().edit();
1275
                        } catch (ReadException e) {
1276
                                throw new StartEditionLayerException(getName(),e);
1277
                        } catch (DataException e) {
1278
                                throw new StartEditionLayerException(getName(),e);
1279
                        }
1280
                }
1281
                setSpatialCacheEnabled(b);
1282
                callEditionChanged(LayerEvent
1283
                                .createEditionChangedEvent(this, "edition"));
1284

    
1285
        }
1286

    
1287
        public void clearSpatialCache()
1288
        {
1289
                spatialCache.clearAll();
1290
        }
1291

    
1292
        public boolean isSpatialCacheEnabled() {
1293
                return spatialCacheEnabled;
1294
        }
1295

    
1296
        public void setSpatialCacheEnabled(boolean spatialCacheEnabled) {
1297
                this.spatialCacheEnabled = spatialCacheEnabled;
1298
        }
1299

    
1300
        public SpatialCache getSpatialCache() {
1301
                return spatialCache;
1302
        }
1303

    
1304
        /**
1305
         * Siempre es un numero mayor de 1000
1306
         * @param maxFeatures
1307
         */
1308
        public void setMaxFeaturesInEditionCache(int maxFeatures) {
1309
                if (maxFeatures > spatialCache.getMaxFeatures()) {
1310
                        spatialCache.setMaxFeatures(maxFeatures);
1311
                }
1312

    
1313
        }
1314

    
1315
        /**
1316
         * This method returns a boolean that is used by the FPopMenu
1317
         * to make visible the properties menu or not. It is visible by
1318
         * default, and if a later don't have to show this menu only
1319
         * has to override this method.
1320
         * @return
1321
         * If the properties menu is visible (or not)
1322
         */
1323
        public boolean isPropertiesMenuVisible(){
1324
                return true;
1325
        }
1326

    
1327
        public void reload() throws ReloadLayerException {
1328
                super.reload();
1329
                try {
1330
                        DataManager dataManager=DALLocator.getDataManager();
1331
                        DataStoreParameters storeParameters;
1332

    
1333
                        storeParameters = getFeatureStore().getParameters();
1334

    
1335
                        DataStore dataStore=dataManager.createStore(storeParameters);
1336
                        setDataStore(dataStore);
1337
                        getFeatureStore().refresh();
1338
                } catch (ReadException e) {
1339
                        throw new ReloadLayerException(getName(),e);
1340
                }catch (LoadLayerException e) {
1341
                        throw new ReloadLayerException(getName(),e);
1342
                } catch (DataException e) {
1343
                        throw new ReloadLayerException(getName(),e);
1344
                }
1345
                //        try {
1346
                //            this.source.getDriver().reload();
1347
                //            if (this.getLegend() == null) {
1348
                //                if (this.getRecordset().getDriver() instanceof WithDefaultLegend) {
1349
                //                    WithDefaultLegend aux = (WithDefaultLegend) this.getRecordset().getDriver();
1350
                //                    this.setLegend((IVectorLegend) aux.getDefaultLegend());
1351
                //                    this.setLabelingStrategy(aux.getDefaultLabelingStrategy());
1352
                //                } else {
1353
                //                    this.setLegend(LegendFactory.createSingleSymbolLegend(
1354
                //                            this.getShapeType()));
1355
                //                }
1356
                //            }
1357
                //
1358
                //        } catch (LegendLayerException e) {
1359
                //            this.setAvailable(false);
1360
                //            throw new ReloadLayerException(getName(),e);
1361
                //        } catch (ReadException e) {
1362
                //            this.setAvailable(false);
1363
                //            throw new ReloadLayerException(getName(),e);
1364
                //        }
1365

    
1366

    
1367
        }
1368

    
1369
        protected void setLoadSelection(XMLEntity xml) {
1370
                this.loadSelection = xml;
1371
        }
1372

    
1373
        protected void setLoadLegend(IVectorLegend legend) {
1374
                this.loadLegend = legend;
1375
        }
1376

    
1377
        protected void putLoadSelection() throws XMLException {
1378
                //        if (this.loadSelection == null) return;
1379
                //        try {
1380
                //            this.getRecordset().getSelectionSupport().setXMLEntity(this.loadSelection);
1381
                //        } catch (ReadDriverException e) {
1382
                //            throw new XMLException(e);
1383
                //        }
1384
                //        this.loadSelection = null;
1385

    
1386
        }
1387
        protected void putLoadLegend() throws LegendLayerException {
1388
                if (this.loadLegend == null) {
1389
                        return;
1390
                }
1391
                this.setLegend(this.loadLegend);
1392
                this.loadLegend = null;
1393
        }
1394

    
1395
        protected void cleanLoadOptions() {
1396
                this.loadLegend = null;
1397
                this.loadSelection = null;
1398
        }
1399

    
1400
        public boolean isWritable() {
1401
                try {
1402
                        return getFeatureStore().allowWrite();
1403
                } catch (ReadException e) {
1404
                        e.printStackTrace();
1405
                }
1406
                return false;
1407
        }
1408

    
1409
        public FLayer cloneLayer() throws Exception {
1410
                FLyrVect clonedLayer = new FLyrVect();
1411
                clonedLayer.setDataStore(getDataStore());
1412
                if (isJoined()) {
1413
                        clonedLayer.setIsJoined(true);
1414
                }
1415
                clonedLayer.setVisible(isVisible());
1416
                //        clonedLayer.setISpatialIndex(getISpatialIndex());
1417
                clonedLayer.setName(getName());
1418
                clonedLayer.setCoordTrans(getCoordTrans());
1419

    
1420
                clonedLayer.setLegend((IVectorLegend)getLegend().cloneLegend());
1421

    
1422
                clonedLayer.setIsLabeled(isLabeled());
1423
                clonedLayer.setLabelingStrategy(getLabelingStrategy());
1424

    
1425
                return clonedLayer;
1426
        }
1427

    
1428

    
1429
        private boolean isOnePoint(AffineTransform graphicsTransform, ViewPort viewPort, double dpi, CartographicSupport csSym, Geometry geom, int[] xyCoords) {
1430
                return isOnePoint(graphicsTransform, viewPort, geom, xyCoords) && csSym.getCartographicSize(viewPort, dpi, geom) <= 1;
1431
        }
1432

    
1433
        private boolean isOnePoint(AffineTransform graphicsTransform, ViewPort viewPort, Geometry geom, int[] xyCoords) {
1434
                boolean onePoint = false;
1435
                int type=geom.getType() % Geometry.TYPES.Z;
1436
                if (type!=Geometry.TYPES.POINT && type!=Geometry.TYPES.MULTIPOINT) {
1437

    
1438
                        Envelope geomBounds = geom.getEnvelope();
1439

    
1440
                        ICoordTrans ct = getCoordTrans();
1441

    
1442
                        // Se supone que la geometria ya esta reproyectada
1443
                        // if (ct!=null) {
1444
                        // // geomBounds = ct.getInverted().convert(geomBounds);
1445
                        // geomBounds = geomBounds.convert(ct);
1446
                        // }
1447

    
1448
                        double dist1Pixel = viewPort.getDist1pixel();
1449

    
1450
                        onePoint = (geomBounds.getLength(0)  <= dist1Pixel
1451
                                        && geomBounds.getLength(1) <= dist1Pixel);
1452

    
1453
                        if (onePoint) {
1454
                                // avoid out of range exceptions
1455
                                org.gvsig.fmap.geom.primitive.Point2D p = new org.gvsig.fmap.geom.primitive.Point2D(geomBounds.getMinimum(0), geomBounds.getMinimum(1));
1456
                                p.transform(viewPort.getAffineTransform());
1457
                                p.transform(graphicsTransform);
1458
                                xyCoords[0] = (int) p.getX();
1459
                                xyCoords[1] = (int) p.getY();
1460

    
1461
                        }
1462

    
1463
                }
1464
                return onePoint;
1465
        }
1466
        /*
1467
         * jaume. Stuff from ILabeled.
1468
         */
1469
        private boolean isLabeled;
1470
        protected ILabelingStrategy strategy;
1471

    
1472
        public boolean isLabeled() {
1473
                return isLabeled;
1474
        }
1475

    
1476
        public void setIsLabeled(boolean isLabeled) {
1477
                this.isLabeled = isLabeled;
1478
        }
1479

    
1480
        public ILabelingStrategy getLabelingStrategy() {
1481
                return strategy;
1482
        }
1483

    
1484
        public void setLabelingStrategy(ILabelingStrategy strategy) {
1485
                this.strategy = strategy;
1486
                try {
1487
                        strategy.setLayer(this);
1488
                } catch (ReadException e) {
1489
                        // TODO Auto-generated catch block
1490
                        e.printStackTrace();
1491
                }
1492

    
1493
        }
1494

    
1495
        public void drawLabels(BufferedImage image, Graphics2D g, ViewPort viewPort,
1496
                        Cancellable cancel, double scale, double dpi) throws ReadException {
1497
                if (strategy!=null && isWithinScale(scale)) {
1498
                        strategy.draw(image, g, viewPort, cancel, dpi);
1499
                }
1500
        }
1501

    
1502
        public void printLabels(Graphics2D g, ViewPort viewPort,
1503
                        Cancellable cancel, double scale,
1504
                        PrintRequestAttributeSet properties) throws ReadException {
1505
                if (strategy != null) {
1506
                        strategy.print(g, viewPort, cancel, properties);
1507
                }
1508
        }
1509
        //M?todos para el uso de HyperLinks en capas FLyerVect
1510

    
1511
        /**
1512
         * Return true, because a Vectorial Layer supports HyperLink
1513
         */
1514
        public boolean allowLinks()
1515
        {
1516
                return true;
1517
        }
1518

    
1519
        /**
1520
         * Returns an instance of AbstractLinkProperties that contains the information
1521
         * of the HyperLink
1522
         * @return Abstra
1523
         */
1524
        public AbstractLinkProperties getLinkProperties()
1525
        {
1526
                return linkProperties;
1527
        }
1528

    
1529
        /**
1530
         * Provides an array with URIs. Returns one URI by geometry that includes the point
1531
         * in its own geometry limits with a allowed tolerance.
1532
         * @param layer, the layer
1533
         * @param point, the point to check that is contained or not in the geometries in the layer
1534
         * @param tolerance, the tolerance allowed. Allowed margin of error to detect if the  point
1535
         *                 is contained in some geometries of the layer
1536
         * @return
1537
         * @throws ReadException
1538
         * @throws BehaviorException
1539
         */
1540
        public URI[] getLink(Point2D point, double tolerance) throws ReadException
1541
        {
1542
                //return linkProperties.getLink(this)
1543
                return linkProperties.getLink(this,point,tolerance);
1544
        }
1545

    
1546
        public void load() throws LoadLayerException {
1547
                super.load();
1548
        }
1549

    
1550
        public FeatureStore getFeatureStore() throws ReadException {
1551
                return (FeatureStore)getDataStore();
1552
        }
1553

    
1554
        public FeatureSet queryByPoint(Point2D mapPoint, double tol, FeatureType featureType) throws DataException {
1555
                Geometry geom = GeometryLocator.getGeometryManager().getGeometryFactory()
1556
                .createCircle(mapPoint, tol);
1557

    
1558
                return queryByGeometry(geom, featureType);
1559
                //                return queryByEnvelope(geom.getEnvelope(), featureType);
1560
        }
1561

    
1562

    
1563
        public FeatureSet queryByGeometry(Geometry geom, FeatureType featureType) throws DataException {
1564
                FeatureQuery featureQuery=featureStore.createFeatureQuery();
1565
                String geomName=featureStore.getDefaultFeatureType().getDefaultGeometryAttributeName();
1566
                featureQuery.setFeatureType(featureType);
1567
                IntersectsGeometryEvaluator iee=new IntersectsGeometryEvaluator(geom,getMapContext().getViewPort().getProjection(),featureStore.getDefaultFeatureType(),geomName);
1568
                featureQuery.setFilter(iee);
1569
                return getFeatureStore().getFeatureSet(featureQuery);
1570

    
1571
        }
1572

    
1573
        public FeatureSet queryByEnvelope(Envelope envelope, FeatureType featureType)
1574
        throws DataException {
1575
                FeatureQuery featureQuery=featureStore.createFeatureQuery();
1576
                String geomName=featureStore.getDefaultFeatureType().getDefaultGeometryAttributeName();
1577
                featureQuery.setFeatureType(featureType);
1578
                InEnvelopeEvaluator iee=new InEnvelopeEvaluator(envelope,getMapContext().getViewPort().getProjection(),featureStore.getDefaultFeatureType(),geomName);
1579
                featureQuery.setFilter(iee);
1580
                return getFeatureStore().getFeatureSet(featureQuery);
1581

    
1582
        }
1583

    
1584
        public XMLItem[] getInfo(Point p, double tolerance, Cancellable cancel) throws LoadLayerException, DataException {
1585
                Point2D pReal = this.getMapContext().getViewPort().toMapPoint(p);
1586
                FeatureSet featureCollection=null;
1587
                try {
1588
                        featureCollection = queryByPoint(pReal, tolerance, getFeatureStore().getDefaultFeatureType());
1589
                } catch (DataException e) {
1590
                        // TODO Auto-generated catch block
1591
                        e.printStackTrace();
1592
                }
1593
                VectorialXMLItem[] item = new VectorialXMLItem[1];
1594
                item[0] = new VectorialXMLItem(featureCollection, this);
1595

    
1596
                return item;
1597
        }
1598

    
1599
        public void legendCleared(LegendClearEvent event) {
1600
                // this.updateDrawVersion(); TODO
1601
                LegendChangedEvent e = LegendChangedEvent.createLegendChangedEvent(
1602
                                legend, legend);
1603
                this.callLegendChanged(e);
1604
        }
1605

    
1606
        public boolean symbolChanged(SymbolLegendEvent e) {
1607
                LegendChangedEvent ev = LegendChangedEvent.createLegendChangedEvent(
1608
                                legend, legend);
1609
                this.callLegendChanged(ev);
1610
                return true;
1611
        }
1612

    
1613
        public void update(Observable observable, Object notification) {
1614
                if (observable.equals(this.featureStore)) {
1615
                        if (notification instanceof FeatureStoreNotification) {
1616
                                FeatureStoreNotification event = (FeatureStoreNotification) notification;
1617
                                if (event.getType() == FeatureStoreNotification.AFTER_CANCELEDITING
1618
                                                || event.getType() == FeatureStoreNotification.AFTER_DELETE
1619
                                                || event.getType() == FeatureStoreNotification.AFTER_UNDO
1620
                                                || event.getType() == FeatureStoreNotification.AFTER_REDO
1621
                                                || event.getType() == FeatureStoreNotification.AFTER_REFRESH
1622
                                                || event.getType() == FeatureStoreNotification.AFTER_UPDATE
1623
                                                || event.getType() == FeatureStoreNotification.AFTER_UPDATE_TYPE
1624
                                                || event.getType() == FeatureStoreNotification.SELECTION_CHANGE
1625
                                                || event.getType() == FeatureStoreNotification.AFTER_INSERT) {
1626
                                        this.updateDrawVersion();
1627

    
1628
                                } else if (event.getType() == FeatureStoreNotification.AFTER_FINISHEDITING
1629
                                                || event.getType() == FeatureStoreNotification.TRANSFORM_CHANGE
1630
                                                || event.getType() == FeatureStoreNotification.RESOURCE_CHANGED) {
1631
                                        this.setAvailable(false);
1632

    
1633
                                        //                                        try {
1634
                                        //                                                reload();
1635
                                        //                                        } catch (ReloadLayerException e) {
1636
                                        //                                                this.setAvailable(false);
1637
                                        //                                        }
1638
                                }
1639

    
1640
                        }
1641

    
1642
                }
1643

    
1644
        }
1645

    
1646
        /*
1647
         * (non-Javadoc)
1648
         *
1649
         * @see org.gvsig.metadata.Metadata#getMetadataChildren()
1650
         */
1651
        public Set getMetadataChildren() {
1652
                Set ret = new TreeSet();
1653
                ret.add(this.featureStore);
1654
                return ret;
1655
        }
1656

    
1657
        /*
1658
         * (non-Javadoc)
1659
         *
1660
         * @see org.gvsig.metadata.Metadata#getMetadataID()
1661
         */
1662
        public Object getMetadataID() {
1663
                return "Layer(" + this.getName() + "):"
1664
                + this.featureStore.getMetadataID();
1665
        }
1666

    
1667
        /*
1668
         * (non-Javadoc)
1669
         *
1670
         * @see org.gvsig.metadata.Metadata#getMetadataName()
1671
         */
1672
        public String getMetadataName() {
1673
                return "Layer '" + this.getName() + "':"
1674
                + this.featureStore.getMetadataName();
1675
        }
1676
        public String getTypeVectorLayer() throws DataException {
1677

    
1678
                String typeString="";
1679
                int typeShape=(this).getShapeType();
1680
                FeatureStore fs=(this).getFeatureStore();
1681
                FeatureSet set=fs.getFeatureSet();
1682

    
1683
                if (Geometry.TYPES.GEOMETRY==typeShape){
1684
                        if (set.getSize()>0){
1685
                                int type=((Geometry)set.getDefaultFeatureType().get(set.getDefaultFeatureType().getDefaultGeometryAttributeIndex())).getType();
1686
                                if ((type & Geometry.TYPES.Z) == Geometry.TYPES.Z){
1687
                                        typeString="Geometries3D";
1688
                                }else{
1689
                                        typeString="Geometries2D";
1690
                                }
1691
                        }
1692
                }else{
1693
                        if (set.getSize()>0){
1694
                                int type = ((FeatureAttributeDescriptor) set
1695
                                                .getDefaultFeatureType().get(
1696
                                                                set.getDefaultFeatureType()
1697
                                                                                .getDefaultGeometryAttributeIndex()))
1698
                                                .getGeometryType();
1699
                                if (Geometry.TYPES.POINT == type){
1700
                                        typeString="Point2D";
1701
                                } else if (Geometry.TYPES.SURFACE == type){
1702
                                        typeString="Line2D";
1703
                                } else if (Geometry.TYPES.SOLID == type){
1704
                                        typeString="Polygon2D";
1705
                                } else if (Geometry.TYPES.MULTIPOINT == type){
1706
                                        typeString="MultiPint2D";
1707
                                } else if ((Geometry.TYPES.POINT | Geometry.TYPES.Z)  == type ){
1708
                                        typeString="Point3D";
1709
                                } else if ((Geometry.TYPES.SURFACE | Geometry.TYPES.Z)  == type ){
1710
                                        typeString="Line3D";
1711
                                } else if ((Geometry.TYPES.SOLID | Geometry.TYPES.Z)  == type ){
1712
                                        typeString="Polygon3D";
1713
                                } else if ((Geometry.TYPES.MULTIPOINT | Geometry.TYPES.Z)  == type ){
1714
                                        typeString="MultiPoint3D";
1715
                                }
1716

    
1717
                                return typeString;
1718
                        }
1719
                }
1720
                return "";
1721
        }
1722

    
1723
}