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