Statistics
| Revision:

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

History | View | Annotate | Download (19.4 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 com.iver.cit.gvsig.fmap.MapControl;
44
import com.iver.cit.gvsig.fmap.core.FShape;
45
import com.iver.cit.gvsig.fmap.core.GeneralPathX;
46
import com.iver.cit.gvsig.fmap.core.IGeometry;
47
import com.iver.cit.gvsig.fmap.core.ShapeFactory;
48
import com.iver.cit.gvsig.fmap.drivers.BoundedShapes;
49
import com.iver.cit.gvsig.fmap.drivers.DriverAttributes;
50
import com.iver.cit.gvsig.fmap.drivers.ExternalData;
51
import com.iver.cit.gvsig.fmap.drivers.VectorialFileDriver;
52

    
53
import java.awt.geom.Point2D;
54
import java.awt.geom.Rectangle2D;
55

    
56
import java.io.File;
57
import java.io.FileInputStream;
58
import java.io.IOException;
59

    
60
import java.nio.ByteBuffer;
61
import java.nio.ByteOrder;
62
import java.nio.channels.FileChannel;
63

    
64
import org.apache.log4j.Logger;
65

    
66

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

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

    
106
                if (ret != null) {
107
                        throw ret;
108
                }
109
        }
110

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

    
117
                fin = new FileInputStream(f);
118

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

    
122
                long size = channel.size();
123

    
124
                // Get the file's size and then map it into memory
125
                bb = channel.map(FileChannel.MapMode.READ_ONLY, 0, size);
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 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

    
451
                        case (SHP.MULTIPOINT2D):
452
                                bb.position(bb.position() + 32);
453
                                numPoints = bb.getInt();
454

    
455
                                double[] tempX = new double[numPoints];
456
                                double[] tempY = new double[numPoints];
457

    
458
                                for (i = 0; i < numPoints; i++) {
459
                                        tempX[i] = bb.getDouble();
460
                                        tempY[i] = bb.getDouble();
461
                                }
462

    
463
                                return ShapeFactory.createMultipoint2D(tempX, tempY);
464

    
465
                        case (SHP.MULTIPOINT3D):
466
                                bb.position(bb.position() + 32);
467
                                numPoints = bb.getInt();
468

    
469
                                double[] temX = new double[numPoints];
470
                                double[] temY = new double[numPoints];
471
                                double[] temZ = new double[numPoints];
472

    
473
                                for (i = 0; i < numPoints; i++) {
474
                                        temX[i] = bb.getDouble();
475
                                        temY[i] = bb.getDouble();
476
                                        temZ[i] = bb.getDouble();
477
                                }
478

    
479
                                return ShapeFactory.createMultipoint3D(temX, temY, temZ);
480
                }
481

    
482
                return null;
483
        }
484

    
485
        /**
486
         * @see com.iver.cit.gvsig.fmap.drivers.VectorialFileDriver#getShapeCount()
487
         */
488
        public int getShapeCount() {
489
                return numReg;
490
        }
491

    
492
        /**
493
         * @see com.iver.cit.gvsig.fmap.drivers.VectorialDriver#getShapeType()
494
         */
495
        public int getShapeType() {
496
                int auxType = 0;
497

    
498
                switch (type) {
499
                        case (SHP.POINT2D):
500
                                auxType = auxType | FShape.POINT;
501

    
502
                                break;
503

    
504
                        case (SHP.POLYLINE2D):
505
                                auxType = auxType | FShape.LINE;
506

    
507
                                break;
508

    
509
                        case (SHP.POLYGON2D):
510
                                auxType = auxType | FShape.POLYGON;
511

    
512
                                break;
513

    
514
                        case (SHP.POINT3D):
515
                                auxType = auxType | FShape.POINT;
516

    
517
                                break;
518

    
519
                        case (SHP.POLYLINE3D):
520
                                auxType = auxType | FShape.LINE;
521

    
522
                                break;
523

    
524
                        case (SHP.MULTIPOINT2D):
525
                                auxType = auxType | FShape.MULTI;
526

    
527
                                break;
528

    
529
                        case (SHP.MULTIPOINT3D):
530
                                auxType = auxType | FShape.MULTI;
531

    
532
                                break;
533
                }
534

    
535
                return auxType;
536
        }
