svn-gvsig-desktop / branches / CqCMSDvp / libraries / libCq CMS for java.old / src / org / cresques / io / GdalWriter.java @ 2312
History | View | Annotate | Download (20.2 KB)
1 |
/*
|
---|---|
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 |
|
28 |
import org.cresques.px.PxRaster; |
29 |
|
30 |
import es.gva.cit.jecwcompress.EcwException; |
31 |
import es.gva.cit.jgdal.Gdal; |
32 |
import es.gva.cit.jgdal.GdalBuffer; |
33 |
import es.gva.cit.jgdal.GdalDriver; |
34 |
import es.gva.cit.jgdal.GdalException; |
35 |
import es.gva.cit.jgdal.GdalRasterBand; |
36 |
import es.gva.cit.jgdal.GeoTransform; |
37 |
import es.gva.cit.jogr.OGRSpatialReference; |
38 |
|
39 |
/**
|
40 |
* Driver para la escritura a trav?s de Gdal.
|
41 |
* Puede exportar un fichero de un formato a otro desde un GeoRasterFile
|
42 |
* en cualquier formato soportado por la lectura a un formato que este incluido
|
43 |
* en la lista supportedDrv.
|
44 |
*
|
45 |
* Puede salvar a disco en un formato que este incluido en la lista supportedDrv
|
46 |
* obteniendo los datos que van siendo servidos desde el cliente. Este cliente
|
47 |
* debe implementar un IDataWriter o tener un objeto que lo implemente. Inicialmente
|
48 |
* le pasar? los par?metros de la imagen de salida y cuando el driver comience a
|
49 |
* escribir le ir? solicitando m?s a trav?s del m?todo readData de IDataWriter.
|
50 |
* El cliente ser? el que lleve el control de lo que va sirviendo y lo que le queda
|
51 |
* por servir.
|
52 |
* @author Nacho Brodin (brodin_ign@gva.es)
|
53 |
*/
|
54 |
|
55 |
public class GdalWriter extends GeoRasterWriter{ |
56 |
|
57 |
public final int windowSizeX = 386; |
58 |
public final int windowSizeY = 195; |
59 |
public final int panelSizeX = 350; |
60 |
public final int panelSizeY = 105; |
61 |
public final String panelLayout = "BorderLayout"; |
62 |
|
63 |
private GdalDriver drv;
|
64 |
private Gdal dset_destino=null; |
65 |
private GdalRasterBand rband=null; |
66 |
private String drvType=null; //Tipo de driver |
67 |
private String[] supportedDrv = {"GTiff"}; //Lista de drivers de escritura que soporta |
68 |
private GeoTransform geot=null; //Datos de georeferenciaci?n |
69 |
private OGRSpatialReference oSRS; //Datos de proyecci?n |
70 |
private GdalBuffer buf=null; //Buffer de origen de gdal |
71 |
private GdalBuffer bufBandR=null, bufBandG=null, bufBandB=null; |
72 |
private int nBlocks=0; //N?mero de bloques en Y en el que se divide la imagen para escribir |
73 |
private int anchoResto=0; //Tama?o del ?ltimo bloque de la imagen. |
74 |
private String[] params = null; //Par?metros de creaci?n del dataset. |
75 |
private GdalSupportOptions support = null; |
76 |
private boolean consulta = false; |
77 |
|
78 |
/**
|
79 |
*
|
80 |
* @author Nacho Brodin <brodin_ign@gva.es>
|
81 |
*
|
82 |
* Opciones que soporta el driver de escritura de Gdal.
|
83 |
*/
|
84 |
class GdalSupportOptions extends WriterSupportOptions{ |
85 |
|
86 |
private String[] photometric = {"YCBR","MINISBLACK","MINISWHITE","RGB","CMYK","CIELAB","ICCLAB","ITULAB","CBCR"}; |
87 |
private String[] interleave = {"BAND","PIXEL"}; |
88 |
private String[] compress = {"JPEG","LZW","PACKBITS","DEFLATE","NONE"}; |
89 |
|
90 |
private String photometricDefault = "RGB"; |
91 |
private String interleaveDefault = "BAND"; |
92 |
private String compressDefault = "NONE"; |
93 |
|
94 |
private boolean tfw = false; |
95 |
|
96 |
GdalSupportOptions(String ext){
|
97 |
super(ext);
|
98 |
} |
99 |
|
100 |
/**
|
101 |
* @param defaultPhot Tipo de imagen
|
102 |
*/
|
103 |
public void setPhotometric(String defaultPhot ){ |
104 |
this.photometricDefault = defaultPhot;
|
105 |
} |
106 |
|
107 |
/**
|
108 |
* @param defaultInt
|
109 |
*/
|
110 |
public void setInterleave(String defaultInt){ |
111 |
this.interleaveDefault = defaultInt;
|
112 |
} |
113 |
|
114 |
/**
|
115 |
* @param defaultComp
|
116 |
*/
|
117 |
public void setCompress(String defaultComp){ |
118 |
this.compressDefault = defaultComp;
|
119 |
} |
120 |
|
121 |
/**
|
122 |
* Asigna true o false si se desea generar un fichero tfw con la
|
123 |
* georeferenciaci?n o no;
|
124 |
* @param tfw true se genera el fichero tfw y false no se genera
|
125 |
*/
|
126 |
public void setTfw(boolean tfw){ |
127 |
this.tfw = tfw;
|
128 |
} |
129 |
|
130 |
/**
|
131 |
* @return
|
132 |
*/
|
133 |
public String[] getPhotometricList(){return photometric;} |
134 |
|
135 |
/**
|
136 |
* @return
|
137 |
*/
|
138 |
public String[] getInterleaveList(){return interleave;} |
139 |
|
140 |
/**
|
141 |
* @return
|
142 |
*/
|
143 |
public String[] getCompressList(){return compress;} |
144 |
|
145 |
/**
|
146 |
* @return
|
147 |
*/
|
148 |
public String getPhotometric(){return photometricDefault;} |
149 |
|
150 |
/**
|
151 |
* @return
|
152 |
*/
|
153 |
public String getInterleave(){return interleaveDefault;} |
154 |
|
155 |
/**
|
156 |
* Obtiene el par?metro de compresi?n
|
157 |
* @return
|
158 |
*/
|
159 |
public String getCompress(){return compressDefault;} |
160 |
|
161 |
/**
|
162 |
* Devuelve true o false si se genera un fichero tfw con la
|
163 |
* georeferenciaci?n o no;
|
164 |
* @param tfw true se genera el fichero tfw y false no se genera
|
165 |
*/
|
166 |
public boolean getTfw(){return tfw;} |
167 |
|
168 |
} |
169 |
|
170 |
private class Mode{ |
171 |
public final static int fileWrite = 0; |
172 |
public final static int dataWrite = 1; |
173 |
} |
174 |
|
175 |
static {
|
176 |
GeoRasterWriter.registerWriterExtension("tif", EcwWriter.class);
|
177 |
} |
178 |
|
179 |
/**
|
180 |
* Constructor para la obtenci?n de par?metros del driver
|
181 |
* @param drvType Tipo de driver
|
182 |
*/
|
183 |
public GdalWriter(String drvType){ |
184 |
|
185 |
this.support = new GdalSupportOptions(drvType); |
186 |
this.ident = this.drvType = drvType; |
187 |
this.driver = "tif"; |
188 |
this.support.setBlockSize(64); |
189 |
this.support.setPhotometric("RGB"); |
190 |
this.support.setInterleave("BAND"); |
191 |
this.support.setCompress("NONE"); |
192 |
this.support.setWriteGeoref(true); |
193 |
this.support.setTfw(false); |
194 |
|
195 |
this.consulta = true; |
196 |
|
197 |
} |
198 |
|
199 |
/**
|
200 |
* Constructor para salvar una sola imagen completa
|
201 |
* @param raster PxRaster de la imagen de origen
|
202 |
* @param outfilename Nombre del fichero de salida
|
203 |
* @param infilename Nombre del fichero de entrada
|
204 |
* @param drvType Tipo de driver
|
205 |
*/
|
206 |
|
207 |
public GdalWriter( PxRaster raster,
|
208 |
String outfilename,
|
209 |
String infilename,
|
210 |
String drvType)throws GdalException, IOException { |
211 |
|
212 |
this.support = new GdalSupportOptions(drvType); |
213 |
this.ident = this.drvType = drvType; |
214 |
this.driver = "tif"; |
215 |
|
216 |
this.outfilename = outfilename;
|
217 |
this.infilename = infilename;
|
218 |
this.currentRaster = raster;
|
219 |
|
220 |
this.sizeWindowX = raster.getFWidth();
|
221 |
this.sizeWindowY = raster.getFHeight();
|
222 |
|
223 |
//Obtenemos la georeferenciaci?n
|
224 |
|
225 |
if(support.getGeoref()){
|
226 |
double maxX=currentRaster.getExtent().maxX();
|
227 |
double minX=currentRaster.getExtent().minX();
|
228 |
double maxY=currentRaster.getExtent().maxY();
|
229 |
double minY=currentRaster.getExtent().minY();
|
230 |
|
231 |
//System.out.println("Extent->"+maxX+" "+minX+" "+maxY+" "+minY);
|
232 |
|
233 |
geot = new GeoTransform();
|
234 |
geot.adfgeotransform[0] = minX;
|
235 |
geot.adfgeotransform[3] = maxY;
|
236 |
geot.adfgeotransform[1] = (maxX-minX)/currentRaster.getFWidth();
|
237 |
geot.adfgeotransform[5] = (minY-maxY)/currentRaster.getFHeight();
|
238 |
} |
239 |
|
240 |
nBands = currentRaster.getBandCount(); |
241 |
|
242 |
this.support.setBlockSize(currentRaster.getBlockSize());
|
243 |
|
244 |
if(sizeWindowX<0 || sizeWindowY<0) |
245 |
throw new IOException("Tama?o del fichero de salida erroneo."); |
246 |
|
247 |
if(nBands==3) |
248 |
this.support.setPhotometric("PHOTOMETRIC=RGB"); |
249 |
else if (nBands==1) |
250 |
this.support.setPhotometric("PHOTOMETRIC=MINISBLACK"); |
251 |
else this.support.setPhotometric(""); |
252 |
|
253 |
params = new String[2]; |
254 |
params[0] = new String("TILED=YES"); |
255 |
params[1] = new String(this.support.getPhotometric()); |
256 |
|
257 |
init(); |
258 |
|
259 |
/*oSRS = new OGRSpatialReference();
|
260 |
try{
|
261 |
oSRS.setUTM(currentRaster.geoFile.getUTM(), currentRaster.geoFile.getZone());
|
262 |
oSRS.setWellKnownGeogCS(currentRaster.geoFile.getGeogCS());
|
263 |
//System.out.println(currentRaster.geoFile.getGeogCS()+"Nueva Proyecci?n ==> "+oSRS.exportToWkt());
|
264 |
dset_destino.setProjection(oSRS.exportToWkt());
|
265 |
}catch(Exception e){
|
266 |
e.printStackTrace();
|
267 |
}*/
|
268 |
|
269 |
} |
270 |
|
271 |
|
272 |
|
273 |
/**
|
274 |
* Constructor para salvar datos servidos por el cliente
|
275 |
* @param dataWriter Objeto servidor de datos para el driver de escritura
|
276 |
* @param outSizeX N?mero de pixels en X de la imagen de salida
|
277 |
* @param outSizeY N?mero de pixels en Y de la imagen de salida
|
278 |
* @param outFilename Fichero de salida
|
279 |
* @param extentMaxX Posici?n en X m?xima del extent
|
280 |
* @param extentMinX Posici?n en X m?nima del extent
|
281 |
* @param extentMaxY Posici?n en Y m?xima del extent
|
282 |
* @param extentMinY Posici?n en Y m?nima del extent
|
283 |
* @param nBands N?mero de bandas
|
284 |
* @param drvType Tipo de driver
|
285 |
* @throws GdalException
|
286 |
* @throws IOException
|
287 |
*/
|
288 |
|
289 |
public GdalWriter( IDataWriter dataWriter,
|
290 |
int outSizeX,
|
291 |
int outSizeY,
|
292 |
String outFilename,
|
293 |
double extentMaxX,
|
294 |
double extentMinX,
|
295 |
double extentMaxY,
|
296 |
double extentMinY,
|
297 |
int nBands,
|
298 |
int sizeBlock,
|
299 |
String drvType)throws GdalException, IOException { |
300 |
|
301 |
this.support = new GdalSupportOptions(drvType); |
302 |
this.ident = this.drvType = drvType; |
303 |
this.driver = "tif"; |
304 |
|
305 |
this.dataWriter = dataWriter;
|
306 |
this.outfilename = outFilename;
|
307 |
|
308 |
this.sizeWindowX = outSizeX;
|
309 |
this.sizeWindowY = outSizeY;
|
310 |
|
311 |
if(sizeWindowX<0 || sizeWindowY<0) |
312 |
throw new IOException("Tama?o del fichero de salida erroneo."); |
313 |
|
314 |
this.nBands = nBands;
|
315 |
|
316 |
//Calculamos la georeferenciaci?n a partir del extend pasado por el cliente.
|
317 |
|
318 |
if(support.getGeoref()){
|
319 |
double maxX = extentMaxX;
|
320 |
double minX = extentMinX;
|
321 |
double maxY = extentMaxY;
|
322 |
double minY = extentMinY;
|
323 |
|
324 |
this.support.setBlockSize(sizeBlock);
|
325 |
|
326 |
geot = new GeoTransform();
|
327 |
geot.adfgeotransform[0] = minX;
|
328 |
geot.adfgeotransform[3] = maxY;
|
329 |
geot.adfgeotransform[1] = (maxX-minX)/outSizeX;
|
330 |
geot.adfgeotransform[5] = (minY-maxY)/outSizeY;
|
331 |
} |
332 |
setParams(); |
333 |
|
334 |
init(); |
335 |
|
336 |
} |
337 |
|
338 |
/**
|
339 |
*Asigna par?metros de creaci?n del dataset de Gdal
|
340 |
*/
|
341 |
private void setParams(){ |
342 |
|
343 |
params = new String[5]; |
344 |
|
345 |
params[0] = new String("TILED=YES"); |
346 |
params[1] = new String("PHOTOMETRIC="+this.support.getPhotometric()); |
347 |
params[2] = new String("INTERLEAVE="+this.support.getInterleave()); |
348 |
params[3] = new String("COMPRESS="+this.support.getCompress()); |
349 |
|
350 |
String tfw = null; |
351 |
if(this.support.getTfw()) |
352 |
tfw = new String("YES"); |
353 |
else
|
354 |
tfw = new String("NO"); |
355 |
|
356 |
params[4] = new String("TFW="+tfw); |
357 |
|
358 |
} |
359 |
|
360 |
/**
|
361 |
* Asigna el tipo de driver con el que se salvar? la imagen
|
362 |
* @param drvType Tipo de driver
|
363 |
*/
|
364 |
|
365 |
public void setDriverType(String drvType){ |
366 |
|
367 |
this.drvType = drvType;
|
368 |
|
369 |
} |
370 |
|
371 |
|
372 |
/**
|
373 |
* Creaci?n del dataset de destino.
|
374 |
* @throws EcwException
|
375 |
*/
|
376 |
|
377 |
private void init() throws GdalException{ |
378 |
|
379 |
//Controlamos que el tipo de driver sea correcto
|
380 |
|
381 |
if(drvType==null) |
382 |
throw new GdalException("Tipo de driver sin especificar."); |
383 |
boolean okdrvtype=false; |
384 |
for(int i=0;i<supportedDrv.length ;i++) |
385 |
if(drvType.equals( supportedDrv[i]))okdrvtype=true; |
386 |
if(okdrvtype==false) |
387 |
throw new GdalException("El tipo de driver no est? soportado por GdalWriter."); |
388 |
|
389 |
//Obtenemos el driver y creamos el dataset del destino
|
390 |
|
391 |
drv=Gdal.getDriverByName(drvType); |
392 |
System.out.println("++++++>"+params.length); |
393 |
for(int i=0;i<params.length;i++)System.out.println("=====>"+params[i]); |
394 |
if(dset_destino!=null){ |
395 |
dset_destino.close(); |
396 |
dset_destino = null;
|
397 |
} |
398 |
|
399 |
dset_destino = drv.create(outfilename, sizeWindowX, sizeWindowY, nBands, Gdal.GDT_Byte, params); |
400 |
|
401 |
if(this.support.getGeoref()) |
402 |
dset_destino.setGeoTransform(geot); |
403 |
|
404 |
nBlocks = (int)(sizeWindowY / this.support.getBlockSize()); |
405 |
anchoResto = sizeWindowY-(nBlocks*this.support.getBlockSize());
|
406 |
|
407 |
//System.out.println("---"+nBlocks+" "+sizeBlock+" "+anchoResto);
|
408 |
} |
409 |
|
410 |
/**
|
411 |
* A partir de un elemento que contiene una propiedad y un valor
|
412 |
* lo parsea y asigna el valor a su variable.
|
413 |
* @param propValue elemento con la forma propiedad=valor
|
414 |
*/
|
415 |
private void readProperty(String propValue){ |
416 |
|
417 |
String prop = propValue.substring(0, propValue.indexOf("=")); |
418 |
if(propValue.startsWith(prop)){
|
419 |
String value = propValue.substring(propValue.indexOf("=")+1, propValue.length()); |
420 |
if(value!=null && !value.equals("")){ |
421 |
if(prop.equals("BLOCKSIZE")) |
422 |
this.support.setBlockSize(Integer.parseInt(value)); |
423 |
if(prop.equals("GEOREF")){ |
424 |
boolean georef = true; |
425 |
if(value.equals("yes")) |
426 |
georef = true;
|
427 |
else
|
428 |
georef = false;
|
429 |
this.support.setWriteGeoref(georef);
|
430 |
} |
431 |
if(prop.equals("INTERLEAVE")) |
432 |
this.support.setInterleave(value);
|
433 |
if(prop.equals("PHOTOMETRIC")) |
434 |
this.support.setPhotometric(value);
|
435 |
if(prop.equals("COMPRESS")) |
436 |
this.support.setCompress(value);
|
437 |
if(prop.equals("TFW")){ |
438 |
boolean tfw = true; |
439 |
if(value.equals("yes")) |
440 |
tfw = true;
|
441 |
else
|
442 |
tfw = false;
|
443 |
this.support.setTfw(tfw);
|
444 |
} |
445 |
} |
446 |
|
447 |
} |
448 |
|
449 |
} |
450 |
|
451 |
/**
|
452 |
* Asigna propiedades al driver a partir de un vector de
|
453 |
* strings donde cada elemento tiene la estructura de
|
454 |
* propiedad=valor.
|
455 |
* @param props Propiedades
|
456 |
*/
|
457 |
public void setProps(String[] props){ |
458 |
|
459 |
for(int iProps=0;iProps<props.length;iProps++) |
460 |
readProperty(props[iProps]); |
461 |
|
462 |
setParams(); |
463 |
try{
|
464 |
if(!consulta)init();
|
465 |
}catch(GdalException e){
|
466 |
e.printStackTrace(); |
467 |
} |
468 |
|
469 |
} |
470 |
|
471 |
/**
|
472 |
* Escribe tres bandas en el GDALRasterBand desde el IDataWriter con una
|
473 |
* altura definida por sizeY.
|
474 |
* @param buftmp Buffer
|
475 |
* @param sizeY Altura en pixels del bloque leido
|
476 |
* @param posicionY Posici?n y a partir de la cual se escribe en el GDALRasterBand destino
|
477 |
*/
|
478 |
private void writeBands(int[] buftmp, int sizeY, int posicionY){ |
479 |
|
480 |
//leemos el bloque origen
|
481 |
buftmp = dataWriter.readData(sizeWindowX, sizeY, 0);
|
482 |
|
483 |
bufBandR.buffByte = new byte[buftmp.length]; |
484 |
bufBandG.buffByte = new byte[buftmp.length]; |
485 |
bufBandB.buffByte = new byte[buftmp.length]; |
486 |
|
487 |
//Escribimos el bloque destino
|
488 |
|
489 |
for(int i=0;i<buftmp.length;i++){ |
490 |
bufBandR.buffByte[i] = (byte)(((buftmp[i] & 0xff0000)>>16) & 0xff); |
491 |
bufBandG.buffByte[i] = (byte)(((buftmp[i] & 0xff00)>>8) & 0xff); |
492 |
bufBandB.buffByte[i] = (byte)((buftmp[i] & 0xff) & 0xff); |
493 |
//if(i==0 || i==1 || i==2)System.out.println("<**>"+buftmp[i]+" + "+bufBandR.buffByte[i]+" - "+bufBandG.buffByte[i]+" - "+bufBandB.buffByte[i]);
|
494 |
} |
495 |
|
496 |
try{
|
497 |
rband=dset_destino.getRasterBand(1);
|
498 |
rband.writeRaster(0, posicionY, sizeWindowX, sizeY, bufBandR, Gdal.GDT_Byte);
|
499 |
rband=dset_destino.getRasterBand(2);
|
500 |
rband.writeRaster(0, posicionY, sizeWindowX, sizeY, bufBandG, Gdal.GDT_Byte);
|
501 |
rband=dset_destino.getRasterBand(3);
|
502 |
rband.writeRaster(0, posicionY, sizeWindowX, sizeY, bufBandB, Gdal.GDT_Byte);
|
503 |
}catch(GdalException e){
|
504 |
e.printStackTrace(); |
505 |
} |
506 |
|
507 |
} |
508 |
|
509 |
/**
|
510 |
* Funci?n que gestiona la lectura desde el origen y la escritura
|
511 |
* de Gdal sobre el fichero destino.
|
512 |
* @param mode Modo de escritura
|
513 |
* @throws IOException
|
514 |
*/
|
515 |
private void write(int mode)throws IOException{ |
516 |
|
517 |
buf = new GdalBuffer();
|
518 |
bufBandR = new GdalBuffer();
|
519 |
bufBandG = new GdalBuffer();
|
520 |
bufBandB = new GdalBuffer();
|
521 |
int [] buftmp = null; |
522 |
//long t1 = System.currentTimeMillis();
|
523 |
try{
|
524 |
if(mode==Mode.fileWrite){
|
525 |
|
526 |
for(int iBand=0;iBand<this.nBands;iBand++){ |
527 |
rband=dset_destino.getRasterBand(iBand+1);
|
528 |
for(int iBlock=0;iBlock<nBlocks;iBlock++){ |
529 |
|
530 |
//leemos el bloque origen
|
531 |
buf.buffByte = currentRaster.getGeoFile().getWindow(0, iBlock*this.support.getBlockSize(), sizeWindowX, this.support.getBlockSize(), iBand+1); |
532 |
|
533 |
//Escribimos el bloque destino
|
534 |
rband.writeRaster(0,iBlock*this.support.getBlockSize(), sizeWindowX, this.support.getBlockSize(), buf,Gdal.GDT_Byte); |
535 |
} |
536 |
} |
537 |
|
538 |
}else if(mode==Mode.dataWrite){ |
539 |
|
540 |
//for(int iBlock=1;iBlock<=nBlocks;iBlock++){
|
541 |
for(int iBlock=0;iBlock<nBlocks;iBlock++){ |
542 |
|
543 |
int posicionY = iBlock*this.support.getBlockSize(); |
544 |
writeBands(buftmp, this.support.getBlockSize(), posicionY);
|
545 |
|
546 |
} |
547 |
|
548 |
} |
549 |
|
550 |
if(anchoResto!=0){ |
551 |
|
552 |
if(mode==Mode.fileWrite){
|
553 |
|
554 |
for(int iBand=0;iBand<this.nBands;iBand++){ |
555 |
rband=dset_destino.getRasterBand(iBand+1);
|
556 |
|
557 |
//leemos el bloque origen
|
558 |
buf.buffByte = currentRaster.getGeoFile().getWindow(0, nBlocks*this.support.getBlockSize(), sizeWindowX, anchoResto, iBand+1); |
559 |
|
560 |
//Escribimos el bloque destino
|
561 |
rband.writeRaster(0,nBlocks*this.support.getBlockSize(), sizeWindowX, anchoResto, buf,Gdal.GDT_Byte); |
562 |
} |
563 |
|
564 |
}else if(mode==Mode.dataWrite){ |
565 |
|
566 |
int posicionY = nBlocks*this.support.getBlockSize(); |
567 |
writeBands(buftmp, anchoResto, posicionY); |
568 |
|
569 |
} |
570 |
|
571 |
} |
572 |
|
573 |
}catch(GdalException e){
|
574 |
e.printStackTrace(); |
575 |
} |
576 |
|
577 |
} |
578 |
|
579 |
/**
|
580 |
* Realiza la funci?n de compresi?n a partir de un GeoRasterFile.
|
581 |
* @throws IOException
|
582 |
*/
|
583 |
|
584 |
public void fileWrite()throws IOException{ |
585 |
|
586 |
if(currentRaster==null) |
587 |
throw new IOException("No se ha asignado un fichero de entrada."); |
588 |
|
589 |
this.write(Mode.fileWrite);
|
590 |
|
591 |
} |
592 |
|
593 |
|
594 |
/**
|
595 |
* Realiza la escritura de datos con los datos que le pasa el cliente.
|
596 |
* @throws IOException
|
597 |
*/
|
598 |
|
599 |
public void dataWrite()throws IOException{ |
600 |
|
601 |
if(dataWriter==null) |
602 |
throw new IOException("No se ha obtenido un objeto de entrada para la escritura valido."); |
603 |
|
604 |
this.write(Mode.dataWrite);
|
605 |
|
606 |
} |
607 |
|
608 |
/**
|
609 |
* Cierra el compresor ecw.
|
610 |
* @throws GdalException
|
611 |
*/
|
612 |
|
613 |
public void writeClose(){ |
614 |
|
615 |
try{
|
616 |
dset_destino.close(); |
617 |
oSRS = null;
|
618 |
}catch(GdalException e){
|
619 |
e.printStackTrace(); |
620 |
} |
621 |
|
622 |
} |
623 |
|
624 |
/**
|
625 |
* Devuelve la configuraci?n de la ventana de dialogo
|
626 |
* para las propiedades del driver de escritura de Gdal.
|
627 |
* @return XML de configuraci?n del dialogo.
|
628 |
*/
|
629 |
public String getXMLPropertiesDialog(){ |
630 |
|
631 |
StringBuffer options = null; |
632 |
options = new StringBuffer(); |
633 |
options.append("<window sizex=\""+this.windowSizeX+"\" sizey=\""+this.windowSizeY+"\">"); |
634 |
options.append("<panel sizex=\""+this.panelSizeX+"\" sizey=\""+this.panelSizeY+"\" layout=\""+this.panelLayout+"\" border=\"yes\">"); |
635 |
|
636 |
options.append("<panel layout=\"FlowLayout\" position=\"North\" align=\"left\">");
|
637 |
options.append("<label>Tama?o bloque:</label>");
|
638 |
options.append("<combo ident=\"BLOCKSIZE\" selected=\""+this.support.getBlockSize() +"\">"); |
639 |
for(int i=0;i<this.support.getBlockSizeList().length;i++) |
640 |
options.append("<elem>"+this.support.getBlockSizeList()[i]+"</elem>"); |
641 |
options.append("</combo>");
|
642 |
options.append("<label>Georef Si/No:</label>");
|
643 |
String sel = null; |
644 |
if(this.support.getGeoref()) |
645 |
sel = new String("yes"); |
646 |
else
|
647 |
sel = new String("no"); |
648 |
options.append("<check ident=\"GEOREF\" selected=\""+sel +"\" text=\"\">"); |
649 |
options.append("</check>");
|
650 |
options.append("</panel>");
|
651 |
|
652 |
options.append("<panel layout=\"FlowLayout\" position=\"Center\" align=\"left\">");
|
653 |
options.append("<label>Photometric:</label>");
|
654 |
options.append("<combo ident=\"PHOTOMETRIC\" selected=\""+this.support.getPhotometric() +"\">"); |
655 |
for(int i=0;i<this.support.getPhotometricList().length;i++) |
656 |
options.append("<elem>"+this.support.getPhotometricList()[i]+"</elem>"); |
657 |
options.append("</combo>");
|
658 |
options.append("<label>Interleave:</label>");
|
659 |
options.append("<combo ident=\"INTERLEAVE\" selected=\""+this.support.getInterleave() +"\">"); |
660 |
for(int i=0;i<this.support.getInterleaveList().length;i++) |
661 |
options.append("<elem>"+this.support.getInterleaveList()[i]+"</elem>"); |
662 |
options.append("</combo>");
|
663 |
options.append("</panel>");
|
664 |
|
665 |
options.append("<panel layout=\"FlowLayout\" position=\"South\" align=\"left\">");
|
666 |
options.append("<label>Compresi?n:</label>");
|
667 |
options.append("<combo ident=\"COMPRESS\" selected=\""+this.support.getCompress() +"\">"); |
668 |
for(int i=0;i<this.support.getCompressList().length;i++) |
669 |
options.append("<elem>"+this.support.getCompressList()[i]+"</elem>"); |
670 |
options.append("</combo>");
|
671 |
options.append("<label>Generar Tfw:</label>");
|
672 |
sel = null;
|
673 |
if(this.support.getTfw()) |
674 |
sel = new String("yes"); |
675 |
else
|
676 |
sel = new String("no"); |
677 |
options.append("<check ident=\"TFW\" selected=\""+sel +"\" text=\"\">"); |
678 |
options.append("</check>");
|
679 |
options.append("</panel>");
|
680 |
|
681 |
options.append("</panel>");
|
682 |
options.append("</window>");
|
683 |
|
684 |
return options.toString();
|
685 |
|
686 |
|
687 |
} |
688 |
} |