Revision 12333 trunk/libraries/libRaster/src/org/gvsig/raster/dataset/io/GdalWriter.java

View differences:

GdalWriter.java
66 66
 * @author Nacho Brodin (nachobrodin@gmail.com)
67 67
 */
68 68
public class GdalWriter extends GeoRasterWriter {
69
	   
69

  
70 70
	public static void register() {
71 71
		ExtensionPoints extensionPoints = ExtensionPointsSingleton.getInstance();
72
		
72

  
73 73
		extensionPoints.add("RasterWriter", "tif", GdalWriter.class);
74 74
		fileFeature.put("tif", new GTiffFeatures());
75
		
75

  
76 76
		extensionPoints.add("RasterWriter", "img", GdalWriter.class);
77 77
		fileFeature.put("img", new HFAFeatures());
78
	 
78

  
79 79
		extensionPoints.add("RasterWriter", "bmp", GdalWriter.class);
80 80
		fileFeature.put("bmp", new BMPFeatures());
81
		
81

  
82 82
		extensionPoints.add("RasterWriter", "pgm", GdalWriter.class);
83 83
		fileFeature.put("pgm", new PNM_PgmFeatures());
84
		
84

  
85 85
		extensionPoints.add("RasterWriter", "ppm", GdalWriter.class);
86 86
		fileFeature.put("ppm", new PNM_PpmFeatures());
87
		
87

  
88 88
		extensionPoints.add("RasterWriter", "mpl", GdalWriter.class);
89 89
		fileFeature.put("mpl", new ILWIS_MprFeatures());
90
		
90

  
91 91
		extensionPoints.add("RasterWriter", "rst", GdalWriter.class);
92 92
		fileFeature.put("rst", new IDRISIFeatures());
93
		
93

  
94 94
		extensionPoints.add("RasterWriter", "rmf", GdalWriter.class);
95 95
		fileFeature.put("rmf", new RMFFeatures());
96
		
96

  
97 97
		//No salva datos. Siempre sale negra la imagen
98 98
		//extensionPoints.add("RasterWriter", "aux", GdalWriter.class);
99 99
		//fileFeature.put("aux", new PAuxFeatures());
100 100
	}
101
    
102
    private es.gva.cit.jgdal.GdalDriver		drv;
103
    private Gdal 							dset_destino = null;
104
    private GdalRasterBand 					rband = null;
105
    private GeoTransform 					geot = null; //Datos de georeferenciaci?n
106
    //private OGRSpatialReference 			oSRS; //Datos de proyecci?n						
107
    private GdalBuffer[]					bufBands = null;
108
    private int 							nBlocks = 0; //N?mero de bloques en Y en el que se divide la imagen para escribir
109
    private int 							anchoResto = 0; //Tama?o del ?ltimo bloque de la imagen.
110
    private boolean							write = true; //Cuando est? a true se puede escribir en la imagen de salida. Si est? a false el proceso es interrumpido
111
    private int 							dataType = RasterBuffer.TYPE_UNDEFINED;
112 101

  
113
    /**
114
     * Carga los par?metros de este driver.
115
     */
116
    public void loadParams(String ident) {
117
    	WriteFileFormatFeatures wfff = (WriteFileFormatFeatures)fileFeature.get(ident);
118
    	wfff.loadParams();
119
    	driverParams = wfff.getParams();
120
    }
121
    
122
    /**
123
     * Constructor para la obtenci?n de par?metros del driver
124
     * @param drvType        Tipo de driver
125
     */
126
    public GdalWriter(String fileName) {
127
    	ident = RasterUtilities.getExtensionFromFileName(fileName);
128
    	driver = ((WriteFileFormatFeatures)fileFeature.get(ident)).getDriverName();
129
    	
130
    	loadParams(ident);
131
    }
102
		private es.gva.cit.jgdal.GdalDriver		drv;
103
		private Gdal 							dset_destino = null;
104
		private GdalRasterBand 					rband = null;
105
		private GeoTransform 					geot = null; //Datos de georeferenciaci?n
106
		//private OGRSpatialReference 			oSRS; //Datos de proyecci?n
107
		private GdalBuffer[]					bufBands = null;
108
		private int 							nBlocks = 0; //N?mero de bloques en Y en el que se divide la imagen para escribir
109
		private int 							anchoResto = 0; //Tama?o del ?ltimo bloque de la imagen.
110
		private boolean							write = true; //Cuando est? a true se puede escribir en la imagen de salida. Si est? a false el proceso es interrumpido
111
		private int 							dataType = RasterBuffer.TYPE_UNDEFINED;
132 112

  
133
    /**
134
     * Constructor para salvar datos servidos por el cliente
135
     * @param dataWriter       	Objeto servidor de datos para el driver de escritura
136
     * @param outFilename      	Fichero de salida
137
     * @param blockSize        	Tama?o de bloque
138
     * @param Extent           	extent
139
     * @param compresion	   	Compresi?n si la tiene
140
     * @param outSizeX		  	Tama?o de salida en X
141
     * @param outSizeY			Tama?o de salida en Y
142
     * @param dataType			Tipo de dato 
143
     * @throws GdalException
144
     * @throws IOException
145
     */
146
    public GdalWriter(	IDataWriter dataWriter, 
147
     					String outFileName, 
148
     					Integer nBands,
149
     					Extent ex,
150
     					Integer outSizeX,
151
     					Integer outSizeY,
152
     					Integer dataType,
153
     					Params params)throws GdalException, IOException {
154
               
155
    	ident = outFileName.toLowerCase().substring(outFileName.lastIndexOf(".") + 1); 
156
    	driver = ((WriteFileFormatFeatures)fileFeature.get(ident)).getDriverName();
157
        this.dataType = dataType.intValue();
158
        this.extent = ex;
159
        percent = 0;
160
        
161
        this.dataWriter = dataWriter;
162
        this.outFileName = outFileName;
113
		/**
114
		 * Carga los par?metros de este driver.
115
		 */
116
		public void loadParams(String ident) {
117
			WriteFileFormatFeatures wfff = (WriteFileFormatFeatures)fileFeature.get(ident);
118
			wfff.loadParams();
119
			driverParams = wfff.getParams();
120
		}
163 121

  
164
        this.sizeWindowX = outSizeX.intValue();
165
        this.sizeWindowY = outSizeY.intValue();
122
		/**
123
		 * Constructor para la obtenci?n de par?metros del driver
124
		 * @param drvType        Tipo de driver
125
		 */
126
		public GdalWriter(String fileName) {
127
			ident = RasterUtilities.getExtensionFromFileName(fileName);
128
			driver = ((WriteFileFormatFeatures)fileFeature.get(ident)).getDriverName();
166 129

  
167
        if ((sizeWindowX < 0) || (sizeWindowY < 0)) 
168
            throw new IOException("Tama?o del fichero de salida erroneo.");
169
        
170
        this.nBands = nBands.intValue();
130
			loadParams(ident);
131
		}
171 132

  
172
        //Calculamos la georeferenciaci?n a partir del extend pasado por el cliente.
173
        
174
        double maxX = ex.maxX();
175
        double minX = ex.minX();
176
        double maxY = ex.maxY();
177
        double minY = ex.minY();
178
      
179
        geot = new GeoTransform();
180
        geot.adfgeotransform[0] = minX;
181
        geot.adfgeotransform[3] = maxY; //-((pixelSizeY * outSizeY)-minY);
182
        geot.adfgeotransform[1] = (double) ((maxX - minX) / outSizeX.intValue()); //pixelSizeX;
183
        geot.adfgeotransform[5] = (double) ((minY - maxY) / outSizeY.intValue()); //pixelSizeY;
133
		/**
134
		 * Constructor para salvar datos servidos por el cliente
135
		 * @param dataWriter       	Objeto servidor de datos para el driver de escritura
136
		 * @param outFilename      	Fichero de salida
137
		 * @param blockSize        	Tama?o de bloque
138
		 * @param Extent           	extent
139
		 * @param compresion	   	Compresi?n si la tiene
140
		 * @param outSizeX		  	Tama?o de salida en X
141
		 * @param outSizeY			Tama?o de salida en Y
142
		 * @param dataType			Tipo de dato
143
		 * @throws GdalException
144
		 * @throws IOException
145
		 */
146
		public GdalWriter(	IDataWriter dataWriter,
147
							 String outFileName,
148
							 Integer nBands,
149
							 Extent ex,
150
							 Integer outSizeX,
151
							 Integer outSizeY,
152
							 Integer dataType,
153
							 Params params)throws GdalException, IOException {
184 154

  
185
        if(params == null)
186
        	loadParams(ident);
187
        else 
188
        	this.driverParams = params;
189
        
190
        init();
191
    }
192
    
193
    /**
194
     * Asigna el tipo de driver con el que se salvar? la imagen
195
     * @param drvType        Tipo de driver
196
     */
197
    public void setDriverType(String drvType) {
198
        this.driver = drvType;
199
    }
155
			ident = outFileName.toLowerCase().substring(outFileName.lastIndexOf(".") + 1);
156
			driver = ((WriteFileFormatFeatures)fileFeature.get(ident)).getDriverName();
157
				this.dataType = dataType.intValue();
158
				this.extent = ex;
159
				percent = 0;
200 160

  
201
    /**
202
     * Creaci?n del dataset de destino.
203
     * @throws EcwException
204
     */
205
    private void init() throws GdalException {
206
        //Controlamos que el tipo de driver sea correcto
207
        if (driver == null) {
208
            throw new GdalException("Tipo de driver sin especificar.");
209
        }
161
				this.dataWriter = dataWriter;
162
				this.outFileName = outFileName;
210 163

  
211
        boolean okdrvtype = false;
164
				this.sizeWindowX = outSizeX.intValue();
165
				this.sizeWindowY = outSizeY.intValue();
212 166

  
213
        String[] types = GeoRasterWriter.getDriversType();
214
        for (int i = 0; i < GeoRasterWriter.getNTypes(); i++)
215
            if (driver.equals(types[i]))
216
                okdrvtype = true;
217
            
218
        if (okdrvtype == false)
219
            throw new GdalException("El tipo de driver " + driver + " no est? soportado por GdalWriter.");
220
        
221
        //Obtenemos el driver y creamos el dataset del destino
222
        drv = Gdal.getDriverByName(driver);
223
        
224
        if (dset_destino != null) {
225
            dset_destino.close();
226
            dset_destino = null;
227
        }
228
                
229
        dset_destino = drv.create(outFileName, sizeWindowX, sizeWindowY,
230
                                  nBands, RasterUtilities.getGdalTypeFromRasterBufType(dataType), gdalParamsFromRasterParams(driverParams));
231
        
232
        dset_destino.setGeoTransform(geot);
233
        
234
        int blockSize = 256;
235
        try {
236
        	blockSize = Integer.parseInt(driverParams.getParamById("blocksize").defaultValue);
237
        }catch(NumberFormatException e) {
238
        	//Se queda con el valor de inicializaci?n
239
        }
240
        
241
        nBlocks = (int) (sizeWindowY / blockSize);
242
        anchoResto = sizeWindowY - (nBlocks * blockSize);
243
    }
244
    
245
    public void anotherFile(String fileName)throws GdalException {
246
    	dset_destino = drv.create(fileName, sizeWindowX, sizeWindowY,
247
                nBands, RasterUtilities.getGdalTypeFromRasterBufType(dataType), gdalParamsFromRasterParams(driverParams));
248
    }
167
				if ((sizeWindowX < 0) || (sizeWindowY < 0))
168
						throw new IOException("Tama?o del fichero de salida erroneo.");
249 169

  
250
    /**
251
     * Convierte los par?metros obtenidos desde el objeto params a parametros
252
     * comprensibles por la librer?a gdal
253
     * @param p Params
254
     * @return Array de par?metros
255
     */
256
    private String[] gdalParamsFromRasterParams(Params p) {
257
    	if(p == null)
258
    		return null;
259
    	ArrayList paramList = new ArrayList();
260
    	Param phot = (Param)p.getParamById("photometric");
261
    	if(phot != null)
262
    		paramList.add("PHOTOMETRIC=" + phot.defaultValue);
263
    	Param inter = (Param)p.getParamById("interleave");
264
    	if(inter != null)
265
    		paramList.add("INTERLEAVE=" + inter.defaultValue);
266
    	Param comp = (Param)p.getParamById("compression");
267
    	if(comp != null)
268
    		paramList.add("COMPRESS=" + comp.defaultValue);
269
    	Param comp1 = (Param)p.getParamById("compress");
270
    	if(comp1 != null)
271
    		paramList.add("COMPRESS=" + comp1.defaultValue);
272
    	Param rrd = (Param)p.getParamById("rrd");
273
    	if(rrd != null)
274
    		paramList.add("HFA_USE_RRD=" + rrd.defaultValue);
275
    	Param mtw = (Param)p.getParamById("Mtw");
276
    	if(mtw != null)
277
    		paramList.add("MTW=" + mtw.defaultValue);
278
    	Param tw = (Param)p.getParamById("Tile Width");
279
    	if(tw != null)
280
    		paramList.add("BLOCKXSIZE=" + tw.defaultValue);
281
    	Param th = (Param)p.getParamById("Tile Height");
282
    	if(th != null)
283
    		paramList.add("BLOCKYSIZE=" + th.defaultValue);
170
				this.nBands = nBands.intValue();
284 171

  
285
    	if(paramList.size() == 0)
286
    		return null;
287
    	
288
    	String[] result = new String[paramList.size()];
289
    	for (int i = 0; i < result.length; i++)
172
				//Calculamos la georeferenciaci?n a partir del extend pasado por el cliente.
173

  
174
				double maxX = ex.maxX();
175
				double minX = ex.minX();
176
				double maxY = ex.maxY();
177
				double minY = ex.minY();
178

  
179
				geot = new GeoTransform();
180
				geot.adfgeotransform[0] = minX;
181
				geot.adfgeotransform[3] = maxY; //-((pixelSizeY * outSizeY)-minY);
182
				geot.adfgeotransform[1] = (double) ((maxX - minX) / outSizeX.intValue()); //pixelSizeX;
183
				geot.adfgeotransform[5] = (double) ((minY - maxY) / outSizeY.intValue()); //pixelSizeY;
184

  
185
				if(params == null)
186
					loadParams(ident);
187
				else
188
					this.driverParams = params;
189

  
190
				init();
191
		}
192

  
193
		/**
194
		 * Asigna el tipo de driver con el que se salvar? la imagen
195
		 * @param drvType        Tipo de driver
196
		 */
197
		public void setDriverType(String drvType) {
198
				this.driver = drvType;
199
		}
200

  
201
		/**
202
		 * Creaci?n del dataset de destino.
203
		 * @throws EcwException
204
		 */
205
		private void init() throws GdalException {
206
				//Controlamos que el tipo de driver sea correcto
207
				if (driver == null) {
208
						throw new GdalException("Tipo de driver sin especificar.");
209
				}
210

  
211
				boolean okdrvtype = false;
212

  
213
				String[] types = GeoRasterWriter.getDriversType();
214
				for (int i = 0; i < GeoRasterWriter.getNTypes(); i++)
215
						if (driver.equals(types[i]))
216
								okdrvtype = true;
217

  
218
				if (okdrvtype == false)
219
						throw new GdalException("El tipo de driver " + driver + " no est? soportado por GdalWriter.");
220

  
221
				//Obtenemos el driver y creamos el dataset del destino
222
				drv = Gdal.getDriverByName(driver);
223

  
224
				if (dset_destino != null) {
225
						dset_destino.close();
226
						dset_destino = null;
227
				}
228

  
229
				dset_destino = drv.create(outFileName, sizeWindowX, sizeWindowY,
230
																	nBands, RasterUtilities.getGdalTypeFromRasterBufType(dataType), gdalParamsFromRasterParams(driverParams));
231

  
232
				dset_destino.setGeoTransform(geot);
233

  
234
				int blockSize = 256;
235
				try {
236
					blockSize = Integer.parseInt((String) driverParams.getParamById("blocksize").defaultValue);
237
				}catch(NumberFormatException e) {
238
					//Se queda con el valor de inicializaci?n
239
				}
240

  
241
				nBlocks = (int) (sizeWindowY / blockSize);
242
				anchoResto = sizeWindowY - (nBlocks * blockSize);
243
		}
244

  
245
		public void anotherFile(String fileName)throws GdalException {
246
			dset_destino = drv.create(fileName, sizeWindowX, sizeWindowY,
247
								nBands, RasterUtilities.getGdalTypeFromRasterBufType(dataType), gdalParamsFromRasterParams(driverParams));
248
		}
249

  
250
		/**
251
		 * Convierte los par?metros obtenidos desde el objeto params a parametros
252
		 * comprensibles por la librer?a gdal
253
		 * @param p Params
254
		 * @return Array de par?metros
255
		 */
256
		private String[] gdalParamsFromRasterParams(Params p) {
257
			if(p == null)
258
				return null;
259
			ArrayList paramList = new ArrayList();
260
			Param phot = (Param)p.getParamById("photometric");
261
			if(phot != null)
262
				paramList.add("PHOTOMETRIC=" + phot.defaultValue);
263
			Param inter = (Param)p.getParamById("interleave");
264
			if(inter != null)
265
				paramList.add("INTERLEAVE=" + inter.defaultValue);
266
			Param comp = (Param)p.getParamById("compression");
267
			if(comp != null)
268
				paramList.add("COMPRESS=" + comp.defaultValue);
269
			Param comp1 = (Param)p.getParamById("compress");
270
			if(comp1 != null)
271
				paramList.add("COMPRESS=" + comp1.defaultValue);
272
			Param rrd = (Param)p.getParamById("rrd");
273
			if(rrd != null)
274
				paramList.add("HFA_USE_RRD=" + rrd.defaultValue);
275
			Param mtw = (Param)p.getParamById("Mtw");
276
			if(mtw != null)
277
				paramList.add("MTW=" + mtw.defaultValue);
278
			Param tw = (Param)p.getParamById("Tile Width");
279
			if(tw != null)
280
				paramList.add("BLOCKXSIZE=" + tw.defaultValue);
281
			Param th = (Param)p.getParamById("Tile Height");
282
			if(th != null)
283
				paramList.add("BLOCKYSIZE=" + th.defaultValue);
284

  
285
			if(paramList.size() == 0)
286
				return null;
287

  
288
			String[] result = new String[paramList.size()];
289
			for (int i = 0; i < result.length; i++)
290 290
			result[i] = (String)paramList.get(i);
291
    	return result;
292
    }
293
    
294
    /**
295
     * A partir de un elemento que contiene una propiedad y un valor
296
     * lo parsea y asigna el valor a su variable.
297
     * @param propValue        elemento con la forma propiedad=valor
298
     */
299
   /* private void readProperty(String propValue) {
300
        String prop = propValue.substring(0, propValue.indexOf("="));
291
			return result;
292
		}
301 293

  
302
        if (propValue.startsWith(prop)) {
303
            String value = propValue.substring(propValue.indexOf("=") + 1, propValue.length());
294
		/**
295
		 * A partir de un elemento que contiene una propiedad y un valor
296
		 * lo parsea y asigna el valor a su variable.
297
		 * @param propValue        elemento con la forma propiedad=valor
298
		 */
299
	 /* private void readProperty(String propValue) {
300
				String prop = propValue.substring(0, propValue.indexOf("="));
304 301

  
305
            if ((value != null) && !value.equals("")) {
306
                if (prop.equals("BLOCKSIZE"))
307
                    driverParams.changeParamValue("blocksize", value);
308
                if (prop.equals("INTERLEAVE")) 
309
                	driverParams.changeParamValue("interleave", value);
310
                if (prop.equals("PHOTOMETRIC"))
311
                	driverParams.changeParamValue("photometric", value);
312
                if (prop.equals("COMPRESS"))
313
                	driverParams.changeParamValue("compression", value);
314
                if (prop.equals("TFW"))
315
                    driverParams.changeParamValue("tfw", value);
316
            }
317
        }
318
    }*/
302
				if (propValue.startsWith(prop)) {
303
						String value = propValue.substring(propValue.indexOf("=") + 1, propValue.length());
319 304

  
320
    /**
321
     * Asigna propiedades al driver a partir de un vector de
322
     * strings donde cada elemento tiene la estructura de
323
     * propiedad=valor.
324
     * @param props        Propiedades
325
     */
326
    /*public void setProps(String[] props) {
327
        for (int iProps = 0; iProps < props.length; iProps++)
328
            readProperty(props[iProps]);
305
						if ((value != null) && !value.equals("")) {
306
								if (prop.equals("BLOCKSIZE"))
307
										driverParams.changeParamValue("blocksize", value);
308
								if (prop.equals("INTERLEAVE"))
309
									driverParams.changeParamValue("interleave", value);
310
								if (prop.equals("PHOTOMETRIC"))
311
									driverParams.changeParamValue("photometric", value);
312
								if (prop.equals("COMPRESS"))
313
									driverParams.changeParamValue("compression", value);
314
								if (prop.equals("TFW"))
315
										driverParams.changeParamValue("tfw", value);
316
						}
317
				}
318
		}*/
329 319

  
330
        loadParams();
320
		/**
321
		 * Asigna propiedades al driver a partir de un vector de
322
		 * strings donde cada elemento tiene la estructura de
323
		 * propiedad=valor.
324
		 * @param props        Propiedades
325
		 */
326
		/*public void setProps(String[] props) {
327
				for (int iProps = 0; iProps < props.length; iProps++)
328
						readProperty(props[iProps]);
331 329

  
332
        try {
333
            if (!consulta)
334
                init();
335
        } catch (GdalException e) {
336
            e.printStackTrace();
337
        }
338
    }*/
330
				loadParams();
339 331

  
340
    /**
341
     * Escritura de datos tipo Byte.
342
     * @param sizeY Alto del bloque que se escribe.
343
     * @param posicionY Posici?ny a partir desde donde se comienza.
344
     */
345
    public void writeByteBand(int sizeY, int posicionY) {
346
    	byte[][] buftmp = dataWriter.readByteData(sizeWindowX, sizeY);
347
    	for(int iBand = 0; iBand < nBands; iBand ++)
348
        	bufBands[iBand].buffByte = new byte[buftmp[iBand].length];	
349
  
350
    	//Escribimos el bloque destino
351
    	for (int iBand = 0; iBand < buftmp.length; iBand++)
352
    		for (int i = 0; i < buftmp[iBand].length; i++)
353
    			bufBands[iBand].buffByte[i] = buftmp[iBand][i];
354
    	
355
        for (int iBand = 0; iBand < buftmp.length; iBand++){
356
        	try {
332
				try {
333
						if (!consulta)
334
								init();
335
				} catch (GdalException e) {
336
						e.printStackTrace();
337
				}
338
		}*/
339

  
340
		/**
341
		 * Escritura de datos tipo Byte.
342
		 * @param sizeY Alto del bloque que se escribe.
343
		 * @param posicionY Posici?ny a partir desde donde se comienza.
344
		 */
345
		public void writeByteBand(int sizeY, int posicionY) {
346
			byte[][] buftmp = dataWriter.readByteData(sizeWindowX, sizeY);
347
			for(int iBand = 0; iBand < nBands; iBand ++)
348
					bufBands[iBand].buffByte = new byte[buftmp[iBand].length];
349

  
350
			//Escribimos el bloque destino
351
			for (int iBand = 0; iBand < buftmp.length; iBand++)
352
				for (int i = 0; i < buftmp[iBand].length; i++)
353
					bufBands[iBand].buffByte[i] = buftmp[iBand][i];
354

  
355
				for (int iBand = 0; iBand < buftmp.length; iBand++){
356
					try {
357 357
				rband = dset_destino.getRasterBand(iBand + 1);
358 358
				rband.writeRaster(0, posicionY, sizeWindowX, sizeY, bufBands[iBand], Gdal.GDT_Byte);
359
        	} catch (GdalException e) {
359
					} catch (GdalException e) {
360 360
				//No se est? escribiendo ...
361 361
			}
362
        }
363
    }
364
    
365
    /**
366
     * Escritura de datos tipo Short.
367
     * @param sizeY Alto del bloque que se escribe.
368
     * @param posicionY Posici?ny a partir desde donde se comienza.
369
     */
370
    public void writeShortBand(int sizeY, int posicionY) {
371
    	short[][] buftmp = dataWriter.readShortData(sizeWindowX, sizeY);
372
    	for(int iBand = 0; iBand < nBands; iBand ++)
373
        	bufBands[iBand].buffShort = new short[buftmp[iBand].length];	
374
  
375
    	//Escribimos el bloque destino
376
    	for (int iBand = 0; iBand < buftmp.length; iBand++)
377
    		for (int i = 0; i < buftmp[iBand].length; i++)
378
    			bufBands[iBand].buffShort[i] = buftmp[iBand][i];
379
    	
380
        for (int iBand = 0; iBand < buftmp.length; iBand++){
381
        	try {
362
				}
363
		}
364

  
365
		/**
366
		 * Escritura de datos tipo Short.
367
		 * @param sizeY Alto del bloque que se escribe.
368
		 * @param posicionY Posici?ny a partir desde donde se comienza.
369
		 */
370
		public void writeShortBand(int sizeY, int posicionY) {
371
			short[][] buftmp = dataWriter.readShortData(sizeWindowX, sizeY);
372
			for(int iBand = 0; iBand < nBands; iBand ++)
373
					bufBands[iBand].buffShort = new short[buftmp[iBand].length];
374

  
375
			//Escribimos el bloque destino
376
			for (int iBand = 0; iBand < buftmp.length; iBand++)
377
				for (int i = 0; i < buftmp[iBand].length; i++)
378
					bufBands[iBand].buffShort[i] = buftmp[iBand][i];
379

  
380
				for (int iBand = 0; iBand < buftmp.length; iBand++){
381
					try {
382 382
				rband = dset_destino.getRasterBand(iBand + 1);
383 383
				rband.writeRaster(0, posicionY, sizeWindowX, sizeY, bufBands[iBand], Gdal.GDT_Int16);
384
        	} catch (GdalException e) {
384
					} catch (GdalException e) {
385 385
				//No se est? escribiendo ...
386 386
			}
387
        }
388
    }
389
        
390
    /**
391
     * Escritura de datos tipo Int.
392
     * @param sizeY Alto del bloque que se escribe.
393
     * @param posicionY Posici?ny a partir desde donde se comienza.
394
     */
395
    public void writeIntBand(int sizeY, int posicionY) {
396
    	int[][] buftmp = dataWriter.readIntData(sizeWindowX, sizeY);
397
    	for(int iBand = 0; iBand < nBands; iBand ++)
398
        	bufBands[iBand].buffInt = new int[buftmp[iBand].length];	
399
  
400
    	//Escribimos el bloque destino
401
    	for (int iBand = 0; iBand < buftmp.length; iBand++)
402
    		for (int i = 0; i < buftmp[iBand].length; i++)
403
    			bufBands[iBand].buffInt[i] = buftmp[iBand][i];
404
    	
405
        for (int iBand = 0; iBand < buftmp.length; iBand++){
406
        	try {
387
				}
388
		}
389

  
390
		/**
391
		 * Escritura de datos tipo Int.
392
		 * @param sizeY Alto del bloque que se escribe.
393
		 * @param posicionY Posici?ny a partir desde donde se comienza.
394
		 */
395
		public void writeIntBand(int sizeY, int posicionY) {
396
			int[][] buftmp = dataWriter.readIntData(sizeWindowX, sizeY);
397
			for(int iBand = 0; iBand < nBands; iBand ++)
398
					bufBands[iBand].buffInt = new int[buftmp[iBand].length];
399

  
400
			//Escribimos el bloque destino
401
			for (int iBand = 0; iBand < buftmp.length; iBand++)
402
				for (int i = 0; i < buftmp[iBand].length; i++)
403
					bufBands[iBand].buffInt[i] = buftmp[iBand][i];
404

  
405
				for (int iBand = 0; iBand < buftmp.length; iBand++){
406
					try {
407 407
				rband = dset_destino.getRasterBand(iBand + 1);
408 408
				rband.writeRaster(0, posicionY, sizeWindowX, sizeY, bufBands[iBand], Gdal.GDT_Int32);
409
        	} catch (GdalException e) {
409
					} catch (GdalException e) {
410 410
				//No se est? escribiendo ...
411 411
			}
412
        }
413
    }
414
    
415
    /**
416
     * Escritura de datos tipo Float.
417
     * @param sizeY Alto del bloque que se escribe.
418
     * @param posicionY Posici?ny a partir desde donde se comienza.
419
     */
420
    public void writeFloatBand(int sizeY, int posicionY) {
421
    	float[][] buftmp = dataWriter.readFloatData(sizeWindowX, sizeY);
422
    	for(int iBand = 0; iBand < nBands; iBand ++)
423
        	bufBands[iBand].buffFloat = new float[buftmp[iBand].length];	
424
  
425
    	//Escribimos el bloque destino
426
    	for (int iBand = 0; iBand < buftmp.length; iBand++)
427
    		for (int i = 0; i < buftmp[iBand].length; i++)
428
    			bufBands[iBand].buffFloat[i] = buftmp[iBand][i];
429
    	
430
        for (int iBand = 0; iBand < buftmp.length; iBand++){
431
        	try {
412
				}
413
		}
414

  
415
		/**
416
		 * Escritura de datos tipo Float.
417
		 * @param sizeY Alto del bloque que se escribe.
418
		 * @param posicionY Posici?ny a partir desde donde se comienza.
419
		 */
420
		public void writeFloatBand(int sizeY, int posicionY) {
421
			float[][] buftmp = dataWriter.readFloatData(sizeWindowX, sizeY);
422
			for(int iBand = 0; iBand < nBands; iBand ++)
423
					bufBands[iBand].buffFloat = new float[buftmp[iBand].length];
424

  
425
			//Escribimos el bloque destino
426
			for (int iBand = 0; iBand < buftmp.length; iBand++)
427
				for (int i = 0; i < buftmp[iBand].length; i++)
428
					bufBands[iBand].buffFloat[i] = buftmp[iBand][i];
429

  
430
				for (int iBand = 0; iBand < buftmp.length; iBand++){
431
					try {
432 432
				rband = dset_destino.getRasterBand(iBand + 1);
433 433
				rband.writeRaster(0, posicionY, sizeWindowX, sizeY, bufBands[iBand], Gdal.GDT_Float32);
434
        	} catch (GdalException e) {
434
					} catch (GdalException e) {
435 435
				//No se est? escribiendo ...
436 436
			}
437
        }
438
    }
439
    
440
    /**
441
     * Escritura de datos tipo Double.
442
     * @param sizeY Alto del bloque que se escribe.
443
     * @param posicionY Posici?ny a partir desde donde se comienza.
444
     */
445
    public void writeDoubleBand(int sizeY, int posicionY) {
446
    	double[][] buftmp = dataWriter.readDoubleData(sizeWindowX, sizeY);
447
    	for(int iBand = 0; iBand < nBands; iBand ++)
448
        	bufBands[iBand].buffDouble = new double[buftmp[iBand].length];	
449
  
450
    	//Escribimos el bloque destino
451
    	for (int iBand = 0; iBand < buftmp.length; iBand++)
452
    		for (int i = 0; i < buftmp[iBand].length; i++)
453
    			bufBands[iBand].buffDouble[i] = buftmp[iBand][i];
454
    	
455
        for (int iBand = 0; iBand < buftmp.length; iBand++){
456
        	try {
437
				}
438
		}
439

  
440
		/**
441
		 * Escritura de datos tipo Double.
442
		 * @param sizeY Alto del bloque que se escribe.
443
		 * @param posicionY Posici?ny a partir desde donde se comienza.
444
		 */
445
		public void writeDoubleBand(int sizeY, int posicionY) {
446
			double[][] buftmp = dataWriter.readDoubleData(sizeWindowX, sizeY);
447
			for(int iBand = 0; iBand < nBands; iBand ++)
448
					bufBands[iBand].buffDouble = new double[buftmp[iBand].length];
449

  
450
			//Escribimos el bloque destino
451
			for (int iBand = 0; iBand < buftmp.length; iBand++)
452
				for (int i = 0; i < buftmp[iBand].length; i++)
453
					bufBands[iBand].buffDouble[i] = buftmp[iBand][i];
454

  
455
				for (int iBand = 0; iBand < buftmp.length; iBand++){
456
					try {
457 457
				rband = dset_destino.getRasterBand(iBand + 1);
458 458
				rband.writeRaster(0, posicionY, sizeWindowX, sizeY, bufBands[iBand], Gdal.GDT_Float64);
459
        	} catch (GdalException e) {
459
					} catch (GdalException e) {
460 460
				//No se est? escribiendo ...
461 461
			}
462
        }
463
    }
464
    /**
465
     * Escritura para tipo de dato ARGB.
466
     * @param sizeY Alto del bloque que se escribe.
467
     * @param posicionY Posici?ny a partir desde donde se comienza.
468
     */
469
    public void writeARGBBand(int sizeY, int posicionY) {
470
    	int[] buftmp = dataWriter.readARGBData(sizeWindowX, sizeY, 0);
471
     	for(int iBand = 0; iBand < nBands; iBand ++)
472
         	bufBands[iBand].buffByte = new byte[buftmp.length];	
473
     	
474
         //Escribimos el bloque destino
475
         for (int i = 0; i < buftmp.length; i++) {
476
             bufBands[0].buffByte[i] = (byte) (((buftmp[i] & 0xff0000) >> 16) &
477
                                    0xff);
478
             bufBands[1].buffByte[i] = (byte) (((buftmp[i] & 0xff00) >> 8) & 0xff);
479
             bufBands[2].buffByte[i] = (byte) ((buftmp[i] & 0xff) & 0xff);
480
         }
462
				}
463
		}
464
		/**
465
		 * Escritura para tipo de dato ARGB.
466
		 * @param sizeY Alto del bloque que se escribe.
467
		 * @param posicionY Posici?ny a partir desde donde se comienza.
468
		 */
469
		public void writeARGBBand(int sizeY, int posicionY) {
470
			int[] buftmp = dataWriter.readARGBData(sizeWindowX, sizeY, 0);
471
			 for(int iBand = 0; iBand < nBands; iBand ++)
472
					 bufBands[iBand].buffByte = new byte[buftmp.length];
481 473

  
482
         try {
483
             rband = dset_destino.getRasterBand(1);
484
             rband.writeRaster(0, posicionY, sizeWindowX, sizeY, bufBands[0],
485
                               Gdal.GDT_Byte);
486
             rband = dset_destino.getRasterBand(2);
487
             rband.writeRaster(0, posicionY, sizeWindowX, sizeY, bufBands[1],
488
                               Gdal.GDT_Byte);
489
             rband = dset_destino.getRasterBand(3);
490
             rband.writeRaster(0, posicionY, sizeWindowX, sizeY, bufBands[2],
491
                               Gdal.GDT_Byte);
492
         } catch (GdalException e) {
493
             e.printStackTrace();
494
         }
495
    }
496
    
497
    /**
498
     * Escribe tres bandas en el GDALRasterBand desde el IDataWriter con una
499
     * altura definida por sizeY.
500
     * @param buftmp        Buffer
501
     * @param sizeY        Altura en pixels del bloque leido
502
     * @param posicionY        Posici?n y a partir de la cual se escribe en el GDALRasterBand destino
503
     */
504
    private void writeBands(int sizeY, int posicionY) {
505
        //leemos el bloque origen
506
        
507
        switch(dataType){
508
        case RasterBuffer.TYPE_IMAGE: 
509
        	writeARGBBand(sizeY, posicionY);
510
        	break;
511
        case RasterBuffer.TYPE_BYTE:
512
        	writeByteBand(sizeY, posicionY);
513
        	break;
514
        case RasterBuffer.TYPE_SHORT:
515
        	writeShortBand(sizeY, posicionY);
516
        	break;
517
        case RasterBuffer.TYPE_INT:
518
        	writeIntBand(sizeY, posicionY);
519
        	break;
520
        case RasterBuffer.TYPE_FLOAT:
521
        	writeFloatBand(sizeY, posicionY);
522
        	break;
523
        case RasterBuffer.TYPE_DOUBLE:
524
        	writeDoubleBand(sizeY, posicionY);
525
        	break;
526
        }
527
    }
474
				 //Escribimos el bloque destino
475
				 for (int i = 0; i < buftmp.length; i++) {
476
						 bufBands[0].buffByte[i] = (byte) (((buftmp[i] & 0xff0000) >> 16) &
477
																		0xff);
478
						 bufBands[1].buffByte[i] = (byte) (((buftmp[i] & 0xff00) >> 8) & 0xff);
479
						 bufBands[2].buffByte[i] = (byte) ((buftmp[i] & 0xff) & 0xff);
480
				 }
528 481

  
529
    /**
530
     * Funci?n que gestiona la lectura desde el origen y la escritura
531
     * de Gdal sobre el fichero destino.
532
     * @param mode        Modo de escritura
533
     * @throws IOException
534
     */
535
    private void write(int mode) throws IOException {
536
        bufBands = new GdalBuffer[nBands];
537
        for(int iBand = 0; iBand < nBands; iBand ++)
538
        	bufBands[iBand] = new GdalBuffer();
539
        
540
        int blockSize = 256;
541
        try {
542
        	blockSize = Integer.parseInt(driverParams.getParamById("blocksize").defaultValue);
543
        }catch(NumberFormatException e) {
544
        	//Se queda con el valor de inicializaci?n
545
        }
546
        
547
        percent = 0;
548
        nBlocks = (int) (sizeWindowY / blockSize);
549
    	int increment = (blockSize * 100) / sizeWindowY;
550
        
551
        if (mode == GeoRasterWriter.MODE_FILEWRITE) {
552
        	/*for (int iBand = 0; iBand < this.nBands; iBand++) {
553
                    rband = dset_destino.getRasterBand(iBand + 1);
482
				 try {
483
						 rband = dset_destino.getRasterBand(1);
484
						 rband.writeRaster(0, posicionY, sizeWindowX, sizeY, bufBands[0],
485
															 Gdal.GDT_Byte);
486
						 rband = dset_destino.getRasterBand(2);
487
						 rband.writeRaster(0, posicionY, sizeWindowX, sizeY, bufBands[1],
488
															 Gdal.GDT_Byte);
489
						 rband = dset_destino.getRasterBand(3);
490
						 rband.writeRaster(0, posicionY, sizeWindowX, sizeY, bufBands[2],
491
															 Gdal.GDT_Byte);
492
				 } catch (GdalException e) {
493
						 e.printStackTrace();
494
				 }
495
		}
554 496

  
555
                    for (int iBlock = 0; iBlock < nBlocks; iBlock++) {
556
                    	if(write){
557
	                        //leemos el bloque origen
558
	                        buf.buffByte = currentRaster.getGeoFile().getWindow(0,
559
	                                                                            iBlock * this.support.getBlockSize(),
560
	                                                                            sizeWindowX,
561
	                                                                            this.support.getBlockSize(),
562
	                                                                            iBand +
563
	                                                                            1);
497
		/**
498
		 * Escribe tres bandas en el GDALRasterBand desde el IDataWriter con una
499
		 * altura definida por sizeY.
500
		 * @param buftmp        Buffer
501
		 * @param sizeY        Altura en pixels del bloque leido
502
		 * @param posicionY        Posici?n y a partir de la cual se escribe en el GDALRasterBand destino
503
		 */
504
		private void writeBands(int sizeY, int posicionY) {
505
				//leemos el bloque origen
564 506

  
565
	                        //Escribimos el bloque destino
566
	                        rband.writeRaster(0,
567
	                                          iBlock * this.support.getBlockSize(),
568
	                                          sizeWindowX,
569
	                                          this.support.getBlockSize(), buf,
570
	                                          Gdal.GDT_Byte);
571
                    	}//else
572
                    		//this.writeClose();
573
                    }
574
                }*/
575
        } else if (mode == GeoRasterWriter.MODE_DATAWRITE) {
576
        	for (int iBlock = 0; iBlock < nBlocks; iBlock++) {
577
        		int posicionY = iBlock * blockSize;
578
        		if(write)
579
        			writeBands( blockSize, posicionY);
580
        		percent = (iBlock + 1) * increment;
581
        	}
582
        }
507
				switch(dataType){
508
				case RasterBuffer.TYPE_IMAGE:
509
					writeARGBBand(sizeY, posicionY);
510
					break;
511
				case RasterBuffer.TYPE_BYTE:
512
					writeByteBand(sizeY, posicionY);
513
					break;
514
				case RasterBuffer.TYPE_SHORT:
515
					writeShortBand(sizeY, posicionY);
516
					break;
517
				case RasterBuffer.TYPE_INT:
518
					writeIntBand(sizeY, posicionY);
519
					break;
520
				case RasterBuffer.TYPE_FLOAT:
521
					writeFloatBand(sizeY, posicionY);
522
					break;
523
				case RasterBuffer.TYPE_DOUBLE:
524
					writeDoubleBand(sizeY, posicionY);
525
					break;
526
				}
527
		}
583 528

  
584
        if (anchoResto != 0) {
585
        	if (mode == GeoRasterWriter.MODE_FILEWRITE) {
586
        		/*for (int iBand = 0; iBand < this.nBands; iBand++) {
587
                        rband = dset_destino.getRasterBand(iBand + 1);
588
                        if(write){
589
	                        //leemos el bloque origen
590
	                        buf.buffByte = currentRaster.getGeoFile().getWindow(0,
591
	                                                                            nBlocks * this.support.getBlockSize(),
592
	                                                                            sizeWindowX,
593
	                                                                            anchoResto,
594
	                                                                            iBand +
595
	                                                                            1);
529
		/**
530
		 * Funci?n que gestiona la lectura desde el origen y la escritura
531
		 * de Gdal sobre el fichero destino.
532
		 * @param mode        Modo de escritura
533
		 * @throws IOException
534
		 */
535
		private void write(int mode) throws IOException {
536
				bufBands = new GdalBuffer[nBands];
537
				for(int iBand = 0; iBand < nBands; iBand ++)
538
					bufBands[iBand] = new GdalBuffer();
596 539

  
597
	                        //Escribimos el bloque destino
598
	                        rband.writeRaster(0,
599
	                                          nBlocks * this.support.getBlockSize(),
600
	                                          sizeWindowX, anchoResto, buf,
601
	                                          Gdal.GDT_Byte);
602
                        }//else
603
                        	//this.writeClose();
604
                    }*/
605
        	} else if (mode == GeoRasterWriter.MODE_DATAWRITE) {
606
        		int posicionY = nBlocks * blockSize;
607
        		if(write)
608
        			writeBands(anchoResto, posicionY);
609
        		percent = nBlocks * increment;
610
        	}
611
        }
612
        
613
    }
540
				int blockSize = 256;
541
				try {
542
					blockSize = Integer.parseInt((String) driverParams.getParamById("blocksize").defaultValue);
543
				}catch(NumberFormatException e) {
544
					//Se queda con el valor de inicializaci?n
545
				}
614 546

  
615
    /**
616
     * Realiza la funci?n de compresi?n a partir de un GeoRasterFile.
617
     * @throws IOException
618
     */
619
    public void fileWrite() throws IOException {
620
        write(GeoRasterWriter.MODE_FILEWRITE);
621
    }
547
				percent = 0;
548
				nBlocks = (int) (sizeWindowY / blockSize);
549
			int increment = (blockSize * 100) / sizeWindowY;
622 550

  
623
    /**
624
     * Realiza una copia en el formato especificado.
625
     * @throws IOException
626
     */
627
    public static void createCopy(es.gva.cit.jgdal.GdalDriver driverDst, String dst, String src, 
628
    		boolean bstrict, String[] params, IProjection proj) throws IOException, GdalException {
629
        if (dst == null || src == null) {
630
            throw new IOException("No se ha asignado un fichero de entrada.");
631
        }
551
				if (mode == GeoRasterWriter.MODE_FILEWRITE) {
552
					/*for (int iBand = 0; iBand < this.nBands; iBand++) {
553
										rband = dset_destino.getRasterBand(iBand + 1);
632 554

  
633
        GdalDriver gdalFile;
555
										for (int iBlock = 0; iBlock < nBlocks; iBlock++) {
556
											if(write){
557
													//leemos el bloque origen
558
													buf.buffByte = currentRaster.getGeoFile().getWindow(0,
559
																																							iBlock * this.support.getBlockSize(),
560
																																							sizeWindowX,
561
																																							this.support.getBlockSize(),
562
																																							iBand +
563
																																							1);
564

  
565
													//Escribimos el bloque destino
566
													rband.writeRaster(0,
567
																						iBlock * this.support.getBlockSize(),
568
																						sizeWindowX,
569
																						this.support.getBlockSize(), buf,
570
																						Gdal.GDT_Byte);
571
											}//else
572
												//this.writeClose();
573
										}
574
								}*/
575
				} else if (mode == GeoRasterWriter.MODE_DATAWRITE) {
576
					for (int iBlock = 0; iBlock < nBlocks; iBlock++) {
577
						int posicionY = iBlock * blockSize;
578
						if(write)
579
							writeBands( blockSize, posicionY);
580
						percent = (iBlock + 1) * increment;
581
					}
582
				}
583

  
584
				if (anchoResto != 0) {
585
					if (mode == GeoRasterWriter.MODE_FILEWRITE) {
586
						/*for (int iBand = 0; iBand < this.nBands; iBand++) {
587
												rband = dset_destino.getRasterBand(iBand + 1);
588
												if(write){
589
													//leemos el bloque origen
590
													buf.buffByte = currentRaster.getGeoFile().getWindow(0,
591
																																							nBlocks * this.support.getBlockSize(),
592
																																							sizeWindowX,
593
																																							anchoResto,
594
																																							iBand +
595
																																							1);
596

  
597
													//Escribimos el bloque destino
598
													rband.writeRaster(0,
599
																						nBlocks * this.support.getBlockSize(),
600
																						sizeWindowX, anchoResto, buf,
601
																						Gdal.GDT_Byte);
602
												}//else
603
													//this.writeClose();
604
										}*/
605
					} else if (mode == GeoRasterWriter.MODE_DATAWRITE) {
606
						int posicionY = nBlocks * blockSize;
607
						if(write)
608
							writeBands(anchoResto, posicionY);
609
						percent = nBlocks * increment;
610
					}
611
				}
612

  
613
		}
614

  
615
		/**
616
		 * Realiza la funci?n de compresi?n a partir de un GeoRasterFile.
617
		 * @throws IOException
618
		 */
619
		public void fileWrite() throws IOException {
620
				write(GeoRasterWriter.MODE_FILEWRITE);
621
		}
622

  
623
		/**
624
		 * Realiza una copia en el formato especificado.
625
		 * @throws IOException
626
		 */
627
		public static void createCopy(es.gva.cit.jgdal.GdalDriver driverDst, String dst, String src,
628
				boolean bstrict, String[] params, IProjection proj) throws IOException, GdalException {
629
				if (dst == null || src == null) {
630
						throw new IOException("No se ha asignado un fichero de entrada.");
631
				}
632

  
633
				GdalDriver gdalFile;
634 634
		try {
635 635
			gdalFile = new GdalDriver(proj, src);
636
	        driverDst.createCopy(dst, gdalFile.getNative(), bstrict, params);
637
	        if(dst.endsWith(".jpg") || dst.endsWith(".jpeg"))
638
	        	RasterUtilities.createWorldFile(dst, gdalFile.getExtent(), gdalFile.getWidth(), gdalFile.getHeight());
639
	        gdalFile.close();
636
					driverDst.createCopy(dst, gdalFile.getNative(), bstrict, params);
637
					if(dst.endsWith(".jpg") || dst.endsWith(".jpeg"))
638
						RasterUtilities.createWorldFile(dst, gdalFile.getExtent(), gdalFile.getWidth(), gdalFile.getHeight());
639
					gdalFile.close();
640 640
		} catch (NotSupportedExtensionException e) {
641 641
			e.printStackTrace();
642 642
		}
643
    }
644
    
645
    /**
646
     * Realiza la escritura de datos con los datos que le pasa el cliente.
647
     * @throws IOException
648
     */
649
    public void dataWrite() throws IOException {
650
        if (dataWriter == null)
651
            throw new IOException("No se ha obtenido un objeto de entrada para la escritura valido.");
643
		}
652 644

  
653
        write(GeoRasterWriter.MODE_DATAWRITE);
654
        
655
        if(driverParams.getParamById("tfw") != null && driverParams.getParamById("tfw").defaultValue.equals("true")) {
656
    		if(extent != null)
657
    			RasterUtilities.createWorldFile(this.outFileName, extent, sizeWindowX, sizeWindowY);
658
    	}
659
    }
645
		/**
646
		 * Realiza la escritura de datos con los datos que le pasa el cliente.
647
		 * @throws IOException
648
		 */
649
		public void dataWrite() throws IOException {
650
				if (dataWriter == null)
651
						throw new IOException("No se ha obtenido un objeto de entrada para la escritura valido.");
660 652

  
661
    /**
662
     * Cancela el salvado de datos.
663
     * @throws GdalException
664
     */
665
    public void writeClose() {
666
        try {
667
        	if(dset_destino != null)
668
        		dset_destino.close();        		
669
           //oSRS = null;
670
        } catch (GdalException e) {
671
            e.printStackTrace();
672
        }
673
    }
653
				write(GeoRasterWriter.MODE_DATAWRITE);
674 654

  
675
    /**
676
     * Cancela el salvado de datos.
677
     */
678
    public void writeCancel() {
679
       write = false; 
680
    }
681
    
682
    /**
683
     * Obtiene el valor a la variable write que estar? a true cuando se est? escribiendo
684
     *  o puede escribirse la imagen de salida. El cancelar la operaci?n de escritura
685
     * pondr? esta variable a false deteniendose la escritura y cerrandose el dataset
686
     * de salida. 
687
     * @return True si puede escribirse y false si no puede
688
     */
689
    public boolean isWrite() {
655
				if(driverParams.getParamById("tfw") != null && driverParams.getParamById("tfw").defaultValue.equals("true")) {
656
				if(extent != null)
657
					RasterUtilities.createWorldFile(this.outFileName, extent, sizeWindowX, sizeWindowY);
658
			}
659
		}
660

  
661
		/**
662
		 * Cancela el salvado de datos.
663
		 * @throws GdalException
664
		 */
665
		public void writeClose() {
666
				try {
667
					if(dset_destino != null)
668
						dset_destino.close();
669
					 //oSRS = null;
670
				} catch (GdalException e) {
671
						e.printStackTrace();
672
				}
673
		}
674

  
675
		/**
676
		 * Cancela el salvado de datos.
677
		 */
678
		public void writeCancel() {
679
			 write = false;
680
		}
681

  
682
		/**
683
		 * Obtiene el valor a la variable write que estar? a true cuando se est? escribiendo
684
		 *  o puede escribirse la imagen de salida. El cancelar la operaci?n de escritura
685
		 * pondr? esta variable a false deteniendose la escritura y cerrandose el dataset
686
		 * de salida.
687
		 * @return True si puede escribirse y false si no puede
688
		 */
689
		public boolean isWrite() {
690 690
		return write;
691 691
	}
692 692

  
693
    /**
694
     * Asigna el valor a la variable write que estar? a true cuando se est? escribiendo
695
     *  o puede escribirse la imagen de salida. El cancelar la operaci?n de escritura
696
     * pondr? esta variable a false deteniendose la escritura y cerrandose el dataset
697
     * de salida. 
698
     * @param write Variable booleana. True si puede escribirse y false si no puede
699
     */
693
		/**
694
		 * Asigna el valor a la variable write que estar? a true cuando se est? escribiendo
695
		 *  o puede escribirse la imagen de salida. El cancelar la operaci?n de escritura
696
		 * pondr? esta variable a false deteniendose la escritura y cerrandose el dataset
697
		 * de salida.
698
		 * @param write Variable booleana. True si puede escribirse y false si no puede
699
		 */
700 700
	public void setWrite(boolean write) {
701 701
		this.write = write;
702 702
	}
703
	
703

  
704 704
	 /**
705
     * Asigna los par?metros del driver modificados por el cliente.
706
     * @param Params
707
     */
708
    public void setParams(Params params) {
705
		 * Asigna los par?metros del driver modificados por el cliente.
706
		 * @param Params
707
		 */
708
		public void setParams(Params params) {
709 709
		this.driverParams = params;
710
		
710

  
711 711
		int blockSize = 256;
712
        try {
713
        	blockSize = Integer.parseInt(driverParams.getParamById("blocksize").defaultValue);
714
        	nBlocks = (int) (sizeWindowY / blockSize);
715
            anchoResto = sizeWindowY - (nBlocks * blockSize);
716
        }catch(NumberFormatException e) {
717
        	//Se queda con el valor de inicializaci?n
718
        }
712
				try {
713
					blockSize = Integer.parseInt((String) driverParams.getParamById("blocksize").defaultValue);
714
					nBlocks = (int) (sizeWindowY / blockSize);
715
						anchoResto = sizeWindowY - (nBlocks * blockSize);
716
				}catch(NumberFormatException e) {
717
					//Se queda con el valor de inicializaci?n
718
				}
719 719
	}
720 720

  
721 721
}

Also available in: Unified diff