svn-gvsig-desktop / tags / v1_1_Build_1002 / libraries / libCq_CMS_praster / src / org / cresques / io / GeoRasterWriter.java @ 12070
History | View | Annotate | Download (9.86 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 | |||
63 | /**
|
||
64 | * Registra un formato de escritura
|
||
65 | * @param ext Extensi?n del fichero registrado
|
||
66 | * @param clase Clase que maneja el formato registrado
|
||
67 | */
|
||
68 | public static void registerWriterExtension(String ext, Class clase) { |
||
69 | if (supportedExtensions == null) { |
||
70 | supportedExtensions = new TreeMap(); |
||
71 | } |
||
72 | |||
73 | ext = ext.toLowerCase(); |
||
74 | System.out.println("Write RASTER: extension '" + ext + "' supported."); |
||
75 | supportedExtensions.put(ext, clase); |
||
76 | } |
||
77 | |||
78 | /**
|
||
79 | * Obtiene la lista de extensiones registradas
|
||
80 | * @return Lista de extensiones registradas o null si no hay ninguna
|
||
81 | */
|
||
82 | public static String[] getDriversExtensions(){ |
||
83 | if (supportedExtensions.size() == 0) |
||
84 | return null; |
||
85 | String[] list = new String[supportedExtensions.size()]; |
||
86 | Set values = supportedExtensions.entrySet();
|
||
87 | int i = 0; |
||
88 | for (Iterator it=values.iterator(); it.hasNext(); ) { |
||
89 | list[i] = (String)((Map.Entry)it.next()).getKey(); |
||
90 | i++; |
||
91 | } |
||
92 | |||
93 | return list;
|
||
94 | } |
||
95 | |||
96 | /**
|
||
97 | * Obtiene la lista de tipos de driver
|
||
98 | * @return Lista de tipos de driver registradas o null si no hay ninguno
|
||
99 | */
|
||
100 | public static String[] getDriversType(){ |
||
101 | if (typeList.size() == 0) |
||
102 | return null; |
||
103 | String[] list = new String[typeList.size()]; |
||
104 | Set values = typeList.entrySet();
|
||
105 | int i = 0; |
||
106 | for (Iterator it=values.iterator(); it.hasNext(); ) { |
||
107 | list[i] = (String)((Map.Entry)it.next()).getValue(); |
||
108 | i++; |
||
109 | } |
||
110 | |||
111 | return list;
|
||
112 | } |
||
113 | |||
114 | /**
|
||
115 | * Obtiene el tipo de driver a partir de la extensi?n
|
||
116 | * @param ext Extensi?n
|
||
117 | * @return Tipo
|
||
118 | */
|
||
119 | public static String getDriverType(String ext){ |
||
120 | return (String)typeList.get(ext); |
||
121 | } |
||
122 | |||
123 | /**
|
||
124 | * Devuelve el n?mero de drivers soportados
|
||
125 | * @return N?mero de drivers soportados
|
||
126 | */
|
||
127 | public static int getNDrivers() { |
||
128 | return supportedExtensions.size();
|
||
129 | } |
||
130 | |||
131 | /**
|
||
132 | * Devuelve el n?mero de tipos de driver registrados
|
||
133 | * @return N?mero de tipos de driver soportados
|
||
134 | */
|
||
135 | public static int getNTypes() { |
||
136 | return typeList.size();
|
||
137 | } |
||
138 | |||
139 | /**
|
||
140 | * Devuelve el identificador del driver
|
||
141 | * @return Identificador del driver
|
||
142 | */
|
||
143 | public String getIdent() { |
||
144 | return ident;
|
||
145 | } |
||
146 | |||
147 | /**
|
||
148 | * Obtiene el nombre del driver.
|
||
149 | * @return Nombre del driver
|
||
150 | */
|
||
151 | public String getDriverName() { |
||
152 | return driver;
|
||
153 | } |
||
154 | |||
155 | /**
|
||
156 | *
|
||
157 | * @return
|
||
158 | */
|
||
159 | public String getDriverType() { |
||
160 | return driver;
|
||
161 | } |
||
162 | |||
163 | /**
|
||
164 | * Factoria para obtener escritores de los distintos tipos de raster.
|
||
165 | *
|
||
166 | * @param fName Nombre del fichero.
|
||
167 | * @return GeoRasterWriter, o null si hay problemas.
|
||
168 | */
|
||
169 | public static GeoRasterWriter getWriter(String fName) { |
||
170 | String ext = fName.toLowerCase().substring(fName.lastIndexOf('.')+1); |
||
171 | GeoRasterWriter grw = null;
|
||
172 | |||
173 | if (!supportedExtensions.containsKey(ext))
|
||
174 | return grw;
|
||
175 | |||
176 | Class clase = (Class) supportedExtensions.get(ext); |
||
177 | Class [] args = {String.class}; |
||
178 | try {
|
||
179 | Constructor hazNuevo = clase.getConstructor(args);
|
||
180 | Object [] args2 = {fName}; |
||
181 | grw = (GeoRasterWriter) hazNuevo.newInstance(args2); |
||
182 | } catch (SecurityException e) { |
||
183 | e.printStackTrace(); |
||
184 | } catch (NoSuchMethodException e) { |
||
185 | e.printStackTrace(); |
||
186 | } catch (IllegalArgumentException e) { |
||
187 | e.printStackTrace(); |
||
188 | } catch (InstantiationException e) { |
||
189 | e.printStackTrace(); |
||
190 | } catch (IllegalAccessException e) { |
||
191 | e.printStackTrace(); |
||
192 | } catch (InvocationTargetException e) { |
||
193 | e.printStackTrace(); |
||
194 | } |
||
195 | return grw;
|
||
196 | } |
||
197 | |||
198 | /**
|
||
199 | * Factoria para obtener escritores de los distintos tipos de raster.
|
||
200 | *
|
||
201 | * @param fName Nombre del fichero.
|
||
202 | * @return GeoRasterWriter, o null si hay problemas.
|
||
203 | */
|
||
204 | public static GeoRasterWriter getWriter(IDataWriter dataWriter, |
||
205 | String outFileName,
|
||
206 | int blockSize,
|
||
207 | int nBands,
|
||
208 | ViewPortData vp, |
||
209 | int compresion,
|
||
210 | int outSizeX,
|
||
211 | int outSizeY,
|
||
212 | int dataType) {
|
||
213 | String ext = outFileName.toLowerCase().substring(outFileName.lastIndexOf('.')+1); |
||
214 | GeoRasterWriter grw = null;
|
||
215 | |||
216 | if (!supportedExtensions.containsKey(ext))
|
||
217 | return grw;
|
||
218 | |||
219 | Class clase = (Class) supportedExtensions.get(ext); |
||
220 | Class [] args = {IDataWriter.class, String.class, Integer.class, Integer.class, |
||
221 | ViewPortData.class, Integer.class, Integer.class, Integer.class, Integer.class}; |
||
222 | try {
|
||
223 | Constructor hazNuevo = clase.getConstructor(args);
|
||
224 | Object [] args2 = {dataWriter, outFileName, new Integer(blockSize), new Integer(nBands), |
||
225 | vp, new Integer(compresion), new Integer(outSizeX), new Integer(outSizeY), new Integer(dataType)}; |
||
226 | grw = (GeoRasterWriter) hazNuevo.newInstance(args2); |
||
227 | } catch (SecurityException e) { |
||
228 | e.printStackTrace(); |
||
229 | } catch (NoSuchMethodException e) { |
||
230 | e.printStackTrace(); |
||
231 | } catch (IllegalArgumentException e) { |
||
232 | e.printStackTrace(); |
||
233 | } catch (InstantiationException e) { |
||
234 | e.printStackTrace(); |
||
235 | } catch (IllegalAccessException e) { |
||
236 | e.printStackTrace(); |
||
237 | } catch (InvocationTargetException e) { |
||
238 | e.printStackTrace(); |
||
239 | } |
||
240 | return grw;
|
||
241 | } |
||
242 | 10645 | nacho | |
243 | /**
|
||
244 | * Factoria para obtener escritores de los distintos tipos de raster.
|
||
245 | *
|
||
246 | * @param fName Nombre del fichero.
|
||
247 | * @return GeoRasterWriter, o null si hay problemas.
|
||
248 | */
|
||
249 | public static GeoRasterWriter getWriter(IDataWriter dataWriter, |
||
250 | String outFileName,
|
||
251 | int blockSize,
|
||
252 | int nBands,
|
||
253 | Extent ex, |
||
254 | int compresion,
|
||
255 | int outSizeX,
|
||
256 | int outSizeY,
|
||
257 | int dataType) {
|
||
258 | String ext = outFileName.toLowerCase().substring(outFileName.lastIndexOf('.')+1); |
||
259 | GeoRasterWriter grw = null;
|
||
260 | |||
261 | if (!supportedExtensions.containsKey(ext))
|
||
262 | return grw;
|
||
263 | |||
264 | Class clase = (Class) supportedExtensions.get(ext); |
||
265 | Class [] args = {IDataWriter.class, String.class, Integer.class, Integer.class, |
||
266 | Extent.class, Integer.class, Integer.class, Integer.class, Integer.class}; |
||
267 | try {
|
||
268 | Constructor hazNuevo = clase.getConstructor(args);
|
||
269 | Object [] args2 = {dataWriter, outFileName, new Integer(blockSize), new Integer(nBands), |
||
270 | ex, new Integer(compresion), new Integer(outSizeX), new Integer(outSizeY), new Integer(dataType)}; |
||
271 | grw = (GeoRasterWriter) hazNuevo.newInstance(args2); |
||
272 | } catch (SecurityException e) { |
||
273 | e.printStackTrace(); |
||
274 | } catch (NoSuchMethodException e) { |
||
275 | e.printStackTrace(); |
||
276 | } catch (IllegalArgumentException e) { |
||
277 | e.printStackTrace(); |
||
278 | } catch (InstantiationException e) { |
||
279 | e.printStackTrace(); |
||
280 | } catch (IllegalAccessException e) { |
||
281 | e.printStackTrace(); |
||
282 | } catch (InvocationTargetException e) { |
||
283 | e.printStackTrace(); |
||
284 | } |
||
285 | return grw;
|
||
286 | } |
||
287 | 8026 | nacho | |
288 | /**
|
||
289 | * Asigna propiedades al driver a partir de un vector de
|
||
290 | * strings donde cada elemento tiene la estructura de
|
||
291 | * propiedad=valor.
|
||
292 | * @param props Propiedades
|
||
293 | */
|
||
294 | public abstract void setProps(String[] props); |
||
295 | |||
296 | /**
|
||
297 | * Realiza la funci?n de compresi?n a partir de un GeoRasterFile.
|
||
298 | * @throws IOException
|
||
299 | */
|
||
300 | public abstract void fileWrite() throws IOException; |
||
301 | |||
302 | /**
|
||
303 | * Realiza la funci?n de compresi?n a partir de los datos pasados por el cliente.
|
||
304 | * @throws IOException
|
||
305 | */
|
||
306 | public abstract void dataWrite() throws IOException; |
||
307 | |||
308 | /**
|
||
309 | * Cierra el driver
|
||
310 | */
|
||
311 | public abstract void writeClose(); |
||
312 | |||
313 | /**
|
||
314 | * Cancela el grabado de datos
|
||
315 | */
|
||
316 | public abstract void writeCancel(); |
||
317 | |||
318 | /**
|
||
319 | * Devuelve la configuraci?n de la ventana de dialogo
|
||
320 | * para las propiedades del driver de escritura que se est? tratando.
|
||
321 | * @return Texto XML con las propiedades
|
||
322 | */
|
||
323 | public abstract String getXMLPropertiesDialog(); |
||
324 | } |