Revision 11074

View differences:

trunk/libraries/libRaster/src/org/gvsig/raster/RasterLibrary.java
6 6
import org.gvsig.raster.dataset.io.EcwDriver;
7 7
import org.gvsig.raster.dataset.io.GdalDriver;
8 8
import org.gvsig.raster.dataset.io.GdalWriter;
9
import org.gvsig.raster.dataset.io.MemoryRasterDriver;
9 10

  
10 11
/**
11 12
 * 
......
56 57
	public static void wakeUp(){
57 58
		readersClassList.add(GdalDriver.class);
58 59
		readersClassList.add(EcwDriver.class);
60
		readersClassList.add(MemoryRasterDriver.class);
59 61
		writersClassList.add(GdalWriter.class);
60 62
		
61 63
		//Limpiamos el directorio temporal
trunk/libraries/libRaster/src/org/gvsig/raster/dataset/io/IRegistrableRasterFormat.java
1
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
2
 *
3
 * Copyright (C) 2007 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
/**
22
 * Interfaz que deben implementar las clases que contiene los par?metros de un driver. 
23
 * Cuando se registra un driver se hace por la extesi?n si es un fichero o por el nombre
24
 * del formato si es de otro tipo. Este interfaz permite a los objetos que se usan como par?metro
25
 * para un driver obtener el nombre de formato con el que se ha registrado.
26
 * 
27
 * @author Nacho Brodin (nachobrodin@gmail.com)
28
 *
29
 */
30
public interface IRegistrableRasterFormat {
31
	/**
32
	 * Obtiene el identificador del formato con el que se ha registrado.
33
	 * @return ID del formato.
34
	 */
35
	public String getFormatID();
36
}
0 37

  
trunk/libraries/libRaster/src/org/gvsig/raster/buffer/RasterBuffer.java
1
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
2
 *
3
 * Copyright (C) 2007 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.buffer;
20

  
21
import java.io.FileNotFoundException;
22

  
23
import org.gvsig.raster.buffer.cache.RasterCache;
24
import org.gvsig.raster.buffer.cache.RasterReadOnlyHugeBuffer;
25
import org.gvsig.raster.dataset.IBuffer;
26
import org.gvsig.raster.dataset.NotSupportedExtensionException;
27
import org.gvsig.raster.dataset.RasterDriverException;
28
import org.gvsig.raster.util.DataClassList;
29
import org.gvsig.raster.util.Histogram;
30
import org.gvsig.raster.util.HistogramException;
31
import org.gvsig.raster.util.RasterUtilities;
32

  
33
/**
34
 * Rectangulo de pixeles. Para cada tipo de datos java hay un buffer distinto donde cada elemento es
35
 * accedido de la siguiente forma: [banda][fila][columna]
36
 * m[1][2][0] = cte;-> Sustituye el elemento de la fila 2 de la banda 1 columna 0
37
 * m[1][0] = array; -> Sustituye la fila 0 de la banda 1 
38
 * m[0] = matriz cuadrada; -> Sustituye la banda entera.
39
 * 
40
 */
