Statistics
| Revision:

root / trunk / libraries / libCq CMS for java.old / src / org / cresques / io / GdalWriter.java @ 2849

History | View | Annotate | Download (26.4 KB)

1 2809 nacho
/*
2
 * Cresques Mapping Suite. Graphic Library for constructing mapping applications.
3
 *
4
 * Copyright (C) 2004-5.
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 2
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., 59 Temple Place - Suite 330, Boston, MA  02111-1307,USA.
19
 *
20
 * For more information, contact:
21
 *
22
 * cresques@gmail.com
23
 */
24
package org.cresques.io;
25
26
import es.gva.cit.jecwcompress.EcwException;
27
import es.gva.cit.jgdal.Gdal;
28
import es.gva.cit.jgdal.GdalBuffer;
29
import es.gva.cit.jgdal.GdalDriver;
30
import es.gva.cit.jgdal.GdalException;
31
import es.gva.cit.jgdal.GdalRasterBand;
32
import es.gva.cit.jgdal.GeoTransform;
33
import es.gva.cit.jogr.OGRSpatialReference;
34
35
import org.cresques.px.PxRaster;
36
37
import java.io.IOException;
38
39
40
/**
41
 * Driver para la escritura a trav?s de Gdal.
42
 * Puede exportar un fichero de un formato a otro desde un GeoRasterFile
43
 * en cualquier formato soportado por la lectura a un formato que este incluido
44
 * en la lista supportedDrv.
45
 *
46
 * Puede salvar a disco en un formato que este incluido en la lista supportedDrv
47
 * obteniendo los datos que van siendo servidos desde el cliente. Este cliente
48
 * debe implementar un IDataWriter o tener un objeto que lo implemente. Inicialmente
49
 * le pasar? los par?metros de la imagen de salida y cuando el driver comience a
50
 * escribir le ir? solicitando m?s a trav?s del m?todo readData de IDataWriter.
51
 * El cliente ser? el que lleve el control de lo que va sirviendo y lo que le queda
52
 * por servir.
53
 * @author Nacho Brodin (brodin_ign@gva.es)
54
 */
