Statistics
| Revision:

svn-gvsig-desktop / tags / v1_1_Build_1003 / libraries / libCq CMS for java.old / src / org / cresques / io / GdalWriter.java @ 12271

History | View | Annotate | Download (29.7 KB)

1
/*
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 java.io.BufferedOutputStream;
27
import java.io.DataOutputStream;
28
import java.io.File;
29
import java.io.FileOutputStream;
30
import java.io.IOException;
31

    
32
import org.cresques.cts.IProjection;
33
import org.cresques.geo.ViewPortData;
34
import org.cresques.i18n.Messages;
35
import org.cresques.io.data.WriterSupportOptions;
36
import org.cresques.io.exceptions.NotSupportedExtensionException;
37
import org.cresques.px.Extent;
38
import org.cresques.px.PxRaster;
39

    
40
import es.gva.cit.jecwcompress.EcwException;
41
import es.gva.cit.jgdal.Gdal;
42
import es.gva.cit.jgdal.GdalBuffer;
43
import es.gva.cit.jgdal.GdalDriver;
44
import es.gva.cit.jgdal.GdalException;
45
import es.gva.cit.jgdal.GdalRasterBand;
46
import es.gva.cit.jgdal.GeoTransform;
47
import es.gva.cit.jogr.OGRSpatialReference;
48

    
49

    
50
/**
51
 * Driver para la escritura a trav?s de Gdal.
52
 * Puede exportar un fichero de un formato a otro desde un GeoRasterFile
53
 * en cualquier formato soportado por la lectura a un formato que este incluido
54
 * en la lista supportedDrv.
55
 *
56
 * Puede salvar a disco en un formato que este incluido en la lista supportedDrv
57
 * obteniendo los datos que van siendo servidos desde el cliente. Este cliente
58
 * debe implementar un IDataWriter o tener un objeto que lo implemente. Inicialmente
59
 * le pasar? los par?metros de la imagen de salida y cuando el driver comience a
60
 * escribir le ir? solicitando m?s a trav?s del m?todo readData de IDataWriter.
61
 * El cliente ser? el que lleve el control de lo que va sirviendo y lo que le queda
62
 * por servir.
63
 * @author Nacho Brodin (brodin_ign@gva.es)
64
 */