537

    
538
        /**
539
         * @see com.iver.cit.gvsig.fmap.drivers.VectorialFileDriver#initialize()
540
         */
541
        public void initialize() throws IOException {
542
                // create a new header.
543
                ShapeFileHeader myHeader = new ShapeFileHeader();
544

    
545
                // read the header
546
                myHeader.readHeader(bb);
547

    
548
                extent = new Rectangle2D.Double(myHeader.myXmin, myHeader.myYmin,
549
                                myHeader.myXmax - myHeader.myXmin,
550
                                myHeader.myYmax - myHeader.myYmin);
551

    
552
                type = myHeader.myShapeType;
553

    
554
                double x = myHeader.myXmin;
555
                double y = myHeader.myYmin;
556
                double w = myHeader.myXmax - myHeader.myXmin;
557
                double h = myHeader.myYmax - myHeader.myYmin;
558

    
559
                if (w == 0) {
560
                        x -= 0.1;
561
                        w = 0.2;
562
                }
563

    
564
                if (h == 0) {
565
                        y -= 0.1;
566
                        h = 0.2;
567
                }
568

    
569
                // String strFichDbf = m_Path.toLowerCase().replaceAll("\\.shp", ".dbf");
570
                String strFichDbf = file.getAbsolutePath().replaceAll("\\.shp", ".dbf");
571
                strFichDbf = strFichDbf.replaceAll("\\.SHP", ".DBF");
572

    
573
                DbaseFileNIO m_FichDbf = new DbaseFileNIO();
574

    
575
                m_FichDbf.open(new File(strFichDbf));
576
                numReg = m_FichDbf.getRecordCount();
577
                m_posShapes = new int[numReg];
578

    
579
                // read the records.
580
                int tempCurrentLength = myHeader.getHeaderLength();
581
                int numReg = 0;
582

    
583
                int pos1;
584

    
585
                while (tempCurrentLength < myHeader.myFileLength) {
586
                        // read the record header
587
                        // ShapeFileRecord tempRecord = new ShapeFileRecord();
588
                        // Bytes 0 to 4 represent the record number in the file, these may be out of order.
589
                        bb.order(ByteOrder.BIG_ENDIAN);
590

    
591
                        // tempRecord.setIndex(in.readInt());
592
                        bb.getInt();
593

    
594
                        // read the content length of this record in 16 bit words, excluding the index.
595
                        // in.setLittleEndianMode(false);
596
                        int tempContentLength = bb.getInt();
597

    
598
                        pos1 = bb.position();
599

    
600
                        m_posShapes[numReg] = bb.position();
601

    
602
                        // Posicionamos
603
                        bb.position((pos1 + (2 * tempContentLength)));
604
                        numReg = numReg + 1;
605

    
606
                        // update the current length the 4 is for the index, and content length.
607
                        tempCurrentLength = tempCurrentLength + 4 + tempContentLength;
608
                }
609
        }
610

    
611
        /**
612
         * Reads the Point from the shape file.
613
         *
614
         * @param in ByteBuffer.
615
         *
616
         * @return Point2D.
617
         */
618
        private Point2D.Double readPoint(ByteBuffer in) {
619
                // create a new point
620
                Point2D.Double tempPoint = new Point2D.Double();
621

    
622
                // bytes 1 to 4 are the type and have already been read.
623
                // bytes 4 to 12 are the X coordinate
624
                in.order(ByteOrder.LITTLE_ENDIAN);
625
                tempPoint.setLocation(in.getDouble(), in.getDouble());
626

    
627
                return tempPoint;
628
        }
629

    
630
        /**
631
         * Lee un rect?ngulo del fichero.
632
         *
633
         * @param in ByteBuffer.
634
         *
635
         * @return Rect?ngulo.
636
         *
637
         * @throws IOException
638
         */
639
        private Rectangle2D.Double readRectangle(ByteBuffer in)
