Statistics
| Revision:

svn-gvsig-desktop / trunk / org.gvsig.desktop / org.gvsig.desktop.compat.cdc / org.gvsig.fmap.dal / org.gvsig.fmap.dal.file / org.gvsig.fmap.dal.file.shp / src / main / java / org / gvsig / fmap / dal / store / shp / utils / SHPFile.java @ 41240

History | View | Annotate | Download (22.8 KB)

1
/**
2
 * gvSIG. Desktop Geographic Information System.
3
 *
4
 * Copyright (C) 2007-2013 gvSIG Association.
5
 *
6
 * This program is free software; you can redistribute it and/or
7
 * modify it under the terms of the GNU General Public License
8
 * as published by the Free Software Foundation; either version 3
9
 * of the License, or (at your option) any later version.
10
 *
11
 * This program is distributed in the hope that it will be useful,
12
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
 * GNU General Public License for more details.
15
 *
16
 * You should have received a copy of the GNU General Public License
17
 * along with this program; if not, write to the Free Software
18
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
19
 * MA  02110-1301, USA.
20
 *
21
 * For any additional information, do not hesitate to contact us
22
 * at info AT gvsig.com, or visit our website www.gvsig.com.
23
 */
24
package org.gvsig.fmap.dal.store.shp.utils;
25

    
26
import java.io.BufferedReader;
27
import java.io.File;
28
import java.io.FileInputStream;
29
import java.io.FileReader;
30
import java.io.IOException;
31
import java.nio.ByteOrder;
32
import java.nio.channels.FileChannel;
33

    
34
import org.slf4j.Logger;
35
import org.slf4j.LoggerFactory;
36

    
37
import org.gvsig.fmap.dal.exception.CloseException;
38
import org.gvsig.fmap.dal.exception.DataException;
39
import org.gvsig.fmap.dal.exception.FileNotFoundException;
40
import org.gvsig.fmap.dal.exception.ReadException;
41
import org.gvsig.fmap.dal.store.shp.SHPStoreParameters;
42
import org.gvsig.fmap.geom.Geometry;
43
import org.gvsig.fmap.geom.Geometry.SUBTYPES;
44
import org.gvsig.fmap.geom.Geometry.TYPES;
45
import org.gvsig.fmap.geom.GeometryLocator;
46
import org.gvsig.fmap.geom.GeometryManager;
47
import org.gvsig.fmap.geom.aggregate.MultiPoint;
48
import org.gvsig.fmap.geom.exception.CreateEnvelopeException;
49
import org.gvsig.fmap.geom.exception.CreateGeometryException;
50
import org.gvsig.fmap.geom.primitive.Curve;
51
import org.gvsig.fmap.geom.primitive.Envelope;
52
import org.gvsig.fmap.geom.primitive.OrientablePrimitive;
53
import org.gvsig.fmap.geom.primitive.Point;
54
import org.gvsig.fmap.geom.primitive.PointGeometryType;
55
import org.gvsig.fmap.geom.primitive.Surface;
56
import org.gvsig.fmap.geom.type.GeometryType;
57
import org.gvsig.fmap.geom.type.GeometryTypeNotSupportedException;
58
import org.gvsig.fmap.geom.type.GeometryTypeNotValidException;
59
import org.gvsig.utils.bigfile.BigByteBuffer2;
60

    
61
/**
62
 * @author jmvivo
63
 * 
64
 */