65
public class GdalWriter extends GeoRasterWriter {
66
        
67
        //Datos de registro de drivers
68
    static {
69
        GeoRasterWriter.registerWriterExtension("tif", GdalWriter.class);
70
        //GeoRasterWriter.registerWriterExtension("tiff", GdalWriter.class);
71
        typeList.put("tif", "GTiff");
72
        //typeList.put("tiff", "GTiff");
73
    }
74

    
75
    public final int                                 windowSizeX = 386;
76
    public final int                                 windowSizeY = 195;
77
    public final int                                 panelSizeX = 358;
78
    public final int                                 panelSizeY = 105;
79
    public final String                         panelLayout = "BorderLayout";
80
    private GdalDriver                                 drv;
81
    private Gdal                                         dset_destino = null;
82
    private GdalRasterBand                         rband = null;
83
    private GeoTransform                         geot = null; //Datos de georeferenciaci?n
84
    private OGRSpatialReference         oSRS; //Datos de proyecci?n                                                
85
    private GdalBuffer                                 buf = null; //Buffer de origen de gdal
86
    private GdalBuffer                                 bufBandR = null;
87
    private GdalBuffer                                 bufBandG = null;
88
    private GdalBuffer                                 bufBandB = null;
89
    private int                                         nBlocks = 0; //N?mero de bloques en Y en el que se divide la imagen para escribir
90
    private int                                         anchoResto = 0; //Tama?o del ?ltimo bloque de la imagen.
91
    private String[]                                 params = null; //Par?metros de creaci?n del dataset.
92
    private GdalSupportOptions                 support = null;
93
    private boolean                                 consulta = false;
94
    private        boolean                                        write = true; //Cuando est? a true se puede escribir en la imagen de salida. Si est? a false el proceso es interrumpido
95

    
96
    /**
97
     * Constructor para la obtenci?n de par?metros del driver
98
     * @param drvType        Tipo de driver
99
     */
100
    public GdalWriter(String fileName) {
101
            ident = fileName.toLowerCase().substring(fileName.lastIndexOf(".") + 1); 
102
            driver = (String)typeList.get(ident);
103
        support = new GdalSupportOptions(driver);
104
        support.setBlockSize(blockSizeDefault);
105
        support.setPhotometric("RGB");
106
        support.setInterleave("BAND");
107
        support.setCompress("NONE");
108
        support.setWriteGeoref(true);
109
        support.setTfw(false);
110
        consulta = true;
111
    }
112

    
113
    /**
114
     * Constructor para salvar una sola imagen completa
115
     * @param raster        PxRaster de la imagen de  origen
116
     * @param outfilename        Nombre del fichero de salida
117
     * @param infilename        Nombre del fichero de entrada
118
     * @param drvType        Tipo de driver
119
     */
120
    public GdalWriter(PxRaster raster, String outFileName, String inFileName) throws GdalException, IOException {
121
            ident = outFileName.toLowerCase().substring(outFileName.lastIndexOf(".") + 1); 
122
            driver = (String)typeList.get(ident);
123
        support = new GdalSupportOptions(driver);   
124
        
125
        this.outFileName = outFileName;
126
        this.inFileName = inFileName;
127
        currentRaster = raster;
128

    
129
        sizeWindowX = raster.getFWidth();
130
        sizeWindowY = raster.getFHeight();
131

    
132
        //Obtenemos la georeferenciaci?n
133
        if (support.getGeoref()) {
134
            double maxX = currentRaster.getExtent().maxX();
135
            double minX = currentRaster.getExtent().minX();
136
            double maxY = currentRaster.getExtent().maxY();
137
            double minY = currentRaster.getExtent().minY();
138

    
139
            geot = new GeoTransform();
140
            geot.adfgeotransform[0] = minX;
141
            geot.adfgeotransform[3] = maxY;
142
            geot.adfgeotransform[1] = (maxX - minX) / currentRaster.getFWidth();
143
            geot.adfgeotransform[5] = (minY - maxY) / currentRaster.getFHeight();
144
        }
145

    
146
        nBands = currentRaster.getBandCount();
147

    
148
        this.support.setBlockSize(64/*currentRaster.getBlockSize()*/);
149

    
150
        if ((sizeWindowX < 0) || (sizeWindowY < 0)) {
151
            throw new IOException("Tama?o del fichero de salida erroneo.");
152
        }
153

    
154
        if (nBands == 3) {
155
            this.support.setPhotometric("PHOTOMETRIC=RGB");
156
        } else if (nBands == 1) {
157
            this.support.setPhotometric("PHOTOMETRIC=MINISBLACK");
158
        } else {
159
            this.support.setPhotometric("");
160
        }
161

    
162
        params = new String[2];
163
        params[0] = new String("TILED=YES");
164
        params[1] = new String(this.support.getPhotometric());
165

    
166
        init();
167

    
168
        /*oSRS = new OGRSpatialReference();
169
        try{
170
                oSRS.setUTM(currentRaster.geoFile.getUTM(), currentRaster.geoFile.getZone());
171
                  oSRS.setWellKnownGeogCS(currentRaster.geoFile.getGeogCS());
172
                  //System.out.println(currentRaster.geoFile.getGeogCS()+"Nueva Proyecci?n ==> "+oSRS.exportToWkt());
173
                  dset_destino.setProjection(oSRS.exportToWkt());
174
        }catch(Exception e){
175
                e.printStackTrace();
176
        }*/
177
    }
178

    
179
    /**
180
     * Constructor para salvar datos servidos por el cliente
181
     * @param dataWriter        Objeto servidor de datos para el driver de escritura
182
     * @param outSizeX        N?mero de pixels en X de la imagen de salida
183
     * @param outSizeY        N?mero de pixels en Y de la imagen de salida
184
     * @param outFilename        Fichero de salida
185
     * @param extentMaxX        Posici?n en X m?xima del extent
186
     * @param extentMinX        Posici?n en X m?nima del extent
187
     * @param extentMaxY        Posici?n en Y m?xima del extent
188
     * @param extentMinY        Posici?n en Y m?nima del extent
189
     * @param nBands        N?mero de bandas
190
     * @param drvType        Tipo de driver
191
     * @throws GdalException
192
     * @throws IOException
193
     */
194
    public GdalWriter(        IDataWriter dataWriter, 
195
                                             String outFileName, 
196
                                             Integer blockSize, 
197
                                             Integer nBands,
198
                                             ViewPortData vp,
199
                                             Integer compresion,
200
                                             Integer outSizeX,
201
                                             Integer outSizeY)throws GdalException, IOException {
202
               
203
            ident = outFileName.toLowerCase().substring(outFileName.lastIndexOf(".") + 1); 
204
            driver = (String)typeList.get(ident);
205
        support = new GdalSupportOptions(driver);
206
        
207
        this.dataWriter = dataWriter;
208
        this.outFileName = outFileName;
209

    
210
        this.sizeWindowX = outSizeX.intValue();
211
        this.sizeWindowY = outSizeY.intValue();
212

    
213
        if ((sizeWindowX < 0) || (sizeWindowY < 0)) {
214
            throw new IOException("Tama?o del fichero de salida erroneo.");
215
        }
216

    
217
        this.nBands = nBands.intValue();
218

    
219
        //Calculamos la georeferenciaci?n a partir del extend pasado por el cliente.
220
        if (support.getGeoref()) {
221
                Extent ex = vp.getExtent();
222
            double maxX = ex.maxX();
223
            double minX = ex.minX();
224
            double maxY = ex.maxY();
225
            double minY = ex.minY();
226

    
227
            this.support.setBlockSize(blockSize.intValue());
228
            
229
            geot = new GeoTransform();
230
            geot.adfgeotransform[0] = minX;
231
            geot.adfgeotransform[3] = maxY; //-((pixelSizeY * outSizeY)-minY);
232
            geot.adfgeotransform[1] = (double) ((maxX - minX) / outSizeX.intValue()); //pixelSizeX;
233
            geot.adfgeotransform[5] = (double) ((minY - maxY) / outSizeY.intValue()); //pixelSizeY;
234
        }
235

    
236
        setParams();
237

    
238
        init();
239
    }
240

    
241
    /**
242
     *Asigna par?metros de creaci?n del dataset de Gdal
243
     */
244
    private void setParams() {
245
        params = new String[5];
246

    
247
        params[0] = new String("TILED=YES");
248
        params[1] = new String("PHOTOMETRIC=" + this.support.getPhotometric());
249
        params[2] = new String("INTERLEAVE=" + this.support.getInterleave());
250
        params[3] = new String("COMPRESS=" + this.support.getCompress());
251

    
252
        String tfw = null;
253

    
254
        if (this.support.getTfw()) {
255
            tfw = new String("YES");
256
        } else {
257
            tfw = new String("NO");
258
        }
259

    
260
        params[4] = new String("TFW=" + tfw);
261
    }
262

    
263
    /**
264
     * Asigna el tipo de driver con el que se salvar? la imagen
265
     * @param drvType        Tipo de driver
266
     */
267
    public void setDriverType(String drvType) {
268
        this.driver = drvType;
269
    }
270

    
271
    /**
272
     * Creaci?n del dataset de destino.
273
     * @throws EcwException
274
     */
275
    private void init() throws GdalException {
276
        //Controlamos que el tipo de driver sea correcto
277
        if (driver == null) {
278
            throw new GdalException("Tipo de driver sin especificar.");
279
        }
280

    
281
        boolean okdrvtype = false;
282

    
283
        String[] types = GeoRasterWriter.getDriversType();
284
        for (int i = 0; i < GeoRasterWriter.getNTypes(); i++)
285
            if (driver.equals(types[i])) {
286
                okdrvtype = true;
287
            }
288

    
289
        if (okdrvtype == false) {
290
            throw new GdalException("El tipo de driver "+driver+" no est? soportado por GdalWriter.");
291
        }
292

    
293
        //Obtenemos el driver y creamos el dataset del destino
294
        drv = Gdal.getDriverByName(driver);
295
        
296
        if (dset_destino != null) {
297
            dset_destino.close();
298
            dset_destino = null;
299
        }
300

    
301
        dset_destino = drv.create(outFileName, sizeWindowX, sizeWindowY,
302
                                  nBands, Gdal.GDT_Byte, params);
303

    
304
        if (this.support.getGeoref()) {
305
            dset_destino.setGeoTransform(geot);
306
        }
307

    
308
        nBlocks = (int) (sizeWindowY / this.support.getBlockSize());
309
        anchoResto = sizeWindowY - (nBlocks * this.support.getBlockSize());
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

    
412
        try {
413
            rband = dset_destino.getRasterBand(1);
414
            rband.writeRaster(0, posicionY, sizeWindowX, sizeY, bufBandR,
415
                              Gdal.GDT_Byte);
416
            rband = dset_destino.getRasterBand(2);
417
            rband.writeRaster(0, posicionY, sizeWindowX, sizeY, bufBandG,
418
                              Gdal.GDT_Byte);
419
            rband = dset_destino.getRasterBand(3);
420
            rband.writeRaster(0, posicionY, sizeWindowX, sizeY, bufBandB,
421
                              Gdal.GDT_Byte);
422
        } catch (GdalException e) {
423
            e.printStackTrace();
424
        }
425
    }
426

    
427
    /**
428
     * Funci?n que gestiona la lectura desde el origen y la escritura
429
     * de Gdal sobre el fichero destino.
430
     * @param mode        Modo de escritura
431
     * @throws IOException
432
     */
433
    private void write(int mode) throws IOException {
434
        buf = new GdalBuffer();
435
        bufBandR = new GdalBuffer();
436
        bufBandG = new GdalBuffer();
437
        bufBandB = new GdalBuffer();
438

    
439
        int[] buftmp = null;
440

    
441
        //long t1 = System.currentTimeMillis();
442
        try {
443
            if (mode == Mode.fileWrite) {
444
                for (int iBand = 0; iBand < this.nBands; iBand++) {
445
                    rband = dset_destino.getRasterBand(iBand + 1);
446

    
447
                    for (int iBlock = 0; iBlock < nBlocks; iBlock++) {
448
                            if(write){
449
                                //leemos el bloque origen
450
                                buf.buffByte = currentRaster.getGeoFile().getWindow(0,
451
                                                                                    iBlock * this.support.getBlockSize(),
452
                                                                                    sizeWindowX,
453
                                                                                    this.support.getBlockSize(),
454
                                                                                    iBand +
455
                                                                                    1);
456
        
457
                                //Escribimos el bloque destino
458
                                rband.writeRaster(0,
459
                                                  iBlock * this.support.getBlockSize(),
460
                                                  sizeWindowX,
461
                                                  this.support.getBlockSize(), buf,
462
                                                  Gdal.GDT_Byte);
463
                            }/*else
464
                                    this.writeClose();*/
465
                    }
466
                }
467
            } else if (mode == Mode.dataWrite) {
468
                //for(int iBlock=1;iBlock<=nBlocks;iBlock++){
469
                for (int iBlock = 0; iBlock < nBlocks; iBlock++) {
470
                    int posicionY = iBlock * this.support.getBlockSize();
471
                    if(write)
472
                            writeBands(buftmp, this.support.getBlockSize(), posicionY);
473
                    /*else
474
                            this.writeClose();*/
475
                }
476
            }
477

    
478
            if (anchoResto != 0) {
479
                if (mode == Mode.fileWrite) {
480
                    for (int iBand = 0; iBand < this.nBands; iBand++) {
481
                        rband = dset_destino.getRasterBand(iBand + 1);
482
                        if(write){
483
                                //leemos el bloque origen
484
                                buf.buffByte = currentRaster.getGeoFile().getWindow(0,
485
                                                                                    nBlocks * this.support.getBlockSize(),
486
                                                                                    sizeWindowX,
487
                                                                                    anchoResto,
488
                                                                                    iBand +
489
                                                                                    1);
490
        
491
                                //Escribimos el bloque destino
492
                                rband.writeRaster(0,
493
                                                  nBlocks * this.support.getBlockSize(),
494
                                                  sizeWindowX, anchoResto, buf,
495
                                                  Gdal.GDT_Byte);
496
                        }/*else
497
                                this.writeClose();*/
498
                    }
499
                } else if (mode == Mode.dataWrite) {
500
                    int posicionY = nBlocks * this.support.getBlockSize();
501
                    if(write)
502
                            writeBands(buftmp, anchoResto, posicionY);
503
                    /*else
504
                            this.writeClose();*/
505
                }
506
            }
507
        } catch (GdalException e) {
508
            e.printStackTrace();
509
        }
510
    }
511

    
512
    /**
513
     * Realiza la funci?n de compresi?n a partir de un GeoRasterFile.
514
     * @throws IOException
515
     */
516
    public void fileWrite() throws IOException {
517
        if (currentRaster == null) {
518
            throw new IOException("No se ha asignado un fichero de entrada.");
519
        }
520

    
521
        this.write(Mode.fileWrite);
522
    }
523

    
524
    /**
525
     * Realiza una copia en el formato especificado.
526
     * @throws IOException
527
     */
528
    public static void createCopy(GdalDriver driverDst, String dst, String src, 
529
                    boolean bstrict, String[] params, IProjection proj) throws IOException, GdalException {
530
        if (dst == null || src == null) {
531
            throw new IOException("No se ha asignado un fichero de entrada.");
532
        }
533
        try{
534
                GdalFile gdalFile = new GdalFile(proj, src);
535
                driverDst.createCopy(dst, gdalFile.file, bstrict, params);
536
                if(dst.endsWith(".jpg") || dst.endsWith(".jpeg") && GeoRasterWriter.writeTfw)
537
                        GdalWriter.createWorldFile(dst, gdalFile);
538
                gdalFile.close();
539
                GeoRasterWriter.writeTfw = true;
540
            } catch (NotSupportedExtensionException e) {
541
                    e.printStackTrace();
542
            }
543
    }
544
    
545
    /**
546
         * Crea un fichero de georeferenciaci?n
547
         * @param img
548
         * @param name
549
         * @return
550
         * @throws IOException
551
         */
552
        private static void createWorldFile(String name, GdalFile gdalFile) throws IOException{
553
            File tfw = null;
554
            
555
            String extWorldFile = ".wld";
556
            if(name.endsWith("tif"))
557
                    extWorldFile = ".tfw";
558
            if(name.endsWith("jpg") || name.endsWith("jpeg"))
559
                    extWorldFile = ".jpgw";
560
                                
561
            tfw = new File(name.substring(0, name.lastIndexOf(".")) + extWorldFile);
562
            
563
            //Generamos un world file para gdal
564
            DataOutputStream dos = new DataOutputStream( new BufferedOutputStream(new FileOutputStream(tfw)) );
565
            dos.writeBytes((gdalFile.getExtent().getMax().getX() - gdalFile.getExtent().getMin().getX())/gdalFile.getWidth()+"\n");
566
            dos.writeBytes("0.0\n");
567
            dos.writeBytes("0.0\n");
568
            dos.writeBytes("-"+Math.abs((gdalFile.getExtent().getMax().getY() - gdalFile.getExtent().getMin().getY())/gdalFile.getHeight())+"\n");
569
            dos.writeBytes(""+gdalFile.getExtent().getMin().getX()+"\n");
570
            dos.writeBytes(""+gdalFile.getExtent().getMax().getY()+"\n");
571
            dos.close();    
572
        }
573

    
574
    
575
    /**
576
     * Realiza la escritura de datos con los datos que le pasa el cliente.
577
     * @throws IOException
578
     */
579
    public void dataWrite() throws IOException {
580
        if (dataWriter == null) {
581
            throw new IOException("No se ha obtenido un objeto de entrada para la escritura valido.");
582
        }
583

    
584
        this.write(Mode.dataWrite);
585
    }
586

    
587
    /**
588
     * Cancela el salvado de datos.
589
     * @throws GdalException
590
     */
591
    public void writeClose() {
592
        try {
593
                if(dset_destino != null)
594
                        dset_destino.close();
595
            oSRS = null;
596
        } catch (GdalException e) {
597
            e.printStackTrace();
598
        }
599
    }
600

    
601
    /**
602
     * Cancela el salvado de datos.
603
     */
604
    public void writeCancel() {
605
       write = false; 
606
    }
607
    
608
    /**
609
     * Devuelve la configuraci?n de la ventana de dialogo
610
     * para las propiedades del driver de escritura de Gdal.
611
     * @return XML de configuraci?n del dialogo.
612
     */
613
    public String getXMLPropertiesDialog() {
614
        StringBuffer options = null;
615
        options = new StringBuffer();
616
        options.append("<window sizex=\"" + this.windowSizeX + "\" sizey=\"" +
617
                       this.windowSizeY + "\">");
618
        options.append("<panel sizex=\"" + this.panelSizeX + "\" sizey=\"" +
619
                       this.panelSizeY + "\" layout=\"" + this.panelLayout +
620
                       "\" border=\"yes\">");
621

    
622
        options.append("<panel layout=\"FlowLayout\" position=\"North\" align=\"left\">");
623
        options.append("<label>"+Messages.getText("Block_Size_")+"</label>");
624
        options.append("<combo ident=\"BLOCKSIZE\" selected=\"" +
625
                       this.support.getBlockSize() + "\">");
626

    
627
        for (int i = 0; i < this.support.getBlockSizeList().length; i++)
628
            options.append("<elem>" + this.support.getBlockSizeList()[i] +
629
                           "</elem>");
630

    
631
        options.append("</combo>");
632
        //options.append("<label>Georef Si/No:</label>");
633

    
634
        String sel = null;
635

    
636
        if (this.support.getGeoref()) {
637
            sel = new String("yes");
638
        } else {
639
            sel = new String("no");
640
        }
641

    
642
        /*options.append("<check ident=\"GEOREF\" selected=\"" + sel +
643
                       "\" text=\"\">");
644
        options.append("</check>");*/
645
        options.append("</panel>");
646

    
647
        options.append("<panel layout=\"FlowLayout\" position=\"Center\" align=\"left\">");
648
        options.append("<label>"+Messages.getText("Photometric_")+"</label>");
649
        options.append("<combo ident=\"PHOTOMETRIC\" selected=\"" +
650
                       this.support.getPhotometric() + "\">");
651

    
652
        for (int i = 0; i < this.support.getPhotometricList().length; i++)
653
            options.append("<elem>" + this.support.getPhotometricList()[i] +
654
                           "</elem>");
655

    
656
        options.append("</combo>");
657
        options.append("<label>"+Messages.getText("Interleave_")+"</label>");
658
        options.append("<combo ident=\"INTERLEAVE\" selected=\"" +
659
                       this.support.getInterleave() + "\">");
660

    
661
        for (int i = 0; i < this.support.getInterleaveList().length; i++)
662
            options.append("<elem>" + this.support.getInterleaveList()[i] +
663
                           "</elem>");
664

    
665
        options.append("</combo>");
666
        options.append("</panel>");
667

    
668
        options.append("<panel layout=\"FlowLayout\" position=\"South\" align=\"left\">");
669
        options.append("<label>"+Messages.getText("Compression_")+"</label>");
670
        options.append("<combo ident=\"COMPRESS\" selected=\"" +
671
                       this.support.getCompress() + "\">");
672

    
673
        for (int i = 0; i < this.support.getCompressList().length; i++)
674
            options.append("<elem>" + this.support.getCompressList()[i] +
675
                           "</elem>");
676

    
677
        options.append("</combo>");
678
        options.append("<label>"+Messages.getText("Generate_Tfw_")+"</label>");
679
        sel = null;
680

    
681
        if (this.support.getTfw()) {
682
            sel = new String("yes");
683
        } else {
684
            sel = new String("no");
685
        }
686

    
687
        options.append("<check ident=\"TFW\" selected=\"" + sel +
688
                       "\" text=\"\">");
689
        options.append("</check>");
690
        options.append("</panel>");
691

    
692
        options.append("</panel>");
693
        options.append("</window>");
694

    
695
        return options.toString();
696
    }
697

    
698
    /**
699
     * Obtiene el valor a la variable write que estar? a true cuando se est? escribiendo
700
     *  o puede escribirse la imagen de salida. El cancelar la operaci?n de escritura
701
     * pondr? esta variable a false deteniendose la escritura y cerrandose el dataset
702
     * de salida. 
703
     * @return True si puede escribirse y false si no puede
704
     */
705
    public boolean isWrite() {
706
                return write;
707
        }
708

    
709
    /**
710
     * Asigna el valor a la variable write que estar? a true cuando se est? escribiendo
711
     *  o puede escribirse la imagen de salida. El cancelar la operaci?n de escritura
712
     * pondr? esta variable a false deteniendose la escritura y cerrandose el dataset
713
     * de salida. 
714
     * @param write Variable booleana. True si puede escribirse y false si no puede
715
     */
716
        public void setWrite(boolean write) {
717
                this.write = write;
718
        }
719
        
720
        /**
721
         * Obtiene las opciones de salvado.
722
         * @return GdalSupportOptions
723
         */
724
        public GdalSupportOptions getSupport(){
725
            return this.support; 
726
    }
727
        
728
    /**
729
     *
730
     * @author Nacho Brodin (brodin_ign@gva.es)
731
     *
732
     * Opciones que soporta el driver de escritura de Gdal.
733
     */
734
    public class GdalSupportOptions extends WriterSupportOptions {
735
        private String[]         photometric = {
736
                                           "YCBR", "MINISBLACK", "MINISWHITE",
737
                                           "RGB", "CMYK", "CIELAB", "ICCLAB",
738
                                           "ITULAB", "CBCR"
739
                                       };
740
        private String[]         interleave = { "BAND", "PIXEL" };
741
        private String[]         compress = { "LZW", "PACKBITS", "DEFLATE", "NONE" };
742
        private String                 photometricDefault = "RGB";
743
        private String                 interleaveDefault = "BAND";
744
        private String                 compressDefault = "NONE";
745
       
746
        private boolean tfw = false;
747

    
748
        public GdalSupportOptions(String ext) {
749
            super(ext);
750
        }
751

    
752
        /**
753
         * @param defaultPhot        Tipo de imagen
754
         */
755
        public void setPhotometric(String defaultPhot) {
756
            this.photometricDefault = defaultPhot;
757
        }
758

    
759
        /**
760
         * @param defaultInt
761
         */
762
        public void setInterleave(String defaultInt) {
763
            this.interleaveDefault = defaultInt;
764
        }
765

    
766
        /**
767
         * @param defaultComp
768
         */
769
        public void setCompress(String defaultComp) {
770
            this.compressDefault = defaultComp;
771
        }
772

    
773
        /**
774
         * Asigna true o false si se desea generar un fichero tfw con la
775
         * georeferenciaci?n o no;
776
         * @param tfw true se genera el fichero tfw y false no se genera
777
         */
778
        public void setTfw(boolean tfw) {
779
            this.tfw = tfw;
780
        }
781

    
782
        /**
783
         * @return
784
         */
785
        public String[] getPhotometricList() {
786
            return photometric;
787
        }
788

    
789
        /**
790
         * @return
791
         */
792
        public String[] getInterleaveList() {
793
            return interleave;
794
        }
795

    
796
        /**
797
         * @return
798
         */
799
        public String[] getCompressList() {
800
            return compress;
801
        }
802

    
803
        /**
804
         * @return
805
         */
806
        public String getPhotometric() {
807
            return photometricDefault;
808
        }
809

    
810
        /**
811
         * @return
812
         */
813
        public String getInterleave() {
814
            return interleaveDefault;
815
        }
816

    
817
        /**
818
         * Obtiene el par?metro de compresi?n
819
         * @return
820
         */
821
        public String getCompress() {
822
            return compressDefault;
823
        }
824

    
825
        /**
826
         * Devuelve true o false si se genera un fichero tfw con la
827
         * georeferenciaci?n o no;
828
         * @param tfw true se genera el fichero tfw y false no se genera
829
         */
830
        public boolean getTfw() {
831
            return tfw;
832
        }
833
    }
834

    
835
    private class Mode {
836
        public final static int fileWrite = 0;
837
        public final static int dataWrite = 1;
838
    }
839
}