svn-gvsig-desktop / trunk / libraries / libRaster / src / org / gvsig / raster / dataset / io / GdalWriter.java @ 11453
History | View | Annotate | Download (24.1 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.io; |
20 |
|
21 |
import java.io.IOException; |
22 |
|
23 |
import org.cresques.cts.IProjection; |
24 |
import org.gvsig.raster.buffer.RasterBuffer; |
25 |
import org.gvsig.raster.dataset.GeoRasterWriter; |
26 |
import org.gvsig.raster.dataset.IDataWriter; |
27 |
import org.gvsig.raster.dataset.NotSupportedExtensionException; |
28 |
import org.gvsig.raster.dataset.WriterParams; |
29 |
import org.gvsig.raster.shared.Extent; |
30 |
import org.gvsig.raster.util.RasterUtilities; |
31 |
import org.gvsig.raster.util.extensionPoints.ExtensionPoints; |
32 |
import org.gvsig.raster.util.extensionPoints.ExtensionPointsSingleton; |
33 |
|
34 |
import es.gva.cit.jgdal.Gdal; |
35 |
import es.gva.cit.jgdal.GdalBuffer; |
36 |
import es.gva.cit.jgdal.GdalException; |
37 |
import es.gva.cit.jgdal.GdalRasterBand; |
38 |
import es.gva.cit.jgdal.GeoTransform; |
39 |
|
40 |
|
41 |
/**
|
42 |
* Driver para la escritura a trav?s de Gdal.
|
43 |
* Puede exportar un fichero de un formato a otro desde un GeoRasterFile
|
44 |
* en cualquier formato soportado por la lectura a un formato que este incluido
|
45 |
* en la lista supportedDrv.
|
46 |
*
|
47 |
* Puede salvar a disco en un formato que este incluido en la lista supportedDrv
|
48 |
* obteniendo los datos que van siendo servidos desde el cliente. Este cliente
|
49 |
* debe implementar un IDataWriter o tener un objeto que lo implemente. Inicialmente
|
50 |
* le pasar? los par?metros de la imagen de salida y cuando el driver comience a
|
51 |
* escribir le ir? solicitando m?s a trav?s del m?todo readData de IDataWriter.
|
52 |
* El cliente ser? el que lleve el control de lo que va sirviendo y lo que le queda
|
53 |
* por servir.
|
54 |
* @author Nacho Brodin (nachobrodin@gmail.com)
|
55 |
*/
|
56 |
public class GdalWriter extends GeoRasterWriter { |
57 |
|
58 |
static {
|
59 |
ExtensionPoints extensionPoints = ExtensionPointsSingleton.getInstance(); |
60 |
extensionPoints.add("RasterWriter", "tif", GdalWriter.class); |
61 |
typeList.put("tif", "GTiff"); |
62 |
} |
63 |
|
64 |
private es.gva.cit.jgdal.GdalDriver drv;
|
65 |
private Gdal dset_destino = null; |
66 |
private GdalRasterBand rband = null; |
67 |
private GeoTransform geot = null; //Datos de georeferenciaci?n |
68 |
//private OGRSpatialReference oSRS; //Datos de proyecci?n
|
69 |
private GdalBuffer[] bufBands = null; |
70 |
private int nBlocks = 0; //N?mero de bloques en Y en el que se divide la imagen para escribir |
71 |
private int anchoResto = 0; //Tama?o del ?ltimo bloque de la imagen. |
72 |
private String[] params = null; //Par?metros de creaci?n del dataset. |
73 |
private boolean consulta = false; |
74 |
private boolean write = true; //Cuando est? a true se puede escribir en la imagen de salida. Si est? a false el proceso es interrumpido |
75 |
private int dataType = RasterBuffer.TYPE_UNDEFINED; |
76 |
|
77 |
/**
|
78 |
* Carga los par?metros de este driver.
|
79 |
*/
|
80 |
public void loadParams() { |
81 |
super.loadParams();
|
82 |
|
83 |
driverParams.setParam( "photometric",
|
84 |
"RGB",
|
85 |
WriterParams.CHOICE, |
86 |
new String[]{"YCBR", "MINISBLACK", "MINISWHITE", "RGB", "CMYK", "CIELAB", "ICCLAB", "ITULAB", "CBCR"}); |
87 |
|
88 |
driverParams.setParam( "interleave",
|
89 |
"BAND",
|
90 |
WriterParams.CHOICE, |
91 |
new String[]{ "BAND", "PIXEL"}); |
92 |
|
93 |
driverParams.setParam( "compression",
|
94 |
"NONE",
|
95 |
WriterParams.CHOICE, |
96 |
new String[]{"LZW", "PACKBITS", "DEFLATE", "NONE"}); |
97 |
|
98 |
driverParams.setParam( "tfw",
|
99 |
"false",
|
100 |
WriterParams.CHECK, |
101 |
null);
|
102 |
} |
103 |
|
104 |
/**
|
105 |
* Constructor para la obtenci?n de par?metros del driver
|
106 |
* @param drvType Tipo de driver
|
107 |
*/
|
108 |
public GdalWriter(String fileName) { |
109 |
ident = RasterUtilities.getExtensionFromFileName(fileName); |
110 |
driver = (String)typeList.get(ident);
|
111 |
|
112 |
loadParams(); |
113 |
|
114 |
consulta = true;
|
115 |
} |
116 |
|
117 |
/**
|
118 |
* Constructor para salvar datos servidos por el cliente
|
119 |
* @param dataWriter Objeto servidor de datos para el driver de escritura
|
120 |
* @param outFilename Fichero de salida
|
121 |
* @param blockSize Tama?o de bloque
|
122 |
* @param Extent extent
|
123 |
* @param compresion Compresi?n si la tiene
|
124 |
* @param outSizeX Tama?o de salida en X
|
125 |
* @param outSizeY Tama?o de salida en Y
|
126 |
* @param dataType Tipo de dato
|
127 |
* @throws GdalException
|
128 |
* @throws IOException
|
129 |
*/
|
130 |
public GdalWriter( IDataWriter dataWriter,
|
131 |
String outFileName,
|
132 |
Integer nBands,
|
133 |
Extent ex, |
134 |
Integer outSizeX,
|
135 |
Integer outSizeY,
|
136 |
Integer dataType,
|
137 |
WriterParams params)throws GdalException, IOException { |
138 |
|
139 |
ident = outFileName.toLowerCase().substring(outFileName.lastIndexOf(".") + 1); |
140 |
driver = (String)typeList.get(ident);
|
141 |
this.dataType = dataType.intValue();
|
142 |
this.extent = ex;
|
143 |
|
144 |
this.dataWriter = dataWriter;
|
145 |
this.outFileName = outFileName;
|
146 |
|
147 |
this.sizeWindowX = outSizeX.intValue();
|
148 |
this.sizeWindowY = outSizeY.intValue();
|
149 |
|
150 |
if ((sizeWindowX < 0) || (sizeWindowY < 0)) |
151 |
throw new IOException("Tama?o del fichero de salida erroneo."); |
152 |
|
153 |
this.nBands = nBands.intValue();
|
154 |
|
155 |
//Calculamos la georeferenciaci?n a partir del extend pasado por el cliente.
|
156 |
|
157 |
double maxX = ex.maxX();
|
158 |
double minX = ex.minX();
|
159 |
double maxY = ex.maxY();
|
160 |
double minY = ex.minY();
|
161 |
|
162 |
geot = new GeoTransform();
|
163 |
geot.adfgeotransform[0] = minX;
|
164 |
geot.adfgeotransform[3] = maxY; //-((pixelSizeY * outSizeY)-minY); |
165 |
geot.adfgeotransform[1] = (double) ((maxX - minX) / outSizeX.intValue()); //pixelSizeX; |
166 |
geot.adfgeotransform[5] = (double) ((minY - maxY) / outSizeY.intValue()); //pixelSizeY; |
167 |
|
168 |
if(params == null) |
169 |
loadParams(); |
170 |
else
|
171 |
this.driverParams = params;
|
172 |
|
173 |
init(); |
174 |
} |
175 |
|
176 |
/**
|
177 |
* Asigna el tipo de driver con el que se salvar? la imagen
|
178 |
* @param drvType Tipo de driver
|
179 |
*/
|
180 |
public void setDriverType(String drvType) { |
181 |
this.driver = drvType;
|
182 |
} |
183 |
|
184 |
/**
|
185 |
* Creaci?n del dataset de destino.
|
186 |
* @throws EcwException
|
187 |
*/
|
188 |
private void init() throws GdalException { |
189 |
//Controlamos que el tipo de driver sea correcto
|
190 |
if (driver == null) { |
191 |
throw new GdalException("Tipo de driver sin especificar."); |
192 |
} |
193 |
|
194 |
boolean okdrvtype = false; |
195 |
|
196 |
String[] types = GeoRasterWriter.getDriversType(); |
197 |
for (int i = 0; i < GeoRasterWriter.getNTypes(); i++) |
198 |
if (driver.equals(types[i]))
|
199 |
okdrvtype = true;
|
200 |
|
201 |
if (okdrvtype == false) |
202 |
throw new GdalException("El tipo de driver "+driver+" no est? soportado por GdalWriter."); |
203 |
|
204 |
//Obtenemos el driver y creamos el dataset del destino
|
205 |
drv = Gdal.getDriverByName(driver); |
206 |
|
207 |
if (dset_destino != null) { |
208 |
dset_destino.close(); |
209 |
dset_destino = null;
|
210 |
} |
211 |
|
212 |
dset_destino = drv.create(outFileName, sizeWindowX, sizeWindowY, |
213 |
nBands, RasterUtilities.getGdalTypeFromRasterBufType(dataType), params); |
214 |
|
215 |
dset_destino.setGeoTransform(geot); |
216 |
|
217 |
int blockSize = 256; |
218 |
try {
|
219 |
blockSize = Integer.parseInt(driverParams.getParamById("blocksize").defaultValue); |
220 |
}catch(NumberFormatException e) { |
221 |
//Se queda con el valor de inicializaci?n
|
222 |
} |
223 |
|
224 |
nBlocks = (int) (sizeWindowY / blockSize);
|
225 |
anchoResto = sizeWindowY - (nBlocks * blockSize); |
226 |
} |
227 |
|
228 |
public void anotherFile(String fileName)throws GdalException { |
229 |
dset_destino = drv.create(fileName, sizeWindowX, sizeWindowY, |
230 |
nBands, RasterUtilities.getGdalTypeFromRasterBufType(dataType), params); |
231 |
} |
232 |
|
233 |
/**
|
234 |
* A partir de un elemento que contiene una propiedad y un valor
|
235 |
* lo parsea y asigna el valor a su variable.
|
236 |
* @param propValue elemento con la forma propiedad=valor
|
237 |
*/
|
238 |
private void readProperty(String propValue) { |
239 |
String prop = propValue.substring(0, propValue.indexOf("=")); |
240 |
|
241 |
if (propValue.startsWith(prop)) {
|
242 |
String value = propValue.substring(propValue.indexOf("=") + 1, propValue.length()); |
243 |
|
244 |
if ((value != null) && !value.equals("")) { |
245 |
if (prop.equals("BLOCKSIZE")) |
246 |
driverParams.changeParamValue("blocksize", value);
|
247 |
if (prop.equals("INTERLEAVE")) |
248 |
driverParams.changeParamValue("interleave", value);
|
249 |
if (prop.equals("PHOTOMETRIC")) |
250 |
driverParams.changeParamValue("photometric", value);
|
251 |
if (prop.equals("COMPRESS")) |
252 |
driverParams.changeParamValue("compression", value);
|
253 |
if (prop.equals("TFW")) |
254 |
driverParams.changeParamValue("tfw", value);
|
255 |
} |
256 |
} |
257 |
} |
258 |
|
259 |
/**
|
260 |
* Asigna propiedades al driver a partir de un vector de
|
261 |
* strings donde cada elemento tiene la estructura de
|
262 |
* propiedad=valor.
|
263 |
* @param props Propiedades
|
264 |
*/
|
265 |
public void setProps(String[] props) { |
266 |
for (int iProps = 0; iProps < props.length; iProps++) |
267 |
readProperty(props[iProps]); |
268 |
|
269 |
loadParams(); |
270 |
|
271 |
try {
|
272 |
if (!consulta)
|
273 |
init(); |
274 |
} catch (GdalException e) {
|
275 |
e.printStackTrace(); |
276 |
} |
277 |
} |
278 |
|
279 |
/**
|
280 |
* Escritura de datos tipo Byte.
|
281 |
* @param sizeY Alto del bloque que se escribe.
|
282 |
* @param posicionY Posici?ny a partir desde donde se comienza.
|
283 |
*/
|
284 |
public void writeByteBand(int sizeY, int posicionY) { |
285 |
byte[][] buftmp = dataWriter.readByteData(sizeWindowX, sizeY); |
286 |
for(int iBand = 0; iBand < nBands; iBand ++) |
287 |
bufBands[iBand].buffByte = new byte[buftmp[iBand].length]; |
288 |
|
289 |
//Escribimos el bloque destino
|
290 |
for (int iBand = 0; iBand < buftmp.length; iBand++) |
291 |
for (int i = 0; i < buftmp[iBand].length; i++) |
292 |
bufBands[iBand].buffByte[i] = buftmp[iBand][i]; |
293 |
|
294 |
for (int iBand = 0; iBand < buftmp.length; iBand++){ |
295 |
try {
|
296 |
rband = dset_destino.getRasterBand(iBand + 1);
|
297 |
rband.writeRaster(0, posicionY, sizeWindowX, sizeY, bufBands[iBand], Gdal.GDT_Byte);
|
298 |
} catch (GdalException e) {
|
299 |
//No se est? escribiendo ...
|
300 |
} |
301 |
} |
302 |
} |
303 |
|
304 |
/**
|
305 |
* Escritura de datos tipo Short.
|
306 |
* @param sizeY Alto del bloque que se escribe.
|
307 |
* @param posicionY Posici?ny a partir desde donde se comienza.
|
308 |
*/
|
309 |
public void writeShortBand(int sizeY, int posicionY) { |
310 |
short[][] buftmp = dataWriter.readShortData(sizeWindowX, sizeY); |
311 |
for(int iBand = 0; iBand < nBands; iBand ++) |
312 |
bufBands[iBand].buffShort = new short[buftmp[iBand].length]; |
313 |
|
314 |
//Escribimos el bloque destino
|
315 |
for (int iBand = 0; iBand < buftmp.length; iBand++) |
316 |
for (int i = 0; i < buftmp[iBand].length; i++) |
317 |
bufBands[iBand].buffShort[i] = buftmp[iBand][i]; |
318 |
|
319 |
for (int iBand = 0; iBand < buftmp.length; iBand++){ |
320 |
try {
|
321 |
rband = dset_destino.getRasterBand(iBand + 1);
|
322 |
rband.writeRaster(0, posicionY, sizeWindowX, sizeY, bufBands[iBand], Gdal.GDT_Int16);
|
323 |
} catch (GdalException e) {
|
324 |
//No se est? escribiendo ...
|
325 |
} |
326 |
} |
327 |
} |
328 |
|
329 |
/**
|
330 |
* Escritura de datos tipo Int.
|
331 |
* @param sizeY Alto del bloque que se escribe.
|
332 |
* @param posicionY Posici?ny a partir desde donde se comienza.
|
333 |
*/
|
334 |
public void writeIntBand(int sizeY, int posicionY) { |
335 |
int[][] buftmp = dataWriter.readIntData(sizeWindowX, sizeY); |
336 |
for(int iBand = 0; iBand < nBands; iBand ++) |
337 |
bufBands[iBand].buffInt = new int[buftmp[iBand].length]; |
338 |
|
339 |
//Escribimos el bloque destino
|
340 |
for (int iBand = 0; iBand < buftmp.length; iBand++) |
341 |
for (int i = 0; i < buftmp[iBand].length; i++) |
342 |
bufBands[iBand].buffInt[i] = buftmp[iBand][i]; |
343 |
|
344 |
for (int iBand = 0; iBand < buftmp.length; iBand++){ |
345 |
try {
|
346 |
rband = dset_destino.getRasterBand(iBand + 1);
|
347 |
rband.writeRaster(0, posicionY, sizeWindowX, sizeY, bufBands[iBand], Gdal.GDT_Int32);
|
348 |
} catch (GdalException e) {
|
349 |
//No se est? escribiendo ...
|
350 |
} |
351 |
} |
352 |
} |
353 |
|
354 |
/**
|
355 |
* Escritura de datos tipo Float.
|
356 |
* @param sizeY Alto del bloque que se escribe.
|
357 |
* @param posicionY Posici?ny a partir desde donde se comienza.
|
358 |
*/
|
359 |
public void writeFloatBand(int sizeY, int posicionY) { |
360 |
float[][] buftmp = dataWriter.readFloatData(sizeWindowX, sizeY); |
361 |
for(int iBand = 0; iBand < nBands; iBand ++) |
362 |
bufBands[iBand].buffFloat = new float[buftmp[iBand].length]; |
363 |
|
364 |
//Escribimos el bloque destino
|
365 |
for (int iBand = 0; iBand < buftmp.length; iBand++) |
366 |
for (int i = 0; i < buftmp[iBand].length; i++) |
367 |
bufBands[iBand].buffFloat[i] = buftmp[iBand][i]; |
368 |
|
369 |
for (int iBand = 0; iBand < buftmp.length; iBand++){ |
370 |
try {
|
371 |
rband = dset_destino.getRasterBand(iBand + 1);
|
372 |
rband.writeRaster(0, posicionY, sizeWindowX, sizeY, bufBands[iBand], Gdal.GDT_Float32);
|
373 |
} catch (GdalException e) {
|
374 |
//No se est? escribiendo ...
|
375 |
} |
376 |
} |
377 |
} |
378 |
|
379 |
/**
|
380 |
* Escritura de datos tipo Double.
|
381 |
* @param sizeY Alto del bloque que se escribe.
|
382 |
* @param posicionY Posici?ny a partir desde donde se comienza.
|
383 |
*/
|
384 |
public void writeDoubleBand(int sizeY, int posicionY) { |
385 |
double[][] buftmp = dataWriter.readDoubleData(sizeWindowX, sizeY); |
386 |
for(int iBand = 0; iBand < nBands; iBand ++) |
387 |
bufBands[iBand].buffDouble = new double[buftmp[iBand].length]; |
388 |
|
389 |
//Escribimos el bloque destino
|
390 |
for (int iBand = 0; iBand < buftmp.length; iBand++) |
391 |
for (int i = 0; i < buftmp[iBand].length; i++) |
392 |
bufBands[iBand].buffDouble[i] = buftmp[iBand][i]; |
393 |
|
394 |
for (int iBand = 0; iBand < buftmp.length; iBand++){ |
395 |
try {
|
396 |
rband = dset_destino.getRasterBand(iBand + 1);
|
397 |
rband.writeRaster(0, posicionY, sizeWindowX, sizeY, bufBands[iBand], Gdal.GDT_Float64);
|
398 |
} catch (GdalException e) {
|
399 |
//No se est? escribiendo ...
|
400 |
} |
401 |
} |
402 |
} |
403 |
/**
|
404 |
* Escritura para tipo de dato ARGB.
|
405 |
* @param sizeY Alto del bloque que se escribe.
|
406 |
* @param posicionY Posici?ny a partir desde donde se comienza.
|
407 |
*/
|
408 |
public void writeARGBBand(int sizeY, int posicionY) { |
409 |
int[] buftmp = dataWriter.readARGBData(sizeWindowX, sizeY, 0); |
410 |
for(int iBand = 0; iBand < nBands; iBand ++) |
411 |
bufBands[iBand].buffByte = new byte[buftmp.length]; |
412 |
|
413 |
//Escribimos el bloque destino
|
414 |
for (int i = 0; i < buftmp.length; i++) { |
415 |
bufBands[0].buffByte[i] = (byte) (((buftmp[i] & 0xff0000) >> 16) & |
416 |
0xff);
|
417 |
bufBands[1].buffByte[i] = (byte) (((buftmp[i] & 0xff00) >> 8) & 0xff); |
418 |
bufBands[2].buffByte[i] = (byte) ((buftmp[i] & 0xff) & 0xff); |
419 |
} |
420 |
|
421 |
try {
|
422 |
rband = dset_destino.getRasterBand(1);
|
423 |
rband.writeRaster(0, posicionY, sizeWindowX, sizeY, bufBands[0], |
424 |
Gdal.GDT_Byte); |
425 |
rband = dset_destino.getRasterBand(2);
|
426 |
rband.writeRaster(0, posicionY, sizeWindowX, sizeY, bufBands[1], |
427 |
Gdal.GDT_Byte); |
428 |
rband = dset_destino.getRasterBand(3);
|
429 |
rband.writeRaster(0, posicionY, sizeWindowX, sizeY, bufBands[2], |
430 |
Gdal.GDT_Byte); |
431 |
} catch (GdalException e) {
|
432 |
e.printStackTrace(); |
433 |
} |
434 |
} |
435 |
|
436 |
/**
|
437 |
* Escribe tres bandas en el GDALRasterBand desde el IDataWriter con una
|
438 |
* altura definida por sizeY.
|
439 |
* @param buftmp Buffer
|
440 |
* @param sizeY Altura en pixels del bloque leido
|
441 |
* @param posicionY Posici?n y a partir de la cual se escribe en el GDALRasterBand destino
|
442 |
*/
|
443 |
private void writeBands(int sizeY, int posicionY) { |
444 |
//leemos el bloque origen
|
445 |
|
446 |
switch(dataType){
|
447 |
case RasterBuffer.TYPE_IMAGE:
|
448 |
writeARGBBand(sizeY, posicionY); |
449 |
break;
|
450 |
case RasterBuffer.TYPE_BYTE:
|
451 |
writeByteBand(sizeY, posicionY); |
452 |
break;
|
453 |
case RasterBuffer.TYPE_SHORT:
|
454 |
writeShortBand(sizeY, posicionY); |
455 |
break;
|
456 |
case RasterBuffer.TYPE_INT:
|
457 |
writeIntBand(sizeY, posicionY); |
458 |
break;
|
459 |
case RasterBuffer.TYPE_FLOAT:
|
460 |
writeFloatBand(sizeY, posicionY); |
461 |
break;
|
462 |
case RasterBuffer.TYPE_DOUBLE:
|
463 |
writeDoubleBand(sizeY, posicionY); |
464 |
break;
|
465 |
} |
466 |
} |
467 |
|
468 |
/**
|
469 |
* Funci?n que gestiona la lectura desde el origen y la escritura
|
470 |
* de Gdal sobre el fichero destino.
|
471 |
* @param mode Modo de escritura
|
472 |
* @throws IOException
|
473 |
*/
|
474 |
private void write(int mode) throws IOException { |
475 |
bufBands = new GdalBuffer[nBands];
|
476 |
for(int iBand = 0; iBand < nBands; iBand ++) |
477 |
bufBands[iBand] = new GdalBuffer();
|
478 |
|
479 |
int blockSize = 256; |
480 |
try {
|
481 |
blockSize = Integer.parseInt(driverParams.getParamById("blocksize").defaultValue); |
482 |
}catch(NumberFormatException e) { |
483 |
//Se queda con el valor de inicializaci?n
|
484 |
} |
485 |
|
486 |
if (mode == GeoRasterWriter.MODE_FILEWRITE) {
|
487 |
/*for (int iBand = 0; iBand < this.nBands; iBand++) {
|
488 |
rband = dset_destino.getRasterBand(iBand + 1);
|
489 |
|
490 |
for (int iBlock = 0; iBlock < nBlocks; iBlock++) {
|
491 |
if(write){
|
492 |
//leemos el bloque origen
|
493 |
buf.buffByte = currentRaster.getGeoFile().getWindow(0,
|
494 |
iBlock * this.support.getBlockSize(),
|
495 |
sizeWindowX,
|
496 |
this.support.getBlockSize(),
|
497 |
iBand +
|
498 |
1);
|
499 |
|
500 |
//Escribimos el bloque destino
|
501 |
rband.writeRaster(0,
|
502 |
iBlock * this.support.getBlockSize(),
|
503 |
sizeWindowX,
|
504 |
this.support.getBlockSize(), buf,
|
505 |
Gdal.GDT_Byte);
|
506 |
}//else
|
507 |
//this.writeClose();
|
508 |
}
|
509 |
}*/
|
510 |
} else if (mode == GeoRasterWriter.MODE_DATAWRITE) { |
511 |
for (int iBlock = 0; iBlock < nBlocks; iBlock++) { |
512 |
int posicionY = iBlock * blockSize;
|
513 |
if(write)
|
514 |
writeBands( blockSize, posicionY); |
515 |
} |
516 |
} |
517 |
|
518 |
if (anchoResto != 0) { |
519 |
if (mode == GeoRasterWriter.MODE_FILEWRITE) {
|
520 |
/*for (int iBand = 0; iBand < this.nBands; iBand++) {
|
521 |
rband = dset_destino.getRasterBand(iBand + 1);
|
522 |
if(write){
|
523 |
//leemos el bloque origen
|
524 |
buf.buffByte = currentRaster.getGeoFile().getWindow(0,
|
525 |
nBlocks * this.support.getBlockSize(),
|
526 |
sizeWindowX,
|
527 |
anchoResto,
|
528 |
iBand +
|
529 |
1);
|
530 |
|
531 |
//Escribimos el bloque destino
|
532 |
rband.writeRaster(0,
|
533 |
nBlocks * this.support.getBlockSize(),
|
534 |
sizeWindowX, anchoResto, buf,
|
535 |
Gdal.GDT_Byte);
|
536 |
}//else
|
537 |
//this.writeClose();
|
538 |
}*/
|
539 |
} else if (mode == GeoRasterWriter.MODE_DATAWRITE) { |
540 |
int posicionY = nBlocks * blockSize;
|
541 |
if(write)
|
542 |
writeBands(anchoResto, posicionY); |
543 |
} |
544 |
} |
545 |
|
546 |
} |
547 |
|
548 |
/**
|
549 |
* Realiza la funci?n de compresi?n a partir de un GeoRasterFile.
|
550 |
* @throws IOException
|
551 |
*/
|
552 |
public void fileWrite() throws IOException { |
553 |
write(GeoRasterWriter.MODE_FILEWRITE); |
554 |
} |
555 |
|
556 |
/**
|
557 |
* Realiza una copia en el formato especificado.
|
558 |
* @throws IOException
|
559 |
*/
|
560 |
public static void createCopy(es.gva.cit.jgdal.GdalDriver driverDst, String dst, String src, |
561 |
boolean bstrict, String[] params, IProjection proj) throws IOException, GdalException { |
562 |
if (dst == null || src == null) { |
563 |
throw new IOException("No se ha asignado un fichero de entrada."); |
564 |
} |
565 |
|
566 |
GdalDriver gdalFile; |
567 |
try {
|
568 |
gdalFile = new GdalDriver(proj, src);
|
569 |
driverDst.createCopy(dst, gdalFile.getNative(), bstrict, params); |
570 |
if(dst.endsWith(".jpg") || dst.endsWith(".jpeg")) |
571 |
RasterUtilities.createWorldFile(dst, gdalFile.getExtent(), gdalFile.getWidth(), gdalFile.getHeight()); |
572 |
gdalFile.close(); |
573 |
} catch (NotSupportedExtensionException e) {
|
574 |
e.printStackTrace(); |
575 |
} |
576 |
} |
577 |
|
578 |
/**
|
579 |
* Realiza la escritura de datos con los datos que le pasa el cliente.
|
580 |
* @throws IOException
|
581 |
*/
|
582 |
public void dataWrite() throws IOException { |
583 |
if (dataWriter == null) |
584 |
throw new IOException("No se ha obtenido un objeto de entrada para la escritura valido."); |
585 |
|
586 |
write(GeoRasterWriter.MODE_DATAWRITE); |
587 |
|
588 |
if(driverParams.getParamById("tfw").defaultValue.equals("true")) { |
589 |
if(extent != null) |
590 |
RasterUtilities.createWorldFile(this.outFileName, extent, sizeWindowX, sizeWindowY);
|
591 |
} |
592 |
} |
593 |
|
594 |
/**
|
595 |
* Cancela el salvado de datos.
|
596 |
* @throws GdalException
|
597 |
*/
|
598 |
public void writeClose() { |
599 |
try {
|
600 |
if(dset_destino != null) |
601 |
dset_destino.close(); |
602 |
//oSRS = null;
|
603 |
} catch (GdalException e) {
|
604 |
e.printStackTrace(); |
605 |
} |
606 |
} |
607 |
|
608 |
/**
|
609 |
* Cancela el salvado de datos.
|
610 |
*/
|
611 |
public void writeCancel() { |
612 |
write = false;
|
613 |
} |
614 |
|
615 |
/**
|
616 |
* Obtiene el valor a la variable write que estar? a true cuando se est? escribiendo
|
617 |
* o puede escribirse la imagen de salida. El cancelar la operaci?n de escritura
|
618 |
* pondr? esta variable a false deteniendose la escritura y cerrandose el dataset
|
619 |
* de salida.
|
620 |
* @return True si puede escribirse y false si no puede
|
621 |
*/
|
622 |
public boolean isWrite() { |
623 |
return write;
|
624 |
} |
625 |
|
626 |
/**
|
627 |
* Asigna el valor a la variable write que estar? a true cuando se est? escribiendo
|
628 |
* o puede escribirse la imagen de salida. El cancelar la operaci?n de escritura
|
629 |
* pondr? esta variable a false deteniendose la escritura y cerrandose el dataset
|
630 |
* de salida.
|
631 |
* @param write Variable booleana. True si puede escribirse y false si no puede
|
632 |
*/
|
633 |
public void setWrite(boolean write) { |
634 |
this.write = write;
|
635 |
} |
636 |
|
637 |
/**
|
638 |
* Asigna los par?metros del driver modificados por el cliente.
|
639 |
* @param WriterParams
|
640 |
*/
|
641 |
public void setParams(WriterParams params) { |
642 |
this.driverParams = params;
|
643 |
|
644 |
int blockSize = 256; |
645 |
try {
|
646 |
blockSize = Integer.parseInt(driverParams.getParamById("blocksize").defaultValue); |
647 |
nBlocks = (int) (sizeWindowY / blockSize);
|
648 |
anchoResto = sizeWindowY - (nBlocks * blockSize); |
649 |
}catch(NumberFormatException e) { |
650 |
//Se queda con el valor de inicializaci?n
|
651 |
} |
652 |
} |
653 |
} |