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