65
public class SHPFile {
66

    
67
    private static final Logger logger = LoggerFactory.getLogger(SHPFile.class);
68
    private Envelope extent;
69
    private int type;
70
    private int subType;
71
    private String srsParameters;
72

    
73
    private FileInputStream fin;
74
    private FileChannel channel;
75
    private BigByteBuffer2 bb;
76
    private FileInputStream finShx;
77
    private FileChannel channelShx;
78
    private BigByteBuffer2 bbShx;
79

    
80
    private SHPStoreParameters params;
81

    
82
    private int[] supportedGeometryTypes;
83
    private final GeometryManager gManager = GeometryLocator
84
        .getGeometryManager();
85

    
86
    private GeometryType gtypeNull;
87
    private PointGeometryType gtypePoint2D;
88
    private GeometryType gtypeCurve2D;
89
    private GeometryType gtypeSurface2D;
90
    private GeometryType gtypeMultiPoint2D;
91

    
92
    public SHPFile(SHPStoreParameters params) {
93
        this.params = params;
94
        try {
95
            gtypeNull = gManager.getGeometryType(TYPES.NULL, SUBTYPES.GEOM2D);
96
            gtypePoint2D =
97
                (PointGeometryType) gManager.getGeometryType(TYPES.POINT,
98
                    SUBTYPES.GEOM2D);
99
            gtypeCurve2D =
100
                gManager.getGeometryType(TYPES.CURVE, SUBTYPES.GEOM2D);
101
            gtypeSurface2D =
102
                gManager.getGeometryType(TYPES.SURFACE, SUBTYPES.GEOM2D);
103
            gtypeMultiPoint2D =
104
                gManager.getGeometryType(TYPES.MULTIPOINT, SUBTYPES.GEOM2D);
105

    
106
        } catch (GeometryTypeNotSupportedException e) {
107
            throw new RuntimeException(
108
                "Unable to get the 2D geometry types to use", e);
109
        } catch (GeometryTypeNotValidException e) {
110
            throw new RuntimeException(
111
                "Unable to get the 2D geometry types to use", e);
112
        }
113
    }
114

    
115
    /*
116
     * (non-Javadoc)
117
     * 
118
     * @see org.gvsig.fmap.dal.Resource#doClose()
119
     */
120
    public void close() throws CloseException {
121
        CloseException ret = null;
122

    
123
        // FIXME: Arreglar esto para que se acumulen los errores
124
        try {
125
            channel.close();
126
            channelShx.close();
127
        } catch (IOException e) {
128
            ret = new CloseException("SHPFile.close", e);
129
        } finally {
130
            try {
131
                fin.close();
132
                finShx.close();
133
            } catch (IOException e1) {
134
                ret = new CloseException("SHPFile.close", e1);
135
            }
136
        }
137

    
138
        if (ret != null) {
139
            throw ret;
140
        }
141
        bb = null;
142
        bbShx = null;
143
        fin = null;
144
        finShx = null;
145
        channel = null;
146
        channelShx = null;
147
        srsParameters = null;
148
    }
149

    
150
    public boolean isOpen() {
151
        return this.fin != null;
152
    }
153

    
154
    public synchronized void open() throws DataException {
155
        try {
156
            fin = new FileInputStream(this.params.getSHPFile());
157
        } catch (java.io.FileNotFoundException e) {
158
            throw new FileNotFoundException(this.params.getSHPFileName());
159
        }
160

    
161
        // Open the file and then get a channel from the stream
162
        channel = fin.getChannel();
163

    
164
        // long size = channel.size();
165

    
166
        // Get the file's size and then map it into memory
167
        // bb = channel.map(FileChannel.MapMode.READ_ONLY, 0, size);
168
        try {
169
            bb = new BigByteBuffer2(channel, FileChannel.MapMode.READ_ONLY);
170
        } catch (IOException e) {
171
            throw new ReadException(this.params.getSHPFileName(), e);
172

    
173
        }
174
        try {
175
            finShx = new FileInputStream(this.params.getSHXFile());
176
        } catch (java.io.FileNotFoundException e) {
177
            throw new FileNotFoundException(this.params.getSHXFileName());
178
        }
179

    
180
        // Open the file and then get a channel from the stream
181
        channelShx = finShx.getChannel();
182

    
183
        // long sizeShx = channelShx.size();
184

    
185
        // Get the file's size and then map it into memory
186
        // bb = channel.map(FileChannel.MapMode.READ_ONLY, 0, size);
187
        // bbShx = channelShx.map(FileChannel.MapMode.READ_ONLY, 0, sizeShx);
188
        try {
189
            bbShx =
190
                new BigByteBuffer2(channelShx, FileChannel.MapMode.READ_ONLY);
191
        } catch (IOException e) {
192
            throw new ReadException(this.params.getSHXFileName(), e);
193

    
194
        }
195
        bbShx.order(ByteOrder.BIG_ENDIAN);
196

    
197
        // create a new header.
198
        ShapeFileHeader2 myHeader = new ShapeFileHeader2();
199

    
200
        bb.position(0);
201

    
202
        // read the header
203
        myHeader.readHeader(bb);
204

    
205
        double[] min = new double[2];
206
        min[0] = myHeader.myXmin;
207
        min[1] = myHeader.myYmin;
208
        double[] max = new double[2];
209
        max[0] = myHeader.myXmax;
210
        max[1] = myHeader.myYmax;
211

    
212
        try {
213
            extent =
214
                gManager.createEnvelope(min[0], min[1], max[0], max[1],
215
                    SUBTYPES.GEOM2D);
216
        } catch (CreateEnvelopeException e1) {
217
            logger.error("Error creating the envelope", e1);
218
        }
219
        // extent = new Rectangle2D.Double(myHeader.myXmin, myHeader.myYmin,
220
        // myHeader.myXmax - myHeader.myXmin,
221
        // myHeader.myYmax - myHeader.myYmin);
222

    
223
        type = myHeader.myShapeType;
224
        subType = getGeometrySubType();
225

    
226
        this.initSupportedGeometryTypes();
227

    
228
        double x = myHeader.myXmin;
229
        double y = myHeader.myYmin;
230
        double w = myHeader.myXmax - myHeader.myXmin;
231
        double h = myHeader.myYmax - myHeader.myYmin;
232

    
233
        if (w == 0) {
234
            x -= 0.1;
235
            w = 0.2;
236
        }
237

    
238
        if (h == 0) {
239
            y -= 0.1;
240
            h = 0.2;
241
        }
242

    
243
        // TODO: SRS
244
        File prjFile = SHP.getPrjFile(this.params.getSHPFile());
245
        if (prjFile.exists()) {
246
            BufferedReader input = null;
247
            try {
248
                input = new BufferedReader(new FileReader(prjFile));
249
            } catch (java.io.FileNotFoundException e) {
250
                throw new FileNotFoundException(prjFile.getAbsolutePath());
251
            }
252

    
253
            try {
254
                this.srsParameters = input.readLine();
255
            } catch (IOException e) {
256
                throw new ReadException("SHPFile.open prj", e);
257
            } finally {
258
                try {
259
                    input.close();
260
                } catch (IOException e) {
261
                    // TODO ???
262
                }
263
            }
264

    
265
        } else {
266
            this.srsParameters = null;
267
        }
268
    }
269

    
270
    public Envelope getFullExtent() throws ReadException {
271
        return this.extent;
272
    }
273

    
274
    public boolean isEditable() {
275
        return this.params.getDBFFile().canWrite()
276
            && this.params.getSHPFile().canWrite()
277
            && this.params.getSHXFile().canWrite();
278
    }
279

    
280
    public int getGeometryType() throws ReadException {
281
        int auxType = 0;
282

    
283
        switch (type) {
284
        case (SHP.POINT2D):
285
        case (SHP.POINT3D):
286
            auxType = auxType | Geometry.TYPES.POINT;
287

    
288
            break;
289

    
290
        case (SHP.POLYLINE2D):
291
        case (SHP.POLYLINE3D):
292
            auxType = auxType | Geometry.TYPES.MULTICURVE;
293

    
294
            break;
295

    
296
        case (SHP.POLYGON2D):
297
        case (SHP.POLYGON3D):
298
            auxType = auxType | Geometry.TYPES.MULTISURFACE;
299

    
300
            break;
301
        case (SHP.MULTIPOINT2D):
302
        case (SHP.MULTIPOINT3D):
303
            auxType = auxType | Geometry.TYPES.MULTIPOINT;
304

    
305
            break;
306
        }
307

    
308
        return auxType;
309
    }
310

    
311
    public int getGeometrySubType() throws ReadException {
312
        switch (type) {
313
        case (SHP.POINT2D):
314
        case (SHP.POLYLINE2D):
315
        case (SHP.POLYGON2D):
316
        case (SHP.MULTIPOINT2D):
317
            return SUBTYPES.GEOM2D;
318
        case (SHP.POINT3D):
319
        case (SHP.POLYLINE3D):
320
        case (SHP.POLYGON3D):
321
        case (SHP.MULTIPOINT3D):
322
            return SUBTYPES.GEOM3D;
323
        case (SHP.POINTM):
324
        case (SHP.POLYLINEM):
325
        case (SHP.POLYGONM):
326
        case (SHP.MULTIPOINTM):
327
            return SUBTYPES.GEOM2DM;
328
        }
329

    
330
        return SUBTYPES.UNKNOWN;
331
    }
332

    
333
    /**
334
     * Gets the geometry with the index provided.
335
     * Set to synchronized to prevent concurrent threads issue (?)
336
     * 
337
     * @param position
338
     * @return
339
     * @throws ReadException
340
     * @throws CreateGeometryException
341
     */
342
    public synchronized Geometry getGeometry(long position)
343
        throws ReadException, CreateGeometryException {
344

    
345
        int shapeType;
346
        bb.position(getPositionForRecord(position));
347
        bb.order(ByteOrder.LITTLE_ENDIAN);
348
        shapeType = bb.getInt();
349
        
350
        // el shape tal con tema tal y n?mro tal es null
351
        if (shapeType == SHP.NULL) {
352
            return gtypeNull.create();
353
        }
354
        
355
        /*
356
         * Inconsistency: this particular shape is not
357
         * of the expected type. This can be because the SHP file
358
         * is corrupt and it can cause "out of memory error"
359
         * because the code will possibly try to instantiate a
360
         * huge (absurd) array, so it's safer to return a null geometry
361
         */
362
        if (shapeType != type) {
363
            return gtypeNull.create();
364
        }
365

    
366
        // retrieve that shape.
367
        // tempRecord.setShape(readShape(tempShapeType, tempContentLength, in));
368
        switch (type) {
369
        case (SHP.POINT2D):
370
        case (SHP.POINT3D):
371
        case (SHP.POINTM):
372
            Point point = readPoint(bb);
373
            fillPoint(point);
374
            return point;
375

    
376
        case (SHP.POLYLINE2D):
377
            Curve curve = (Curve) gtypeCurve2D.create();
378
            fillCurve(curve);
379
            return curve;
380

    
381
        case (SHP.POLYGON2D):
382
            Surface surface = (Surface) gtypeSurface2D.create();
383
            fillSurface(surface);
384
            return surface;
385

    
386
        case (SHP.POLYLINE3D):
387
            Curve curve3D =
388
                (Curve) gManager.create(TYPES.CURVE, SUBTYPES.GEOM3D);
389
            fillCurve(curve3D);
390
            fillZ(curve3D);
391
            return curve3D;
392

    
393
        case (SHP.POLYGON3D):
394
            Surface surface3D =
395
                (Surface) gManager.create(TYPES.SURFACE, SUBTYPES.GEOM3D);
396
            fillSurface(surface3D);
397
            fillZ(surface3D);
398
            return surface3D;
399

    
400
        case (SHP.MULTIPOINT2D):
401

    
402
            Point p = null;
403
            int numPoints;
404
            int i;
405
            int j;
406
            bb.position(bb.position() + 32);
407
            numPoints = bb.getInt();
408

    
409
            Point[] points = new Point[numPoints];
410

    
411
            for (i = 0; i < numPoints; i++) {
412
                points[i] =
413
                    (Point) gManager.create(TYPES.POINT, SUBTYPES.GEOM2D);
414
                points[i].setX(bb.getDouble());
415
                points[i].setY(bb.getDouble());
416
            }
417

    
418
            MultiPoint multipoint = (MultiPoint) gtypeMultiPoint2D.create();
419
            // MultiPoint multipoint =
420
            // (MultiPoint)GeometryLocator.getGeometryManager().create(TYPES.MULTIPOINT,
421
            // SUBTYPES.GEOM2D);
422
            for (int k = 0; k < points.length; k++) {
423
                multipoint.addPoint(points[k]);
424
            }
425

    
426
            return multipoint;
427

    
428
        case (SHP.MULTIPOINT3D):
429
            bb.position(bb.position() + 32);
430
            numPoints = bb.getInt();
431

    
432
            double[] temX = new double[numPoints];
433
            double[] temY = new double[numPoints];
434
            double[] temZ = new double[numPoints];
435

    
436
            for (i = 0; i < numPoints; i++) {
437
                temX[i] = bb.getDouble();
438
                temY[i] = bb.getDouble();
439
                // temZ[i] = bb.getDouble();
440
            }
441

    
442
            for (i = 0; i < numPoints; i++) {
443
                temZ[i] = bb.getDouble();
444
            }
445

    
446
            MultiPoint multipoint3D =
447
                (MultiPoint) gManager.create(TYPES.MULTIPOINT, SUBTYPES.GEOM3D);
448
            for (int k = 0; k < temX.length; k++) {
449
                Point pointAux =
450
                    (Point) gManager.create(TYPES.POINT, SUBTYPES.GEOM3D);
451
                pointAux.setX(temX[k]);
452
                pointAux.setY(temY[k]);
453
                pointAux.setCoordinateAt(2, temZ[k]);
454
                multipoint3D.addPoint(pointAux);
455
            }
456
            return multipoint3D;
457
        }
458

    
459
        return null;
460
    }
461

    
462
    private void fillPoint(Point point) throws ReadException {
463
        if (subType == Geometry.SUBTYPES.GEOM3D) {
464
            point.setCoordinateAt(Geometry.DIMENSIONS.Z, bb.getDouble());
465
        } else
466
            if (subType == Geometry.SUBTYPES.GEOM2DM) {
467
                point.setCoordinateAt(2, bb.getDouble());
468
            }
469
    }
470

    
471
    private void fillCurve(Curve curve)
472
        throws CreateGeometryException, ReadException {
473
        Point p = null;
474
        int numParts;
475
        int numPoints;
476
        int i;
477
        int j;
478

    
479
        bb.position(bb.position() + 32);
480
        numParts = bb.getInt();
481
        numPoints = bb.getInt();
482

    
483
        int[] tempParts = new int[numParts];
484

    
485
        for (i = 0; i < numParts; i++) {
486
            tempParts[i] = bb.getInt();
487
        }
488

    
489
        j = 0;
490

    
491
        for (i = 0; i < numPoints; i++) {
492
            p = readPoint(bb);
493

    
494
            if (i == tempParts[j]) {
495
                curve.addMoveToVertex(p);
496

    
497
                if (j < (numParts - 1)) {
498
                    j++;
499
                }
500
            } else {
501
                curve.addVertex(p);
502
            }
503
        }
504
    }
505

    
506
    private void fillSurface(Surface surface)
507
        throws CreateGeometryException, ReadException {
508
        Point p = null;
509
        int numParts;
510
        int numPoints;
511
        int i;
512
        int partIndex;
513

    
514
        bb.position(bb.position() + 32);
515
        numParts = bb.getInt();
516
        numPoints = bb.getInt();
517

    
518
        int[] tempParts = new int[numParts];
519

    
520
        for (i = 0; i < numParts; i++) {
521
            tempParts[i] = bb.getInt();
522
        }
523

    
524
        partIndex = 0;
525

    
526
        for (i = 0; i < numPoints; i++) {
527
            p = readPoint(bb);
528

    
529
            if (i == tempParts[partIndex]) {
530
                surface.addMoveToVertex(p);
531
                if (partIndex < (numParts - 1)) {
532
                    partIndex++;
533
                }
534
            } else {
535
                if ((i == tempParts[partIndex] - 1) || (i == numPoints - 1)) {
536
                    surface.closePrimitive();
537
                } else {
538
                    surface.addVertex(p);
539
                }
540
            }
541
        }
542
    }
543

    
544
    private void fillZ(OrientablePrimitive orientablePrimitive)
545
        throws CreateGeometryException, ReadException {
546
        double[] boxZ = new double[2];
547
        boxZ[0] = bb.getDouble();
548
        boxZ[1] = bb.getDouble();
549

    
550
        for (int i = 0; i < orientablePrimitive.getNumVertices(); i++) {
551
            orientablePrimitive.setCoordinateAt(i, 2, bb.getDouble());
552
        }
553
    }
554

    
555
    private long getPositionForRecord(long numRec) {
556
        // shx file has a 100 bytes header, then, records
557
        // 8 bytes length, one for each entity.
558
        // first 4 bytes are the offset
559
        // next 4 bytes are length
560

    
561
        int posIndex = 100 + ((int) numRec * 8);
562
        // bbShx.position(posIndex);
563
        long pos = 8 + 2 * bbShx.getInt(posIndex);
564

    
565
        return pos;
566
    }
567

    
568
    /**
569
     * Reads the Point from the shape file.
570
     * 
571
     * @param in
572
     *            ByteBuffer.
573
     * 
574
     * @return Point2D.
575
     * @throws ReadException
576
     * @throws CreateGeometryException
577
     */
578
    private Point readPoint(BigByteBuffer2 in)
579
        throws CreateGeometryException, ReadException {
580
        // bytes 1 to 4 are the type and have already been read.
581
        // bytes 4 to 12 are the X coordinate
582
        in.order(ByteOrder.LITTLE_ENDIAN);
583

    
584
        return Geometry.SUBTYPES.GEOM2D == subType ? gtypePoint2D.createPoint(
585
            in.getDouble(), in.getDouble()) : gManager.createPoint(
586
            in.getDouble(),
587
            in.getDouble(), subType);
588
    }
589

    
590
    /**
591
     * Lee un rect?ngulo del fichero.
592
     * 
593
     * @param in
594
     *            ByteBuffer.
595
     * 
596
     * @return Rect?ngulo.
597
     * @throws CreateEnvelopeException
598
     * 
599
     * @throws IOException
600
     */
601
    private Envelope readRectangle(BigByteBuffer2 in)
602
        throws CreateEnvelopeException {
603
        in.order(ByteOrder.LITTLE_ENDIAN);
604
        double x = in.getDouble();
605
        double y = in.getDouble();
606

    
607
        double x2 = in.getDouble();
608

    
609
        if (x2 - x == 0) {
610
            x2 += 0.2;
611
            x -= 0.1;
612
        }
613

    
614
        double y2 = in.getDouble();
615

    
616
        if (y2 - y == 0) {
617
            y2 += 0.2;
618
            y -= 0.1;
619
        }
620
        Envelope tempEnvelope =
621
            gManager.createEnvelope(x, y, x2, y2, SUBTYPES.GEOM2D);
622
        return tempEnvelope;
623
    }
624

    
625
    /**
626
     * Gets the geometry bbox with the index provided.
627
     * Set to synchronized to prevent concurrent threads issue (?)
628
     * 
629
     * @param featureIndex
630
     * @return
631
     * @throws ReadException
632
     * @throws CreateEnvelopeException
633
     * @throws CreateGeometryException
634
     */
635
    public synchronized Envelope getBoundingBox(long featureIndex)
636
        throws ReadException, CreateEnvelopeException, CreateGeometryException {
637
        Point p = null;
638
        Envelope BoundingBox = null;
639
        try {
640
            bb.position(getPositionForRecord(featureIndex));
641
        } catch (Exception e) {
642
            throw new ReadException("getBondingBox (" + featureIndex + ")", e);
643
            // logger.error(" Shapefile is corrupted. Drawing aborted. ="+e+
644
            // "  "+"index = "+index);
645
        }
646
        bb.order(ByteOrder.LITTLE_ENDIAN);
647

    
648
        int tipoShape = bb.getInt();
649

    
650
        // AZABALA: si tipoShape viene con valores erroneos deja de funcionar
651
        // el metodo getShape(i)
652
        // if (tipoShape != SHP.NULL) {
653
        // type = tipoShape;
654

    
655
        // }
656

    
657
        // retrieve that shape.
658
        // tempRecord.setShape(readShape(tempShapeType, tempContentLength, in));
659
        switch (tipoShape) {
660
        case (SHP.POINT2D):
661
        case (SHP.POINT3D):
662
            p = readPoint(bb);
663
            BoundingBox =
664
                gManager.createEnvelope(p.getX() - 0.1, p.getY() - 0.1,
665
                    p.getX() + 0.2, p.getY() + 0.2, SUBTYPES.GEOM2D);
666
            // new Rectangle2D.Double(p.getX() - 0.1,
667
            // p.getY() - 0.1, 0.2, 0.2);
668

    
669
            break;
670

    
671
        case (SHP.POLYLINE2D):
672
        case (SHP.POLYGON2D):
673
        case (SHP.MULTIPOINT2D):
674
        case (SHP.POLYLINE3D):
675
        case (SHP.POLYGON3D):
676
        case (SHP.MULTIPOINT3D):
677

    
678
            // BoundingBox
679
            BoundingBox = readRectangle(bb);
680

    
681
            break;
682
        }
683

    
684
        return BoundingBox;
685
    }
686

    
687
    /**
688
     * @return
689
     */
690
    public String getSRSParameters() {
691
        return this.srsParameters;
692
    }
693

    
694
    private void initSupportedGeometryTypes() throws ReadException {
695
        switch (this.getGeometryType()) {
696
        case Geometry.TYPES.POINT:
697
            supportedGeometryTypes =
698
                new int[] { Geometry.TYPES.POINT, Geometry.TYPES.NULL };
699
            break;
700
        case Geometry.TYPES.MULTIPOINT:
701
            supportedGeometryTypes =
702
                new int[] { Geometry.TYPES.MULTIPOINT, Geometry.TYPES.NULL };
703
            break;
704
        case Geometry.TYPES.MULTICURVE:
705
            supportedGeometryTypes =
706
                new int[] { Geometry.TYPES.CURVE, Geometry.TYPES.ELLIPSE,
707
                    Geometry.TYPES.ARC, Geometry.TYPES.CIRCLE,
708
                    Geometry.TYPES.SURFACE, Geometry.TYPES.NULL,
709
                    Geometry.TYPES.MULTICURVE };
710
            break;
711
        case Geometry.TYPES.MULTISURFACE:
712
            supportedGeometryTypes =
713
                new int[] { Geometry.TYPES.ELLIPSE, Geometry.TYPES.CIRCLE,
714
                    Geometry.TYPES.SURFACE, Geometry.TYPES.NULL,
715
                    Geometry.TYPES.MULTISURFACE };
716
            break;
717

    
718
        default:
719
            supportedGeometryTypes = new int[] {};
720
        }
721
    }
722

    
723
    public boolean canWriteGeometry(int gvSIGgeometryType) {
724
        for (int i = 0; i < supportedGeometryTypes.length; i++) {
725
            if (gvSIGgeometryType == supportedGeometryTypes[i]) {
726
                return true;
727
            }
728
        }
729
        return false;
730
    }
731
}