41
public abstract class RasterBuffer implements IBuffer {
42
	//Espacio en memoria (en Megas) que hay que sobrepasar para empezar a cachear.
43
	private static int		cacheMemorySize = 25;
44
	//Espacio en memoria (en Megas) que hay que sobrepasar para empezar a cachear en multipagina.
45
	private static int		multicacheMemorySize = 100;
46
	
47
	public double 			noDataValue = -99999;
48
	protected int			percent = 0;
49
	
50
    protected int 			width;
51
    protected int 			height;
52
    protected int 			nBands;
53
    protected int 			dataType;
54
    
55
    /**
56
     * Variable est?tica que si est? a false desactiva el uso de cach?. Puede ser usada por un cliente
57
     * para cargar siempre los datos en memoria. independientemente de su tama?o. 
58
     */
59
    public static boolean	cacheOn = true;
60
    /**
61
     * Fuerza la carga de los datos en cach? independientemente de su tama?o. Su
62
     * uso suele ser util solo para depuraci?n. Su valor por defecto y recomendado
63
     * es siempre false.
64
     */
65
    public static boolean 	forceToLoadInCache = false;
66
    /**
67
     * Fuerza la carga de los datos en cach? de solo lectura independientemente de su tama?o. Su
68
     * uso suele ser util solo para depuraci?n. Su valor por defecto y recomendado
69
     * es siempre false.
70
     */
71
    public static boolean 	forceToLoadInReadOnlyCache = false;
72
    /**
73
     * Valor con el que se rellena una banda no valida del buffer. Una banda no valida es la que 
74
     * no tiene datos asignados y tampoco puede ser null. Todas las bandas no validas de un buffer
75
     * apuntan por referencia a la misma banda.
76
     */
77
    protected double		notValidValue = 0D;
78

  
79
    /**
80
     * Genera instancias del buffer de datos adecuado al tama?o del raster. Si no hay muchos datos
81
     * (menos de cacheMemorySize) crear? un buffer en memoria. Si hay m?s de esta cantidad
82
     * entonces crearemos un buffer cacheado (RasterCache). A partir de la cantidad se?alada
83
     * por multicacheMemorySize haremos un buffer cacheado donde cada p?gina no ocupa todo
84
     * el ancho del raster ya que este ser? muy grande. La gesti?n de una cache donde cada
85
     * pagina ha de partir una l?nea lleva una complejidad a?adida.
86
     *  
87
     * @param dataType Tipo de dato
88
     * @param width Ancho
89
     * @param height Alto
90
     * @param bandNr Banda
91
     * @param malloc
92
     * @return
93
     * @throws RasterDriverException 
94
     * @throws NotSupportedExtensionException 
95
     * @throws FileNotFoundException 
96
     */
97
    public static RasterBuffer getBuffer(int dataType, int width, int height, int bandNr, boolean malloc, String filePath) 
98
    	/*throws FileNotFoundException, NotSupportedExtensionException, RasterDriverException*/{
99
    	//Opci?n de cachear siempre activada (Solo DEBUG)
100
    	if(forceToLoadInCache)
101
    		return new RasterCache(dataType, width, height, bandNr);
102
    	if(forceToLoadInReadOnlyCache && filePath != null){
103
			try {
104
				return new RasterReadOnlyHugeBuffer(dataType, width, height, bandNr, filePath);
105
			} catch (FileNotFoundException e) {
106
				//TODO: EXCEPTION: Modificar el lanzamiento de excepciones del RasterBuffer
107
				e.printStackTrace();
108
			} catch (NotSupportedExtensionException e) {
109
				e.printStackTrace();
110
			} catch (RasterDriverException e) {
111
				e.printStackTrace();
112
			}
113
    	}
114
    		
115
    	if(cacheOn){
116
	    	long size = (RasterUtilities.getBytesFromRasterBufType(dataType) * width * height * bandNr) / 1024;
117
	    	long ms1 = cacheMemorySize * 1024;
118
	    	long ms2 = multicacheMemorySize * 1024;
119
	    	if(size <= ms1)
120
	    		return new RasterMemoryBuffer(dataType, width, height, bandNr, malloc);
121
	    	else{
122
	    		//if(filePath == null)
123
	    			return new RasterCache(dataType, width, height, bandNr);
124
		    	/*else 
125
		    		return new RasterReadOnlyHugeBuffer(dataType, width, height, bandNr, filePath);*/
126
	    	}	
127
    	}else
128
    		return new RasterMemoryBuffer(dataType, width, height, bandNr, malloc);
129
    }
130
    
131
    /**
132
     * Reserva de memoria para el rasterbuf
133
     * @param dataType Tipo de dato
134
     * @param width Ancho
135
     * @param height Alto
136
     * @param bandNr Numero de bandas
137
     * @param orig
138
     */
139
    public abstract void malloc(int dataType, int width, int height, int bandNr);
140
   
141
    /*
142
     *  (non-Javadoc)
143
     * @see org.gvsig.fmap.driver.IBuffer#getWidth()
144
     */
145
    public int getWidth() {
146
        return width;
147
    }
148

  
149
   /*
150
    *  (non-Javadoc)
151
    * @see org.gvsig.fmap.driver.IBuffer#getHeight()
152
    */
153
    public int getHeight() {
154
        return height;
155
    }
156

  
157
    /*
158
     *  (non-Javadoc)
159
     * @see org.gvsig.fmap.driver.IBuffer#getBandCount()
160
     */
161
    public int getBandCount() {
162
        return nBands;
163
    }
164

  
165
    /**
166
     * Obtiene el tipo de dato. Los tipos de dato posibles est?n definidos en IRaster.
167
     * @return tipo de datos
168
     */
169
	public int getDataType() {
170
		return dataType;
171
	}
172
	
173
	/**
174
	 * Asigna el tipo de dato. Los tipos de dato posibles est?n definidos en IRaster.
175
	 * @param dataType Tipo de dato del buffer
176
	 */
177
	public void setDataType(int dataType) {
178
		this.dataType = dataType;
179
	}
180

  
181
    /**
182
     * Obtiene el tama?o del tipo de dato en bytes
183
     * @return Tipo de dato
184
     */
185
    public int getDataSize() {
186
        if (dataType == TYPE_BYTE) {
187
            return 1;
188
        } else if ((dataType == TYPE_SHORT) | (dataType == TYPE_USHORT)) {
189
            return 2;
190
        } else if (dataType == TYPE_INT) {
191
            return 4;
192
        }else if (dataType == TYPE_FLOAT) {
193
            return 8;
194
        }else if (dataType == TYPE_DOUBLE) {
195
            return 16;
196
        }
197

  
198
        return 0;
199
    }
200

  
201
    /**
202
     * Obtiene el tama?o del buffer
203
     * @return tama?o del buffer
204
     */
205
    public long sizeof() {
206
        return getDataSize() * width * height * nBands;
207
    }
208
    
209
    /**
210
     * Replica la banda de una posici?n sobre otra. Si la banda de destino no existe
211
     * se crea nueva. Si la posici?n de la banda de destino est? intercalada entre bandas 
212
     * que ya existen las otras se desplazan hacia abajo, NO se machacan los datos de ninguna.
213
     * Los datos se replican por referencia por lo que al modificar la banda original las
214
     * del resto quedar?n afectadas.
215
     * @param orig. Posici?n de la banda de origen. 
216
     * @param dest. Posici?n de la banda destino
217
     */   
218
    public abstract void replicateBand(int orig, int dest);
219
    
220
    /**
221
     * Cambia bandas de posici?n. Las posiciones deben existir como bandas del raster. 
222
     * Cada elemento del array representa una banda existente en el buffer (de longitud
223
     * rasterBuf.length) y el valor contenido dentro la banda que le corresponde. Por ejemplo
224
     * si pasamos un array {1, 0, 3, 2} significa que el buffer tiene cuatro bandas y que 
225
     * cambiamos la 0 por la 1 y la 2 por la 3. Un array {0, 1, 2, 3} en el mismo 
226
     * caso no producir?a nig?n cambio.
227
     * 
228
     * Si quisieramos asignar en un buffer monobanda su banda a la segunda posici?n habria
229
     * que insertar una vacia, por ejemplo con addBandFloat(0, null) se insertaria una 
230
     * banda nula en la posici?n 0 y la banda que estaba en la 0 pasar?a a la segunda.
231
     * 
232
     */
233
    public abstract void switchBands(int[] bandPosition);
234
    	
235
    /**
236
     * Convierte un tipo de dato a cadena
237
     * @param type Tipo de dato
238
     * @return cadena  que representa el tipo de dato
239
     */
240
    public static String typesToString(int type) {
241
        switch (type) {
242
        case RasterBuffer.TYPE_IMAGE:
243
            return new String("Image");
244

  
245
        case RasterBuffer.TYPE_BYTE:
246
            return new String("Byte");
247

  
248
        case RasterBuffer.TYPE_DOUBLE:
249
            return new String("Double");
250

  
251
        case RasterBuffer.TYPE_FLOAT:
252
            return new String("Float");
253

  
254
        case RasterBuffer.TYPE_INT:
255
        	return new String("Integer");
256
        	
257
        case RasterBuffer.TYPE_USHORT:
258
        case RasterBuffer.TYPE_SHORT:
259
            return new String("Short");
260
        }
261

  
262
        return null;
263
    }
264
    
265
    /**
266
     * Ajusta el raster al ancho y alto solicitado por el vecino m?s cercano. Promedia el valor de dos
267
     * pixeles contiguos.
268
     * @param w Nuevo ancho
269
     * @param h Nuevo alto
270
     */
271
    public abstract RasterBuffer adjustRasterNearestNeighbourInterpolation(int w, int h, int[] bands);
272
    
273
    /**
274
     * Ajusta el raster al ancho y alto solicitado ajustando con una interpolaci?n bilineal. Promedia
275
     * el valor de cuatro pixeles adyacentes.
276
     * @param w Nuevo ancho
277
     * @param h Nuevo alto
278
     */
279
    public abstract RasterBuffer adjustRasterBilinearInterpolation(int w, int h, int[] bands);
280
    
281
    /**
282
     * Ajusta el raster al ancho y alto solicitado ajustando con una interpolaci?n de distancia inversa.
283
     * Asigna el valor de un pixel en funci?n inversa de la distancia.
284
     * 
285
     * @param w Nuevo ancho
286
     * @param h Nuevo alto
287
     */
288
    public abstract RasterBuffer adjustRasterInverseDistanceInterpolation(int w, int h, int[] bands);
289
    
290
    /**
291
     * Ajusta el raster al ancho y alto solicitado ajustando con una interpolaci?n de spline bicubica.
292
     * @param w Nuevo ancho
293
     * @param h Nuevo alto
294
     */
295
    public abstract RasterBuffer adjustRasterBicubicSplineInterpolation(int w, int h, int[] bands);
296
    
297
    /**
298
     * Ajusta el raster al ancho y alto solicitado ajustando con una interpolaci?n BSpline.
299
     * @param w Nuevo ancho
300
     * @param h Nuevo alto
301
     */
302
    public abstract RasterBuffer adjustRasterBSplineInterpolation(int w, int h, int[] bands);
303
    
304
    /*
305
     *  (non-Javadoc)
306
     * @see org.gvsig.fmap.driver.IBuffer#getNoDataValue()
307
     */
308
    public double getNoDataValue(){
309
    	return noDataValue;
310
    }
311
    
312
    /*
313
     *  (non-Javadoc)
314
     * @see org.gvsig.fmap.driver.IBuffer#getByteNoDataValue()
315
     */
316
    public byte getByteNoDataValue(){
317
    	return (byte)noDataValue;
318
    }
319
    
320
    /*
321
     *  (non-Javadoc)
322
     * @see org.gvsig.fmap.driver.IBuffer#getShortNoDataValue()
323
     */
324
    public short getShortNoDataValue(){
325
    	return (short)noDataValue;
326
    }
327
    
328
    /*
329
     *  (non-Javadoc)
330
     * @see org.gvsig.fmap.driver.IBuffer#getIntNoDataValue()
331
     */
332
    public int getIntNoDataValue(){
333
    	return (int)noDataValue;
334
    }
335
    
336
    /*
337
     *  (non-Javadoc)
338
     * @see org.gvsig.fmap.driver.IBuffer#getFloatNoDataValue()
339
     */
340
    public float getFloatNoDataValue(){
341
    	return (float)noDataValue;
342
    }
343
    
344
    /*
345
     *  (non-Javadoc)
346
     * @see org.gvsig.fmap.driver.IBuffer#setNoDataValue(double)
347
     */
348
    public void setNoDataValue(double nd){
349
    	noDataValue = nd;
350
    }
351
    
352
    /*
353
     *  (non-Javadoc)
354
     * @see org.gvsig.fmap.driver.IBuffer#getNotValidValue()
355
     */
356
    public double getNotValidValue(){
357
    	return notValidValue;
358
    }
359
    
360
    /*
361
	 *  (non-Javadoc)
362
	 * @see org.gvsig.fmap.driver.IBuffer#setNotValidValue(java.lang.Object)
363
	 */
364
    public void setNotValidValue(double value){
365
    	this.notValidValue = value;
366
    }
367
    
368
    /*
369
     *  (non-Javadoc)
370
     * @see org.gvsig.fmap.driver.IBuffer#cloneBuffer()
371
     */
372
    public abstract IBuffer cloneBuffer();
373
    
374
    /*
375
     * (non-Javadoc)
376
     * @see org.gvsig.raster.driver.datasetproperties.IHistogramable#getHistogram()
377
     */
378
	public Histogram getHistogram() throws HistogramException {
379
		percent = 0;
380
		if(getDataType() != IBuffer.TYPE_BYTE)
381
			return null;
382
		Histogram hist = new Histogram(getBandCount(), 256);
383
		for (int iBand = 0; iBand < getBandCount(); iBand++) 
384
			for (int row = 0; row < getHeight(); row++) 
385
				for (int col = 0; col < getWidth(); col++) 
386
					hist.incrementPxValue(iBand, (getElemByte(row, col, iBand) & 0xff));
387
		percent = 100;
388
		return hist;
389
	}
390

  
391
	/*
392
	 * (non-Javadoc)
393
	 * @see org.gvsig.raster.driver.datasetproperties.IHistogramable#getHistogramUsingClasses(org.gvsig.raster.shared.DataClassList)
394
 	 */
395
	public Histogram getHistogramUsingClasses(DataClassList classes) throws HistogramException {
396
		Histogram hist = new Histogram(getBandCount(), classes.length());
397
		for (int iBand = 0; iBand < getBandCount(); iBand++) { 
398
			for (int col = 0; col < getHeight(); col++) {
399
				for (int row = 0; row < getWidth(); row++) {
400
					int pixelValue = -1;
401
					switch(this.getDataType()){
402
					case IBuffer.TYPE_BYTE: pixelValue = classes.getClassPosition((double)(getElemByte(row, col, iBand)  & 0xff)); break;
403
					case IBuffer.TYPE_SHORT: pixelValue = classes.getClassPosition((double)(getElemShort(row, col, iBand) & 0xffff)); break;
404
					case IBuffer.TYPE_INT: pixelValue = classes.getClassPosition((double)(getElemInt(row, col, iBand) & 0xffffff)); break;
405
					case IBuffer.TYPE_FLOAT: pixelValue = classes.getClassPosition((double)getElemFloat(row, col, iBand)); break;
406
					case IBuffer.TYPE_DOUBLE: pixelValue = classes.getClassPosition((double)getElemDouble(row, col, iBand)); break;
407
					}		 
408
					if(pixelValue >= 0)
409
						hist.incrementPxValue(iBand, pixelValue);
410
				}		
411
			}
412
		}
413
		return hist;
414
	}
415
}
0 416

  
trunk/libraries/libRaster/src/org/gvsig/raster/buffer/IBand.java
1
package org.gvsig.raster.buffer;
2

  
3
import org.gvsig.raster.dataset.IBuffer;
4

  
5
/**
6
 * 
7
 * @author Nacho Brodin (nachobrodin@gmail.com)
8
 *
9
 */
