Statistics
| Revision:

root / trunk / libraries / libFMap / src / com / iver / cit / gvsig / fmap / drivers / shp / DemoSHPDriver.java @ 3020

History | View | Annotate | Download (24.2 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 com.iver.cit.gvsig.fmap.drivers.shp;
42

    
43
import java.awt.geom.Point2D;
44
import java.awt.geom.Rectangle2D;
45
import java.io.File;
46
import java.io.FileInputStream;
47
import java.io.IOException;
48
import java.nio.ByteOrder;
49
import java.nio.channels.FileChannel;
50

    
51
import org.apache.log4j.Logger;
52

    
53
import com.iver.cit.gvsig.fmap.core.FShape;
54
import com.iver.cit.gvsig.fmap.core.GeneralPathX;
55
import com.iver.cit.gvsig.fmap.core.IGeometry;
56
import com.iver.cit.gvsig.fmap.core.ShapeFactory;
57
import com.iver.cit.gvsig.fmap.drivers.BoundedShapes;
58
import com.iver.cit.gvsig.fmap.drivers.DriverAttributes;
59
import com.iver.cit.gvsig.fmap.drivers.ExternalData;
60
import com.iver.cit.gvsig.fmap.drivers.VectorialFileDriver;
61
import com.iver.utiles.bigfile.BigByteBuffer;
62

    
63

    
64
/**
65
* Driver del formato SHP.
66
*
67
* @author $author$
68
*/
69
public class DemoSHPDriver implements VectorialFileDriver, BoundedShapes,
70
    ExternalData {
71
    private static Logger logger = Logger.getLogger(DemoSHPDriver.class.getName());
72
    private File file;
73
    private BigByteBuffer bb;
74
    private FileChannel channel;
75
    private FileInputStream fin;
76
    private int type;
77
    private long[] m_posShapes;
78
    private int numReg;
79
    private Rectangle2D extent; 
80

    
81
    /**
82
     * Cierra el fichero.
83
     *
84
     * @throws IOException
85
     *
86
     * @see com.iver.cit.gvsig.fmap.drivers.VectorialFileDriver#close()
87
     */
88
    public synchronized void close() throws IOException {
89
        IOException ret = null;
90
        
91
        try {
92
            channel.close();
93
        } catch (IOException e) {
94
            ret = e;
95
        } finally {
96
            try {
97
                fin.close();
98
            } catch (IOException e1) {
99
                ret = e1;
100
            }
101
        }
102

    
103
        if (ret != null) {
104
            throw ret;
105
        }
106
        else // Si todo ha ido bien, preparamos para liberar memoria.
107
            bb = null;
108
    }
109

    
110
    /**
111
     * @see com.iver.cit.gvsig.fmap.drivers.VectorialFileDriver#open(java.io.File)
112
     */
113
    public synchronized void open(File f) throws IOException {
114
        file = f;
115

    
116
        fin = new FileInputStream(f);
117

    
118
        // Open the file and then get a channel from the stream
119
        channel = fin.getChannel();
120

    
121
        long size = channel.size();
122

    
123
        // Get the file's size and then map it into memory
124
        // bb = channel.map(FileChannel.MapMode.READ_ONLY, 0, size);
125
       bb = new BigByteBuffer(channel, FileChannel.MapMode.READ_ONLY);
126
    }
127

    
128
    /**
129
     * DOCUMENT ME!
130
     *
131
     * @param index DOCUMENT ME!
132
     *
133
     * @return DOCUMENT ME!
134
     *
135
     * @throws IOException
136
     *
137
     * @see com.iver.cit.gvsig.fmap.drivers.VectorialFileDriver#getShape(int)
138
     */
139

    
140
    /* public FShape getShapeByID(int ID) {
141
       Point2D.Double p = new Point2D.Double();
142
       Point2D.Double pAnt = null;
143
       int numParts;
144
       int numPoints;
145
       int i;
146
       int j;
147
       int numReg;
148
       int numeroPuntos;
149
       int hasta;
150
       int desde;
151
       Rectangle2D.Double BoundingBox = new Rectangle2D.Double();
152
    
153
               SHPShape shapeShp=null;
154
       FShape resulShape = null;
155
       try {
156
           bb.position(m_posShapes[ID]);
157
           bb.order(ByteOrder.LITTLE_ENDIAN);
158
           int tipoShape = bb.getInt();
159
           m_shapeType = tipoShape;
160
           // retrieve that shape.
161
           // tempRecord.setShape(readShape(tempShapeType, tempContentLength, in));
162
           if (tipoShape == FConstant.SHAPE_TYPE_POINT) {
163
               p = readPoint(bb);
164
               resulShape = new FShape(new FPoint(p.getX(),p.getY()),FConstant.SHAPE_TYPE_POINT);
165
               //Comprobaci?n punto.
166
               //System.err.println("p.x = "+p.x);
167
               //System.err.println("p.y = "+p.y);
168
    
169
           } else if ((tipoShape == FConstant.SHAPE_TYPE_POLYLINE) ||
170
                   (tipoShape == FConstant.SHAPE_TYPE_POLYGON)) {
171
               // BoundingBox
172
               BoundingBox = readRectangle(bb);
173
               numParts = bb.getInt();
174
               numPoints = bb.getInt();
175
               // part indexes.
176
               // Geometry geom = GeometryFactory.toGeometryArray();
177
               GeneralPathX elShape = new GeneralPathX(GeneralPathX.WIND_EVEN_ODD,
178
                       numPoints);
179
               int[] tempParts = new int[numParts];
180
               for (i = 0; i < numParts; i++) {
181
                   tempParts[i] = bb.getInt();
182
               }
183
               j = 0;
184
               ///Line2D.Double line2D;
185
               FPoint[] points=new FPoint[numPoints];
186
               for (i = 0; i < numPoints; i++) {
187
                       p=readPoint(bb);
188
                   points[i] = new FPoint(p.x,p.y);
189
                   // System.out.println("x= " + p.x + " y=" + p.y);
190
                   // System.out.println("x= " + (float) p.x + " y=" + (float) p.y);
191
                   if (i == tempParts[j]) {
192
                       elShape.moveTo(p.x, p.y);
193
                       if (j < (numParts - 1)) {
194
                           j++;
195
                       }
196
                   } else {
197
                       elShape.lineTo(p.x, p.y);
198
                   }
199
               }
200
               //FGeometry pol=new FPolyLine(points,tempParts,BoundingBox);
201
    
202
               resulShape = new FShape(tipoShape,elShape);
203
           } else if (tipoShape == FConstant.SHAPE_TYPE_MULTIPOINT) {
204
               // BoundingBox
205
               BoundingBox = readRectangle(bb);
206
               numPoints = bb.getInt();
207
               FPoint[] tempPoints = new FPoint[numPoints];
208
               for (i = 0; i < numPoints; i++) {
209
                       Point2D p2=readPoint(bb);
210
                   tempPoints[i] = new FPoint(p2.getX(),p2.getY(),0);
211
               }
212
               FMultiPoint multipoint = new FMultiPoint(tempPoints,BoundingBox);
213
               resulShape = new FShape(multipoint,tipoShape);
214
           } else if (tipoShape == FConstant.SHAPE_TYPE_POINTZ) {
215
               FPoint p3d = new FPoint();
216
               p3d.read(bb);
217
               resulShape = new FShape(p3d,tipoShape);
218
           } else if ((tipoShape == FConstant.SHAPE_TYPE_POLYLINEZ) ||
219
                   (tipoShape == FConstant.SHAPE_TYPE_POLYGONZ)) {
220
               // BoundingBox
221
               BoundingBox = readRectangle(bb);
222
               numParts = bb.getInt();
223
               numPoints = bb.getInt();
224
               // part indexes.
225
               // Geometry geom = GeometryFactory.toGeometryArray();
226
    
227
               GeneralPathX elShape = new GeneralPathX(GeneralPathX.WIND_EVEN_ODD,
228
                       numPoints);
229
               int[] tempParts = new int[numParts];
230
               for (i = 0; i < numParts; i++) {
231
                   tempParts[i] = bb.getInt();
232
               }
233
               j = 0;
234
              //Line2D.Double line2D;
235
               FPoint[] points=new FPoint[numPoints];
236
               for (i = 0; i < numPoints; i++) {
237
                   p = readPoint(bb);
238
                   points[i]=new FPoint(p.x,p.y);
239
    
240
                   if (i == tempParts[j]) {
241
                       elShape.moveTo(p.x, p.y);
242
                       if (j < (numParts - 1)) {
243
                           j++;
244
                       }
245
                   } else {
246
                       elShape.lineTo(p.x, p.y);
247
                   }
248
    
249
               }
250
    
251
               double[] boxZ = new double[2];
252
               boxZ[0] = bb.getDouble();
253
               boxZ[1] = bb.getDouble();
254
               double[] pZ = new double[numPoints];
255
               for (i = 0; i < numPoints; i++) {
256
                   pZ[i] = bb.getDouble();
257
               }
258
               //FGeometry pol=new FPolyLine(points,tempParts,BoundingBox);
259
               resulShape = new FShape(tipoShape, elShape, pZ);
260
           } else if (tipoShape == FConstant.SHAPE_TYPE_MULTIPOINTZ) {
261
               // BoundingBox
262
               BoundingBox = readRectangle(bb);
263
               numPoints = bb.getInt();
264
               FPoint[] tempPoints3D = new FPoint[numPoints];
265
               for (i = 0; i < numPoints; i++) {
266
                   tempPoints3D[i] = new FPoint();
267
                   tempPoints3D[i].read(bb);
268
               }
269
               FMultiPoint multipoint3D = new FMultiPoint(tempPoints3D,BoundingBox);
270
               resulShape = new FShape(multipoint3D,tipoShape);
271
           }
272
       } catch (Exception e) {
273
           System.err.println("Fallo en getShapeByID. ID=" + ID +
274
               " m_posShapes[ID]=" + m_posShapes[ID]);
275
           System.err.println("getShapeByID: " + e.getMessage());
276
           e.printStackTrace();
277
       }
278
       return resulShape;
279
       }
280
     */
281

    
282
    /**
283
     * Devuelve la geometria a partir de un ?ndice.
284
     *
285
     * @param index DOCUMENT ME!
286
     *
287
     * @return DOCUMENT ME!
288
     *
289
     * @throws IOException DOCUMENT ME!
290
     */
291
    public synchronized IGeometry getShape(int index) throws IOException {
292
        Point2D.Double p = new Point2D.Double();
293
        Point2D.Double pAnt = null;
294
        int numParts;
295
        int numPoints;
296
        int i;
297
        int j;
298
        int numReg;
299
        int numeroPuntos;
300
        int hasta;
301
        int desde;
302
        int shapeType;
303

    
304
        //Rectangle2D.Double BoundingBox;
305
        bb.position(m_posShapes[index]);
306
        bb.order(ByteOrder.LITTLE_ENDIAN);
307

    
308
        ///bb.position(bb.position()+4);
309
        shapeType = bb.getInt();
310
        //el shape tal con tema tal y n?mro tal es null
311
        if (shapeType==SHP.NULL){
312
            logger.info("El shape ="+index+ " del tema ="+this.toString()+" es null");
313
            return null;
314
        }
315
            
316
        // retrieve that shape.
317
        // tempRecord.setShape(readShape(tempShapeType, tempContentLength, in));
318
        switch (type) {
319
            case (SHP.POINT2D):
320
                p = readPoint(bb);
321

    
322
                return ShapeFactory.createPoint2D(p.getX(), p.getY());
323

    
324
            case (SHP.POLYLINE2D):
325

    
326
                //BoundingBox = readRectangle(bb);
327
                //bb.getDouble();
328
                //bb.getDouble();
329
                //bb.getDouble();
330
                //bb.getDouble();
331
                bb.position(bb.position() + 32);
332
                numParts = bb.getInt();
333
                numPoints = bb.getInt();
334

    
335
                // part indexes.
336
                // Geometry geom = GeometryFactory.toGeometryArray();
337
                GeneralPathX elShape = new GeneralPathX(GeneralPathX.WIND_EVEN_ODD,
338
                        numPoints);
339

    
340
                int[] tempParts = new int[numParts];
341

    
342
                for (i = 0; i < numParts; i++) {
343
                    tempParts[i] = bb.getInt();
344
                }
345

    
346
                j = 0;
347

    
348
                for (i = 0; i < numPoints; i++) {
349
                    p = readPoint(bb);
350

    
351
                    if (i == tempParts[j]) {
352
                        elShape.moveTo(p.x, p.y);
353

    
354
                        if (j < (numParts - 1)) {
355
                            j++;
356
                        }
357
                    } else {
358
                        elShape.lineTo(p.x, p.y);
359
                    }
360
                }
361

    
362
                return ShapeFactory.createPolyline2D(elShape);
363

    
364
            case (SHP.POLYGON2D):
365

    
366
                //                  BoundingBox = readRectangle(bb);
367
                bb.getDouble();
368
                bb.getDouble();
369
                bb.getDouble();
370
                bb.getDouble();
371

    
372
                numParts = bb.getInt();
373

    
374
                numPoints = bb.getInt();
375

    
376
                // part indexes.
377
                // Geometry geom = GeometryFactory.toGeometryArray();
378
                elShape = new GeneralPathX(GeneralPathX.WIND_EVEN_ODD, numPoints);
379

    
380
                tempParts = new int[numParts];
381

    
382
                for (i = 0; i < numParts; i++) {
383
                    tempParts[i] = bb.getInt();
384
                }
385

    
386
                j = 0;
387

    
388
                for (i = 0; i < numPoints; i++) {
389
                    p = readPoint(bb);
390

    
391
                    if (i == tempParts[j]) {
392
                        elShape.moveTo(p.x, p.y);
393

    
394
                        if (j < (numParts - 1)) {
395
                            j++;
396
                        }
397
                    } else {
398
                        elShape.lineTo(p.x, p.y);
399
                    }
400
                }
401

    
402
                return ShapeFactory.createPolygon2D(elShape);
403

    
404
            case (SHP.POINT3D):
405

    
406
                double x = bb.getDouble();
407
                double y = bb.getDouble();
408
                double z = bb.getDouble();
409

    
410
                return ShapeFactory.createPoint3D(x, y, z);
411

    
412
            case (SHP.POLYLINE3D):
413
                bb.position(bb.position() + 32);
414
                numParts = bb.getInt();
415
                numPoints = bb.getInt();
416
                elShape = new GeneralPathX(GeneralPathX.WIND_EVEN_ODD, numPoints);
417
                tempParts = new int[numParts];
418

    
419
                for (i = 0; i < numParts; i++) {
420
                    tempParts[i] = bb.getInt();
421
                }
422

    
423
                j = 0;
424

    
425
                for (i = 0; i < numPoints; i++) {
426
                    p = readPoint(bb);
427

    
428
                    if (i == tempParts[j]) {
429
                        elShape.moveTo(p.x, p.y);
430

    
431
                        if (j < (numParts - 1)) {
432
                            j++;
433
                        }
434
                    } else {
435
                        elShape.lineTo(p.x, p.y);
436
                    }
437
                }
438

    
439
                double[] boxZ = new double[2];
440
                boxZ[0] = bb.getDouble();
441
                boxZ[1] = bb.getDouble();
442

    
443
                double[] pZ = new double[numPoints];
444

    
445
                for (i = 0; i < numPoints; i++) {
446
                    pZ[i] = bb.getDouble();
447
                }
448

    
449
                return ShapeFactory.createPolyline3D(elShape, pZ);
450
            case (SHP.POLYGON3D):
451
            bb.position(bb.position() + 32);
452
            numParts = bb.getInt();
453
            numPoints = bb.getInt();
454
            elShape = new GeneralPathX(GeneralPathX.WIND_EVEN_ODD, numPoints);
455
            tempParts = new int[numParts];
456

    
457
            for (i = 0; i < numParts; i++) {
458
                tempParts[i] = bb.getInt();
459
            }
460

    
461
            j = 0;
462

    
463
            for (i = 0; i < numPoints; i++) {
464
                p = readPoint(bb);
465

    
466
                if (i == tempParts[j]) {
467
                    elShape.moveTo(p.x, p.y);
468

    
469
                    if (j < (numParts - 1)) {
470
                        j++;
471
                    }
472
                } else {
473
                    elShape.lineTo(p.x, p.y);
474
                }
475
            }
476

    
477
            double[] boxpoZ = new double[2];
478
            boxpoZ[0] = bb.getDouble();
479
            boxpoZ[1] = bb.getDouble();
480

    
481
            double[] poZ = new double[numPoints];
482

    
483
            for (i = 0; i < numPoints; i++) {
484
                poZ[i] = bb.getDouble();
485
            }
486

    
487
            return ShapeFactory.createPolygon3D(elShape, poZ);
488
            
489
            case (SHP.MULTIPOINT2D):
490
                bb.position(bb.position() + 32);
491
                numPoints = bb.getInt();
492

    
493
                double[] tempX = new double[numPoints];
494
                double[] tempY = new double[numPoints];
495

    
496
                for (i = 0; i < numPoints; i++) {
497
                    tempX[i] = bb.getDouble();
498
                    tempY[i] = bb.getDouble();
499
                }
500

    
501
                return ShapeFactory.createMultipoint2D(tempX, tempY);
502

    
503
            case (SHP.MULTIPOINT3D):
504
                bb.position(bb.position() + 32);
505
                numPoints = bb.getInt();
506

    
507
                double[] temX = new double[numPoints];
508
                double[] temY = new double[numPoints];
509
                double[] temZ = new double[numPoints];
510

    
511
                for (i = 0; i < numPoints; i++) {
512
                    temX[i] = bb.getDouble();
513
                    temY[i] = bb.getDouble();
514
                    //temZ[i] = bb.getDouble();
515
                }
516
                
517
                for (i = 0; i < numPoints; i++) {
518
                    temZ[i] = bb.getDouble();
519
                }
520
                return ShapeFactory.createMultipoint3D(temX, temY, temZ);
521
        }
522

    
523
        return null;
524
    }
525

    
526
    /**
527
     * @see com.iver.cit.gvsig.fmap.drivers.VectorialFileDriver#getShapeCount()
528
     */
529
    public int getShapeCount() {
530
        return numReg;
531
    }
532

    
533
    /**
534
     * @see com.iver.cit.gvsig.fmap.drivers.VectorialDriver#getShapeType()
535
     */
536
    public synchronized int getShapeType() {
537
        int auxType = 0;
538

    
539
        switch (type) {
540
            case (SHP.POINT2D):
541
            case (SHP.POINT3D):
542
                auxType = auxType | FShape.POINT;
543

    
544
                break;
545

    
546
            case (SHP.POLYLINE2D):
547
            case (SHP.POLYLINE3D):
548
                auxType = auxType | FShape.LINE;
549

    
550
                break;
551

    
552
            case (SHP.POLYGON2D):
553
            case (SHP.POLYGON3D):
554
                auxType = auxType | FShape.POLYGON;
555

    
556
                break;
557
            case (SHP.MULTIPOINT2D):
558
            case (SHP.MULTIPOINT3D):
559
                auxType = auxType | FShape.MULTIPOINT;
560

    
561
                break;
562
        }
563

    
564
        return auxType;
565
    }
566

    
567

    
568
    /**
569
     * @see com.iver.cit.gvsig.fmap.drivers.VectorialFileDriver#initialize()
570
     */
571
    public void initialize() throws IOException {
572
        // create a new header.
573
        ShapeFileHeader myHeader = new ShapeFileHeader();
574

    
575
        // read the header
576
        myHeader.readHeader(bb);
577

    
578
        extent = new Rectangle2D.Double(myHeader.myXmin, myHeader.myYmin,
579
                myHeader.myXmax - myHeader.myXmin,
580
                myHeader.myYmax - myHeader.myYmin);
581

    
582
        type = myHeader.myShapeType;
583

    
584
        double x = myHeader.myXmin;
585
        double y = myHeader.myYmin;
586
        double w = myHeader.myXmax - myHeader.myXmin;
587
        double h = myHeader.myYmax - myHeader.myYmin;
588

    
589
        if (w == 0) {
590
            x -= 0.1;
591
            w = 0.2;
592
        }
593

    
594
        if (h == 0) {
595
            y -= 0.1;
596
            h = 0.2;
597
        }
598

    
599
        // String strFichDbf = m_Path.toLowerCase().replaceAll("\\.shp", ".dbf");
600
        String strFichDbf = file.getAbsolutePath().replaceAll("\\.shp", ".dbf");
601
        strFichDbf = strFichDbf.replaceAll("\\.SHP", ".DBF");
602

    
603
        DbaseFileNIO m_FichDbf = new DbaseFileNIO();
604

    
605
        m_FichDbf.open(new File(strFichDbf));
606
        numReg = m_FichDbf.getRecordCount();
607
        m_posShapes = new long[numReg];
608

    
609
        // read the records.
610
        int tempCurrentLength = myHeader.getHeaderLength();
611
        int numReg = 0;
612

    
613
        long pos1;
614

    
615
        while (tempCurrentLength < myHeader.myFileLength) {
616
            // read the record header
617
            // ShapeFileRecord tempRecord = new ShapeFileRecord();
618
            // Bytes 0 to 4 represent the record number in the file, these may be out of order.
619
            bb.order(ByteOrder.BIG_ENDIAN);
620

    
621
            // tempRecord.setIndex(in.readInt());
622
            bb.getInt();
623

    
624
            // read the content length of this record in 16 bit words, excluding the index.
625
            // in.setLittleEndianMode(false);
626
            int tempContentLength = bb.getInt();
627

    
628
            pos1 = bb.position();
629

    
630
            m_posShapes[numReg] = bb.position();
631

    
632
            // Posicionamos
633
            bb.position((pos1 + (2 * tempContentLength)));
634
            numReg = numReg + 1;
635

    
636
            // update the current length the 4 is for the index, and content length.
637
            tempCurrentLength = tempCurrentLength + 4 + tempContentLength;
638
        }
639
    }
640

    
641
    /**
642
     * Reads the Point from the shape file.
643
     *
644
     * @param in ByteBuffer.
645
     *
646
     * @return Point2D.
647
     */
648
    private Point2D.Double readPoint(BigByteBuffer in) {
649
        // create a new point
650
        Point2D.Double tempPoint = new Point2D.Double();
651

    
652
        // bytes 1 to 4 are the type and have already been read.
653
        // bytes 4 to 12 are the X coordinate
654
        in.order(ByteOrder.LITTLE_ENDIAN);
655
        tempPoint.setLocation(in.getDouble(), in.getDouble());
656

    
657
        return tempPoint;
658
    }
659

    
660
    /**
661
     * Lee un rect?ngulo del fichero.
662
     *
663
     * @param in ByteBuffer.
664
     *
665
     * @return Rect?ngulo.
666
     *
667
     * @throws IOException
668
     */
669
    private Rectangle2D.Double readRectangle(BigByteBuffer in)
670
        throws IOException {
671
        Rectangle2D.Double tempRect = new Rectangle2D.Double();
672
        in.order(ByteOrder.LITTLE_ENDIAN);
673
        tempRect.x = in.getDouble();
674
        tempRect.y = in.getDouble();
675

    
676
        tempRect.width = in.getDouble() - tempRect.x;
677

    
678
        if (tempRect.width == 0) {
679
            tempRect.width = 0.2;
680
            tempRect.x -= 0.1;
681
        }
682

    
683
        tempRect.height = in.getDouble() - tempRect.y;
684

    
685
        if (tempRect.height == 0) {
686
            tempRect.height = 0.2;
687
            tempRect.y -= 0.1;
688
        }
689

    
690
        return tempRect;
691
    }
692

    
693
    /**
694
     * @see com.iver.cit.gvsig.fmap.drivers.VectorialFileDriver#getFullExtent()
695
     */
696
    public Rectangle2D getFullExtent() throws IOException {
697
        return extent;
698
    }
699

    
700
    /**
701
     * Obtiene el extent del shape a partir de un ?ndice.
702
     *
703
     * @param index ?ndice.
704
     *
705
     * @return Rect?ngulo.
706
     *
707
     * @throws IOException
708
     *
709
     * @see com.iver.cit.gvsig.fmap.drivers.BoundedShapes#getShapeBounds()
710
     */
711
    public synchronized Rectangle2D getShapeBounds(int index) throws IOException {
712
        Point2D p = new Point2D.Double();
713
        Rectangle2D BoundingBox = new Rectangle2D.Double();
714
        bb.position(m_posShapes[index]);
715
        bb.order(ByteOrder.LITTLE_ENDIAN);
716

    
717
        int tipoShape = bb.getInt();
718

    
719
        if (tipoShape != SHP.NULL) {
720
            type = tipoShape;
721
        }
722

    
723
        // retrieve that shape.
724
        // tempRecord.setShape(readShape(tempShapeType, tempContentLength, in));
725
        switch (tipoShape) {
726
            case (SHP.POINT2D):
727
            case (SHP.POINT3D):
728
                p = readPoint(bb);
729
                BoundingBox = new Rectangle2D.Double(p.getX() - 0.1,
730
                        p.getY() - 0.1, 0.2, 0.2);
731

    
732
                break;
733

    
734
            case (SHP.POLYLINE2D):
735
            case (SHP.POLYGON2D):
736
            case (SHP.MULTIPOINT2D):
737
            case (SHP.POLYLINE3D):
738
            case (SHP.POLYGON3D):
739
            case (SHP.MULTIPOINT3D):
740

    
741
                // BoundingBox
742
                BoundingBox = readRectangle(bb);
743

    
744
                break;
745
        }
746

    
747
        return BoundingBox;
748
    }
749

    
750
    /**
751
     * @see com.iver.cit.gvsig.fmap.drivers.VectorialFileDriver#accept(java.io.File)
752
     */
753
    public boolean accept(File f) {
754
        return (f.getName().toUpperCase().endsWith("SHP"));
755
    }
756

    
757
    /**
758
     * @see com.hardcode.driverManager.Driver#getType()
759
     */
760
    public String getName() {
761
        return "gvSIG shp driver";
762
    }
763

    
764
    /**
765
     * @see com.iver.cit.gvsig.fmap.drivers.VectorialFileDriver#getDataDriverName()
766
     */
767
    public String getDataDriverName() {
768
        return "gdbms dbf driver";
769
    }
770

    
771
    /**
772
     * @see com.iver.cit.gvsig.fmap.drivers.VectorialFileDriver#getDataFile(java.io.File)
773
     */
774
    public File getDataFile(File f) {
775
        String str = f.getAbsolutePath();
776

    
777
        return new File(str.substring(0, str.length() - 3) + "dbf");
778
    }
779

    
780
    /* (non-Javadoc)
781
     * @see com.iver.cit.gvsig.fmap.drivers.BoundedShapes#getShapeType(int)
782
     */
783
    public int getShapeType(int index) {
784
        // Por ahora todos los fichero .shp contienen
785
        // entidades del mismo tipo. Si trabajamos con
786
        // alguno mixto, tendremos que cambiar esta funci?n.
787
        return getShapeType();
788
    }
789

    
790
   /* (non-Javadoc)
791
    * @see com.iver.cit.gvsig.fmap.drivers.VectorialDriver#getDriverAttributes()
792
    */
793
   public DriverAttributes getDriverAttributes() {
794
       // TODO Auto-generated method stub
795
       return null;
796
   }
797
}