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

View differences:

GdalWriter.java
19 19
package org.gvsig.raster.dataset.io;
20 20

  
21 21
import java.io.IOException;
22
import java.util.ArrayList;
22 23

  
23 24
import org.cresques.cts.IProjection;
24 25
import org.gvsig.raster.buffer.RasterBuffer;
25 26
import org.gvsig.raster.dataset.GeoRasterWriter;
26
import org.gvsig.raster.dataset.IBuffer;
27 27
import org.gvsig.raster.dataset.IDataWriter;
28 28
import org.gvsig.raster.dataset.NotSupportedExtensionException;
29 29
import org.gvsig.raster.dataset.Params;
30
import org.gvsig.raster.dataset.properties.WriteFileFormatFeatures;
30
import org.gvsig.raster.dataset.Params.Param;
31
import org.gvsig.raster.dataset.io.features.GTiffFeatures;
32
import org.gvsig.raster.dataset.io.features.HFAFeatures;
33
import org.gvsig.raster.dataset.io.features.WriteFileFormatFeatures;
31 34
import org.gvsig.raster.shared.Extent;
32 35
import org.gvsig.raster.util.RasterUtilities;
33 36
import org.gvsig.raster.util.extensionPoints.ExtensionPoints;
......
60 63
	   
61 64
    static {
62 65
		ExtensionPoints extensionPoints = ExtensionPointsSingleton.getInstance();
63
		WriteFileFormatFeatures features = null;
64 66
		
65
		features = new WriteFileFormatFeatures("GTiff", "tif", -1, new int[]{0, 1, 2, 3, 4, 5}, GdalWriter.class);
66 67
		extensionPoints.add("RasterWriter", "tif", GdalWriter.class);
67
		fileFeature.put("tif", features);
68
		fileFeature.put("tif", new GTiffFeatures());
68 69
		
69
		features = new WriteFileFormatFeatures("HFA", "img", -1, new int[]{0, 1, 2, 3, 4, 5}, GdalWriter.class);
70 70
		extensionPoints.add("RasterWriter", "img", GdalWriter.class);
71
		fileFeature.put("img", features);
71
		fileFeature.put("img", new HFAFeatures());
72
		
73
		//Imagenes 1 banda (monocromo) o 3 (RGB) en 8 bits. Georef = .wld 
74
		/*features = new WriteFileFormatFeatures("BMP", "bmp", -1, null, GdalWriter.class);
75
		extensionPoints.add("RasterWriter", "bmp", GdalWriter.class);
76
		fileFeature.put("bmp", features);*/
72 77
	}
73 78
    
74
    private es.gva.cit.jgdal.GdalDriver	drv;
79
    private es.gva.cit.jgdal.GdalDriver		drv;
75 80
    private Gdal 							dset_destino = null;
76
    private GdalRasterBand 				rband = null;
81
    private GdalRasterBand 					rband = null;
77 82
    private GeoTransform 					geot = null; //Datos de georeferenciaci?n
78 83
    //private OGRSpatialReference 			oSRS; //Datos de proyecci?n						
79 84
    private GdalBuffer[]					bufBands = null;
80 85
    private int 							nBlocks = 0; //N?mero de bloques en Y en el que se divide la imagen para escribir
81 86
    private int 							anchoResto = 0; //Tama?o del ?ltimo bloque de la imagen.
82
    private String[] 						params = null; //Par?metros de creaci?n del dataset.
83
    private boolean 						consulta = false;
84
    private boolean						write = true; //Cuando est? a true se puede escribir en la imagen de salida. Si est? a false el proceso es interrumpido
87
    private boolean							write = true; //Cuando est? a true se puede escribir en la imagen de salida. Si est? a false el proceso es interrumpido
85 88
    private int 							dataType = RasterBuffer.TYPE_UNDEFINED;
86 89

  
87 90
    /**
88 91
     * Carga los par?metros de este driver.
89 92
     */
