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