640
                throws IOException {
641
                Rectangle2D.Double tempRect = new Rectangle2D.Double();
642
                in.order(ByteOrder.LITTLE_ENDIAN);
643
                tempRect.x = in.getDouble();
644
                tempRect.y = in.getDouble();
645

    
646
                tempRect.width = in.getDouble() - tempRect.x;
647

    
648
                if (tempRect.width == 0) {
649
                        tempRect.width = 0.2;
650
                        tempRect.x -= 0.1;
651
                }
652

    
653
                tempRect.height = in.getDouble() - tempRect.y;
654

    
655
                if (tempRect.height == 0) {
656
                        tempRect.height = 0.2;
657
                        tempRect.y -= 0.1;
658
                }
659

    
660
                return tempRect;
661
        }
662

    
663
        /**
664
         * @see com.iver.cit.gvsig.fmap.drivers.VectorialFileDriver#getFullExtent()
665
         */
666
        public Rectangle2D getFullExtent() throws IOException {
667
                return extent;
668
        }
669

    
670
        /**
671
         * Obtiene el extent del shape a partir de un ?ndice.
672
         *
673
         * @param index ?ndice.
674
         *
675
         * @return Rect?ngulo.
676
         *
677
         * @throws IOException
678
         *
679
         * @see com.iver.cit.gvsig.fmap.drivers.BoundedShapes#getShapeBounds()
680
         */
681
        public Rectangle2D getShapeBounds(int index) throws IOException {
682
                Point2D p = new Point2D.Double();
683
                Rectangle2D BoundingBox = new Rectangle2D.Double();
684
                bb.position(m_posShapes[index]);
685
                bb.order(ByteOrder.LITTLE_ENDIAN);
686

    
687
                int tipoShape = bb.getInt();
688

    
689
                if (tipoShape != SHP.NULL) {
690
                        type = tipoShape;
691
                }
692

    
693
                // retrieve that shape.
694
                // tempRecord.setShape(readShape(tempShapeType, tempContentLength, in));
695
                switch (tipoShape) {
696
                        case (SHP.POINT2D):
697
                        case (SHP.POINT3D):
698
                                p = readPoint(bb);
699
                                BoundingBox = new Rectangle2D.Double(p.getX() - 0.1,
700
                                                p.getY() - 0.1, 0.2, 0.2);
701

    
702
                                break;
703

    
704
                        case (SHP.POLYLINE2D):
705
                        case (SHP.POLYGON2D):
706
                        case (SHP.MULTIPOINT2D):
707
                        case (SHP.POLYLINE3D):
708
                        case (SHP.POLYGON3D):
709
                        case (SHP.MULTIPOINT3D):
710

    
711
                                // BoundingBox
712
                                BoundingBox = readRectangle(bb);
713

    
714
                                break;
715
                }
716

    
717
                return BoundingBox;
718
        }
719

    
720
        /**
721
         * @see com.iver.cit.gvsig.fmap.drivers.VectorialFileDriver#accept(java.io.File)
722
         */
723
        public boolean accept(File f) {
724
                return (f.getName().toUpperCase().endsWith("SHP"));
725
        }
726

    
727
        /**
728
         * @see com.hardcode.driverManager.Driver#getType()
729
         */
730
        public String getName() {
731
                return "gvSIG shp driver";
732
        }
733

    
734
        /**
735
         * @see com.iver.cit.gvsig.fmap.drivers.VectorialFileDriver#getDataDriverName()
736
         */
737
        public String getDataDriverName() {
738
                return "gdbms dbf driver";
739
        }
740

    
741
        /**
742
         * @see com.iver.cit.gvsig.fmap.drivers.VectorialFileDriver#getDataFile(java.io.File)
743
         */
744
        public File getDataFile(File f) {
745
                String str = f.getAbsolutePath();
746

    
747
                return new File(str.substring(0, str.length() - 3) + "dbf");
748
        }
749

    
750
        /* (non-Javadoc)
751
         * @see com.iver.cit.gvsig.fmap.drivers.BoundedShapes#getShapeType(int)
752
         */
753
        public int getShapeType(int index) {
754
                // Por ahora todos los fichero .shp contienen
755
                // entidades del mismo tipo. Si trabajamos con
756
                // alguno mixto, tendremos que cambiar esta funci?n.
757
                return getShapeType();
758
        }
759

    
760
    /* (non-Javadoc)
761
     * @see com.iver.cit.gvsig.fmap.drivers.VectorialDriver#getDriverAttributes()
762
     */
763
    public DriverAttributes getDriverAttributes() {
764
        // TODO Auto-generated method stub
765
        return null;
766
    }
767
}