root / trunk / libraries / libRaster / src-test / org / gvsig / raster / dataset / io / rmf / TestRmfWrite.java @ 18040
History | View | Annotate | Download (6.42 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.rmf; |
20 |
|
21 |
import java.awt.geom.Point2D; |
22 |
import java.io.FileNotFoundException; |
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.dataset.FileNotOpenException; |
30 |
import org.gvsig.raster.dataset.NotSupportedExtensionException; |
31 |
import org.gvsig.raster.dataset.RasterDataset; |
32 |
import org.gvsig.raster.dataset.io.RasterDriverException; |
33 |
import org.gvsig.raster.dataset.properties.DatasetColorInterpretation; |
34 |
import org.gvsig.raster.dataset.properties.DatasetStatistics; |
35 |
import org.gvsig.raster.dataset.serializer.ColorInterpretationRmfSerializer; |
36 |
import org.gvsig.raster.dataset.serializer.GeoInfoRmfSerializer; |
37 |
import org.gvsig.raster.dataset.serializer.GeoPointRmfSerializer; |
38 |
import org.gvsig.raster.dataset.serializer.StatisticsRmfSerializer; |
39 |
import org.gvsig.raster.datastruct.ColorTable; |
40 |
import org.gvsig.raster.datastruct.Extent; |
41 |
import org.gvsig.raster.datastruct.GeoPoint; |
42 |
import org.gvsig.raster.datastruct.Histogram; |
43 |
import org.gvsig.raster.datastruct.ViewPortData; |
44 |
import org.gvsig.raster.datastruct.serializer.ColorTableRmfSerializer; |
45 |
import org.gvsig.raster.datastruct.serializer.HistogramRmfSerializer; |
46 |
import org.gvsig.raster.datastruct.serializer.NoDataRmfSerializer; |
47 |
/**
|
48 |
* Test de escritura de ficheros rmf.
|
49 |
* Escribe un fichero rmf con distintos bloques y a continuaci?n le pasa un
|
50 |
* test de lectura para comprobar que se ha generado bien.
|
51 |
*
|
52 |
* @author Nacho Brodin (nachobrodin@gmail.com)
|
53 |
*/
|
54 |
public class TestRmfWrite extends TestCase { |
55 |
|
56 |
private RmfBlocksManager manager = null; |
57 |
private String baseDir = "./test-images/"; |
58 |
private String path = baseDir + "miniRaster25x24.tif"; |
59 |
private String pathGif = baseDir + "gifTransparente.gif"; |
60 |
private String pathJpg = baseDir + "03AUG23153350-M2AS-000000122423_01_P001-BROWSE.jpg"; |
61 |
private Histogram histogram = null; |
62 |
private ColorTable colorTable = null; |
63 |
private RasterDataset f = null; |
64 |
private RasterDataset f2 = null; |
65 |
|
66 |
static {
|
67 |
RasterLibrary.wakeUp(); |
68 |
} |
69 |
|
70 |
public void start() { |
71 |
this.setUp();
|
72 |
this.testStack();
|
73 |
} |
74 |
|
75 |
public void setUp() { |
76 |
System.err.println("TestRmfWrite running..."); |
77 |
|
78 |
RasterDataset f1 = null;
|
79 |
try {
|
80 |
f = RasterDataset.open(null, path);
|
81 |
f1 = RasterDataset.open(null, pathGif);
|
82 |
f2 = RasterDataset.open(null, pathJpg);
|
83 |
} catch (NotSupportedExtensionException e) {
|
84 |
return;
|
85 |
} catch (RasterDriverException e) {
|
86 |
return;
|
87 |
} |
88 |
BufferFactory ds = new BufferFactory(f);
|
89 |
try {
|
90 |
ds.setAreaOfInterest(); |
91 |
} catch (InterruptedException e1) { |
92 |
e1.printStackTrace(); |
93 |
} catch (RasterDriverException e) {
|
94 |
e.printStackTrace(); |
95 |
} |
96 |
|
97 |
try {
|
98 |
histogram = f.getHistogram().getHistogram(); |
99 |
colorTable = f1.getColorTable(); |
100 |
f.getStatistics().calcFullStatistics(); |
101 |
} catch (FileNotOpenException e) {
|
102 |
e.printStackTrace(); |
103 |
} catch (RasterDriverException e) {
|
104 |
e.printStackTrace(); |
105 |
} catch (InterruptedException e) { |
106 |
e.printStackTrace(); |
107 |
} |
108 |
|
109 |
} |
110 |
|
111 |
public void testStack(){ |
112 |
manager = new RmfBlocksManager(baseDir + "writetest.rmf"); |
113 |
|
114 |
//Histograma
|
115 |
HistogramRmfSerializer ser = new HistogramRmfSerializer(histogram);
|
116 |
manager.addClient(ser); |
117 |
|
118 |
//Tabla de color
|
119 |
//colorTable.setName("Prueba Tabla de Color");
|
120 |
ColorTableRmfSerializer ser1 = new ColorTableRmfSerializer(colorTable);
|
121 |
manager.addClient(ser1); |
122 |
|
123 |
//Estadisticas
|
124 |
DatasetStatistics stat = f.getStatistics(); |
125 |
stat.setTailTrimValue(3.0, new Double(10.0)); |
126 |
stat.setTailTrimValue(4.0, new Double(16.0)); |
127 |
StatisticsRmfSerializer ser2 = new StatisticsRmfSerializer(stat);
|
128 |
manager.addClient(ser2); |
129 |
|
130 |
//Georreferenciaci?n
|
131 |
GeoInfoRmfSerializer ser3 = new GeoInfoRmfSerializer(f2);
|
132 |
manager.addClient(ser3); |
133 |
|
134 |
//Puntos de control
|
135 |
GeoPoint p1 = new GeoPoint();
|
136 |
p1.pixelPoint = new Point2D.Double(10, 10); |
137 |
p1.mapPoint = new Point2D.Double(34223.3, 2344.2); |
138 |
p1.leftViewPort = new ViewPortData();
|
139 |
p1.leftViewPort.setExtent(new Extent(30032.3, 2103.3, 50023.3, 1234.3)); |
140 |
p1.rightViewPort = new ViewPortData();
|
141 |
p1.rightViewPort.setExtent(new Extent(30032.3, 2103.3, 50023.3, 1234.3)); |
142 |
p1.leftCenterPoint = new Point2D.Double(24223.3, 3244.2); |
143 |
p1.rightCenterPoint = new Point2D.Double(2433.3, 6244.2); |
144 |
GeoPoint p2 = new GeoPoint();
|
145 |
p2.pixelPoint = new Point2D.Double(10, 10); |
146 |
p2.mapPoint = new Point2D.Double(34223.3, 2344.2); |
147 |
p2.leftViewPort = new ViewPortData();
|
148 |
p2.leftViewPort.setExtent(new Extent(30032.3, 2103.3, 50023.3, 1234.3)); |
149 |
p2.rightViewPort = new ViewPortData();
|
150 |
p2.rightViewPort.setExtent(new Extent(30032.3, 2103.3, 50023.3, 1234.3)); |
151 |
p2.leftCenterPoint = new Point2D.Double(24223.3, 3244.2); |
152 |
p2.rightCenterPoint = new Point2D.Double(2433.3, 6244.2); |
153 |
|
154 |
p1.leftViewPort.pxSize = new Point2D.Double(32, 34); |
155 |
GeoPointRmfSerializer ser4 = new GeoPointRmfSerializer(new GeoPoint[]{p1, p2}, p1.leftViewPort); |
156 |
manager.addClient(ser4); |
157 |
|
158 |
// Valor NoData
|
159 |
NoDataRmfSerializer ser5 = new NoDataRmfSerializer(Double.valueOf(5450.0)); |
160 |
manager.addClient(ser5); |
161 |
|
162 |
//Interpretaci?n de color
|
163 |
DatasetColorInterpretation ci = f.getColorInterpretation(); |
164 |
ci.setColorInterpValue(0, DatasetColorInterpretation.BLUE_BAND);
|
165 |
ci.setColorInterpValue(2, DatasetColorInterpretation.RED_BAND);
|
166 |
ColorInterpretationRmfSerializer ser6 = new ColorInterpretationRmfSerializer(f.getColorInterpretation());
|
167 |
manager.addClient(ser6); |
168 |
|
169 |
try {
|
170 |
manager.write(); |
171 |
} catch (FileNotFoundException e) { |
172 |
e.printStackTrace(); |
173 |
} catch (IOException e) { |
174 |
e.printStackTrace(); |
175 |
} |
176 |
|
177 |
//Pasamos el test de lectura para comprobar que se ha generado bien
|
178 |
TestRmfRead t = new TestRmfRead();
|
179 |
t.file = "writetest.rmf";
|
180 |
t.start(); |
181 |
} |
182 |
|
183 |
} |