10
public interface IBand{
11
    public final static int TYPE_UNDEFINED = IBuffer.TYPE_UNDEFINED;
12
    public final static int TYPE_BYTE = IBuffer.TYPE_BYTE;
13
    public final static int TYPE_SHORT = IBuffer.TYPE_SHORT;
14
    public final static int TYPE_USHORT = IBuffer.TYPE_USHORT;
15
    public final static int TYPE_INT = IBuffer.TYPE_INT;
16
    public final static int TYPE_FLOAT = IBuffer.TYPE_FLOAT;
17
    public final static int TYPE_DOUBLE = IBuffer.TYPE_DOUBLE;
18
    public final static int TYPE_IMAGE = -1;
19
    
20
    /**
21
     * Ancho de la banda
22
     * @return Entero con el ancho de la banda
23
     */
24
    public int getWidth();
25

  
26
    /**
27
     * Alto de la banda
28
     * @return Entero con el alto de la banda
29
     */
30
    public int getHeight();
31
    
32
    /**
33
     * Obtiene el tipo de dato. Los tipos de dato posibles est?n definidos en IRaster.
34
     * @return tipo de datos
35
     */
36
	public int getDataType();
37
	
38
	/**
39
	 * Obtiene una linea de la banda
40
	 * @return
41
	 */
42
	public Object getLine(int line);
43
	
44
	/**
45
	 * Asigna una linea de la banda
46
	 * @param line N?mero de l?nea
47
	 * @param value Valor representado por un array del tipo de dato correspondiente
48
	 */
49
	public void setLine(int line, Object value);
50
	
51
	/**
52
	 * Obtiene el buffer de datos de la banda
53
	 * @return Array bidimensional del tipo de dato correspondiente si es un buffer en memoria
54
	 * 
55
	 */
56
	public Object getBuf();
57
	
58
}
0 59

  
trunk/libraries/libRaster/src/org/gvsig/raster/buffer/package.html
1
<html>
2
	<body>Clases del nivel de acceso a datos. Estas tienen funcionalidades de 
3
	gesti?n de buffer y cacheado de datos.
