root / trunk / libraries / libRaster / src / org / gvsig / raster / dataset / GeoRasterWriter.java @ 10996
History | View | Annotate | Download (8.16 KB)
1 |
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
|
---|---|
2 |
*
|
3 |
* Copyright (C) 2006 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; |
20 |
|
21 |
import java.io.IOException; |
22 |
import java.lang.reflect.Constructor; |
23 |
import java.lang.reflect.InvocationTargetException; |
24 |
import java.util.Iterator; |
25 |
import java.util.Map; |
26 |
import java.util.Set; |
27 |
import java.util.TreeMap; |
28 |
|
29 |
import org.gvsig.raster.shared.Extent; |
30 |
|
31 |
|
32 |
/**
|
33 |
* Clase abstracta de la que heredan los drivers de escritura. Tiene los
|
34 |
* m?todos abstractos que debe implementar cualquier driver de escritura
|
35 |
* y las funcionalidades y opciones soportadas comunes a todos ellos.
|
36 |
* @author Nacho Brodin (nachobrodin@gmail.com)
|
37 |
*/
|
38 |
public abstract class GeoRasterWriter { |
39 |
|
40 |
public static int blockSizeDefault = 256; |
41 |
|
42 |
private static TreeMap supportedExtensions = null; |
43 |
public static TreeMap typeList = new TreeMap(); |
44 |
protected String outFileName = null; |
45 |
protected String inFileName = null; |
46 |
protected int sizeWindowX = 0; |
47 |
protected int sizeWindowY = 0; |
48 |
protected int ulX = 0; |
49 |
protected int ulY = 0; |
50 |
protected IDataWriter dataWriter = null; |
51 |
protected int nBands = 0; |
52 |
protected String ident = null; |
53 |
protected String driver = null; |
54 |
|
55 |
/**
|
56 |
* Registra un formato de escritura
|
57 |
* @param ext Extensi?n del fichero registrado
|
58 |
* @param clase Clase que maneja el formato registrado
|
59 |
*/
|
60 |
public static void registerWriterExtension(String ext, Class clase) { |
61 |
if (supportedExtensions == null) { |
62 |
supportedExtensions = new TreeMap(); |
63 |
} |
64 |
|
65 |
ext = ext.toLowerCase(); |
66 |
//System.out.println("Write RASTER: extension '" + ext + "' supported.");
|
67 |
supportedExtensions.put(ext, clase); |
68 |
} |
69 |
|
70 |
/**
|
71 |
* Obtiene la lista de extensiones registradas
|
72 |
* @return Lista de extensiones registradas o null si no hay ninguna
|
73 |
*/
|
74 |
public static String[] getDriversExtensions(){ |
75 |
if (supportedExtensions.size() == 0) |
76 |
return null; |
77 |
String[] list = new String[supportedExtensions.size()]; |
78 |
Set values = supportedExtensions.entrySet();
|
79 |
int i = 0; |
80 |
for (Iterator it=values.iterator(); it.hasNext(); ) { |
81 |
list[i] = (String)((Map.Entry)it.next()).getKey(); |
82 |
i++; |
83 |
} |
84 |
|
85 |
return list;
|
86 |
} |
87 |
|
88 |
/**
|
89 |
* Obtiene la lista de tipos de driver
|
90 |
* @return Lista de tipos de driver registradas o null si no hay ninguno
|
91 |
*/
|
92 |
public static String[] getDriversType(){ |
93 |
if (typeList.size() == 0) |
94 |
return null; |
95 |
String[] list = new String[typeList.size()]; |
96 |
Set values = typeList.entrySet();
|
97 |
int i = 0; |
98 |
for (Iterator it=values.iterator(); it.hasNext(); ) { |
99 |
list[i] = (String)((Map.Entry)it.next()).getValue(); |
100 |
i++; |
101 |
} |
102 |
|
103 |
return list;
|
104 |
} |
105 |
|
106 |
/**
|
107 |
* Obtiene el tipo de driver a partir de la extensi?n
|
108 |
* @param ext Extensi?n
|
109 |
* @return Tipo
|
110 |
*/
|
111 |
public static String getDriverType(String ext){ |
112 |
return (String)typeList.get(ext); |
113 |
} |
114 |
|
115 |
/**
|
116 |
* Devuelve el n?mero de drivers soportados
|
117 |
* @return N?mero de drivers soportados
|
118 |
*/
|
119 |
public static int getNDrivers() { |
120 |
return supportedExtensions.size();
|
121 |
} |
122 |
|
123 |
/**
|
124 |
* Devuelve el n?mero de tipos de driver registrados
|
125 |
* @return N?mero de tipos de driver soportados
|
126 |
*/
|
127 |
public static int getNTypes() { |
128 |
return typeList.size();
|
129 |
} |
130 |
|
131 |
/**
|
132 |
* Devuelve el identificador del driver
|
133 |
* @return Identificador del driver
|
134 |
*/
|
135 |
public String getIdent() { |
136 |
return ident;
|
137 |
} |
138 |
|
139 |
/**
|
140 |
* Obtiene el nombre del driver.
|
141 |
* @return Nombre del driver
|
142 |
*/
|
143 |
public String getDriverName() { |
144 |
return driver;
|
145 |
} |
146 |
|
147 |
/**
|
148 |
*
|
149 |
* @return
|
150 |
*/
|
151 |
public String getDriverType() { |
152 |
return driver;
|
153 |
} |
154 |
|
155 |
/**
|
156 |
* Factoria para obtener escritores de los distintos tipos de raster.
|
157 |
*
|
158 |
* @param fName Nombre del fichero.
|
159 |
* @return GeoRasterWriter, o null si hay problemas.
|
160 |
*/
|
161 |
public static GeoRasterWriter getWriter(String fName) { |
162 |
String ext = fName.toLowerCase().substring(fName.lastIndexOf('.')+1); |
163 |
GeoRasterWriter grw = null;
|
164 |
|
165 |
if (!supportedExtensions.containsKey(ext))
|
166 |
return grw;
|
167 |
|
168 |
Class clase = (Class) supportedExtensions.get(ext); |
169 |
Class [] args = {String.class}; |
170 |
try {
|
171 |
Constructor hazNuevo = clase.getConstructor(args);
|
172 |
Object [] args2 = {fName}; |
173 |
grw = (GeoRasterWriter) hazNuevo.newInstance(args2); |
174 |
} catch (SecurityException e) { |
175 |
e.printStackTrace(); |
176 |
} catch (NoSuchMethodException e) { |
177 |
e.printStackTrace(); |
178 |
} catch (IllegalArgumentException e) { |
179 |
e.printStackTrace(); |
180 |
} catch (InstantiationException e) { |
181 |
e.printStackTrace(); |
182 |
} catch (IllegalAccessException e) { |
183 |
e.printStackTrace(); |
184 |
} catch (InvocationTargetException e) { |
185 |
e.printStackTrace(); |
186 |
} |
187 |
return grw;
|
188 |
} |
189 |
|
190 |
/**
|
191 |
* Factoria para obtener escritores de los distintos tipos de raster.
|
192 |
*
|
193 |
* @param fName Nombre del fichero.
|
194 |
* @return GeoRasterWriter, o null si hay problemas.
|
195 |
*/
|
196 |
public static GeoRasterWriter getWriter(IDataWriter dataWriter, |
197 |
String outFileName,
|
198 |
int blockSize,
|
199 |
int nBands,
|
200 |
Extent ex, |
201 |
int compresion,
|
202 |
int outSizeX,
|
203 |
int outSizeY,
|
204 |
int dataType) {
|
205 |
String ext = outFileName.toLowerCase().substring(outFileName.lastIndexOf('.')+1); |
206 |
GeoRasterWriter grw = null;
|
207 |
|
208 |
if (!supportedExtensions.containsKey(ext))
|
209 |
return grw;
|
210 |
|
211 |
Class clase = (Class) supportedExtensions.get(ext); |
212 |
Class [] args = {IDataWriter.class, String.class, Integer.class, Integer.class, |
213 |
Extent.class, Integer.class, Integer.class, Integer.class, Integer.class}; |
214 |
try {
|
215 |
Constructor hazNuevo = clase.getConstructor(args);
|
216 |
Object [] args2 = {dataWriter, outFileName, new Integer(blockSize), new Integer(nBands), |
217 |
ex, new Integer(compresion), new Integer(outSizeX), new Integer(outSizeY), new Integer(dataType)}; |
218 |
grw = (GeoRasterWriter) hazNuevo.newInstance(args2); |
219 |
} catch (SecurityException e) { |
220 |
e.printStackTrace(); |
221 |
} catch (NoSuchMethodException e) { |
222 |
e.printStackTrace(); |
223 |
} catch (IllegalArgumentException e) { |
224 |
e.printStackTrace(); |
225 |
} catch (InstantiationException e) { |
226 |
e.printStackTrace(); |
227 |
} catch (IllegalAccessException e) { |
228 |
e.printStackTrace(); |
229 |
} catch (InvocationTargetException e) { |
230 |
e.printStackTrace(); |
231 |
} |
232 |
return grw;
|
233 |
} |
234 |
|
235 |
/**
|
236 |
* Asigna propiedades al driver a partir de un vector de
|
237 |
* strings donde cada elemento tiene la estructura de
|
238 |
* propiedad=valor.
|
239 |
* @param props Propiedades
|
240 |
*/
|
241 |
public abstract void setProps(String[] props); |
242 |
|
243 |
/**
|
244 |
* Realiza la funci?n de compresi?n a partir de un GeoRasterFile.
|
245 |
* @throws IOException
|
246 |
*/
|
247 |
public abstract void fileWrite() throws IOException; |
248 |
|
249 |
/**
|
250 |
* Realiza la funci?n de compresi?n a partir de los datos pasados por el cliente.
|
251 |
* @throws IOException
|
252 |
*/
|
253 |
public abstract void dataWrite() throws IOException; |
254 |
|
255 |
/**
|
256 |
* Cierra el driver
|
257 |
*/
|
258 |
public abstract void writeClose(); |
259 |
|
260 |
/**
|
261 |
* Cancela el grabado de datos
|
262 |
*/
|
263 |
public abstract void writeCancel(); |
264 |
|
265 |
/**
|
266 |
* Devuelve la configuraci?n de la ventana de dialogo
|
267 |
* para las propiedades del driver de escritura que se est? tratando.
|
268 |
* @return Texto XML con las propiedades
|
269 |
*/
|
270 |
public abstract String getXMLPropertiesDialog(); |
271 |
} |