55
public class GdalWriter extends GeoRasterWriter {
56
    static {
57 2849 nacho
        GeoRasterWriter.registerWriterExtension("tif", GdalWriter.class);
58 2809 nacho
    }
59
60
    public final int windowSizeX = 386;
61
    public final int windowSizeY = 195;
62
    public final int panelSizeX = 350;
63
    public final int panelSizeY = 105;
64
    public final String panelLayout = "BorderLayout";
65
    private GdalDriver drv;
66
    private Gdal dset_destino = null;
67
    private GdalRasterBand rband = null;
68
    private String drvType = null; //Tipo de driver
69
    private String[] supportedDrv = { "GTiff" }; //Lista de drivers de escritura que soporta
70
    private GeoTransform geot = null; //Datos de georeferenciaci?n
71
    private OGRSpatialReference oSRS; //Datos de proyecci?n
72
    private GdalBuffer buf = null; //Buffer de origen de gdal
73
    private GdalBuffer bufBandR = null;
74
    private GdalBuffer bufBandG = null;
75
    private GdalBuffer bufBandB = null;
76
    private int nBlocks = 0; //N?mero de bloques en Y en el que se divide la imagen para escribir
77
    private int anchoResto = 0; //Tama?o del ?ltimo bloque de la imagen.
78
    private String[] params = null; //Par?metros de creaci?n del dataset.
79
    private GdalSupportOptions support = null;
80
    private boolean consulta = false;
81
82
    /**
83
     * Constructor para la obtenci?n de par?metros del driver
84
     * @param drvType        Tipo de driver
85
     */
86
    public GdalWriter(String drvType) {
87
        this.support = new GdalSupportOptions(drvType);
88
        this.ident = this.drvType = drvType;
89
        this.driver = "tif";
90
        this.support.setBlockSize(64);
91
        this.support.setPhotometric("RGB");
92
        this.support.setInterleave("BAND");
93
        this.support.setCompress("NONE");
94
        this.support.setWriteGeoref(true);
95
        this.support.setTfw(false);
96
97
        this.consulta = true;
98
    }
99
100
    /**
101
     * Constructor para salvar una sola imagen completa
102
     * @param raster        PxRaster de la imagen de  origen
103
     * @param outfilename        Nombre del fichero de salida
104
     * @param infilename        Nombre del fichero de entrada
105
     * @param drvType        Tipo de driver
106
     */
107
    public GdalWriter(PxRaster raster, String outfilename, String infilename,
108
                      String drvType) throws GdalException, IOException {
109
        this.support = new GdalSupportOptions(drvType);
110
        this.ident = this.drvType = drvType;
111
        this.driver = "tif";
112
113
        this.outfilename = outfilename;
114
        this.infilename = infilename;
115
        this.currentRaster = raster;
116
117
        this.sizeWindowX = raster.getFWidth();
118
        this.sizeWindowY = raster.getFHeight();
119
120
        //Obtenemos la georeferenciaci?n
121
        if (support.getGeoref()) {
122
            double maxX = currentRaster.getExtent().maxX();
123
            double minX = currentRaster.getExtent().minX();
124
            double maxY = currentRaster.getExtent().maxY();
125
            double minY = currentRaster.getExtent().minY();
126
127
            //                    System.out.println("Extent->"+maxX+" "+minX+" "+maxY+" "+minY);
128
            geot = new GeoTransform();
129
            geot.adfgeotransform[0] = minX;
130
            geot.adfgeotransform[3] = maxY;
131
            geot.adfgeotransform[1] = (maxX - minX) / currentRaster.getFWidth();
132
            geot.adfgeotransform[5] = (minY - maxY) / currentRaster.getFHeight();
133
        }
134
135
        nBands = currentRaster.getBandCount();
136
137
        this.support.setBlockSize(currentRaster.getBlockSize());
138
139
        if ((sizeWindowX < 0) || (sizeWindowY < 0)) {
140
            throw new IOException("Tama?o del fichero de salida erroneo.");
141
        }
142
143
        if (nBands == 3) {
144
            this.support.setPhotometric("PHOTOMETRIC=RGB");
145
        } else if (nBands == 1) {
146
            this.support.setPhotometric("PHOTOMETRIC=MINISBLACK");
147
        } else {
148
            this.support.setPhotometric("");
149
        }
150
151
        params = new String[2];
152
        params[0] = new String("TILED=YES");
153
        params[1] = new String(this.support.getPhotometric());
154
155
        init();
156
157
        /*oSRS = new OGRSpatialReference();
158
        try{
159
                oSRS.setUTM(currentRaster.geoFile.getUTM(), currentRaster.geoFile.getZone());
160
                  oSRS.setWellKnownGeogCS(currentRaster.geoFile.getGeogCS());
161
                  //System.out.println(currentRaster.geoFile.getGeogCS()+"Nueva Proyecci?n ==> "+oSRS.exportToWkt());
162
                  dset_destino.setProjection(oSRS.exportToWkt());
163
        }catch(Exception e){
164
                e.printStackTrace();
165
        }*/
166
    }
167
168
    /**
169
     * Constructor para salvar datos servidos por el cliente
170
     * @param dataWriter        Objeto servidor de datos para el driver de escritura
171
     * @param outSizeX        N?mero de pixels en X de la imagen de salida
172
     * @param outSizeY        N?mero de pixels en Y de la imagen de salida
173
     * @param outFilename        Fichero de salida
174
     * @param extentMaxX        Posici?n en X m?xima del extent
175
     * @param extentMinX        Posici?n en X m?nima del extent
176
     * @param extentMaxY        Posici?n en Y m?xima del extent
177
     * @param extentMinY        Posici?n en Y m?nima del extent
178
     * @param nBands        N?mero de bandas
179
     * @param drvType        Tipo de driver
180
     * @throws GdalException
181
     * @throws IOException
182
     */
183
    public GdalWriter(IDataWriter dataWriter, int outSizeX, int outSizeY,
184
                      String outFilename, double extentMaxX, double extentMinX,
185
                      double extentMaxY, double extentMinY, int nBands,
186
                      int sizeBlock, String drvType)
187
               throws GdalException, IOException {
188
        this.support = new GdalSupportOptions(drvType);
189
        this.ident = this.drvType = drvType;
190
        this.driver = "tif";
191
192
        this.dataWriter = dataWriter;
193
        this.outfilename = outFilename;
194
195
        this.sizeWindowX = outSizeX;
196
        this.sizeWindowY = outSizeY;
197
198
        if ((sizeWindowX < 0) || (sizeWindowY < 0)) {
199
            throw new IOException("Tama?o del fichero de salida erroneo.");
200
        }
201
202
        this.nBands = nBands;
203
204
        //Calculamos la georeferenciaci?n a partir del extend pasado por el cliente.
205
        if (support.getGeoref()) {
206
            double maxX = extentMaxX;
207
            double minX = extentMinX;
208
            double maxY = extentMaxY;
209
            double minY = extentMinY;
210
211
            this.support.setBlockSize(sizeBlock);
212
213
            /*System.out.println("----Extent->"+maxX+" "+minX+" "+maxY+" "+minY);
214

215
            double pixelSizeX = (double)((maxX-minX)/outSizeX);
216
            int indexPoint = String.valueOf(pixelSizeX).indexOf('.');
217
            pixelSizeX = Double.parseDouble(String.valueOf(pixelSizeX).substring(0,indexPoint+3));
218
            double pixelSizeY = (double)((minY-maxY)/outSizeY);
219
            indexPoint = String.valueOf(pixelSizeY).indexOf('.');
220
            pixelSizeY = Double.parseDouble(String.valueOf(pixelSizeY).substring(0,indexPoint+3));
221

222
            System.out.println("----PixelSize->"+pixelSizeX+" "+pixelSizeY);*/
223
            geot = new GeoTransform();
224
            geot.adfgeotransform[0] = minX;
225
            geot.adfgeotransform[3] = maxY; //-((pixelSizeY * outSizeY)-minY);
226
            geot.adfgeotransform[1] = (double) ((maxX - minX) / outSizeX); //pixelSizeX;
227
            geot.adfgeotransform[5] = (double) ((minY - maxY) / outSizeY); //pixelSizeY;
228
229
            //System.out.println("----adfGeo->"+geot.adfgeotransform[0]+" "+geot.adfgeotransform[3]+" "+geot.adfgeotransform[1]+" "+geot.adfgeotransform[5]);
230
        }
231
232
        setParams();
233
234
        init();
235
    }
236
237
    /**
238
     *Asigna par?metros de creaci?n del dataset de Gdal
239
     */
240
    private void setParams() {
241
        params = new String[5];
242
243
        params[0] = new String("TILED=YES");
244
        params[1] = new String("PHOTOMETRIC=" + this.support.getPhotometric());
245
        params[2] = new String("INTERLEAVE=" + this.support.getInterleave());
246
        params[3] = new String("COMPRESS=" + this.support.getCompress());
247
248
        String tfw = null;
249
250
        if (this.support.getTfw()) {
251
            tfw = new String("YES");
252
        } else {
253
            tfw = new String("NO");
254
        }
255
256
        params[4] = new String("TFW=" + tfw);
257
    }
258
259
    /**
260
     * Asigna el tipo de driver con el que se salvar? la imagen
261
     * @param drvType        Tipo de driver
262
     */
263
    public void setDriverType(String drvType) {
264
        this.drvType = drvType;
265
    }
266
267
    /**
268
     * Creaci?n del dataset de destino.
269
     * @throws EcwException
270
     */
271
    private void init() throws GdalException {
272
        //Controlamos que el tipo de driver sea correcto
273
        if (drvType == null) {
274
            throw new GdalException("Tipo de driver sin especificar.");
275
        }
276
277
        boolean okdrvtype = false;
278
279
        for (int i = 0; i < supportedDrv.length; i++)
280
            if (drvType.equals(supportedDrv[i])) {
281
                okdrvtype = true;
282
            }
283
284
        if (okdrvtype == false) {
285 2849 nacho
            throw new GdalException("El tipo de driver "+drvType+" no est? soportado por GdalWriter.");
286 2809 nacho
        }
287
288
        //Obtenemos el driver y creamos el dataset del destino
289 2849 nacho
290 2809 nacho
        drv = Gdal.getDriverByName(drvType);
291
292
        //System.out.println("++++++>"+params.length);
293
        //for(int i=0;i<params.length;i++)System.out.println("=====>"+params[i]);
294
        if (dset_destino != null) {
295
            dset_destino.close();
296
            dset_destino = null;
297
        }
298
299
        dset_destino = drv.create(outfilename, sizeWindowX, sizeWindowY,
300
                                  nBands, Gdal.GDT_Byte, params);
301
302
        if (this.support.getGeoref()) {
303
            dset_destino.setGeoTransform(geot);
304
        }
305
306
        nBlocks = (int) (sizeWindowY / this.support.getBlockSize());
307
        anchoResto = sizeWindowY - (nBlocks * this.support.getBlockSize());
308
309
        //System.out.println("---"+nBlocks+" "+sizeBlock+" "+anchoResto);
310
    }
311
312
    /**
313
     * A partir de un elemento que contiene una propiedad y un valor
314
     * lo parsea y asigna el valor a su variable.
315
     * @param propValue        elemento con la forma propiedad=valor
316
     */
317
    private void readProperty(String propValue) {
318
        String prop = propValue.substring(0, propValue.indexOf("="));
319
320
        if (propValue.startsWith(prop)) {
321
            String value = propValue.substring(propValue.indexOf("=") + 1,
322
                                               propValue.length());
323
324
            if ((value != null) && !value.equals("")) {
325
                if (prop.equals("BLOCKSIZE")) {
326
                    this.support.setBlockSize(Integer.parseInt(value));
327
                }
328
329
                if (prop.equals("GEOREF")) {
330
                    boolean georef = true;
331
332
                    if (value.equals("yes")) {
333
                        georef = true;
334
                    } else {
335
                        georef = false;
336
                    }
337
338
                    this.support.setWriteGeoref(georef);
339
                }
340
341
                if (prop.equals("INTERLEAVE")) {
342
                    this.support.setInterleave(value);
343
                }
344
345
                if (prop.equals("PHOTOMETRIC")) {
346
                    this.support.setPhotometric(value);
347
                }
348
349
                if (prop.equals("COMPRESS")) {
350
                    this.support.setCompress(value);
351
                }
352
353
                if (prop.equals("TFW")) {
354
                    boolean tfw = true;
355
356
                    if (value.equals("yes")) {
357
                        tfw = true;
358
                    } else {
359
                        tfw = false;
360
                    }
361
362
                    this.support.setTfw(tfw);
363
                }
364
            }
365
        }
366
    }
367
368
    /**
369
     * Asigna propiedades al driver a partir de un vector de
370
     * strings donde cada elemento tiene la estructura de
371
     * propiedad=valor.
372
     * @param props        Propiedades
373
     */
374
    public void setProps(String[] props) {
375
        for (int iProps = 0; iProps < props.length; iProps++)
376
            readProperty(props[iProps]);
377
378
        setParams();
379
380
        try {
381
            if (!consulta) {
382
                init();
383
            }
384
        } catch (GdalException e) {
385
            e.printStackTrace();
386
        }
387
    }
388
389
    /**
390
     * Escribe tres bandas en el GDALRasterBand desde el IDataWriter con una
391
     * altura definida por sizeY.
392
     * @param buftmp        Buffer
393
     * @param sizeY        Altura en pixels del bloque leido
394
     * @param posicionY        Posici?n y a partir de la cual se escribe en el GDALRasterBand destino
395
     */
396
    private void writeBands(int[] buftmp, int sizeY, int posicionY) {
397
        //leemos el bloque origen
398
        buftmp = dataWriter.readData(sizeWindowX, sizeY, 0);
399
400
        bufBandR.buffByte = new byte[buftmp.length];
401
        bufBandG.buffByte = new byte[buftmp.length];
402
        bufBandB.buffByte = new byte[buftmp.length];
403
404
        //Escribimos el bloque destino
405
        for (int i = 0; i < buftmp.length; i++) {
406
            bufBandR.buffByte[i] = (byte) (((buftmp[i] & 0xff0000) >> 16) &
407
                                   0xff);
408
            bufBandG.buffByte[i] = (byte) (((buftmp[i] & 0xff00) >> 8) & 0xff);
409
            bufBandB.buffByte[i] = (byte) ((buftmp[i] & 0xff) & 0xff);
410
411
            //if(i==0 || i==1 || i==2)System.out.println("<**>"+buftmp[i]+" + "+bufBandR.buffByte[i]+" - "+bufBandG.buffByte[i]+" - "+bufBandB.buffByte[i]);
412
        }
413
414
        try {
415
            rband = dset_destino.getRasterBand(1);
416
            rband.writeRaster(0, posicionY, sizeWindowX, sizeY, bufBandR,
417
                              Gdal.GDT_Byte);
418
            rband = dset_destino.getRasterBand(2);
419
            rband.writeRaster(0, posicionY, sizeWindowX, sizeY, bufBandG,
420
                              Gdal.GDT_Byte);
421
            rband = dset_destino.getRasterBand(3);
422
            rband.writeRaster(0, posicionY, sizeWindowX, sizeY, bufBandB,
423
                              Gdal.GDT_Byte);
424
        } catch (GdalException e) {
425
            e.printStackTrace();
426
        }
427
    }
428
429
    /**
430
     * Funci?n que gestiona la lectura desde el origen y la escritura
431
     * de Gdal sobre el fichero destino.
432
     * @param mode        Modo de escritura
433
     * @throws IOException
434
     */
435
    private void write(int mode) throws IOException {
436
        buf = new GdalBuffer();
437
        bufBandR = new GdalBuffer();
438
        bufBandG = new GdalBuffer();
439
        bufBandB = new GdalBuffer();
440
441
        int[] buftmp = null;
442
443
        //long t1 = System.currentTimeMillis();
444
        try {
445
            if (mode == Mode.fileWrite) {
446
                for (int iBand = 0; iBand < this.nBands; iBand++) {
447
                    rband = dset_destino.getRasterBand(iBand + 1);
448
449
                    for (int iBlock = 0; iBlock < nBlocks; iBlock++) {
450
                        //leemos el bloque origen
451
                        buf.buffByte = currentRaster.getGeoFile().getWindow(0,
452
                                                                            iBlock * this.support.getBlockSize(),
453
                                                                            sizeWindowX,
454
                                                                            this.support.getBlockSize(),
455
                                                                            iBand +
456
                                                                            1);
457
458
                        //Escribimos el bloque destino
459
                        rband.writeRaster(0,
460
                                          iBlock * this.support.getBlockSize(),
461
                                          sizeWindowX,
462
                                          this.support.getBlockSize(), buf,
463
                                          Gdal.GDT_Byte);
464
                    }
465
                }
466
            } else if (mode == Mode.dataWrite) {
467
                //for(int iBlock=1;iBlock<=nBlocks;iBlock++){
468
                for (int iBlock = 0; iBlock < nBlocks; iBlock++) {
469
                    int posicionY = iBlock * this.support.getBlockSize();
470
                    writeBands(buftmp, this.support.getBlockSize(), posicionY);
471
                }
472
            }
473
474
            if (anchoResto != 0) {
475
                if (mode == Mode.fileWrite) {
476
                    for (int iBand = 0; iBand < this.nBands; iBand++) {
477
                        rband = dset_destino.getRasterBand(iBand + 1);
478
479
                        //leemos el bloque origen
480
                        buf.buffByte = currentRaster.getGeoFile().getWindow(0,
481
                                                                            nBlocks * this.support.getBlockSize(),
482
                                                                            sizeWindowX,
483
                                                                            anchoResto,
484
                                                                            iBand +
485
                                                                            1);
486
487
                        //Escribimos el bloque destino
488
                        rband.writeRaster(0,
489
                                          nBlocks * this.support.getBlockSize(),
490
                                          sizeWindowX, anchoResto, buf,
491
                                          Gdal.GDT_Byte);
492
                    }
493
                } else if (mode == Mode.dataWrite) {
494
                    int posicionY = nBlocks * this.support.getBlockSize();
495
                    writeBands(buftmp, anchoResto, posicionY);
496
                }
497
            }
498
        } catch (GdalException e) {
499
            e.printStackTrace();
500
        }
501
    }
502
503
    /**
504
     * Realiza la funci?n de compresi?n a partir de un GeoRasterFile.
505
     * @throws IOException
506
     */
507
    public void fileWrite() throws IOException {
508
        if (currentRaster == null) {
509
            throw new IOException("No se ha asignado un fichero de entrada.");
510
        }
511
512
        this.write(Mode.fileWrite);
513
    }
514
515
    /**
516
     * Realiza la escritura de datos con los datos que le pasa el cliente.
517
     * @throws IOException
518
     */
519
    public void dataWrite() throws IOException {
520
        if (dataWriter == null) {
521
            throw new IOException("No se ha obtenido un objeto de entrada para la escritura valido.");
522
        }
523
524
        this.write(Mode.dataWrite);
525
    }
526
527
    /**
528
     * Cierra el compresor ecw.
529
     * @throws GdalException
530
     */
531
    public void writeClose() {
532
        try {
533
            dset_destino.close();
534
            oSRS = null;
535
        } catch (GdalException e) {
536
            e.printStackTrace();
537
        }
538
    }
539
540
    /**
541
     * Devuelve la configuraci?n de la ventana de dialogo
542
     * para las propiedades del driver de escritura de Gdal.
543
     * @return XML de configuraci?n del dialogo.
544
     */
545
    public String getXMLPropertiesDialog() {
546
        StringBuffer options = null;
547
        options = new StringBuffer();
548
        options.append("<window sizex=\"" + this.windowSizeX + "\" sizey=\"" +
549
                       this.windowSizeY + "\">");
550
        options.append("<panel sizex=\"" + this.panelSizeX + "\" sizey=\"" +
551
                       this.panelSizeY + "\" layout=\"" + this.panelLayout +
552
                       "\" border=\"yes\">");
553
554
        options.append("<panel layout=\"FlowLayout\" position=\"North\" align=\"left\">");
555
        options.append("<label>Tama?o bloque:</label>");
556
        options.append("<combo ident=\"BLOCKSIZE\" selected=\"" +
557
                       this.support.getBlockSize() + "\">");
558
559
        for (int i = 0; i < this.support.getBlockSizeList().length; i++)
560
            options.append("<elem>" + this.support.getBlockSizeList()[i] +
561
                           "</elem>");
562
563
        options.append("</combo>");
564
        options.append("<label>Georef Si/No:</label>");
565
566
        String sel = null;
567
568
        if (this.support.getGeoref()) {
569
            sel = new String("yes");
570
        } else {
571
            sel = new String("no");
572
        }
573
574
        options.append("<check ident=\"GEOREF\" selected=\"" + sel +
575
                       "\" text=\"\">");
576
        options.append("</check>");
577
        options.append("</panel>");
578
579
        options.append("<panel layout=\"FlowLayout\" position=\"Center\" align=\"left\">");
580
        options.append("<label>Photometric:</label>");
581
        options.append("<combo ident=\"PHOTOMETRIC\" selected=\"" +
582
                       this.support.getPhotometric() + "\">");
583
584
        for (int i = 0; i < this.support.getPhotometricList().length; i++)
585
            options.append("<elem>" + this.support.getPhotometricList()[i] +
586
                           "</elem>");
587
588
        options.append("</combo>");
589
        options.append("<label>Interleave:</label>");
590
        options.append("<combo ident=\"INTERLEAVE\" selected=\"" +
591
                       this.support.getInterleave() + "\">");
592
593
        for (int i = 0; i < this.support.getInterleaveList().length; i++)
594
            options.append("<elem>" + this.support.getInterleaveList()[i] +
595
                           "</elem>");
596
597
        options.append("</combo>");
598
        options.append("</panel>");
599
600
        options.append("<panel layout=\"FlowLayout\" position=\"South\" align=\"left\">");
601
        options.append("<label>Compresi?n:</label>");
602
        options.append("<combo ident=\"COMPRESS\" selected=\"" +
603
                       this.support.getCompress() + "\">");
604
605
        for (int i = 0; i < this.support.getCompressList().length; i++)
606
            options.append("<elem>" + this.support.getCompressList()[i] +
607
                           "</elem>");
608
609
        options.append("</combo>");
610
        options.append("<label>Generar Tfw:</label>");
611
        sel = null;
612
613
        if (this.support.getTfw()) {
614
            sel = new String("yes");
615
        } else {
616
            sel = new String("no");
617
        }
618
619
        options.append("<check ident=\"TFW\" selected=\"" + sel +
620
                       "\" text=\"\">");
621
        options.append("</check>");
622
        options.append("</panel>");
623
624
        options.append("</panel>");
625
        options.append("</window>");
626
627
        return options.toString();
628
    }
629
630
    /**
631
     *
632
     * @author Nacho Brodin (brodin_ign@gva.es)
633
     *
634
     * Opciones que soporta el driver de escritura de Gdal.
635
     */
636
    class GdalSupportOptions extends WriterSupportOptions {
637
        private String[] photometric = {
638
                                           "YCBR", "MINISBLACK", "MINISWHITE",
639
                                           "RGB", "CMYK", "CIELAB", "ICCLAB",
640
                                           "ITULAB", "CBCR"
641
                                       };
642
        private String[] interleave = { "BAND", "PIXEL" };
643
        private String[] compress = { "LZW", "PACKBITS", "DEFLATE", "NONE" };
644
        private String photometricDefault = "RGB";
645
        private String interleaveDefault = "BAND";
646
        private String compressDefault = "NONE";
647
        private boolean tfw = false;
648
649
        GdalSupportOptions(String ext) {
650
            super(ext);
651
        }
652
653
        /**
654
         * @param defaultPhot        Tipo de imagen
655
         */
656
        public void setPhotometric(String defaultPhot) {
657
            this.photometricDefault = defaultPhot;
658
        }
659
660
        /**
661
         * @param defaultInt
662
         */
663
        public void setInterleave(String defaultInt) {
664
            this.interleaveDefault = defaultInt;
665
        }
666
667
        /**
668
         * @param defaultComp
669
         */
670
        public void setCompress(String defaultComp) {
671
            this.compressDefault = defaultComp;
672
        }
673
674
        /**
675
         * Asigna true o false si se desea generar un fichero tfw con la
676
         * georeferenciaci?n o no;
677
         * @param tfw true se genera el fichero tfw y false no se genera
678
         */
679
        public void setTfw(boolean tfw) {
680
            this.tfw = tfw;
681
        }
682
683
        /**
684
         * @return
685
         */
686
        public String[] getPhotometricList() {
687
            return photometric;
688
        }
689
690
        /**
691
         * @return
692
         */
693
        public String[] getInterleaveList() {
694
            return interleave;
695
        }
696
697
        /**
698
         * @return
699
         */
700
        public String[] getCompressList() {
701
            return compress;
702
        }
703
704
        /**
705
         * @return
706
         */
707
        public String getPhotometric() {
708
            return photometricDefault;
709
        }
710
711
        /**
712
         * @return
713
         */
714
        public String getInterleave() {
715
            return interleaveDefault;
716
        }
717
718
        /**
719
         * Obtiene el par?metro de compresi?n
720
         * @return
721
         */
722
        public String getCompress() {
723
            return compressDefault;
724
        }
725
726
        /**
727
         * Devuelve true o false si se genera un fichero tfw con la
728
         * georeferenciaci?n o no;
729
         * @param tfw true se genera el fichero tfw y false no se genera
730
         */
731
        public boolean getTfw() {
732
            return tfw;
733
        }
734
    }
735
736
    private class Mode {
737
        public final static int fileWrite = 0;
738
        public final static int dataWrite = 1;
739
    }
740
}