svn-gvsig-desktop / tags / v1_1_Build_1013 / libraries / libCq_CMS_praster / src / org / cresques / io / GeoRasterWriter.java @ 13521
History | View | Annotate | Download (10.1 KB)
1 | 8026 | nacho | /*
|
---|---|---|---|
2 | * Cresques Mapping Suite. Graphic Library for constructing mapping applications.
|
||
3 | *
|
||
4 | * Copyright (C) 2004-5.
|
||
5 | *
|
||
6 | * This program is free software; you can redistribute it and/or
|
||
7 | * modify it under the terms of the GNU General Public License
|
||
8 | * as published by the Free Software Foundation; either version 2
|
||
9 | * of the License, or (at your option) any later version.
|
||
10 | *
|
||
11 | * This program is distributed in the hope that it will be useful,
|
||
12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||
13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||
14 | * GNU General Public License for more details.
|
||
15 | *
|
||
16 | * You should have received a copy of the GNU General Public License
|
||
17 | * along with this program; if not, write to the Free Software
|
||
18 | * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,USA.
|
||
19 | *
|
||
20 | * For more information, contact:
|
||
21 | *
|
||
22 | * cresques@gmail.com
|
||
23 | */
|
||
24 | package org.cresques.io; |
||
25 | |||
26 | import java.io.IOException; |
||
27 | import java.lang.reflect.Constructor; |
||
28 | import java.lang.reflect.InvocationTargetException; |
||
29 | import java.util.Iterator; |
||
30 | import java.util.Map; |
||
31 | import java.util.Set; |
||
32 | import java.util.TreeMap; |
||
33 | |||
34 | import org.cresques.geo.ViewPortData; |
||
35 | 10645 | nacho | import org.cresques.px.Extent; |
36 | 8026 | nacho | import org.cresques.px.PxRaster; |
37 | |||
38 | |||
39 | /**
|
||
40 | * Clase abstracta de la que heredan los drivers de escritura. Tiene los
|
||
41 | * m?todos abstractos que debe implementar cualquier driver de escritura
|
||
42 | * y las funcionalidades y opciones soportadas comunes a todos ellos.
|
||
43 | * @author Nacho Brodin (brodin_ign@gva.es)
|
||
44 | */
|
||
45 | public abstract class GeoRasterWriter { |
||
46 | |||
47 | public static int blockSizeDefault = 256; |
||
48 | |||
49 | private static TreeMap supportedExtensions = null; |
||
50 | protected static TreeMap typeList = new TreeMap(); |
||
51 | protected String outFileName = null; |
||
52 | protected String inFileName = null; |
||
53 | protected int sizeWindowX = 0; |
||
54 | protected int sizeWindowY = 0; |
||
55 | protected int ulX = 0; |
||
56 | protected int ulY = 0; |
||
57 | protected PxRaster currentRaster;
|
||
58 | protected IDataWriter dataWriter = null; |
||
59 | protected int nBands = 0; |
||
60 | protected String ident = null; |
||
61 | protected String driver = null; |
||
62 | 12080 | nacho | protected static boolean writeTfw = true; |
63 | 8026 | nacho | |
64 | /**
|
||
65 | * Registra un formato de escritura
|
||
66 | * @param ext Extensi?n del fichero registrado
|
||
67 | * @param clase Clase que maneja el formato registrado
|
||
68 | */
|
||
69 | public static void registerWriterExtension(String ext, Class clase) { |
||
70 | if (supportedExtensions == null) { |
||
71 | supportedExtensions = new TreeMap(); |
||
72 | } |
||
73 | |||
74 | ext = ext.toLowerCase(); |
||
75 | System.out.println("Write RASTER: extension '" + ext + "' supported."); |
||
76 | supportedExtensions.put(ext, clase); |
||
77 | } |
||
78 | |||
79 | /**
|
||
80 | * Obtiene la lista de extensiones registradas
|
||
81 | * @return Lista de extensiones registradas o null si no hay ninguna
|
||
82 | */
|
||
83 | public static String[] getDriversExtensions(){ |
||
84 | if (supportedExtensions.size() == 0) |
||
85 | return null; |
||
86 | String[] list = new String[supportedExtensions.size()]; |
||
87 | Set values = supportedExtensions.entrySet();
|
||
88 | int i = 0; |
||
89 | for (Iterator it=values.iterator(); it.hasNext(); ) { |
||
90 | list[i] = (String)((Map.Entry)it.next()).getKey(); |
||
91 | i++; |
||
92 | } |
||
93 | |||
94 | return list;
|
||
95 | } |
||
96 | |||
97 | /**
|
||
98 | 12080 | nacho | * Pone a true o false el flag que dice si se escribir? o no
|
99 | * el fichero de georreferenciaci?n.
|
||
100 | * @param write
|
||
101 | */
|
||
102 | public void setWriteTfw(boolean write) { |
||
103 | writeTfw = write; |
||
104 | } |
||
105 | |||
106 | /**
|
||
107 | 8026 | nacho | * Obtiene la lista de tipos de driver
|
108 | * @return Lista de tipos de driver registradas o null si no hay ninguno
|
||
109 | */
|
||
110 | public static String[] getDriversType(){ |
||
111 | if (typeList.size() == 0) |
||
112 | return null; |
||
113 | String[] list = new String[typeList.size()]; |
||
114 | Set values = typeList.entrySet();
|
||
115 | int i = 0; |
||
116 | for (Iterator it=values.iterator(); it.hasNext(); ) { |
||
117 | list[i] = (String)((Map.Entry)it.next()).getValue(); |
||
118 | i++; |
||
119 | } |
||
120 | |||
121 | return list;
|
||
122 | } |
||
123 | |||
124 | /**
|
||
125 | * Obtiene el tipo de driver a partir de la extensi?n
|
||
126 | * @param ext Extensi?n
|
||
127 | * @return Tipo
|
||
128 | */
|
||
129 | public static String getDriverType(String ext){ |
||
130 | return (String)typeList.get(ext); |
||
131 | } |
||
132 | |||
133 | /**
|
||
134 | * Devuelve el n?mero de drivers soportados
|
||
135 | * @return N?mero de drivers soportados
|
||
136 | */
|
||
137 | public static int getNDrivers() { |
||
138 | return supportedExtensions.size();
|
||
139 | } |
||
140 | |||
141 | /**
|
||
142 | * Devuelve el n?mero de tipos de driver registrados
|
||
143 | * @return N?mero de tipos de driver soportados
|
||
144 | */
|
||
145 | public static int getNTypes() { |
||
146 | return typeList.size();
|
||
147 | } |
||
148 | |||
149 | /**
|
||
150 | * Devuelve el identificador del driver
|
||
151 | * @return Identificador del driver
|
||
152 | */
|
||
153 | public String getIdent() { |
||
154 | return ident;
|
||
155 | } |
||
156 | |||
157 | /**
|
||
158 | * Obtiene el nombre del driver.
|
||
159 | * @return Nombre del driver
|
||
160 | */
|
||
161 | public String getDriverName() { |
||
162 | return driver;
|
||
163 | } |
||
164 | |||
165 | /**
|
||
166 | *
|
||
167 | * @return
|
||
168 | */
|
||
169 | public String getDriverType() { |
||
170 | return driver;
|
||
171 | } |
||
172 | |||
173 | /**
|
||
174 | * Factoria para obtener escritores de los distintos tipos de raster.
|
||
175 | *
|
||
176 | * @param fName Nombre del fichero.
|
||
177 | * @return GeoRasterWriter, o null si hay problemas.
|
||
178 | */
|
||
179 | public static GeoRasterWriter getWriter(String fName) { |
||
180 | String ext = fName.toLowerCase().substring(fName.lastIndexOf('.')+1); |
||
181 | GeoRasterWriter grw = null;
|
||
182 | |||
183 | if (!supportedExtensions.containsKey(ext))
|
||
184 | return grw;
|
||
185 | |||
186 | Class clase = (Class) supportedExtensions.get(ext); |
||
187 | Class [] args = {String.class}; |
||
188 | try {
|
||
189 | Constructor hazNuevo = clase.getConstructor(args);
|
||
190 | Object [] args2 = {fName}; |
||
191 | grw = (GeoRasterWriter) hazNuevo.newInstance(args2); |
||
192 | } catch (SecurityException e) { |
||
193 | e.printStackTrace(); |
||
194 | } catch (NoSuchMethodException e) { |
||
195 | e.printStackTrace(); |
||
196 | } catch (IllegalArgumentException e) { |
||
197 | e.printStackTrace(); |
||
198 | } catch (InstantiationException e) { |
||
199 | e.printStackTrace(); |
||
200 | } catch (IllegalAccessException e) { |
||
201 | e.printStackTrace(); |
||
202 | } catch (InvocationTargetException e) { |
||
203 | e.printStackTrace(); |
||
204 | } |
||
205 | return grw;
|
||
206 | } |
||
207 | |||
208 | /**
|
||
209 | * Factoria para obtener escritores de los distintos tipos de raster.
|
||
210 | *
|
||
211 | * @param fName Nombre del fichero.
|
||
212 | * @return GeoRasterWriter, o null si hay problemas.
|
||
213 | */
|
||
214 | public static GeoRasterWriter getWriter(IDataWriter dataWriter, |
||
215 | String outFileName,
|
||
216 | int blockSize,
|
||
217 | int nBands,
|
||
218 | ViewPortData vp, |
||
219 | int compresion,
|
||
220 | int outSizeX,
|
||
221 | int outSizeY,
|
||
222 | int dataType) {
|
||
223 | String ext = outFileName.toLowerCase().substring(outFileName.lastIndexOf('.')+1); |
||
224 | GeoRasterWriter grw = null;
|
||
225 | |||
226 | if (!supportedExtensions.containsKey(ext))
|
||
227 | return grw;
|
||
228 | |||
229 | Class clase = (Class) supportedExtensions.get(ext); |
||
230 | Class [] args = {IDataWriter.class, String.class, Integer.class, Integer.class, |
||
231 | ViewPortData.class, Integer.class, Integer.class, Integer.class, Integer.class}; |
||
232 | try {
|
||
233 | Constructor hazNuevo = clase.getConstructor(args);
|
||
234 | Object [] args2 = {dataWriter, outFileName, new Integer(blockSize), new Integer(nBands), |
||
235 | vp, new Integer(compresion), new Integer(outSizeX), new Integer(outSizeY), new Integer(dataType)}; |
||
236 | grw = (GeoRasterWriter) hazNuevo.newInstance(args2); |
||
237 | } catch (SecurityException e) { |
||
238 | e.printStackTrace(); |
||
239 | } catch (NoSuchMethodException e) { |
||
240 | e.printStackTrace(); |
||
241 | } catch (IllegalArgumentException e) { |
||
242 | e.printStackTrace(); |
||
243 | } catch (InstantiationException e) { |
||
244 | e.printStackTrace(); |
||
245 | } catch (IllegalAccessException e) { |
||
246 | e.printStackTrace(); |
||
247 | } catch (InvocationTargetException e) { |
||
248 | e.printStackTrace(); |
||
249 | } |
||
250 | return grw;
|
||
251 | } |
||
252 | 10645 | nacho | |
253 | /**
|
||
254 | * Factoria para obtener escritores de los distintos tipos de raster.
|
||
255 | *
|
||
256 | * @param fName Nombre del fichero.
|
||
257 | * @return GeoRasterWriter, o null si hay problemas.
|
||
258 | */
|
||
259 | public static GeoRasterWriter getWriter(IDataWriter dataWriter, |
||
260 | String outFileName,
|
||
261 | int blockSize,
|
||
262 | int nBands,
|
||
263 | Extent ex, |
||
264 | int compresion,
|
||
265 | int outSizeX,
|
||
266 | int outSizeY,
|
||
267 | int dataType) {
|
||
268 | String ext = outFileName.toLowerCase().substring(outFileName.lastIndexOf('.')+1); |
||
269 | GeoRasterWriter grw = null;
|
||
270 | |||
271 | if (!supportedExtensions.containsKey(ext))
|
||
272 | return grw;
|
||
273 | |||
274 | Class clase = (Class) supportedExtensions.get(ext); |
||
275 | Class [] args = {IDataWriter.class, String.class, Integer.class, Integer.class, |
||
276 | Extent.class, Integer.class, Integer.class, Integer.class, Integer.class}; |
||
277 | try {
|
||
278 | Constructor hazNuevo = clase.getConstructor(args);
|
||
279 | Object [] args2 = {dataWriter, outFileName, new Integer(blockSize), new Integer(nBands), |
||
280 | ex, new Integer(compresion), new Integer(outSizeX), new Integer(outSizeY), new Integer(dataType)}; |
||
281 | grw = (GeoRasterWriter) hazNuevo.newInstance(args2); |
||
282 | } catch (SecurityException e) { |
||
283 | e.printStackTrace(); |
||
284 | } catch (NoSuchMethodException e) { |
||
285 | e.printStackTrace(); |
||
286 | } catch (IllegalArgumentException e) { |
||
287 | e.printStackTrace(); |
||
288 | } catch (InstantiationException e) { |
||
289 | e.printStackTrace(); |
||
290 | } catch (IllegalAccessException e) { |
||
291 | e.printStackTrace(); |
||
292 | } catch (InvocationTargetException e) { |
||
293 | e.printStackTrace(); |
||
294 | } |
||
295 | return grw;
|
||
296 | } |
||
297 | 8026 | nacho | |
298 | /**
|
||
299 | * Asigna propiedades al driver a partir de un vector de
|
||
300 | * strings donde cada elemento tiene la estructura de
|
||
301 | * propiedad=valor.
|
||
302 | * @param props Propiedades
|
||
303 | */
|
||
304 | public abstract void setProps(String[] props); |
||
305 | |||
306 | /**
|
||
307 | * Realiza la funci?n de compresi?n a partir de un GeoRasterFile.
|
||
308 | * @throws IOException
|
||
309 | */
|
||
310 | public abstract void fileWrite() throws IOException; |
||
311 | |||
312 | /**
|
||
313 | * Realiza la funci?n de compresi?n a partir de los datos pasados por el cliente.
|
||
314 | * @throws IOException
|
||
315 | */
|
||
316 | public abstract void dataWrite() throws IOException; |
||
317 | |||
318 | /**
|
||
319 | * Cierra el driver
|
||
320 | */
|
||
321 | public abstract void writeClose(); |
||
322 | |||
323 | /**
|
||
324 | * Cancela el grabado de datos
|
||
325 | */
|
||
326 | public abstract void writeCancel(); |
||
327 | |||
328 | /**
|
||
329 | * Devuelve la configuraci?n de la ventana de dialogo
|
||
330 | * para las propiedades del driver de escritura que se est? tratando.
|
||
331 | * @return Texto XML con las propiedades
|
||
332 | */
|
||
333 | public abstract String getXMLPropertiesDialog(); |
||
334 | } |