4
</body>
5
</html>
0 6

  
trunk/libraries/libRaster/src/org/gvsig/raster/buffer/RasterBufferInvalidException.java
1
package org.gvsig.raster.buffer;
2

  
3
/**
4
 * Excepci?n lanzada cuando se detecta que un buffer de raster es incorrecto.
5
 * @author Nacho Brodin (nachobrodin@gmail.com)
6
 *
7
 */
8
public class RasterBufferInvalidException extends Exception{
9
	public RasterBufferInvalidException(String msg){
10
		super(msg);
11
	}
12
}
0 13

  
trunk/libraries/libRaster/src/org/gvsig/raster/buffer/BufferFactory.java
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.buffer;
20

  
21

  
22
import java.awt.geom.Point2D;
23

  
24
import org.gvsig.raster.dataset.FileFoundInListException;
25
import org.gvsig.raster.dataset.FileNotOpenException;
26
import org.gvsig.raster.dataset.IBuffer;
27
import org.gvsig.raster.dataset.NotSupportedExtensionException;
28
import org.gvsig.raster.dataset.RasterDataset;
29
import org.gvsig.raster.dataset.RasterDriverException;
30
import org.gvsig.raster.dataset.RasterMultiDataset;
31
import org.gvsig.raster.dataset.properties.DatasetPalette;
32
import org.gvsig.raster.shared.Extent;
33
import org.gvsig.raster.util.DataClassList;
34
import org.gvsig.raster.util.Histogram;
35
import org.gvsig.raster.util.RasterUtilities;
36

  
37
/**
38
 * <P>
39
 * Clase que representa a una rejilla de datos que tiene como fuente
40
 * un RasterMultifile. Tiene m?todos para a?adir nuevos ficheros fuente a la 
41
 * rejilla que podr?n ser consultados como bandas de uno solo. Estos deber?an tener
42
 * la misma extensi?n que el primero introducido.
43
 * </P>
44
 * <P>
45
 * Para la carga del buffer de datos habr? que asigna las bandas que queremos cargar
46
 * de todas las disponibles con addDrawableBands. Despu?s se seleccionar? el ?rea
47
 * que queremos cargar con setAreaOfInterest. Este ?rea se define con coordenadas
48
 * pixel o reales. Finalmente podemos recuperar el buffer con los datos usando la 
49
 * funci?n getRasterBuf.
50
 * </P>
51
 * @author Nacho Brodin (nachobrodin@gmail.com)
52
 *
53
 */
