Revision 11336
trunk/libraries/libRaster/src-test/org/gvsig/raster/TestTemplate.java | ||
---|---|---|
26 | 26 |
|
27 | 27 |
import junit.framework.TestCase; |
28 | 28 |
|
29 |
import org.gvsig.raster.RasterLibrary; |
|
30 |
import org.gvsig.raster.dataset.properties.DatasetStatistics; |
|
31 |
|
|
32 | 29 |
/** |
33 | 30 |
* |
34 | 31 |
* @author Nacho Brodin (nachobrodin@gmail.com) |
trunk/libraries/libRaster/src-test/org/gvsig/raster/dataset/TestHistogramSerializer.java | ||
---|---|---|
81 | 81 |
} |
82 | 82 |
HistogramRmfSerializer serial1 = new HistogramRmfSerializer(hist1); |
83 | 83 |
String s = serial1.write(); |
84 |
System.out.println(s); |
|
84 |
//System.out.println(s);
|
|
85 | 85 |
|
86 | 86 |
HistogramRmfSerializer serial2 = new HistogramRmfSerializer(); |
87 | 87 |
try { |
... | ... | |
89 | 89 |
} catch (ParsingException e) { |
90 | 90 |
e.printStackTrace(); |
91 | 91 |
} |
92 |
Histogram hist2 = serial2.getHistogram();
|
|
92 |
Histogram hist2 = (Histogram)serial2.getResult();
|
|
93 | 93 |
|
94 | 94 |
assertEquals(hist1.getNumBands(), hist2.getNumBands()); |
95 | 95 |
for (int iBand = 0; iBand < hist1.getNumBands(); iBand++) { |
trunk/libraries/libRaster/src-test/org/gvsig/raster/dataset/io/rmf/TestRmfWrite.java | ||
---|---|---|
1 |
/* |
|
2 |
* Created on 9-ago-2006 |
|
3 |
* |
|
4 |
* To change the template for this generated file go to |
|
5 |
* Window>Preferences>Java>Code Generation>Code and Comments |
|
6 |
*/ |
|
7 |
/* gvSIG. Sistema de Informaci�n Geogr�fica de la Generalitat Valenciana |
|
8 |
* |
|
9 |
* Copyright (C) 2004 IVER T.I. and Generalitat Valenciana. |
|
10 |
* |
|
11 |
* This program is free software; you can redistribute it and/or |
|
12 |
* modify it under the terms of the GNU General Public License |
|
13 |
* as published by the Free Software Foundation; either version 2 |
|
14 |
* of the License, or (at your option) any later version. |
|
15 |
* |
|
16 |
* This program is distributed in the hope that it will be useful, |
|
17 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
18 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
19 |
* GNU General Public License for more details. |
|
20 |
* |
|
21 |
* You should have received a copy of the GNU General Public License |
|
22 |
* along with this program; if not, write to the Free Software |
|
23 |
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,USA. |
|
24 |
*/ |
|
25 |
package org.gvsig.raster.dataset.io.rmf; |
|
26 |
|
|
27 |
import java.io.FileNotFoundException; |
|
28 |
import java.io.IOException; |
|
29 |
|
|
30 |
import junit.framework.TestCase; |
|
31 |
|
|
32 |
import org.gvsig.raster.RasterLibrary; |
|
33 |
import org.gvsig.raster.buffer.BufferFactory; |
|
34 |
import org.gvsig.raster.dataset.FileNotOpenException; |
|
35 |
import org.gvsig.raster.dataset.NotSupportedExtensionException; |
|
36 |
import org.gvsig.raster.dataset.RasterDataset; |
|
37 |
import org.gvsig.raster.dataset.RasterDriverException; |
|
38 |
import org.gvsig.raster.dataset.properties.HistogramRmfSerializer; |
|
39 |
import org.gvsig.raster.util.Histogram; |
|
40 |
|
|
41 |
/** |
|
42 |
* |
|
43 |
* @author Nacho Brodin (nachobrodin@gmail.com) |
|
44 |
* |
|
45 |
*/ |
|
46 |
public class TestRmfWrite extends TestCase { |
|
47 |
|
|
48 |
private RmfBlocksManager manager = null; |
|
49 |
private String baseDir = "./test-images/"; |
|
50 |
private String path = baseDir + "miniRaster25x24.tif"; |
|
51 |
private Histogram histogram = null; |
|
52 |
|
|
53 |
static { |
|
54 |
RasterLibrary.wakeUp(); |
|
55 |
} |
|
56 |
|
|
57 |
public void start() { |
|
58 |
this.setUp(); |
|
59 |
this.testStack(); |
|
60 |
} |
|
61 |
|
|
62 |
public void setUp() { |
|
63 |
System.err.println("TestRmfWrite running..."); |
|
64 |
|
|
65 |
RasterDataset f = null; |
|
66 |
try { |
|
67 |
f = RasterDataset.open(null, path); |
|
68 |
} catch (NotSupportedExtensionException e) { |
|
69 |
return; |
|
70 |
} catch (RasterDriverException e) { |
|
71 |
return; |
|
72 |
} |
|
73 |
BufferFactory ds = new BufferFactory(f); |
|
74 |
ds.setAreaOfInterest(); |
|
75 |
|
|
76 |
try { |
|
77 |
histogram = f.getHistogram().getHistogram(); |
|
78 |
} catch (FileNotOpenException e) { |
|
79 |
e.printStackTrace(); |
|
80 |
} catch (RasterDriverException e) { |
|
81 |
e.printStackTrace(); |
|
82 |
} |
|
83 |
|
|
84 |
} |
|
85 |
|
|
86 |
public void testStack(){ |
|
87 |
manager = new RmfBlocksManager("/tmp/p1.rmf"); |
|
88 |
HistogramRmfSerializer ser = new HistogramRmfSerializer(histogram); |
|
89 |
manager.addClient(ser); |
|
90 |
try { |
|
91 |
manager.write(); |
|
92 |
} catch (FileNotFoundException e) { |
|
93 |
e.printStackTrace(); |
|
94 |
} catch (IOException e) { |
|
95 |
e.printStackTrace(); |
|
96 |
} |
|
97 |
} |
|
98 |
|
|
99 |
} |
|
0 | 100 |
trunk/libraries/libRaster/src-test/org/gvsig/raster/dataset/io/rmf/TestRmfRead.java | ||
---|---|---|
1 |
/* |
|
2 |
* Created on 9-ago-2006 |
|
3 |
* |
|
4 |
* To change the template for this generated file go to |
|
5 |
* Window>Preferences>Java>Code Generation>Code and Comments |
|
6 |
*/ |
|
7 |
/* gvSIG. Sistema de Informaci�n Geogr�fica de la Generalitat Valenciana |
|
8 |
* |
|
9 |
* Copyright (C) 2004 IVER T.I. and Generalitat Valenciana. |
|
10 |
* |
|
11 |
* This program is free software; you can redistribute it and/or |
|
12 |
* modify it under the terms of the GNU General Public License |
|
13 |
* as published by the Free Software Foundation; either version 2 |
|
14 |
* of the License, or (at your option) any later version. |
|
15 |
* |
|
16 |
* This program is distributed in the hope that it will be useful, |
|
17 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
18 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
19 |
* GNU General Public License for more details. |
|
20 |
* |
|
21 |
* You should have received a copy of the GNU General Public License |
|
22 |
* along with this program; if not, write to the Free Software |
|
23 |
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,USA. |
|
24 |
*/ |
|
25 |
package org.gvsig.raster.dataset.io.rmf; |
|
26 |
|
|
27 |
import java.io.FileNotFoundException; |
|
28 |
import java.io.IOException; |
|
29 |
|
|
30 |
import junit.framework.TestCase; |
|
31 |
|
|
32 |
import org.gvsig.raster.RasterLibrary; |
|
33 |
import org.gvsig.raster.buffer.BufferFactory; |
|
34 |
import org.gvsig.raster.dataset.FileNotOpenException; |
|
35 |
import org.gvsig.raster.dataset.NotSupportedExtensionException; |
|
36 |
import org.gvsig.raster.dataset.RasterDataset; |
|
37 |
import org.gvsig.raster.dataset.RasterDriverException; |
|
38 |
import org.gvsig.raster.dataset.properties.HistogramRmfSerializer; |
|
39 |
import org.gvsig.raster.util.Histogram; |
|
40 |
|
|
41 |
/** |
|
42 |
* |
|
43 |
* @author Nacho Brodin (nachobrodin@gmail.com) |
|
44 |
* |
|
45 |
*/ |
|
46 |
public class TestRmfRead extends TestCase { |
|
47 |
|
|
48 |
private RmfBlocksManager manager = null; |
|
49 |
private Histogram histogram = null; |
|
50 |
|
|
51 |
static { |
|
52 |
RasterLibrary.wakeUp(); |
|
53 |
} |
|
54 |
|
|
55 |
public void start() { |
|
56 |
this.setUp(); |
|
57 |
this.testStack(); |
|
58 |
} |
|
59 |
|
|
60 |
public void setUp() { |
|
61 |
System.err.println("TestRmfRead running..."); |
|
62 |
} |
|
63 |
|
|
64 |
public void testStack(){ |
|
65 |
manager = new RmfBlocksManager("/tmp/p.rmf"); |
|
66 |
HistogramRmfSerializer ser = new HistogramRmfSerializer(); |
|
67 |
manager.addClient(ser); |
|
68 |
|
|
69 |
try { |
|
70 |
manager.read(null); |
|
71 |
histogram = (Histogram)manager.getResult(); |
|
72 |
} catch (ParsingException e) { |
|
73 |
e.printStackTrace(); |
|
74 |
} |
|
75 |
|
|
76 |
} |
|
77 |
|
|
78 |
} |
|
0 | 79 |
trunk/libraries/libRaster/src/org/gvsig/raster/dataset/properties/HistogramRmfSerializer.java | ||
---|---|---|
18 | 18 |
*/ |
19 | 19 |
package org.gvsig.raster.dataset.properties; |
20 | 20 |
|
21 |
import java.io.FileNotFoundException; |
|
21 | 22 |
import java.io.IOException; |
22 | 23 |
import java.io.Reader; |
23 | 24 |
import java.io.StringReader; |
... | ... | |
232 | 233 |
b.append("</" + VALUES + ">\n"); |
233 | 234 |
b.append("\t</" + BAND + ">\n"); |
234 | 235 |
} |
235 |
b.append("</" + MAIN_TAG + ">\n");
|
|
236 |
b.append("</" + MAIN_TAG + ">"); |
|
236 | 237 |
return b.toString(); |
237 | 238 |
} |
238 | 239 |
|
239 |
/**
|
|
240 |
* Obtiene el histograma
|
|
241 |
* @return Histogram
|
|
240 |
/* |
|
241 |
* (non-Javadoc)
|
|
242 |
* @see org.gvsig.raster.dataset.io.rmf.IRmfBlock#getResult()
|
|
242 | 243 |
*/ |
243 |
public Histogram getHistogram() {
|
|
244 |
return histogram; |
|
244 |
public Object getResult() {
|
|
245 |
return (Histogram)histogram;
|
|
245 | 246 |
} |
246 | 247 |
|
247 | 248 |
/* |
trunk/libraries/libRaster/src/org/gvsig/raster/dataset/io/rmf/IRmfBlock.java | ||
---|---|---|
18 | 18 |
*/ |
19 | 19 |
package org.gvsig.raster.dataset.io.rmf; |
20 | 20 |
|
21 |
import java.io.FileNotFoundException; |
|
22 |
import java.io.IOException; |
|
23 |
|
|
21 | 24 |
/** |
22 | 25 |
* Interfaz que deben implementar las clases que escriben bloques XML en ficheros RMF. |
23 | 26 |
* Contiene m?todos para escribir y leer un bloque de informaci?n del fichero RMF. La clase |
... | ... | |
42 | 45 |
* serializar. |
43 | 46 |
* @return Texto XML que representa el objeto. |
44 | 47 |
*/ |
45 |
public String write(); |
|
48 |
public String write() throws IOException;
|
|
46 | 49 |
|
47 | 50 |
/** |
48 | 51 |
* Obtiene el tag principal del bloque |
49 | 52 |
* @return Tag principal |
50 | 53 |
*/ |
51 | 54 |
public String getMainTag(); |
55 |
|
|
56 |
/** |
|
57 |
* Obtiene el objeto resultante de haber aplicado un read. |
|
58 |
* @return Object del tipo correspondiente al bloque implementado. |
|
59 |
*/ |
|
60 |
public Object getResult(); |
|
52 | 61 |
} |
trunk/libraries/libRaster/src/org/gvsig/raster/dataset/io/rmf/RmfBlocksManager.java | ||
---|---|---|
18 | 18 |
*/ |
19 | 19 |
package org.gvsig.raster.dataset.io.rmf; |
20 | 20 |
|
21 |
import java.io.BufferedReader; |
|
21 | 22 |
import java.io.File; |
23 |
import java.io.FileInputStream; |
|
24 |
import java.io.FileNotFoundException; |
|
25 |
import java.io.FileWriter; |
|
26 |
import java.io.IOException; |
|
27 |
import java.io.InputStreamReader; |
|
28 |
import java.util.ArrayList; |
|
22 | 29 |
|
23 | 30 |
/** |
24 | 31 |
* Gestor para la escritura de bloques XML en el fichero RMF. Cada cliente que quiere |
... | ... | |
54 | 61 |
* (non-Javadoc) |
55 | 62 |
* @see org.gvsig.raster.dataset.io.rmf.IRmfBlock#read(java.lang.String) |
56 | 63 |
*/ |
57 |
public void read(String xml) { |
|
64 |
public void read(String xml) throws ParsingException { |
|
65 |
File file = new File(path); |
|
66 |
ArrayList lines = new ArrayList(); |
|
58 | 67 |
|
68 |
BufferedReader inGrf = null; |
|
69 |
try { |
|
70 |
inGrf = new BufferedReader(new InputStreamReader(new FileInputStream(file))); |
|
71 |
String str = inGrf.readLine(); |
|
72 |
while(str != null) { |
|
73 |
for (int i = 0; i < clients.size(); i++) { |
|
74 |
IRmfBlock block = ((IRmfBlock)clients.get(i)); |
|
75 |
String main = block.getMainTag(); |
|
76 |
if(str.startsWith("<" + main)) { |
|
77 |
lines.clear(); |
|
78 |
while(str.compareTo("</" + main + ">") != 0) { |
|
79 |
lines.add(str); |
|
80 |
str = inGrf.readLine(); |
|
81 |
} |
|
82 |
lines.add(str); |
|
83 |
StringBuffer buf = new StringBuffer(); |
|
84 |
for (int j = 0; j < lines.size(); j++) |
|
85 |
buf.append((String)lines.get(j)); |
|
86 |
block.read(buf.toString()); |
|
87 |
break; |
|
88 |
} |
|
89 |
} |
|
90 |
|
|
91 |
str = inGrf.readLine(); |
|
92 |
} |
|
93 |
} catch (FileNotFoundException e) { |
|
94 |
throw new ParsingException("File Input error: creating BufferedReader"); |
|
95 |
} catch (IOException ex) { |
|
96 |
throw new ParsingException("File Input error: reading lines"); |
|
97 |
} |
|
98 |
|
|
59 | 99 |
} |
60 | 100 |
|
101 |
/** |
|
102 |
* Creaci?n de nuevo fichero RMF. A?ade la cabecera y vuelca el contenido de |
|
103 |
* todos los IRmfBlock. |
|
104 |
* @param file Fichero |
|
105 |
* @return true si el fichero no existia y se ha creado nuevo |
|
106 |
* @throws IOException |
|
107 |
*/ |
|
108 |
private boolean create(File file) throws IOException { |
|
109 |
if(!file.exists()) { |
|
110 |
file.createNewFile(); |
|
111 |
FileWriter writer = new FileWriter(file); |
|
112 |
writer.write("<?xml version=\"1.0\" encoding=\"ISO-8859-15\"?>\n"); |
|
113 |
writer.write("<RasterMetaFile>\n"); |
|
114 |
for (int i = 0; i < clients.size(); i++) { |
|
115 |
IRmfBlock block = ((IRmfBlock)clients.get(i)); |
|
116 |
writer.write(block.write()); |
|
117 |
} |
|
118 |
writer.write("\n</RasterMetaFile>\n"); |
|
119 |
writer.close(); |
|
120 |
return true; |
|
121 |
} |
|
122 |
return false; |
|
123 |
} |
|
124 |
|
|
61 | 125 |
/* |
62 | 126 |
* (non-Javadoc) |
63 | 127 |
* @see org.gvsig.raster.dataset.io.rmf.IRmfBlock#write() |
64 | 128 |
*/ |
65 |
public String write() { |
|
129 |
public String write() throws IOException {
|
|
66 | 130 |
File file = new File(path); |
67 |
if(!file.exists()) |
|
131 |
ArrayList lines = new ArrayList(); |
|
132 |
|
|
133 |
if(create(file)) |
|
68 | 134 |
return null; |
69 | 135 |
|
136 |
//A?adir bloques al fichero. |
|
137 |
BufferedReader inGrf = new BufferedReader(new InputStreamReader(new FileInputStream(file))); |
|
138 |
String str = inGrf.readLine(); |
|
139 |
while(str != null) { |
|
140 |
lines.add(str); |
|
141 |
str = inGrf.readLine(); |
|
142 |
} |
|
143 |
|
|
70 | 144 |
for (int i = 0; i < clients.size(); i++) { |
71 | 145 |
IRmfBlock block = ((IRmfBlock)clients.get(i)); |
72 | 146 |
String tag = block.getMainTag(); |
73 |
|
|
74 |
String s = ((IRmfBlock)clients.get(i)).write(); |
|
75 |
|
|
147 |
|
|
148 |
for (int line = 0; line < lines.size(); line++) { |
|
149 |
str = (String)lines.get(line); |
|
150 |
if(str.compareTo("</" + getMainTag() + ">") == 0 || str.startsWith("<" + tag )) { |
|
151 |
String xmlBlock = block.write(); |
|
152 |
if(line != 0) |
|
153 |
lines.add(line, xmlBlock); |
|
154 |
if(str.startsWith("<" + tag)) { |
|
155 |
while(((String)lines.get(line + 1)).compareTo("</" + tag + ">") != 0) |
|
156 |
lines.remove(line + 1); |
|
157 |
lines.remove(line + 1); |
|
158 |
} |
|
159 |
break; |
|
160 |
} |
|
161 |
} |
|
76 | 162 |
} |
163 |
|
|
164 |
//Escribir fichero de salida. |
|
165 |
file.delete(); |
|
166 |
file.createNewFile(); |
|
167 |
FileWriter writer = new FileWriter(file); |
|
168 |
|
|
169 |
for (int i = 0; i < lines.size(); i++) |
|
170 |
writer.write((String)lines.get(i) + "\n"); |
|
171 |
writer.close(); |
|
172 |
|
|
77 | 173 |
return null; |
78 | 174 |
} |
79 | 175 |
|
... | ... | |
84 | 180 |
public String getMainTag() { |
85 | 181 |
return MAIN_TAG; |
86 | 182 |
} |
183 |
|
|
184 |
/* |
|
185 |
* (non-Javadoc) |
|
186 |
* @see org.gvsig.raster.dataset.io.rmf.IRmfBlock#getResult() |
|
187 |
*/ |
|
188 |
public Object getResult() { |
|
189 |
return null; |
|
190 |
} |
|
87 | 191 |
} |
Also available in: Unified diff