root / trunk / libraries / libRaster / src / org / gvsig / raster / dataset / RasterMultiDataset.java @ 10996
History | View | Annotate | Download (29.4 KB)
1 |
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
|
---|---|
2 |
*
|
3 |
* Copyright (C) 2006 IVER T.I. and Generalitat Valenciana.
|
4 |
*
|
5 |
* This program is free software; you can redistribute it and/or
|
6 |
* modify it under the terms of the GNU General Public License
|
7 |
* as published by the Free Software Foundation; either version 2
|
8 |
* of the License, or (at your option) any later version.
|
9 |
*
|
10 |
* This program is distributed in the hope that it will be useful,
|
11 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
12 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
13 |
* GNU General Public License for more details.
|
14 |
*
|
15 |
* You should have received a copy of the GNU General Public License
|
16 |
* along with this program; if not, write to the Free Software
|
17 |
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,USA.
|
18 |
*/
|
19 |
package org.gvsig.raster.dataset; |
20 |
|
21 |
import java.awt.geom.Point2D; |
22 |
import java.io.File; |
23 |
import java.util.ArrayList; |
24 |
|
25 |
import org.gvsig.raster.dataaccess.buffer.RasterBuffer; |
26 |
import org.gvsig.raster.dataset.properties.DatasetColorInterpretation; |
27 |
import org.gvsig.raster.dataset.properties.DatasetListHistogram; |
28 |
import org.gvsig.raster.dataset.properties.DatasetListStatistics; |
29 |
import org.gvsig.raster.dataset.properties.DatasetListTransparency; |
30 |
import org.gvsig.raster.dataset.properties.DatasetPalette; |
31 |
import org.gvsig.raster.dataset.properties.DatasetTransparency; |
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.HistogramException; |
36 |
import org.gvsig.raster.util.IHistogramable; |
37 |
|
38 |
|
39 |
/**
|
40 |
* Clase que representa una imagen de raster georreferenciada formada por varias
|
41 |
* imagenes de disco que tienen la misma extensi?n. Contiene funcionalidades para
|
42 |
* abrir ficheros, gestionar el extent, pintar el raster sobre un DataImage con
|
43 |
* su gesti?n de bandas correspondiente.
|
44 |
*
|
45 |
* @author Nacho Brodin (nachobrodin@gmail.com)
|
46 |
*
|
47 |
*/
|
48 |
public class RasterMultiDataset implements IHistogramable{ |
49 |
//File list
|
50 |
private ArrayList files = new ArrayList(); |
51 |
private String name = null; |
52 |
//Band list
|
53 |
private BandList bandList = new BandList(); |
54 |
private ArrayList palettes = new ArrayList(); |
55 |
private DatasetListStatistics stats = null; |
56 |
private DatasetListHistogram histogram = null; |
57 |
|
58 |
//TODO: FUNCIONALIDAD: Contructores igual a RasterDataset + String[] nameFiles
|
59 |
public RasterMultiDataset(String name){ |
60 |
this.name = name;
|
61 |
} |
62 |
|
63 |
/**
|
64 |
* Add a file to the list.
|
65 |
* @param f file to add.
|
66 |
*/
|
67 |
public void addDataset(RasterDataset f)throws FileFoundInListException{ |
68 |
if(findDataset(f))
|
69 |
throw new FileFoundInListException("The file already is in list."); |
70 |
files.add(f); |
71 |
addBands(f); |
72 |
stats = new DatasetListStatistics(files);
|
73 |
} |
74 |
|
75 |
/**
|
76 |
* A?ade un fichero a la lista a partir de su nombre
|
77 |
* @param f fichero a a?adir.
|
78 |
* @throws RasterDriverException
|
79 |
*/
|
80 |
public void addDataset(String fileName)throws FileFoundInListException, NotSupportedExtensionException, RasterDriverException{ |
81 |
if(findDataset(fileName))
|
82 |
throw new FileFoundInListException("The file already is in list."); |
83 |
RasterDataset f = RasterDataset.openFile(null, fileName);
|
84 |
files.add(f); |
85 |
addBands(f); |
86 |
stats = new DatasetListStatistics(files);
|
87 |
} |
88 |
|
89 |
/**
|
90 |
* A?ade el fichero a lista de georrasterfiles y sus bandas a la lista de bandas
|
91 |
* @param grf
|
92 |
*/
|
93 |
private void addBands(RasterDataset grf){ |
94 |
if(grf == null) |
95 |
return;
|
96 |
|
97 |
int dataType = grf.getDataType();
|
98 |
for(int i = 0; i < grf.getBandCount();i++){ |
99 |
try{
|
100 |
Band band = new Band(grf.getFName(), i, dataType);
|
101 |
bandList.addBand(band, i); |
102 |
}catch(BandFoundInListException ex){
|
103 |
//No a?adimos la banda
|
104 |
} |
105 |
} |
106 |
} |
107 |
|
108 |
/**
|
109 |
* Elimina un fichero a la lista a partir de su nombre
|
110 |
* @param fileName Nombre del fichero a eliminar.
|
111 |
*/
|
112 |
public void removeDataset(String fileName){ |
113 |
for(int i=0;i<files.size();i++){ |
114 |
if(((RasterDataset)files.get(i)).getFName().equals(fileName)){
|
115 |
files.remove(i); |
116 |
bandList.removeBands(fileName); |
117 |
return;
|
118 |
} |
119 |
} |
120 |
} |
121 |
|
122 |
/**
|
123 |
* Elimina un fichero a la lista
|
124 |
* @param file Fichero a eliminar
|
125 |
*/
|
126 |
public void removeDataset(RasterDataset file){ |
127 |
for(int i=0;i<files.size();i++){ |
128 |
if(((RasterDataset)files.get(i)).getFName().equals(file.getFName())){
|
129 |
files.remove(i); |
130 |
bandList.removeBands(file.getFName()); |
131 |
return;
|
132 |
} |
133 |
} |
134 |
} |
135 |
|
136 |
/**
|
137 |
* Obtiene el n?mero de ficheros en la lista
|
138 |
* @return integer.
|
139 |
*/
|
140 |
public int getDatasetCount(){ |
141 |
return files.size();
|
142 |
} |
143 |
|
144 |
/**
|
145 |
* Encuentra un fichero en la lista.
|
146 |
* @param file Fichero b?scado.
|
147 |
* @return true si se ha hallado el fichero y false si no se
|
148 |
* ha encontrado
|
149 |
*/
|
150 |
public boolean findDataset(RasterDataset file){ |
151 |
for(int i = 0;i<files.size();i++){ |
152 |
RasterDataset grf = (RasterDataset)files.get(i); |
153 |
if( grf.getFName().equals(file.getFName()))
|
154 |
return true; |
155 |
} |
156 |
return false; |
157 |
} |
158 |
|
159 |
/**
|
160 |
* Encuentra un fichero en la lista.
|
161 |
* @param file Fichero b?scado.
|
162 |
* @return true si se ha hallado el fichero y false si no se
|
163 |
* ha encontrado
|
164 |
*/
|
165 |
public boolean findDataset(String fileName){ |
166 |
for(int i = 0;i<files.size();i++){ |
167 |
if(((RasterDataset)files.get(i)).getFName().equals(fileName))
|
168 |
return true; |
169 |
} |
170 |
return false; |
171 |
} |
172 |
|
173 |
/**
|
174 |
* @see org.javaGeoRaster.io.GeoInfo
|
175 |
*/
|
176 |
public void close(){ |
177 |
for(int i = 0; i < files.size(); i++) |
178 |
((RasterDataset)files.get(i)).close(); |
179 |
} |
180 |
|
181 |
/**
|
182 |
* Obtiene en un array de String la lista de nombres de ficheros
|
183 |
* @return lista de nombres de los ficheros del GeoRasterMultiFile
|
184 |
*/
|
185 |
public String[] getNameDatasetStringList(){ |
186 |
String[] list = new String[files.size()]; |
187 |
for(int i = 0; i < files.size(); i++) |
188 |
list[i] = ((RasterDataset)files.get(i)).getFName(); |
189 |
return list;
|
190 |
} |
191 |
|
192 |
/**
|
193 |
* Inicializa el buffer a valores NoData
|
194 |
* @param raster Buffer a inicializar
|
195 |
* @param bandList Lista de bandas
|
196 |
*/
|
197 |
private void initBufferToNoData(IBuffer raster, BandList bandList){ |
198 |
for(int i = 0; i < bandList.getDrawableBandsCount(); i++){ |
199 |
switch(getDataType()[0]){ |
200 |
case IBuffer.TYPE_BYTE:raster.assign(i, raster.getByteNoDataValue());break; |
201 |
case IBuffer.TYPE_SHORT:raster.assign(i, raster.getShortNoDataValue());break; |
202 |
case IBuffer.TYPE_INT:raster.assign(i, raster.getIntNoDataValue());break; |
203 |
case IBuffer.TYPE_FLOAT:raster.assign(i, raster.getFloatNoDataValue());break; |
204 |
case IBuffer.TYPE_DOUBLE:raster.assign(i, raster.getNoDataValue());break; |
205 |
} |
206 |
} |
207 |
} |
208 |
|
209 |
/**
|
210 |
* A partir de la lista de bandas que dice como cargar el buffer se crean tantos IBuffer como ficheros intervienen
|
211 |
* . Cada IBuffer corresponde a un dataset del RasterMultiDataset y en ellos se reserva memoria solo para las
|
212 |
* bandas que vayan a ser cargadas. Las otras se asignaran a la banda NotValid.
|
213 |
* @param bl Lista de bandas
|
214 |
* @param width Ancho
|
215 |
* @param height Alto
|
216 |
* @return Lista de buffers en el que cada uno corresponde a un dataset.
|
217 |
*/
|
218 |
private IBuffer[] mallocBuffersDatasets(BandList bl, int width, int height){ |
219 |
IBuffer[] buffers = new IBuffer[getDatasetCount()]; |
220 |
for(int i = 0; i < getDatasetCount(); i++){ |
221 |
buffers[i] = RasterBuffer.getBuffer(getDataset(i).getDataType(), width, height, getDataset(i).getBandCount(), false, null); |
222 |
|
223 |
//Asignamos las bandas de cada fichero que no se pintan a null y las que se pintan se reserva memoria
|
224 |
String name = getDataset(i).getFName();
|
225 |
for(int j = 0; j < getDataset(i).getBandCount(); j ++){ |
226 |
if(bl.getBufferBandToDraw(name, j) == null) |
227 |
buffers[i].assignBandToNotValid(j); |
228 |
else
|
229 |
buffers[i].mallocOneBand(getDataset(i).getDataType(), width, height, j); |
230 |
} |
231 |
} |
232 |
return buffers;
|
233 |
} |
234 |
|
235 |
/**
|
236 |
* Mezcla los buffers de los dataset que forman el RasterMultiDataset sobre un solo buffer
|
237 |
* con las directrices que marca la lista de bandas. Esta funci?n es la que realiza el switch
|
238 |
* de las bandas.
|
239 |
* @param b Buffer sobre el que se mezcla
|
240 |
* @param bDataset Buffers que corresponden a los datasets
|
241 |
* @param bandList Objeto que contiene la informaci?n de que bandas de los dataset se escriben sobre
|
242 |
* que banda del buffer.
|
243 |
*/
|
244 |
private void mergeBuffers(IBuffer b, IBuffer[] bDataset, BandList bandList){ |
245 |
for(int iDataset = 0; iDataset < getDatasetCount(); iDataset++){ //Ojo! Los datasets est?n en la misma posici?n que se han metido en mallocBuffersDatasets |
246 |
String name = getDataset(iDataset).getFName();
|
247 |
for(int iBand = 0; iBand < getDataset(iDataset).getBandCount(); iBand ++){ |
248 |
int[] posToDraw = bandList.getBufferBandToDraw(name, iBand); |
249 |
if(posToDraw != null){ |
250 |
for(int i = 0; i < posToDraw.length; i ++){ |
251 |
switch(getDataType()[iDataset]){
|
252 |
case IBuffer.TYPE_BYTE: b.assignBand(posToDraw[i], bDataset[iDataset].getBand(iBand)); break; |
253 |
case IBuffer.TYPE_SHORT: b.assignBand(posToDraw[i], bDataset[iDataset].getBand(iBand)); break; |
254 |
case IBuffer.TYPE_INT: b.assignBand(posToDraw[i], bDataset[iDataset].getBand(iBand)); break; |
255 |
case IBuffer.TYPE_FLOAT: b.assignBand(posToDraw[i], bDataset[iDataset].getBand(iBand)); break; |
256 |
case IBuffer.TYPE_DOUBLE: b.assignBand(posToDraw[i], bDataset[iDataset].getBand(iBand)); break; |
257 |
} |
258 |
} |
259 |
} |
260 |
} |
261 |
} |
262 |
} |
263 |
|
264 |
/**
|
265 |
* Obtiene una ventana de datos de la imagen a partir de coordenadas reales.
|
266 |
* No aplica supersampleo ni subsampleo sino que devuelve una matriz de igual tama?o a los
|
267 |
* pixeles de disco.
|
268 |
* @param x Posici?n X superior izquierda
|
269 |
* @param y Posici?n Y superior izquierda
|
270 |
* @param w Ancho en coordenadas reales
|
271 |
* @param h Alto en coordenadas reales
|
272 |
* @param adjustToExtent Flag que dice si el extent solicitado debe ajustarse al extent del raster o no.
|
273 |
* @param bandList
|
274 |
* @return Buffer de datos
|
275 |
*/
|
276 |
public IBuffer getWindowRaster(double x, double y, double w, double h, boolean adjustToExtent) { |
277 |
|
278 |
Extent selectedExtent = new Extent(x, y, x + w, y - h);
|
279 |
|
280 |
//Leemos pixels completos aunque el valor obtenido sea decimal. Esto se consigue redondeando
|
281 |
//por arriba el m?s alto y por abajo el menor y luego restandolos
|
282 |
|
283 |
Point2D p1 = ((RasterDataset)files.get(0)).worldToRaster(new Point2D.Double(x, y)); |
284 |
Point2D p2 = ((RasterDataset)files.get(0)).worldToRaster(new Point2D.Double(x + w, y - h)); |
285 |
int width = (int)Math.abs(Math.ceil(p2.getX()) - Math.floor(p1.getX())); |
286 |
int height = (int)Math.abs(Math.floor(p1.getY()) - Math.ceil(p2.getY())); |
287 |
|
288 |
int mallocNBands = 0; |
289 |
if(bandList.getDrawableArray() != null) |
290 |
mallocNBands = bandList.getDrawableArray().length; |
291 |
else
|
292 |
bandList.getDrawableBandsCount(); |
293 |
|
294 |
IBuffer raster = RasterBuffer.getBuffer(getDataType()[0], width, height, mallocNBands, false, null); |
295 |
|
296 |
//Caso en el que un buffer no se puedan conmutar las bandas (t?picamente RasterReadOnlyHugeBuffer)
|
297 |
if(!raster.isBandSwitchable())
|
298 |
return RasterBuffer.getBuffer(getDataType()[0], width, height, getDataset(0).getBandCount(), false, getDataset(0).getFName()); |
299 |
|
300 |
for(int iBand = 0; iBand < raster.getBandCount(); iBand ++) |
301 |
raster.assignBandToNotValid(iBand); |
302 |
|
303 |
//Si no vamos a ajustar el extent al raster inicializamos el buffer a noData ya que este puede ser
|
304 |
//m?s grande y salirse de los l?mites.
|
305 |
if(!adjustToExtent)
|
306 |
initBufferToNoData(raster, bandList); |
307 |
|
308 |
//Reservamos memoria para los buffers por dataset
|
309 |
IBuffer[] bufferDatasets = mallocBuffersDatasets(bandList, width, height);
|
310 |
for(int i = 0; i < getDatasetCount(); i++) |
311 |
bufferDatasets[i] = ((RasterDataset)files.get(i)).getWindowRaster(x, y, w, h, bandList, bufferDatasets[i], adjustToExtent); |
312 |
|
313 |
//Mezclamos los buffers de cada dataset en un solo buffer
|
314 |
mergeBuffers(raster, bufferDatasets, bandList); |
315 |
|
316 |
return raster;
|
317 |
} |
318 |
|
319 |
/**
|
320 |
* Obtiene una ventana de datos de la imagen a partir de coordenadas reales.
|
321 |
* Aplica supersampleo o subsampleo en funci?n del tama?o del buffer. Esta operaci?n la gestiona
|
322 |
* el driver.
|
323 |
* @param minX Valor m?nimo de la X en coordenadas reales
|
324 |
* @param minY Valor m?nimo de la Y en coordenadas reales
|
325 |
* @param maxX Valor m?ximo de la X en coordenadas reales
|
326 |
* @param maxY Valor m?ximo de la Y en coordenadas reales
|
327 |
* @param bufWidth ancho del buffer lde datos
|
328 |
* @param bufHeight alto del buffer de datos
|
329 |
* @param adjustToExtent Flag que dice si el extent solicitado debe ajustarse al extent del raster o no.
|
330 |
* @param bandList
|
331 |
* @return Buffer de datos
|
332 |
*/
|
333 |
public IBuffer getWindowRaster(double minX, double minY, double maxX, double maxY, |
334 |
int bufWidth, int bufHeight, boolean adjustToExtent) { |
335 |
int mallocNBands = 0; |
336 |
if(bandList.getDrawableArray() != null) |
337 |
mallocNBands = bandList.getDrawableArray().length; |
338 |
else
|
339 |
bandList.getDrawableBandsCount(); |
340 |
|
341 |
IBuffer raster = RasterBuffer.getBuffer(getDataType()[0], bufWidth, bufHeight, mallocNBands, false, null); |
342 |
|
343 |
//Caso en el que un buffer no se puedan conmutar las bandas (t?picamente RasterReadOnlyHugeBuffer)
|
344 |
if(!raster.isBandSwitchable())
|
345 |
return RasterBuffer.getBuffer(getDataType()[0], bufWidth, bufHeight, getDataset(0).getBandCount(), false, getDataset(0).getFName()); |
346 |
|
347 |
for(int iBand = 0; iBand < raster.getBandCount(); iBand ++) |
348 |
raster.assignBandToNotValid(iBand); |
349 |
|
350 |
//Si no vamos a ajustar el extent al raster inicializamos el buffer a noData ya que este puede ser
|
351 |
//m?s grande y salirse de los l?mites.
|
352 |
if(!adjustToExtent)
|
353 |
initBufferToNoData(raster, bandList); |
354 |
|
355 |
//Reservamos memoria para los buffers por dataset
|
356 |
IBuffer[] bufferDatasets = mallocBuffersDatasets(bandList, bufWidth, bufHeight);
|
357 |
for(int i = 0; i < getDatasetCount(); i++) |
358 |
bufferDatasets[i] = ((RasterDataset)files.get(i)).getWindowRaster(minX, minY, maxX, maxY, bufWidth, bufHeight, bandList, bufferDatasets[i], adjustToExtent); |
359 |
|
360 |
//Mezclamos los buffers de cada dataset en un solo buffer
|
361 |
mergeBuffers(raster, bufferDatasets, bandList); |
362 |
|
363 |
return raster;
|
364 |
} |
365 |
|
366 |
/**
|
367 |
* Obtiene una ventana de datos de la imagen a partir de coordenadas reales.
|
368 |
* No aplica supersampleo ni subsampleo sino que devuelve una matriz de igual tama?o a los
|
369 |
* pixeles de disco.
|
370 |
* @param x Posici?n X superior izquierda
|
371 |
* @param y Posici?n Y superior izquierda
|
372 |
* @param w Ancho en coordenadas pixel
|
373 |
* @param h Alto en coordenadas pixel
|
374 |
* @param bandList
|
375 |
* @return Buffer de datos
|
376 |
*/
|
377 |
public IBuffer getWindowRaster(int x, int y, int w, int h) { |
378 |
IBuffer raster = RasterBuffer.getBuffer(getDataType()[0], w, h, bandList.getDrawableBandsCount(), false, null); |
379 |
|
380 |
//Caso en el que un buffer no se puedan conmutar las bandas (t?picamente RasterReadOnlyHugeBuffer)
|
381 |
if(!raster.isBandSwitchable())
|
382 |
return RasterBuffer.getBuffer(getDataType()[0], w, h, getDataset(0).getBandCount(), false, getDataset(0).getFName()); |
383 |
|
384 |
for(int iBand = 0; iBand < raster.getBandCount(); iBand ++) |
385 |
raster.assignBandToNotValid(iBand); |
386 |
|
387 |
//Reservamos memoria para los buffers por dataset
|
388 |
IBuffer[] bufferDatasets = mallocBuffersDatasets(bandList, w, h);
|
389 |
for(int i = 0; i < getDatasetCount(); i++) |
390 |
bufferDatasets[i] = ((RasterDataset)files.get(i)).getWindowRaster(x, y, w, h, bandList, bufferDatasets[i]); |
391 |
|
392 |
//Mezclamos los buffers de cada dataset en un solo buffer
|
393 |
mergeBuffers(raster, bufferDatasets, bandList); |
394 |
|
395 |
return raster;
|
396 |
} |
397 |
|
398 |
/**
|
399 |
* Obtiene una ventana de datos de la imagen a partir de coordenadas reales.
|
400 |
* Aplica supersampleo o subsampleo en funci?n del tama?o del buffer
|
401 |
* @param x Posici?n X superior izquierda en pixels
|
402 |
* @param y Posici?n Y superior izquierda en pixels
|
403 |
* @param w Ancho en pixels
|
404 |
* @param h Alto en pixels
|
405 |
* @param bufWidth ancho del buffer de datos
|
406 |
* @param bufHeight alto del buffer de datos
|
407 |
* @param bandList
|
408 |
* @return Buffer de datos
|
409 |
*/
|
410 |
public IBuffer getWindowRaster(int x, int y, int w, int h, int bufWidth, int bufHeight) { |
411 |
IBuffer raster = RasterBuffer.getBuffer(getDataType()[0], bufWidth, bufHeight, bandList.getDrawableBandsCount(), false, null); |
412 |
for(int iBand = 0; iBand < raster.getBandCount(); iBand ++) |
413 |
raster.assignBandToNotValid(iBand); |
414 |
|
415 |
//Reservamos memoria para los buffers por dataset
|
416 |
IBuffer[] bufferDatasets = mallocBuffersDatasets(bandList, bufWidth, bufHeight);
|
417 |
|
418 |
//Caso en el que un buffer no se puedan conmutar las bandas (t?picamente RasterReadOnlyHugeBuffer)
|
419 |
if(!raster.isBandSwitchable())
|
420 |
return RasterBuffer.getBuffer(getDataType()[0], bufWidth, bufHeight, getDataset(0).getBandCount(), false, getDataset(0).getFName()); |
421 |
|
422 |
for(int i = 0; i < getDatasetCount(); i++) |
423 |
bufferDatasets[i] = ((RasterDataset)files.get(i)).getWindowRaster(x, y, w, h, bufWidth, bufHeight, bandList, bufferDatasets[i]); |
424 |
|
425 |
//Mezclamos los buffers de cada dataset en un solo buffer
|
426 |
mergeBuffers(raster, bufferDatasets, bandList); |
427 |
|
428 |
return raster;
|
429 |
} |
430 |
|
431 |
//******************************
|
432 |
//Setters and Getters
|
433 |
//******************************
|
434 |
|
435 |
/**
|
436 |
* Calcula el tama?o de los ficheros en disco
|
437 |
* @return tama?o en bytes de todos los ficheros de la lista
|
438 |
*/
|
439 |
public long getFileSize(){ |
440 |
int len = 0; |
441 |
for(int i=0;i<files.size();i++){ |
442 |
if(((RasterDataset)files.get(i)) != null){ |
443 |
File f = new File(((RasterDataset)files.get(i)).getFName()); |
444 |
len += f.length(); |
445 |
} |
446 |
} |
447 |
return len;
|
448 |
} |
449 |
|
450 |
/**
|
451 |
* Obtiene la altura de la imagen a partir de la primera
|
452 |
* @return altura
|
453 |
*/
|
454 |
public double[] getHeight() { |
455 |
double[] lenghts = new double[getDatasetCount()]; |
456 |
for(int i = 0; i < getDatasetCount(); i++) |
457 |
if(((RasterDataset)files.get(i)) != null) |
458 |
lenghts[i] = ((RasterDataset)files.get(i)).getHeight(); |
459 |
return lenghts;
|
460 |
} |
461 |
|
462 |
/**
|
463 |
* Obtiene la anchura de la imagen a partir de la primera
|
464 |
* @return anchura
|
465 |
*/
|
466 |
public double[] getWidth() { |
467 |
double[] lenghts = new double[getDatasetCount()]; |
468 |
for(int i = 0; i < getDatasetCount(); i++) |
469 |
if(((RasterDataset)files.get(i)) != null) |
470 |
lenghts[i] = ((RasterDataset)files.get(i)).getWidth(); |
471 |
return lenghts;
|
472 |
} |
473 |
|
474 |
/**
|
475 |
* Obtiene el n?mero de bandas del fichero
|
476 |
* @return
|
477 |
*/
|
478 |
public int getBandCount(){ |
479 |
return bandList.getBandCount();
|
480 |
} |
481 |
|
482 |
/**
|
483 |
* Obtiene el tipo de dato por banda
|
484 |
* @return tipo de dato por banda
|
485 |
*/
|
486 |
public int[] getDataType() { |
487 |
int[] dt = new int[getDatasetCount()]; |
488 |
for(int i=0;i<files.size();i++) |
489 |
dt[i] = ((RasterDataset)files.get(i)).getDataType(); |
490 |
|
491 |
if(dt.length == 0) |
492 |
return null; |
493 |
else
|
494 |
return dt;
|
495 |
} |
496 |
|
497 |
/**
|
498 |
* Obtiene fichero de la posici?n i.
|
499 |
* @param i Posici?n del fichero a obtener.
|
500 |
* @return GeoRasterFileDataset.
|
501 |
*/
|
502 |
public RasterDataset getDataset(int i){ |
503 |
return (RasterDataset)files.get(i);
|
504 |
} |
505 |
|
506 |
/**
|
507 |
* Obtiene fichero de nombre fileName.
|
508 |
* @param i Posici?n del fichero a obtener.
|
509 |
* @return GeoRasterFile.
|
510 |
*/
|
511 |
public RasterDataset getDataset(String fileName){ |
512 |
for(int i=0;i<files.size();i++){ |
513 |
if(((RasterDataset)files.get(i)).getFName().equals(fileName))
|
514 |
return (RasterDataset)files.get(i);
|
515 |
} |
516 |
return null; |
517 |
} |
518 |
|
519 |
/**
|
520 |
* Asigna el nombre al GeoRasterMultiFile
|
521 |
* @param name Nombre del GeoRasterMultiFile
|
522 |
*/
|
523 |
public void setName(String name){ |
524 |
this.name = name;
|
525 |
} |
526 |
|
527 |
/**
|
528 |
* Obtiene la lista de bandas
|
529 |
* @return BandList
|
530 |
*/
|
531 |
public BandList getBands(){
|
532 |
return bandList;
|
533 |
} |
534 |
|
535 |
/**
|
536 |
* Obtiene la coordenada X m?nima de toda la lista
|
537 |
* @return Coordenada X m?nima
|
538 |
*/
|
539 |
public double getMinX(){ |
540 |
double minx = Double.MAX_VALUE; |
541 |
for(int i = 0; i < files.size(); i++){ |
542 |
double aux = ((RasterDataset)files.get(i)).getExtent().getMin().getX();
|
543 |
if(aux < minx)
|
544 |
minx = aux; |
545 |
} |
546 |
return minx;
|
547 |
} |
548 |
|
549 |
/**
|
550 |
* Obtiene la coordenada Y m?nima de toda la lista
|
551 |
* @return Coordenada Y m?nima
|
552 |
*/
|
553 |
public double getMinY(){ |
554 |
double miny = Double.MAX_VALUE; |
555 |
for(int i = 0; i < files.size(); i++){ |
556 |
double aux = ((RasterDataset)files.get(i)).getExtent().getMin().getY();
|
557 |
if(aux < miny)
|
558 |
miny = aux; |
559 |
} |
560 |
return miny;
|
561 |
} |
562 |
|
563 |
/**
|
564 |
* Obtiene la coordenada Y m?xima de toda la lista
|
565 |
* @return Coordenada Y m?xima
|
566 |
*/
|
567 |
public double getMaxX(){ |
568 |
double maxx = Double.MIN_VALUE; |
569 |
for(int i = 0; i < files.size(); i++){ |
570 |
double aux = ((RasterDataset)files.get(i)).getExtent().getMin().getY();
|
571 |
if(aux > maxx)
|
572 |
maxx = aux; |
573 |
} |
574 |
return maxx;
|
575 |
} |
576 |
|
577 |
/**
|
578 |
* Obtiene la coordenada Y m?xima de toda la lista
|
579 |
* @return Coordenada Y m?xima
|
580 |
*/
|
581 |
public double getMaxY(){ |
582 |
double maxy = Double.MIN_VALUE; |
583 |
for(int i = 0; i < files.size(); i++){ |
584 |
double aux = ((RasterDataset)files.get(i)).getExtent().getMin().getY();
|
585 |
if(aux > maxy)
|
586 |
maxy = aux; |
587 |
} |
588 |
return maxy;
|
589 |
} |
590 |
|
591 |
/**
|
592 |
* Obtiene el extent del multi fichero. Este corresponde al primer
|
593 |
* GeoRasterFile de la lista.
|
594 |
* @return Extent
|
595 |
*/
|
596 |
public Extent getExtent(){
|
597 |
if(files.size() == 0) |
598 |
return null; |
599 |
else
|
600 |
return ((RasterDataset)files.get(0)).getExtent(); |
601 |
} |
602 |
|
603 |
/**
|
604 |
* Este es el extent sobre el que se ajusta una petici?n para que esta no exceda el
|
605 |
* extent m?ximo del raster. Para un raster sin rotar ser? igual al extent
|
606 |
* pero para un raster rotado ser? igual al extent del raster como si no
|
607 |
* tuviera rotaci?n. Esto ha de ser as? ya que la rotaci?n solo se hace sobre la
|
608 |
* vista y las peticiones han de hacerse en coordenadas de la imagen sin shearing
|
609 |
* aplicado.
|
610 |
* @return Extent
|
611 |
*/
|
612 |
public Extent getExtentForRequest() {
|
613 |
return ((RasterDataset)files.get(0)).getExtentForRequest(); |
614 |
} |
615 |
|
616 |
/**
|
617 |
* Obtiene las coordenadas del fichero worldFile (o cabecera del raster) asociado
|
618 |
* o el RMF en caso de que existan. Si la imagen no est? georreferenciada tendr?
|
619 |
* las coordenadas pixel de la misma
|
620 |
* @return Array de seis valores:
|
621 |
* <TABLE BORDER="1">
|
622 |
* <TR><TD><B>0:</B></TD><TD>Valor X de la esquina superior izquierda.</TD></TR>
|
623 |
* <TR><TD><B>1:</B></TD><TD>Tama?o de pixel en X.</TD></TR>
|
624 |
* <TR><TD><B>2:</B></TD><TD>Shearing en X.</TD></TR>
|
625 |
* <TR><TD><B>3:</B></TD><TD>Valor Y de la esquina superior izquierda.</TD></TR>
|
626 |
* <TR><TD><B>4:</B></TD><TD>Shearing en Y.</TD></TR>
|
627 |
* <TR><TD><B>5:</B></TD><TD>Tama?o de pixel en Y.</TD></TR>
|
628 |
* </TABLE>
|
629 |
*/
|
630 |
public double[] getCoordsGeoTransformFile(){ |
631 |
return ((RasterDataset)files.get(0)).getTransform(); |
632 |
} |
633 |
|
634 |
/**
|
635 |
* Obtiene el extent de la ?ltima selecci?n hecha con alguna de las llamadas
|
636 |
* setAreaOfInterest. Este extent es devuelto en coordenadas reales con las transformaciones
|
637 |
* que se hayan aplicado sobre el/los dataset.
|
638 |
* @return Extent Coordenadas reales que representan el ?ltimo ?rea de datos
|
639 |
* solicitada.
|
640 |
*/
|
641 |
public Extent getLastSelectedView(){
|
642 |
return ((RasterDataset)files.get(0)).getView(); |
643 |
} |
644 |
|
645 |
/**
|
646 |
* Obtiene el tama?o de pixel.
|
647 |
* @return array de dos elementos, tama?o de pixel en X y en Y.
|
648 |
*/
|
649 |
public double[] getPixelSize(){ |
650 |
double[] at = ((RasterDataset)files.get(0)).getTransform(); |
651 |
return new double[]{at[1], at[5]}; |
652 |
} |
653 |
|
654 |
/**
|
655 |
* Obtiene el estado de transparencia a partir de los estados de transparencia de todos
|
656 |
* los ficheros que lo componen. Si varios de los ficheros que lo componen tienen banda de
|
657 |
* transparencia estas tendr?n que ser mezcladas sobre una banda de transparencia ?nica.
|
658 |
* @return Objeto FileTransparency con el estado de transparencia
|
659 |
*/
|
660 |
public DatasetListTransparency getTransparencyFilesStatus(){
|
661 |
DatasetListTransparency out = null;
|
662 |
for(int i = 0; i < files.size(); i++){ |
663 |
DatasetTransparency tfs = ((RasterDataset)files.get(i)).getTransparencyDatasetStatus(); |
664 |
if(tfs != null){ |
665 |
if(out == null) |
666 |
out = new DatasetListTransparency(tfs);
|
667 |
else
|
668 |
out.merge(tfs); |
669 |
} |
670 |
} |
671 |
return out;
|
672 |
} |
673 |
|
674 |
/**
|
675 |
* Obtiene la paleta correspondiente a uno de los ficheros que forman el GeoMultiRasterFile
|
676 |
* @param i Posici?n del raster
|
677 |
* @return Paleta asociada a este o null si no tiene
|
678 |
*/
|
679 |
public DatasetPalette getPalette(int i){ |
680 |
if(i >= files.size())
|
681 |
return null; |
682 |
return ((RasterDataset)files.get(i)).getPalette();
|
683 |
} |
684 |
|
685 |
/**
|
686 |
* Obtiene la lista de paletas correspondiente a todos los ficheros que forman el GeoMultiRasterFile
|
687 |
* @return Paleta asociada a este o null si no tiene. Una posici?n null en el array tambi?n indica que
|
688 |
* para ese fichero no hay paletas asociadas.
|
689 |
*/
|
690 |
public DatasetPalette[] getPalettes(){ |
691 |
if(files.size() <= 0) |
692 |
return null; |
693 |
DatasetPalette[] list = new DatasetPalette[files.size()]; |
694 |
for(int i = 0; i < files.size(); i++) |
695 |
list[i] = ((RasterDataset)files.get(i)).getPalette(); |
696 |
return list;
|
697 |
} |
698 |
|
699 |
/**
|
700 |
* Obtiene la paleta correspondiente al nombre del fichero pasado por par?metro.
|
701 |
* @param fileName Nombre del fichero
|
702 |
* @return Paleta o null si no la tiene
|
703 |
*/
|
704 |
public DatasetPalette getPalette(String fileName){ |
705 |
for(int i = 0; i < files.size(); i++){ |
706 |
if(((RasterDataset)files.get(i)).getFName().indexOf(fileName) == 0) |
707 |
return ((RasterDataset)files.get(i)).getPalette();
|
708 |
} |
709 |
return null; |
710 |
} |
711 |
|
712 |
/**
|
713 |
* Convierte un punto desde coordenadas pixel a coordenadas del mundo.
|
714 |
* @param pt Punto a transformar
|
715 |
* @return punto transformado en coordenadas del mundo
|
716 |
*/
|
717 |
public Point2D rasterToWorld(Point2D pt) { |
718 |
return ((RasterDataset)files.get(0)).rasterToWorld(pt); |
719 |
} |
720 |
|
721 |
/**
|
722 |
* Convierte un punto desde del mundo a coordenadas pixel.
|
723 |
* @param pt Punto a transformar
|
724 |
* @return punto transformado en coordenadas pixel
|
725 |
*/
|
726 |
public Point2D worldToRaster(Point2D pt) { |
727 |
return ((RasterDataset)files.get(0)).worldToRaster(pt); |
728 |
} |
729 |
|
730 |
/**
|
731 |
* Dado unas coordenadas reales, un tama?o de buffer y un tama?o de raster.
|
732 |
* Si el buffer es de mayor tama?o que el raster (supersampleo) quiere decir que
|
733 |
* por cada pixel de buffer se repiten varios del raster. Esta funci?n calcula el
|
734 |
* n?mero de pixels de desplazamiento en X e Y que corresponden al primer pixel del
|
735 |
* buffer en la esquina superior izquierda. Esto es necesario porque la coordenada
|
736 |
* solicitada es real y puede no caer sobre un pixel completo. Este calculo es
|
737 |
* util cuando un cliente quiere supersamplear sobre un buffer y que no se lo haga
|
738 |
* el driver autom?ticamente.
|
739 |
* @param dWorldTLX Coordenada real X superior izquierda
|
740 |
* @param dWorldTLY Coordenada real Y superior izquierda
|
741 |
* @param nWidth Ancho del raster
|
742 |
* @param nHeight Alto del raster
|
743 |
* @param bufWidth Ancho del buffer
|
744 |
* @param bufHeight Alto del buffer
|
745 |
* @return Array de dos elementos con el desplazamiento en X e Y.
|
746 |
*/
|
747 |
public int[] calcSteps(double dWorldTLX, double dWorldTLY, double dWorldBRX, double dWorldBRY, |
748 |
double nWidth, double nHeight, int bufWidth, int bufHeight){ |
749 |
return ((RasterDataset)files.get(0)).calcSteps(dWorldTLX, dWorldTLY, dWorldBRX, dWorldBRY, nWidth, nHeight, bufWidth, bufHeight); |
750 |
} |
751 |
|
752 |
/**
|
753 |
* Obtiene el objeto con las estadisticas
|
754 |
* @return MultiFileStatistics
|
755 |
*/
|
756 |
public DatasetListStatistics getStatistics(){
|
757 |
return stats;
|
758 |
} |
759 |
|
760 |
/**
|
761 |
* Obtiene el flag que dice si la imagen est? o no georreferenciada
|
762 |
* @return true si est? georreferenciada y false si no lo est?.
|
763 |
*/
|
764 |
public boolean isGeoreferenced() { |
765 |
for(int i = 0; i < files.size(); i++){ |
766 |
if(((RasterDataset)files.get(i)).isGeoreferenced())
|
767 |
return true; |
768 |
} |
769 |
return false; |
770 |
} |
771 |
|
772 |
//TODO: TEST: Probar getData para multifichero
|
773 |
/**
|
774 |
* Obtiene el valor del raster en la coordenada que se le pasa.
|
775 |
* El valor ser? Double, Int, Byte, etc. dependiendo del tipo de
|
776 |
* raster.
|
777 |
* @param x coordenada X
|
778 |
* @param y coordenada Y
|
779 |
* @return
|
780 |
*/
|
781 |
public Object getData(int x, int y, int band)throws InvalidSetViewException, FileNotOpenException, RasterDriverException{ |
782 |
String file = bandList.getBand(band).getFileName();
|
783 |
for(int i = 0; i < files.size(); i++){ |
784 |
if(((RasterDataset)files.get(i)).getFName().equals(file))
|
785 |
return ((RasterDataset)files.get(i)).getData(x, y, band);
|
786 |
} |
787 |
return null; |
788 |
} |
789 |
|
790 |
/**
|
791 |
* Obtiene el histograma.
|
792 |
*
|
793 |
* @return Histograma
|
794 |
*/
|
795 |
public Histogram getHistogram(DataClassList classes)throws FileNotOpenException, RasterDriverException{ |
796 |
if (histogram == null) |
797 |
histogram = new DatasetListHistogram(this); |
798 |
histogram.setClasses(classes); |
799 |
return histogram.getHistogram();
|
800 |
} |
801 |
|
802 |
/**
|
803 |
* Obtiene el objeto que contiene que contiene la interpretaci?n de
|
804 |
* color por banda para el dataset seleccionado
|
805 |
* @param dataset Dataset del que se necesesita la informaci?n de color dentro del RasterMultiDataset
|
806 |
* @return DatasetColorInterpretation
|
807 |
*/
|
808 |
public DatasetColorInterpretation getColorInterpretation(int dataset){ |
809 |
return ((RasterDataset)files.get(dataset)).getColorInterpretation();
|
810 |
} |
811 |
|
812 |
/**
|
813 |
* Obtiene la proyecci?n asociada al dataset. Como todos los dataset del
|
814 |
* multiDataset deben tener la misma proyecci?n obtenemos esta del primer
|
815 |
* dataset.
|
816 |
* @return Proyecci?n en formato cadena
|
817 |
* @throws RasterDriverException
|
818 |
*/
|
819 |
public String getStringProjection() throws RasterDriverException{ |
820 |
return ((RasterDataset)files.get(0)).getStringProjection(); |
821 |
} |
822 |
|
823 |
/*
|
824 |
* (non-Javadoc)
|
825 |
* @see org.gvsig.raster.driver.datasetproperties.IHistogramable#getHistogram()
|
826 |
*/
|
827 |
public Histogram getHistogram() throws HistogramException { |
828 |
if(histogram == null) |
829 |
histogram = new DatasetListHistogram(this); |
830 |
|
831 |
try {
|
832 |
Histogram tmp = histogram.getHistogram(); |
833 |
return tmp;
|
834 |
} catch (FileNotOpenException e) {
|
835 |
throw new HistogramException("FileNotOpenException"); |
836 |
} catch (RasterDriverException e) {
|
837 |
throw new HistogramException("RasterDriverException"); |
838 |
} |
839 |
} |
840 |
|
841 |
/*
|
842 |
* (non-Javadoc)
|
843 |
* @see org.gvsig.raster.driver.datasetproperties.IHistogramable#getHistogramUsingClasses(org.gvsig.raster.shared.DataClassList)
|
844 |
*/
|
845 |
public Histogram getHistogramUsingClasses(DataClassList classes)throws HistogramException { |
846 |
if(histogram == null) |
847 |
histogram = new DatasetListHistogram(this); |
848 |
histogram.setClasses(classes); |
849 |
try {
|
850 |
return histogram.getHistogram();
|
851 |
} catch (FileNotOpenException e) {
|
852 |
throw new HistogramException("FileNotOpenException"); |
853 |
} catch (RasterDriverException e) {
|
854 |
throw new HistogramException("RasterDriverException"); |
855 |
} |
856 |
} |
857 |
|
858 |
/*
|
859 |
* (non-Javadoc)
|
860 |
* @see org.gvsig.raster.util.IHistogramable#getPercent()
|
861 |
*/
|
862 |
public int getPercent() { |
863 |
if (histogram != null) |
864 |
return histogram.getPercent();
|
865 |
return 0; |
866 |
} |
867 |
|
868 |
} |