54
public class BufferFactory {
55
	
56
	private RasterMultiDataset 		mDataset = new RasterMultiDataset(null);
57
	private IBuffer					rasterBuf = null;
58
	private int						width = 0;
59
	private int						height = 0;
60
	private int[] 					drawableBands = null;
61
	/**
62
	 * Extensi?n de los datos del buffer
63
	 */
64
	private Extent					dataExtent = null;
65
	/**
66
	 * Lista de paletas asociadas a las bandas cargadas en el DataSource. Estas son calculadas
67
	 * en las funciones que asignan las bandas a dibujar (addDrawableBands)
68
	 */
69
	private DatasetPalette[]			palette = null;
70
	/**
71
	 * Activa o desactiva el supersampleo en la carga del buffer.
72
	 */
73
	private boolean					supersamplingLoadingBuffer = true;
74
	
75
	/**
76
	 * Ancho y alto en pixeles del ?ltimo buffer asignado
77
	 */
78
	private double 					nWidth = 0;
79
	private double 					nHeight = 0;
80
	
81
	/**
82
	 * Constructor
83
	 */
84
	public BufferFactory() {}
85
	
86
	/**
87
	 * Constructor
88
	 * @param RasterMultiDataset
89
	 */
90
	public BufferFactory(RasterMultiDataset rmd) {
91
		mDataset = rmd;
92
		width = (int)rmd.getWidth()[0];
93
		height = (int)rmd.getHeight()[0];
94
	}
95
	
96
	/**
97
	 * Constructor
98
	 * @param grf Lista de geoRasterFile
99
	 */
100
	public BufferFactory(RasterDataset[] grf) {
101
		for(int i = 0; i< grf.length; i++)
102
			addFile(grf[i]);
103
	}
104
	
105
	/**
106
	 * Constructor
107
	 * @param grf GeoRasterFile
108
	 */
109
	public BufferFactory(RasterDataset grf) {
110
		addFile(grf);
111
	}
112
	
113
	/**
114
	 * A?ade un GeoRasterFile al Grid
115
	 * @param grf GeoRasterFile a a?adir
116
	 */
117
	public void addFile(RasterDataset grf) {
118
		try{
119
			mDataset.addDataset(grf);
120
			width = grf.getWidth();
121
			height = grf.getHeight();
122
		}catch(FileFoundInListException e) {
123
			//El fichero est? en la lista por lo que no lo a?adimos
124
		}
125
	}
126
	
127
	/**
128
	 * A?ade un GeoRasterFile al Grid
129
	 * @param fileName Nombre del fichero a a?adir
130
	 * @throws NotSupportedExtensionException 
131
	 * @throws RasterDriverException 
132
	 */
133
	public void addFile(String filename) throws NotSupportedExtensionException, RasterDriverException{
134
		try{
135
			mDataset.addDataset(filename);
136
			width = (int)mDataset.getWidth()[0];
137
			height = (int)mDataset.getHeight()[0];
138
		}catch(FileFoundInListException e) {
139
			//El fichero est? en la lista por lo que no lo a?adimos
140
		}
141
	}
142
	
143
	/**
144
	 * Elimina un GeoRasterFile del Grid
145
	 * @param grf GeoRasterFile a eliminar
146
	 */
147
	public void removeFile(RasterDataset grf) {
148
		mDataset.removeDataset(grf);
149
	}
150
	
151
	/**
152
	 * Elimina un GeoRasterFile del Grid
153
	 * @param fileName Nombre del fichero a eliminar su GeoRasterFile
154
	 */
155
	public void removeFile(String fileName) {
156
		mDataset.removeDataset(fileName);
157
	}
158
	
159
	/**
160
	 * Obtiene el n?mero de ficheros del que est? compuesta la fuente de datos.
161
	 * @return
162
	 */
163
	public int getFileCount() {
164
		return  mDataset.getDatasetCount();
165
	}
166
	
167
	/*
168
	 *  (non-Javadoc)
169
	 * @see org.gvsig.fmap.dataaccess.IQueryableRaster#getGeoRasterMultiFile()
170
	 */
171
	public RasterMultiDataset getGeoRasterMultiFile() {
172
		return mDataset;
173
	}
174
	
175
	/**
176
	 * Libera el buffer de memoria
177
	 */
178
	public void free() {
179
		rasterBuf = null;
180
		System.gc();
181
	}
182
	
183
	/**
184
	 * Resetea la asignaci?n de dibujado de las bandas de la imagen
185
	 * sobre el DataImage cuando se hace un update para esta banda.
186
	 */
187
	public void clearDrawableBand() {
188
		for(int i = 0; i< mDataset.getDatasetCount(); i++)
189
			mDataset.getBands().clearDrawableBand();
190
		palette = null;
191
	}
192
	
193
	/*
194
	 *  (non-Javadoc)
195
	 * @see org.gvsig.fmap.dataaccess.IQueryableRaster#addDrawableBands(int[])
196
	 */
197
	public int[] addDrawableBands(int[] drawableBands) {
198
		this.drawableBands = drawableBands;
199
		mDataset.getBands().setDrawableArray(drawableBands);
200
		
201
		int[] files = new int[drawableBands.length];
202
		palette = new DatasetPalette[drawableBands.length];
203
		
204
		for(int i = 0; i< drawableBands.length; i++) {
205
			if(drawableBands[i] < 0 || drawableBands[i] >= mDataset.getBandCount())
206
				continue;
207
			mDataset.getBands().addDrawableBand(i, drawableBands[i]);
208
			String fileName = mDataset.getBands().getBand(drawableBands[i]).getFileName();
209
			files[i] = mDataset.getBands().getFileNumber(fileName);
210
			palette[i] = mDataset.getPalette(fileName);
211
		}
212
		return files;
213
	}
214

  
215
	/*
216
	 *  (non-Javadoc)
217
	 * @see org.gvsig.fmap.dataaccess.IQueryableRaster#setAllDrawableBands()
218
	 */
219
	public int[] setAllDrawableBands() {
220
		clearDrawableBand();
221
		drawableBands = new int[mDataset.getBandCount()];
222
		int[] files = new int[drawableBands.length];
223
		palette = new DatasetPalette[drawableBands.length];
224
		
225
		for(int i = 0; i< mDataset.getBandCount(); i++) {
226
			mDataset.getBands().addDrawableBand(i, i);
227
			this.drawableBands[i] = i;
228
			String fileName = mDataset.getBands().getBand(drawableBands[i]).getFileName();
229
			files[i] = mDataset.getBands().getFileNumber(fileName);
230
			palette[i] = mDataset.getPalette(fileName);
231
		}
232
		return files;
233
	}
234

  
235
	/*
236
	 *  (non-Javadoc)
237
	 * @see org.gvsig.fmap.dataaccess.IQueryableRaster#getDrawableBands()
238
	 */
239
	public int[] getDrawableBands() {
240
		return drawableBands;
241
	}
242
	
243
	/*
244
	 *  (non-Javadoc)
245
	 * @see org.gvsig.fmap.dataaccess.IQueryableRaster#setAreaOfInterest(double, double, double, double)
246
	 */
247
	public void setAreaOfInterest(double x, double y, double w, double h, boolean adjustToExtent) throws ArrayIndexOutOfBoundsException{
248
		dataExtent = new Extent(x, y, x + w, y - h);
249
		if(adjustToExtent) {
250
			Extent adjustedDataExtent = RasterUtilities.calculateAdjustedView(dataExtent, mDataset.getExtent());
251
			double newW = w;  
252
			double newH = h;
253
			if(!RasterUtilities.compareExtents(dataExtent, adjustedDataExtent)) {
254
				//Si el extent ha sido ajustado entonces tenemos que variar tambi?n al ancho y el alto de la petici?n
255
				newW = (adjustedDataExtent.width() * w) / dataExtent.width();  
256
				newH = (adjustedDataExtent.height() * h) / dataExtent.height();
257
			}
258
			rasterBuf = mDataset.getWindowRaster(adjustedDataExtent.getMin().getX(), adjustedDataExtent.getMax().getY(), newW, newH, adjustToExtent);
259
		}else
260
			rasterBuf = mDataset.getWindowRaster(dataExtent.getMin().getX(), dataExtent.getMax().getY(), w, h, adjustToExtent);
261
	}
262
		
263
	/*
264
	 *  (non-Javadoc)
265
	 * @see org.gvsig.fmap.dataaccess.IQueryableRaster#setAreaOfInterest(double, double, double, double, int, int)
266
	 */
267
	public int[] setAreaOfInterest(double minX, double minY, double maxX, double maxY, int bufWidth, int bufHeight, boolean adjustToExtent) throws ArrayIndexOutOfBoundsException{
268
		//TODO: VALIDACI?N: Comprobaci?n de exceso de memoria reservada
269
		dataExtent = new Extent(minX, minY, maxX, maxY);
270
		Extent adjustedDataExtent = new Extent(dataExtent);
271
		if(adjustToExtent)
272
			adjustedDataExtent = RasterUtilities.calculateAdjustedView(dataExtent, mDataset.getExtent());
273

  
274
		minX = adjustedDataExtent.getMin().getX();
275
		minY = adjustedDataExtent.getMin().getY();
276
		maxX = adjustedDataExtent.getMax().getX();
277
		maxY = adjustedDataExtent.getMax().getY();
278
		
279
		//Esta secci?n es para que no supersamplee el driver y pueda hacerse en el cliente
280
		if(!isSupersamplingLoadingBuffer()) {
281
			nWidth = ((adjustedDataExtent.width() * mDataset.getDataset(0).getWidth()) / mDataset.getDataset(0).getExtent().width());
282
			nHeight = ((adjustedDataExtent.height() * mDataset.getDataset(0).getHeight()) / mDataset.getDataset(0).getExtent().height());
283

  
284
			if(bufWidth > Math.ceil(nWidth) && bufHeight > Math.ceil(nHeight)) {				
285
				rasterBuf = mDataset.getWindowRaster(minX, maxY, Math.abs(maxX - minX), Math.abs(maxY - minY), adjustToExtent);
286
				int[] step = mDataset.calcSteps(minX, maxY, maxX, minY, nWidth, nHeight, bufWidth, bufHeight);
287
				return step;
288
			}
289
		}
290
		
291
		rasterBuf = mDataset.getWindowRaster(minX, minY, maxX, maxY, bufWidth, bufHeight, adjustToExtent);
292
		return null;
293
	}
294
	
295
	/*
296
	 *  (non-Javadoc)
297
	 * @see org.gvsig.fmap.dataaccess.IQueryableRaster#setAreaOfInterest(int, int, int, int)
298
	 */
299
	public void setAreaOfInterest(int x, int y, int w, int h) throws ArrayIndexOutOfBoundsException{
300
		if((x + w) > getWidth() || (y + h) > getHeight())
301
			throw new ArrayIndexOutOfBoundsException("Out of Image");
302
		dataExtent = new Extent(mDataset.rasterToWorld(new Point2D.Double(x, y)), 
303
								mDataset.rasterToWorld(new Point2D.Double(x + w, y + h)));
304
		rasterBuf = mDataset.getWindowRaster(x, y, w, h);
305
	}
306
	
307
	/*
308
	 *  (non-Javadoc)
309
	 * @see org.gvsig.fmap.dataaccess.IQueryableRaster#setAreaOfInterest()
310
	 */
311
	public void setAreaOfInterest() {		
312
		dataExtent = mDataset.getExtent();
313
		rasterBuf = mDataset.getWindowRaster(0, 0, (int)mDataset.getWidth()[0], (int)mDataset.getHeight()[0]);
314
	}
315
	
316
	/*
317
	 *  (non-Javadoc)
318
	 * @see org.gvsig.fmap.dataaccess.IQueryableRaster#setAreaOfInterest(int, int, int, int, int, int)
319
	 */
320
	public void setAreaOfInterest(int x, int y, int w, int h, int bufWidth, int bufHeight) throws ArrayIndexOutOfBoundsException{
321
		//TODO: VALIDACI?N: Comprobaci?n de exceso de memoria reservada
322
		if(x < 0 || y < 0 || (x + w) > getWidth() || (y + h) > getHeight())
323
			throw new ArrayIndexOutOfBoundsException("Out of Image");
324
		dataExtent = new Extent(mDataset.rasterToWorld(new Point2D.Double(x, y)), 
325
								mDataset.rasterToWorld(new Point2D.Double(x + w, y + h)));
326

  
327
		rasterBuf = mDataset.getWindowRaster(x, y, w, h, bufWidth, bufHeight);
328
	}
329
	
330
	/**
331
	 * Ajusta el ?rea del grid a un ancho y un alto dado en pixeles. Este ajuste se har? 
332
	 * en relaci?n a un m?todo de interpolaci?n definido en el par?metro.
333
	 * @param w Ancho de la nueva imagen.
334
	 * @param h Alto de la nueva imagen.
335
	 * @param interpolation M?todo de interpolaci?n que se usar? en el ajuste.
336
	 * @param bands Bandas que se desea en el nuevo RasterBuf ajustado. Si este par?metro es null
337
	 * se usar?n todas las bandas de la imagen.
338
	 */
339
	public void setAdjustedWindow(int w, int h, int interpolationMethod, int[] bands) {
340
		if(w == width && h == height)
341
			return;
342
		switch(interpolationMethod) {
343
		case IQueryableRaster.INTERPOLATION_NearestNeighbour:
344
				rasterBuf = ((RasterBuffer)rasterBuf).adjustRasterNearestNeighbourInterpolation(w, h, bands);
345
				break;
346
		case IQueryableRaster.INTERPOLATION_Bilinear:
347
				System.out.println("Method not implemented yet");
348
				break;
349
		case IQueryableRaster.INTERPOLATION_InverseDistance:
350
				System.out.println("Method not implemented yet");
351
				break;
352
		case IQueryableRaster.INTERPOLATION_BicubicSpline:
353
				System.out.println("Method not implemented yet");
354
				break;
355
		case IQueryableRaster.INTERPOLATION_BSpline:
356
				System.out.println("Method not implemented yet");
357
				break;
358
		}
359
		//width = rasterBuf.getWidth();
360
		//height = rasterBuf.getHeight();
361
	}
362
		
363
	/**
364
	 * Obtiene el tipo de datos del grid.
365
	 * @return entero que representa el tipo de dato de las celdas del grid.
366
	 */
367
	public int getDataType() {
368
		return mDataset.getDataType()[0];
369
	}
370

  
371
	/**
372
	 * Obtiene la altura del grid.
373
	 * @return altura en celdas del grid.
374
	 */
375
	public int getHeight() {
376
		return height;
377
	}
378

  
379
	/**
380
	 * Obtiene la anchura del grid.
381
	 * @return anchura en celdas del grid.
382
	 */
383
	public int getWidth() {
384
		return width;
385
	}
386

  
387
	/*
388
	 *  (non-Javadoc)
389
	 * @see org.gvsig.fmap.dataaccess.IQueryableRaster#getXCellSize()
390
	 */
391
	public double getXCellSize() {
392

  
393
		Extent e = mDataset.getExtent();
394
		double dCellsize = (e.getMax().getX() - e.getMin().getX() ) / (double) width;
395
		
396
		return dCellsize;
397
		
398
	}
399

  
400
	/*
401
	 *  (non-Javadoc)
402
	 * @see org.gvsig.fmap.dataaccess.IQueryableRaster#getYCellSize()
403
	 */
404
	public double getYCellSize() {
405

  
406
		return 0;
407
	}
408

  
409
	/*
410
	 *  (non-Javadoc)
411
	 * @see org.gvsig.fmap.dataaccess.IQueryableRaster#isNoData(int, int, int)
412
	 */
413
	public boolean isNoData(int x, int y, int band) {
414

  
415
		return false;
416
		
417
	}
418
	
419
	public void setNoDataValue(double dNoDataValue) {
420
		if(rasterBuf instanceof RasterBuffer)
421
			((RasterBuffer)rasterBuf).setNoDataValue(dNoDataValue);
422
	}
423
	
424
	public double getNoDataValue() {
425
		if(rasterBuf instanceof RasterBuffer)
426
			return ((RasterBuffer)rasterBuf).getNoDataValue();
427
		return 0D;
428
	}
429

  
430
	/*
431
	 *  (non-Javadoc)
432
	 * @see org.gvsig.fmap.dataaccess.IQueryableRaster#setDataType(int)
433
	 */
434
	public void setDataType(int dt) {
435
		
436
	}
437
	
438
	/*
439
	 *  (non-Javadoc)
440
	 * @see org.gvsig.fmap.dataaccess.IQueryableRaster#getBandCount()
441
	 */
442
	public int getBandCount() {
443
		if(rasterBuf != null)
444
			return rasterBuf.getBandCount();
445
		else
446
			return this.getGeoRasterMultiFile().getBandCount();
447
	}
448

  
449
	/**
450
	 * Obtiene el buffer de datos del grid
451
	 * @return RasterBuf
452
	 */
453
	public IBuffer getRasterBuf() {
454
		return rasterBuf;
455
	}
456
		
457
	/**
458
	 * Evalua si una coordenada pixel cae dentro de la imagen.
459
	 * @param x coordenada pixel X
460
	 * @param y coordenada pixel Y
461
	 */
462
	public boolean isPixelInGrid(int x, int y) {
463
		return (x >= 0 && y >= 0 && x <= getWidth() && y <= getHeight());
464
	}
465
	
466
	/**
467
	 * Extent de todo el raster asociado a la fuente de datos.
468
	 */
469
	public Extent getExtent() {
470
		return mDataset.getExtent();
471
	}
472

  
473
	/*
474
	 *  (non-Javadoc)
475
	 * @see org.gvsig.fmap.dataaccess.IQueryableRaster#getData(int, int, int, int)
476
	 */
477
	public RasterBuffer getData(int x, int y, int w, int h) {
478
		return null;
479
	}
480

  
481
	/*
482
	 *  (non-Javadoc)
483
	 * @see org.gvsig.fmap.dataaccess.IQueryableRaster#getCoordsGeoTransformFile()
484
	 */
485
	public double[] getCoordsGeoTransformFile() {
486
		return mDataset.getCoordsGeoTransformFile();		
487
	}
488
	
489
	/*
490
	 *  (non-Javadoc)
491
	 * @see org.gvsig.fmap.dataaccess.IQueryableRaster#getLastSelectedView()
492
	 */
493
	public Extent getLastSelectedView() {
494
		return mDataset.getLastSelectedView();
495
	}
496
		
497
	/**
498
	 * Obtiene el extent correspondiente a los datos cargados en el buffer
499
	 * @return Extent
500
	 */
501
	public Extent getDataExtent() {
502
		return dataExtent;
503
	}
504
	
505
	/*
506
	 * (non-Javadoc)
507
	 * @see org.gvsig.fmap.dataaccess.IQueryableRaster#getPalettes()
508
	 */
509
	public DatasetPalette[] getPalettes() {
510
		return palette;
511
	}
512
	
513
	/**
514
	 * Obtiene el flag que dice si la imagen est? o no georreferenciada
515
	 * @return true si est? georreferenciada y false si no lo est?.
516
	 */
517
	public boolean isGeoreferenced() {
518
		return mDataset.isGeoreferenced();
519
	}
520

  
521
	/**
522
	 * Consulta el flag de supersampleo en la carga del buffer.
523
	 * <P> 
524
	 * Si este flag es false 
525
	 * y pasamos un buffer de tama?o mayor que el n?mero de pixels del ?rea requerida en la 
526
	 * llamada setAreaOfInterest entonces se ajustar? este buffer al n?mero de pixeles contenidos 
527
	 * en el ?rea.
528
	 * </P>
529
	 * <P> 
530
	 * Por ejemplo, si solicitamos un ?rea de 5x4 pixels de un raster y pedimos que nos los grabe 
531
	 * en un buffer de 500x400, si esta variable es false el buffer lo generar? de 5x4. Si esta 
532
	 * variable es true el buffer lo generar? de 500x400.
533
	 * </P>
534
	 *  
535
	 * @return true si el supersampleo en la carga del buffer est? activado y false si no lo est?.
536
	 */
537
	public boolean isSupersamplingLoadingBuffer() {
538
		return supersamplingLoadingBuffer;
539
	}
540

  
541
	/**
542
	 * Activa o desactiva el supersampling en la carga del buffer.
543
	 * <P> 
544
	 * Si este flag es false 
545
	 * y pasamos un buffer de tama?o mayor que el n?mero de pixels del ?rea requerida en la 
546
	 * llamada setAreaOfInterest entonces se ajustar? este buffer al n?mero de pixeles contenidos 
547
	 * en el ?rea.
548
	 * </P>
549
	 * <P> 
550
	 * Por ejemplo, si solicitamos un ?rea de 5x4 pixels de un raster y pedimos que nos los grabe 
551
	 * en un buffer de 500x400, si esta variable es false el buffer lo generar? de 5x4. Si esta 
552
	 * variable es true el buffer lo generar? de 500x400.
553
	 * </P> 
554
	 *
555
	 * @param supersamplingLoadingBuffer true o false para activar o desactivar el supersampling en la 
556
	 * carga del buffer.
557
	 */
558
	public void setSupersamplingLoadingBuffer(boolean supersamplingLoadingBuffer) {
559
		this.supersamplingLoadingBuffer = supersamplingLoadingBuffer;
560
	}
561
	
562
	public double getNHeight() {
563
		return nHeight;
564
	}
565

  
566
	public double getNWidth() {
567
		return nWidth;
568
	}
569

  
570
}
571

  
0 572

  
trunk/libraries/libRaster/src/org/gvsig/raster/buffer/RasterBufferInvalidAccessException.java
1
package org.gvsig.raster.buffer;
2

  
3
/**
4
 * Excepci?n lanzada cuando se detecta un acceso a un tipo de datos incorrecto
5
 * en un RasterBuffer.
6
 * @author Nacho Brodin (nachobrodin@gmail.com)
7
 *
8
 */