90
    public void loadParams() {
91
    	super.loadParams();
92
    	
93
    	driverParams.setParam(	"photometric", 
94
								"RGB", 
95
								Params.CHOICE, 
96
								new String[]{"YCBR", "MINISBLACK", "MINISWHITE", "RGB", "CMYK", "CIELAB", "ICCLAB", "ITULAB", "CBCR"});
97

  
98
    	driverParams.setParam(	"interleave", 
99
								"BAND", 
100
								Params.CHOICE, 
101
								new String[]{ "BAND", "PIXEL"});
102

  
103
    	driverParams.setParam(	"compression", 
104
								"NONE", 
105
								Params.CHOICE, 
106
								new String[]{"LZW", "PACKBITS", "DEFLATE", "NONE"});
107

  
108
    	driverParams.setParam(	"tfw", 
109
								"false", 
110
								Params.CHECK, 
111
								null);
93
    public void loadParams(String ident) {
94
    	WriteFileFormatFeatures wfff = (WriteFileFormatFeatures)fileFeature.get(ident);
95
    	wfff.loadParams();
96
    	driverParams = wfff.getParams();
112 97
    }
113 98
    
114 99
    /**
......
119 104
    	ident = RasterUtilities.getExtensionFromFileName(fileName);
120 105
    	driver = ((WriteFileFormatFeatures)fileFeature.get(ident)).getDriverName();
121 106
    	
122
    	loadParams();
123

  
124
        consulta = true;
107
    	loadParams(ident);
125 108
    }
126 109

  
127 110
    /**
......
177 160
        geot.adfgeotransform[5] = (double) ((minY - maxY) / outSizeY.intValue()); //pixelSizeY;
178 161

  
179 162
        if(params == null)
180
        	loadParams();
163
        	loadParams(ident);
181 164
        else 
182 165
        	this.driverParams = params;
183 166
        
......
210 193
                okdrvtype = true;
211 194
            
212 195
        if (okdrvtype == false)
213
            throw new GdalException("El tipo de driver "+driver+" no est? soportado por GdalWriter.");
196
            throw new GdalException("El tipo de driver " + driver + " no est? soportado por GdalWriter.");
214 197
        
215 198
        //Obtenemos el driver y creamos el dataset del destino
216 199
        drv = Gdal.getDriverByName(driver);
......
221 204
        }
222 205
                
223 206
        dset_destino = drv.create(outFileName, sizeWindowX, sizeWindowY,
224
                                  nBands, RasterUtilities.getGdalTypeFromRasterBufType(dataType), params);
207
                                  nBands, RasterUtilities.getGdalTypeFromRasterBufType(dataType), gdalParamsFromRasterParams(driverParams));
225 208
        
226 209
        dset_destino.setGeoTransform(geot);
227 210
        
......
238 221
    
239 222
    public void anotherFile(String fileName)throws GdalException {
240 223
    	dset_destino = drv.create(fileName, sizeWindowX, sizeWindowY,
241
                nBands, RasterUtilities.getGdalTypeFromRasterBufType(dataType), params);
224
                nBands, RasterUtilities.getGdalTypeFromRasterBufType(dataType), gdalParamsFromRasterParams(driverParams));
242 225
    }
243 226

  
244 227
    /**
228
     * Convierte los par?metros obtenidos desde el objeto params a parametros
229
     * comprensibles por la librer?a gdal
230
     * @param p Params
231
     * @return Array de par?metros
232
     */
233
    private String[] gdalParamsFromRasterParams(Params p) {
234
    	if(p == null)
235
    		return null;
236
    	ArrayList paramList = new ArrayList();
237
    	Param phot = (Param)p.getParamById("photometric");
238
    	if(phot != null)
239
    		paramList.add("PHOTOMETRIC=" + phot.defaultValue);
240
    	Param inter = (Param)p.getParamById("interleave");
241
    	if(inter != null)
242
    		paramList.add("INTERLEAVE=" + inter.defaultValue);
243
    	Param comp = (Param)p.getParamById("compression");
244
    	if(comp != null)
245
    		paramList.add("COMPRESS=" + comp.defaultValue);
246
    	Param comp1 = (Param)p.getParamById("compress");
247
    	if(comp1 != null)
248
    		paramList.add("COMPRESS=" + comp1.defaultValue);
249
    	Param rrd = (Param)p.getParamById("rrd");
250
    	if(rrd != null)
251
    		paramList.add("HFA_USE_RRD=" + rrd.defaultValue);
252

  
253
    	String[] result = new String[paramList.size()];
254
    	for (int i = 0; i < result.length; i++)
255
			result[i] = (String)paramList.get(i);
256
    	return result;
257
    }
258
    
259
    /**
245 260
     * A partir de un elemento que contiene una propiedad y un valor
246 261
     * lo parsea y asigna el valor a su variable.
247 262
     * @param propValue        elemento con la forma propiedad=valor
248 263
     */
249
    private void readProperty(String propValue) {
264
   /* private void readProperty(String propValue) {
250 265
        String prop = propValue.substring(0, propValue.indexOf("="));
251 266

  
252 267
        if (propValue.startsWith(prop)) {
......
265 280
                    driverParams.changeParamValue("tfw", value);
266 281
            }
267 282
        }
268
    }
283
    }*/
269 284

  
270 285
    /**
271 286
     * Asigna propiedades al driver a partir de un vector de
......
273 288
     * propiedad=valor.
274 289
     * @param props        Propiedades
275 290
     */
276
    public void setProps(String[] props) {
291
    /*public void setProps(String[] props) {
277 292
        for (int iProps = 0; iProps < props.length; iProps++)
278 293
            readProperty(props[iProps]);
279 294

  
......
285 300
        } catch (GdalException e) {
286 301
            e.printStackTrace();
287 302
        }
288
    }
303
    }*/
289 304

  
290 305
    /**
291 306
     * Escritura de datos tipo Byte.
......
602 617

  
603 618
        write(GeoRasterWriter.MODE_DATAWRITE);
604 619
        
605
        if(driverParams.getParamById("tfw").defaultValue.equals("true")) {
620
        if(driverParams.getParamById("tfw") != null && driverParams.getParamById("tfw").defaultValue.equals("true")) {
606 621
    		if(extent != null)
607 622
    			RasterUtilities.createWorldFile(this.outFileName, extent, sizeWindowX, sizeWindowY);
608 623
    	}

Also available in: Unified diff