Statistics
| Revision:

svn-gvsig-desktop / trunk / libraries / libRaster / src-test / org / gvsig / raster / buffer / TestNotAdjustToExtent.java @ 27361

History | View | Annotate | Download (4.45 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.buffer;
20

    
21
import junit.framework.TestCase;
22

    
23
import org.gvsig.raster.RasterLibrary;
24
import org.gvsig.raster.dataset.IBuffer;
25
import org.gvsig.raster.dataset.InvalidSetViewException;
26
import org.gvsig.raster.dataset.MultiRasterDataset;
27
import org.gvsig.raster.dataset.NotSupportedExtensionException;
28
import org.gvsig.raster.dataset.io.RasterDriverException;
29
/**
30
 * Prueba del acceso a datos usando el flag setAdjustToExtent a false. Esto consigue que 
31
 * no se ajuste la petici?n a los margenes del raster sino que se dibuje dentro y el resto 
32
 * se rellene con valores NoData.
33
 * 
34
 * @author Nacho Brodin (nachobrodin@gmail.com)
35
 */
36
public class TestNotAdjustToExtent extends TestCase{
37

    
38
        private String baseDir = "./test-images/";
39
        private String path = baseDir + "miniRaster25x24.tif";
40
        private MultiRasterDataset f = null;        
41
        private BufferFactory ds = null;
42
        
43
        public void start(){
44
                this.setUp();
45
                this.testStack();
46
        }
47
        
48
        public void setUp() {
49
                System.err.println("TestAdjustToExtent running...");
50
        }
51
        
52
        static{
53
                RasterLibrary.wakeUp();
54
        }
55
        
56
        public void testStack(){
57
                int[] drawableBands = {0, 1, 2};
58
                try {
59
                        f = MultiRasterDataset.open(null, path);
60
                } catch (NotSupportedExtensionException e) {
61
                        e.printStackTrace();
62
                        return;
63
                } catch (RasterDriverException e) {
64
                        e.printStackTrace();
65
                        return;
66
                }
67
                ds = new BufferFactory(f);
68
                ds.setDrawableBands(drawableBands);
69
                try {
70
                        ds.setAdjustToExtent(false);
71
                        ds.setAreaOfInterest(645800.0, 4923860.0, 645830.0, 4923830, 10, 10); //Superior izquierda
72
                        //ds.setAreaOfInterest(645841.0, 4923860.0, 645871.0, 4923830, 10, 10); //Superior derecha
73
                        //ds.setAreaOfInterest(645841.0, 4923837.0, 645871.0, 4923807.0, 10, 10); //Inferior derecha
74
                        //ds.setAreaOfInterest(645800.0, 4923837.0, 645830.0, 4923807.0, 10, 10); //Inferior izquierda
75
                        //ds.setAreaOfInterest(645810.0, 4923860.0, 645862.0, 4923807.0, 10, 10); //Centro
76
                        dataTest1();
77
                } catch (InvalidSetViewException e) {
78
                        e.printStackTrace();
79
                } catch (InterruptedException e) {
80
                        e.printStackTrace();
81
                } catch (RasterDriverException e) {
82
                        e.printStackTrace();
83
                        return;
84
                }
85
                //print();
86
                
87
        }
88
                
89
        private void dataTest1() throws InterruptedException {
90
                IBuffer raster = ds.getRasterBuf();
91
                //Upper Left
92
                assertEquals((int)(raster.getElemByte(4, 7, 0) & 0xff), 97);
93
                assertEquals((int)(raster.getElemByte(4, 7, 1) & 0xff), 101);
94
                assertEquals((int)(raster.getElemByte(4, 7, 2) & 0xff), 68);
95
                
96
                //Prueba de escritura en disco
97
//                WriterBufferServer writerBufferServer = new WriterBufferServer();
98
//                writerBufferServer.setBuffer(raster, -1);
99
//                
100
//                try {
101
//                        GeoRasterWriter geoRasterWriter = GeoRasterWriter.getWriter(writerBufferServer, "/tmp/test.tif", 3, new AffineTransform(1, 0, 0, -1, 0, 0), raster.getWidth(), raster.getHeight(), raster.getDataType(), GeoRasterWriter.getWriter("test.tif").getParams(), null);
102
//                        geoRasterWriter.dataWrite();
103
//                        geoRasterWriter.writeClose();
104
//                } catch (NotSupportedExtensionException e) {
105
//                        e.printStackTrace();
106
//                } catch (RasterDriverException e) {
107
//                        e.printStackTrace();
108
//                } catch (IOException e) {
109
//                        e.printStackTrace();
110
//                } catch (InterruptedException e) {
111
//                        e.printStackTrace();
112
//                }
113
        }
114
        
115
        /**
116
         * Imprime todos los pixels de la fuente de datos en RGB
117
         */
118
        /*private void print(){
119
                IBuffer raster = ds.getRasterBuf();
120
                for(int line = 0; line < raster.getHeight(); line++){
121
                        for(int col = 0; col < raster.getWidth(); col++)
122
                                System.out.print("(" + (int)(raster.getElemByte(line, col, 0) & 0xff) + " " + (int)(raster.getElemByte(line, col, 1) & 0xff) + " " + (int)(raster.getElemByte(line, col, 2) & 0xff) + ")");
123
                        System.out.println();
124
                }
125
        }*/
126

    
127
}