9
public class RasterBufferInvalidAccessException extends Exception{
10
	public RasterBufferInvalidAccessException(String msg){
11
		super(msg);
12
	}
13
}
0 14

  
trunk/libraries/libRaster/src/org/gvsig/raster/buffer/IQueryableRaster.java
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.buffer;
20

  
21
import org.gvsig.raster.dataset.IBuffer;
22
import org.gvsig.raster.dataset.RasterMultiDataset;
23
import org.gvsig.raster.dataset.properties.DatasetPalette;
24
import org.gvsig.raster.shared.Extent;
25

  
26

  
27
/**
28
 * Interfaz que deben implementar las clases que sirven datos y tienen posibilidad
29
 * de consulta. Tipicamente en gvSIG es implementado por DataSource que ofrecer?
30
 * sus datos a trav?s de un RasterBuffer y su interfaz IBuffer.
31
 * 
32
 * @author Nacho Brodin (nachobrodin@gmail.com)
33
 *
34
 */
35
public interface IQueryableRaster {	  
36
	public final static int INTERPOLATION_Undefined			= 0;
37
	public final static int INTERPOLATION_NearestNeighbour	= 1;
38
	public final static int INTERPOLATION_Bilinear			= 2;
39
	public final static int INTERPOLATION_InverseDistance	= 3;
40
	public final static int INTERPOLATION_BicubicSpline		= 4;
41
	public final static int INTERPOLATION_BSpline			= 5;
42

  
43
	/**
44
	 * Obtiene el ancho de la imagen
45
	 * @return  Ancho en pixeles de la imagen
46
	 */
47
	public int getWidth();
48
	
49
	/**
50
	 * Obtiene el alto de la imagen
51
	 * @return  Alto en pixeles de la imagen
52
	 */
53
	public int getHeight();
54
	
55
	/**
56
	 * Tama?o de celda en X
57
	 * @return 
58
	 */
59
	public double getXCellSize();
60
	
61
	/**
62
	 * Tama?o de celda en Y
63
	 * @return
64
	 */
65
	public double getYCellSize();
66
	
67
	/**
68
	 * Asigna el ?rea de interes en coordenadas del mundo real. Si las coordenadas exceden del tama?o de la imagen
69
	 * estas coordenadas son ajustadas el extent.
70
	 * @param x Coordenada X, esquina superior izquierda
71
	 * @param y Coordenada Y, esquina superior izquierda
72
	 * @param w Ancho del ?rea 
73
	 * @param h Alto del ?rea
74
	 * @param adjustToExtent Flag que dice si el extent solicitado debe ajustarse al extent del raster o no.
75
	 * @throws ArrayIndexOutOfBoundsException
76
	 */
77
	public void setAreaOfInterest(double x, double y, double w, double h, boolean adjustToExtent) throws ArrayIndexOutOfBoundsException;
78
	
79
	/**
80
	 * Asigna el ?rea de interes en coordenadas pixel. Si las coordenadas exceden del tama?o de la imagen
81
	 * lanza una excepci?n.
82
	 * @param x Coordenada X, esquina superior izquierda
83
	 * @param y Coordenada Y, esquina superior izquierda
84
	 * @param w Ancho del ?rea 
85
	 * @param h Alto del ?rea
86
	 * @throws ArrayIndexOutOfBoundsException
87
	 */
88
	public void setAreaOfInterest(int x, int y, int w, int h) throws ArrayIndexOutOfBoundsException;
89
	
90
	/**
91
	 * Asigna el ?rea de inter?s a toda la extensi?n del raster.
92
	 */
93
	public void setAreaOfInterest();
94
	
95
	/**
96
	 * Asigna el ?rea de interes en coordenadas pixel. Esta operaci?n cargar? un RasterBuffer con los datos solicitados por
97
	 * lo que, si al acabar hacemos getRasterBuf obtendremos la matriz de datos. Si las coordenadas exceden del tama?o 
98
	 * de la imagen lanza una excepci?n.
99
	 * @param x Coordenada X, esquina superior izquierda
100
	 * @param y Coordenada Y, esquina superior izquierda
101
	 * @param w Ancho del ?rea 
102
	 * @param h Alto del ?rea
103
	 * @param bufWidth Ancho del buffer
104
	 * @param bufHeight Alto del buffer
105
	 * @throws ArrayIndexOutOfBoundsException
106
	 */
107
	public void setAreaOfInterest(int x, int y, int w, int h, int bufWidth, int bufHeight) throws ArrayIndexOutOfBoundsException;
108
	
109
	/**
110
	 * Asigna el ?rea de interes en coordenadas del mundo real. Si las coordenadas exceden del tama?o de la imagen
111
	 * estas coordenadas son ajustadas el extent.
112
	 * @param x Coordenada X, esquina superior izquierda
113
	 * @param y Coordenada Y, esquina superior izquierda
114
	 * @param w Ancho del ?rea 
115
	 * @param h Alto del ?rea
116
	 * @param bufWidth Ancho del buffer
117
	 * @param bufHeight Alto del buffer
118
	 * @param adjustToExtent Flag que dice si el extent solicitado debe ajustarse al extent del raster o no. 
119
	 * @return En caso de que el buffer sea mayor que el tama?o seleccionado de raster se produce supersampleo. La funci?n devuelve
120
	 * un array de dos elementos que representan el desplazamiento en pixels de X e Y de la esquina superior izquierda. 
121
	 * @throws ArrayIndexOutOfBoundsException
122
	 */
123
	public int[] setAreaOfInterest(double minX, double minY, double maxX, double maxY, int bufWidth, int bufHeight, boolean adjustToExtent) throws ArrayIndexOutOfBoundsException;
124
	
125
	/**
126
	 * Obtiene un buffer desde la posici?n x,y en pixeles de ancho w y alto h
127
	 * @param x Coordenada x de la esquina superior izquierda
128
	 * @param y Coordenada y de la esquina superior izquierda
129
	 * @param w Ancho del grid
130
	 * @param h Alto del grid
131
	 * @return Buffer de datos
132
	 */
133
	public RasterBuffer getData(int x, int y, int w, int h);
134
	
135
	/**
136
	 * Devuelve el tipo de datos del raster
137
	 * @see java.awt.image.DataBuffer
138
	 */
139
	public int getDataType();
140

  
141
	/**
142
	 * Asigna tipo de datos del raster
143
	 * @see java.awt.image.DataBuffer
144
	 */
145
	public void setDataType(int dt);
146

  
147
	/**
148
	 * Devuelve true si la celda contiene un valor de NODATA
149
	 * @param x	coordenada X
150
	 * @param y coordenada Y
151
	 * @return
152
	 */
153
	public boolean isNoData(int x, int y, int band);
154
	
155
	/**
156
	 * Obtiene el n?mero de bandas
157
	 * @return N?mero de bandas
158
	 */
159
	public int getBandCount();
160
	
161
	/**
162
	 * Obtiene el buffer de datos del grid
163
	 * @return RasterBuf
164
	 */
165
	public IBuffer getRasterBuf();
166
	
167
	/**
168
	 * Para este GeoRasterFile asigna que bandas se pintaran
169
	 * sobre el RasterBuf cuando se haga un update. Cada posici?n del vector es una banda
170
	 * del rasterBuf y el contenido de esa posici?n es la banda de la imagen que se dibujar?
171
	 * sobre ese RasterBuf.
172
	 * @param drawableBands	Array con las bandas a dibujar.
173
	 * @return array con tantos elementos como bandas a dibujar. El valor contenido es el fichero del 
174
	 * dataset multifichero al que corresponde la banda.
175
	 */
176
	public int[] addDrawableBands(int[] drawableBands);
177
	
178
	/**
179
	 * Para este GeoRasterFile asigna que bandas se pintaran
180
	 * sobre el RasterBuf cuando se haga un update. Cada posici?n del vector es una banda
181
	 * del rasterBuf y el contenido de esa posici?n es la banda de la imagen que se dibujar?
182
	 * sobre ese RasterBuf. Esta llamada asigna todas las bandas dibujables en su orden natural.
183
	 * @return array con tantos elementos como bandas a dibujar. El valor contenido es el fichero del 
184
	 * dataset multifichero al que corresponde la banda.
185
	 */
186
	public int[] setAllDrawableBands();
187
	
188
	/**
189
	 * Obtiene el array que contiene el orden de bandas. Cada posici?n del vector es una banda
190
	 * del rasterBuf y el contenido de esa posici?n es la banda de la imagen que se dibujar?
191
	 * sobre ese RasterBuf.
192
	 * @return Array de enteros con el orden de las badas
193
	 */
194
	public int[] getDrawableBands();
195
	
196
	/**
197
	 * Obtiene el extent de la fuente de datos
198
	 * @return Extent
199
	 */
200
	public Extent getExtent();
201
	
202
	/**
203
	 * Obtiene el extent correspondiente a los datos cargados en el buffer
204
	 * @return Extent
205
	 */
206
	public Extent getDataExtent();
207
	
208
	/**
209
	 * Obtiene las coordenadas del fichero worldFile (o cabecera del raster) asociado 
210
	 * o el RMF en caso de que existan. Si la imagen no est? georreferenciada tendr?
211
	 * las coordenadas pixel de la misma 
212
	 * @return Array de seis valores:
213
	 * 	<TABLE BORDER="1">
214
	 * 	<TR><TD><B>0:</B></TD><TD>Valor X de la esquina superior izquierda.</TD></TR>
215
	 * 	<TR><TD><B>1:</B></TD><TD>Tama?o de pixel en X.</TD></TR>
216
	 * 	<TR><TD><B>2:</B></TD><TD>Shearing en X.</TD></TR>
217
	 * 	<TR><TD><B>3:</B></TD><TD>Valor Y de la esquina superior izquierda.</TD></TR>
218
	 * 	<TR><TD><B>4:</B></TD><TD>Shearing en Y.</TD></TR>
219
	 * 	<TR><TD><B>5:</B></TD><TD>Tama?o de pixel en Y.</TD></TR>
220
	 * 	</TABLE>
221
	 */
222
	public double[] getCoordsGeoTransformFile();
223
	
224
	/**
225
	 * Obtiene el extent de la ?ltima selecci?n hecha con alguna de las llamadas
226
	 * setAreaOfInterest. Este extent es devuelto en coordenadas reales con las transformaciones
227
	 * que se hayan aplicado sobre el/los dataset.
228
	 * @return Extent Coordenadas reales que representan el ?ltimo ?rea de datos
229
	 * solicitada.
230
	 */
231
	public Extent getLastSelectedView();
232
	
233
	/**
234
	 * Obtiene la estructura que contiene la lista de ficheros del Grid
235
	 * @return GeoRasterMultiFile
236
	 */
237
	public RasterMultiDataset getGeoRasterMultiFile();
238
	
239
	/**
240
	 * Obtiene la lista de paletas asociadas a las bandas cargadas en el DataSource
241
	 * @return Lista con las paletas o null si no hay ninguna asocida. Un nulo en una
242
	 * posici?n del array tambi?n indicar? que para esa banda no hay paletas asociadas.
243
	 */
244
	public DatasetPalette[] getPalettes();
245
	
246
}
0 247

  
... This diff was truncated because it exceeds the maximum size that can be displayed.

Also available in: Unified diff