Statistics
| Revision:

root / trunk / libraries / libRaster / src-test / org / gvsig / raster / dataset / io / TestGdalWriter.java @ 12793

History | View | Annotate | Download (3.77 KB)

1
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
2
 *
3
 * Copyright (C) 2007 IVER T.I. and Generalitat Valenciana.
4
 *
5
 * This program is free software; you can redistribute it and/or
6
 * modify it under the terms of the GNU General Public License
7
 * as published by the Free Software Foundation; either version 2
8
 * of the License, or (at your option) any later version.
9
 *
10
 * This program is distributed in the hope that it will be useful,
11
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13
 * GNU General Public License for more details.
14
 *
15
 * You should have received a copy of the GNU General Public License
16
 * along with this program; if not, write to the Free Software
17
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307,USA.
18
 */
19
package org.gvsig.raster.dataset.io;
20

    
21
import java.awt.geom.AffineTransform;
22
import java.io.File;
23
import java.io.IOException;
24

    
25
import junit.framework.TestCase;
26

    
27
import org.gvsig.raster.RasterLibrary;
28
import org.gvsig.raster.buffer.BufferFactory;
29
import org.gvsig.raster.buffer.cache.WriterBufferServer;
30
import org.gvsig.raster.dataset.GeoRasterWriter;
31
import org.gvsig.raster.dataset.IBuffer;
32
import org.gvsig.raster.dataset.IDataWriter;
33
import org.gvsig.raster.dataset.NotSupportedExtensionException;
34
import org.gvsig.raster.dataset.Params;
35
import org.gvsig.raster.dataset.RasterDataset;
36
import org.gvsig.raster.dataset.RasterDriverException;
37
import org.gvsig.raster.datastruct.Extent;
38

    
39
/**
40
 * Test para salvar un raster a tif variando sus par?metros.
41
 * 
42
 * @author Nacho Brodin (nachobrodin@gmail.com)
43
 *
44
 */
45
public class TestGdalWriter extends TestCase {
46
        
47
        private String baseDir = "./test-images/";
48
        private String path1 = baseDir + "03AUG23153350-M2AS-000000122423_01_P001-BROWSE.jpg";
49
        private String out = baseDir + "testGdalWriter";
50
        private IBuffer buf = null;
51
        private RasterDataset d = null;
52
        
53
        public void start() {
54
                this.setUp();
55
                this.testStack();
56
        }
57
        
58
        static {
59
                RasterLibrary.wakeUp();
60
        }
61
        
62
        public void setUp() {
63
                System.err.println("TestGdalWriter running...");
64
                try {
65
                        d = RasterDataset.open(null, path1);
66
                } catch (NotSupportedExtensionException e) {
67
                        e.printStackTrace();
68
                } catch (RasterDriverException e) {
69
                        e.printStackTrace();
70
                }
71
                BufferFactory bf = new BufferFactory(d);
72
                bf.setDrawableBands(new int[]{0, 1, 2}); 
73
                bf.setAreaOfInterest(0, 0, d.getWidth(), d.getHeight());
74
                buf = bf.getRasterBuf();
75
        }
76
        
77
        public void testStack(){
78
                try {
79
                        File f = new File(out + ".tif");
80
                        f.delete();
81
                        f = new File(out + ".tfw");
82
                        f.delete();
83
                        convertBufferToTif(out + ".tif", d.getAffineTransform(), buf);
84
                } catch (IOException e) {
85
                        e.printStackTrace();
86
                }
87
        }
88
        
89
        /**
90
         * Funci?n para pruebas.
91
         * Convierte los ficheros generados por la funci?n cachear en ficheros tif para comprobar que est?n
92
         * bien generados.
93
         * @param grf
94
         * @param pageBuffer
95
         * @param pageLines
96
         * @throws IOException
97
         */
98
        private void convertBufferToTif(String fileName, AffineTransform at, IBuffer buffer)throws IOException {
99
                IDataWriter dataWriter1 = new WriterBufferServer(buffer);
100
                GeoRasterWriter grw = null;
101
                try {
102
                        Params params = GeoRasterWriter.getWriter(fileName).getParams();
103
                        params.changeParamValue("blocksize", "512");
104
                        params.changeParamValue("tfw", "true");
105
                        params.changeParamValue("interleave", "PIXEL");
106
                        grw = GeoRasterWriter.getWriter(dataWriter1, 
107
                                                                                        fileName,
108
                                                                                        buffer.getBandCount(),
109
                                                                                        at,
110
                                                                                        buffer.getWidth(), 
111
                                                                                        buffer.getHeight(), 
112
                                                                                        buffer.getDataType(),
113
                                                                                        params,
114
                                                                                        null);
115
                        
116
                } catch (NotSupportedExtensionException e) {
117
                        e.printStackTrace();
118
                } catch (RasterDriverException e) {
119
                        e.printStackTrace();
120
                }
121
                grw.dataWrite();
122
                grw.writeClose();
123
        }
124
}