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