svn-gvsig-desktop / trunk / libraries / libRaster / src / org / gvsig / raster / dataset / CompositeDataset.java @ 20119
History | View | Annotate | Download (39.9 KB)
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; |
20 |
|
21 |
import java.awt.geom.AffineTransform; |
22 |
import java.awt.geom.NoninvertibleTransformException; |
23 |
import java.awt.geom.Point2D; |
24 |
import java.io.IOException; |
25 |
|
26 |
import org.cresques.cts.IProjection; |
27 |
import org.gvsig.raster.RasterLibrary; |
28 |
import org.gvsig.raster.buffer.RasterBuffer; |
29 |
import org.gvsig.raster.dataset.io.RasterDriverException; |
30 |
import org.gvsig.raster.dataset.properties.DatasetColorInterpretation; |
31 |
import org.gvsig.raster.dataset.properties.DatasetListHistogram; |
32 |
import org.gvsig.raster.dataset.properties.DatasetListStatistics; |
33 |
import org.gvsig.raster.datastruct.ColorTable; |
34 |
import org.gvsig.raster.datastruct.Extent; |
35 |
import org.gvsig.raster.datastruct.GeoPoint; |
36 |
import org.gvsig.raster.datastruct.Histogram; |
37 |
import org.gvsig.raster.datastruct.HistogramException; |
38 |
import org.gvsig.raster.datastruct.Transparency; |
39 |
import org.gvsig.raster.util.MathUtils; |
40 |
import org.gvsig.raster.util.RasterUtilities; |
41 |
|
42 |
/**
|
43 |
* Esta clase est? compuestas de multiples datasets formando una rejilla de NxM
|
44 |
* rasters. Un cliente de esta clase debe tener una visi?n de la rejilla como si fuese un
|
45 |
* solo raster, gestionando esta el acceso la imagen que corresponda en cada petici?n de
|
46 |
* usuario.
|
47 |
*
|
48 |
* @version 29/08/2007
|
49 |
* @author Nacho Brodin (nachobrodin@gmail.com)
|
50 |
*
|
51 |
*/
|
52 |
public class CompositeDataset implements IRasterDataSource { |
53 |
|
54 |
private MultiRasterDataset[][] mosaic = null; |
55 |
private DatasetListStatistics stats = null; |
56 |
private BandList bandList = new BandList(); |
57 |
private boolean readOnly = false; |
58 |
/**
|
59 |
* Flag que fuerza al buffer en memoria
|
60 |
*/
|
61 |
private boolean forceToMemory = false; |
62 |
|
63 |
/**
|
64 |
* Constructor. Genera la estructura de n filas por n columnas de rasters.
|
65 |
* @param n N?mero de filas
|
66 |
* @param m N?mero de columnas
|
67 |
*/
|
68 |
public CompositeDataset(int n, int m) { |
69 |
mosaic = new MultiRasterDataset[n][m];
|
70 |
} |
71 |
|
72 |
/**
|
73 |
* Constructor. Genera la estructura de n filas por n columnas de rasters y
|
74 |
* las asigna a los raster que se le pasan por par?metro.
|
75 |
* @param n N?mero de filas
|
76 |
* @param m N?mero de columnas
|
77 |
*/
|
78 |
public CompositeDataset(MultiRasterDataset[][] mos) throws MosaicNotValidException { |
79 |
this.mosaic = deleteNullValues(mos);
|
80 |
//this.mosaic = mos;
|
81 |
|
82 |
/*if(!validateMosaic()) {
|
83 |
this.mosaic = null;
|
84 |
throw new MosaicNotValidException("Extends no validos para montar un mosaico");
|
85 |
}*/
|
86 |
init(); |
87 |
|
88 |
} |
89 |
|
90 |
/**
|
91 |
* M?todo que elimina crea un array bidimensional eliminando los nulos del que tiene
|
92 |
* el que se le pasa por par?metro
|
93 |
* @param values
|
94 |
* @return MultiRasterDataset
|
95 |
*/
|
96 |
private MultiRasterDataset[][] deleteNullValues(MultiRasterDataset[][] values) { |
97 |
int n = values.length;
|
98 |
int m = values[0].length; |
99 |
int posInitX = 0; |
100 |
int posInitY = 0; |
101 |
|
102 |
int nRows = n, nCols = m;
|
103 |
//Contador de filas
|
104 |
boolean first = true; |
105 |
for (int row = 0; row < n; row++) { |
106 |
boolean isNull = true; |
107 |
for (int col = 0; col < m; col++) { |
108 |
if(values[row][col] != null) { |
109 |
isNull = false;
|
110 |
if(first) {
|
111 |
posInitX = col; |
112 |
first = false;
|
113 |
} |
114 |
} |
115 |
} |
116 |
if(isNull)
|
117 |
nRows --; |
118 |
} |
119 |
|
120 |
//Contador de columnas
|
121 |
first = true;
|
122 |
for (int col = 0; col < m; col++) { |
123 |
boolean isNull = true; |
124 |
for (int row = 0; row < n; row++) { |
125 |
if(values[row][col] != null) { |
126 |
isNull = false;
|
127 |
if(first) {
|
128 |
posInitY = row; |
129 |
first = false;
|
130 |
} |
131 |
} |
132 |
} |
133 |
if(isNull)
|
134 |
nCols --; |
135 |
} |
136 |
//Copia de datos
|
137 |
MultiRasterDataset[][] result = new MultiRasterDataset[nRows][nCols]; |
138 |
|
139 |
for (int row = 0; row < result.length; row++) |
140 |
for (int col = 0; col < result[row].length; col++) |
141 |
result[row][col] = values[row + posInitY][col + posInitX]; |
142 |
return result;
|
143 |
} |
144 |
|
145 |
/**
|
146 |
* Abre un dataset pasando como par?metros la proyecci?n y un objeto identificador del dataset. Este
|
147 |
* objeto puede ser una ruta a un fichero en disco. En este caso la extensi?n del fichero servir? para
|
148 |
* buscar el driver que lo gestiona. Si proporcionamos un array de cadenas se tratar?n como la ruta a N ficheros
|
149 |
* de disco. Tambi?n puede ser un buffer de datos en memoria o cualquier otro objeto
|
150 |
* que pueda aceptar un driver.
|
151 |
* @param proj PRoyecci?n
|
152 |
* @param datasetOpenParam Par?metros al driver
|
153 |
* @return RasterMultiDatset
|
154 |
* @throws NotSupportedExtensionException
|
155 |
* @throws RasterDriverException
|
156 |
*/
|
157 |
public static CompositeDataset open(IProjection proj, Object datasetOpenParam) throws NotSupportedExtensionException, RasterDriverException { |
158 |
if(datasetOpenParam instanceof String[][]) { |
159 |
String[][] param = (String[][])datasetOpenParam; |
160 |
MultiRasterDataset[][] mosaic = new MultiRasterDataset[param.length][param[0].length]; |
161 |
for (int i = 0; i < param.length; i++) { |
162 |
for (int j = 0; j < param[i].length; j++) |
163 |
mosaic[i][j] = MultiRasterDataset.open(proj, param[i][j]); |
164 |
} |
165 |
CompositeDataset cd; |
166 |
try {
|
167 |
cd = new CompositeDataset(mosaic);
|
168 |
} catch (MosaicNotValidException e) {
|
169 |
return null; |
170 |
} |
171 |
return cd;
|
172 |
} |
173 |
return null; |
174 |
} |
175 |
|
176 |
/**
|
177 |
* Valida que los extends del mosaico sean validos, es decir, que sean correlativos
|
178 |
* formando la matriz. Adem?s tambi?n valida que el tama?o de pixel coincida en todos los
|
179 |
* raster que forman el mosaico.
|
180 |
*
|
181 |
* @param mos
|
182 |
* @throws MosaicNotValidException
|
183 |
*/
|
184 |
public boolean validateMosaic() { |
185 |
int n = mosaic.length;
|
186 |
int m = mosaic[0].length; |
187 |
//Comprobamos en Horizontal
|
188 |
if(m > 1) { |
189 |
for (int row = 0; row < n; row++) { |
190 |
for (int col = 0; col < m; col++) { |
191 |
if(col < (m - 1) && mosaic[row][col] != null) { |
192 |
Extent a = mosaic[row][col].getExtent(); |
193 |
Extent b = mosaic[row][col + 1].getExtent();
|
194 |
if(((int)a.maxX()) != ((int)b.minX())) |
195 |
return false; |
196 |
double psx = MathUtils.clipDecimals(mosaic[row][col].getPixelSizeX(), 2); |
197 |
double psx1 = MathUtils.clipDecimals(mosaic[row][col + 1].getPixelSizeX(), 2); |
198 |
double psy = MathUtils.clipDecimals(mosaic[row][col].getPixelSizeY(), 2); |
199 |
double psy1 = MathUtils.clipDecimals(mosaic[row][col + 1].getPixelSizeY(), 2); |
200 |
if(psx != psx1 || psy != psy1)
|
201 |
return false; |
202 |
if(mosaic[row][col].getBandCount() != mosaic[row][col + 1].getBandCount()) |
203 |
return false; |
204 |
} |
205 |
} |
206 |
} |
207 |
} |
208 |
|
209 |
//Comprobamos en Vertical
|
210 |
if(n > 1) { |
211 |
for (int col = 0; col < m; col++) { |
212 |
for (int row = 0; row < n; row++) { |
213 |
if(row < (n - 1) && mosaic[row][col] != null) { |
214 |
Extent a = mosaic[row][col].getExtent(); |
215 |
Extent b = mosaic[row + 1][col].getExtent();
|
216 |
if(((int)a.minY()) != ((int)b.maxY())) |
217 |
return false; |
218 |
double psx = MathUtils.clipDecimals(mosaic[row][col].getPixelSizeX(), 2); |
219 |
double psx1 = MathUtils.clipDecimals(mosaic[row + 1][col].getPixelSizeX(), 2); |
220 |
double psy = MathUtils.clipDecimals(mosaic[row][col].getPixelSizeY(), 2); |
221 |
double psy1 = MathUtils.clipDecimals(mosaic[row + 1][col].getPixelSizeY(), 2); |
222 |
if(psx != psx1 || psy != psy1)
|
223 |
return false; |
224 |
if(mosaic[row][col].getBandCount() != mosaic[row + 1][col].getBandCount()) |
225 |
return false; |
226 |
} |
227 |
} |
228 |
} |
229 |
} |
230 |
|
231 |
return true; |
232 |
} |
233 |
|
234 |
/*
|
235 |
* (non-Javadoc)
|
236 |
* @see org.gvsig.raster.dataset.IRasterDataSource#addDataset(org.gvsig.raster.dataset.RasterDataset[])
|
237 |
*/
|
238 |
public void addDataset(RasterDataset[] f) throws FileNotFoundInListException { |
239 |
if(mosaic != null) { |
240 |
int n = mosaic.length;
|
241 |
int m = mosaic[0].length; |
242 |
if(f.length == (n * m)) {
|
243 |
for (int i = 0; i < n; i++) { |
244 |
for (int j = 0; j < m; j++) { |
245 |
MultiRasterDataset mrd = new MultiRasterDataset();
|
246 |
mrd.addDataset(new RasterDataset[]{f[i * n + j]}); |
247 |
} |
248 |
} |
249 |
} |
250 |
init(); |
251 |
} |
252 |
} |
253 |
|
254 |
/*
|
255 |
* (non-Javadoc)
|
256 |
* @see org.gvsig.raster.dataset.IRasterDataSource#addDataset(java.lang.String[])
|
257 |
*/
|
258 |
public void addDataset(String[] fileName) throws FileNotFoundInListException, NotSupportedExtensionException, RasterDriverException { |
259 |
if(mosaic != null) { |
260 |
int n = mosaic.length;
|
261 |
int m = mosaic[0].length; |
262 |
if(fileName.length == (n * m)) {
|
263 |
for (int i = 0; i < n; i++) { |
264 |
for (int j = 0; j < m; j++) { |
265 |
MultiRasterDataset mrd = new MultiRasterDataset();
|
266 |
mrd.addDataset(new RasterDataset[]{RasterDataset.open(null, fileName[i * n + j])}); |
267 |
} |
268 |
} |
269 |
} |
270 |
init(); |
271 |
} |
272 |
} |
273 |
|
274 |
/**
|
275 |
* Acciones de inicializaci?n cuando se crea el objeto o se
|
276 |
* a?aden nuevos dataset a este
|
277 |
*/
|
278 |
private void init() { |
279 |
stats = new DatasetListStatistics(mosaic);
|
280 |
|
281 |
//Creamos la lista de bandas
|
282 |
bandList = (BandList)mosaic[0][0].getBands().clone(); |
283 |
int n = mosaic.length;
|
284 |
int m = mosaic[0].length; |
285 |
for (int row = 0; row < n; row++) { |
286 |
for (int col = 0; col < m; col++) { |
287 |
if(row != 0 && col != 0) { //El primero ya est? a?adido |
288 |
for (int i = 0; i < mosaic[0][0].getBandCount(); i++) { |
289 |
if(mosaic[row][col] != null) |
290 |
bandList.getBand(i).setAdditionalName(mosaic[row][col].getBands().getBand(i).getFileName()); |
291 |
} |
292 |
} |
293 |
} |
294 |
} |
295 |
|
296 |
} |
297 |
|
298 |
/**
|
299 |
* Obtiene la lista de nombres de los dataset
|
300 |
* @return
|
301 |
*/
|
302 |
public String[][] getFileNames() { |
303 |
String[][] s = new String[mosaic.length][mosaic[0].length]; |
304 |
for (int i = 0; i < s.length; i++) { |
305 |
for (int j = 0; j < s[i].length; j++) { |
306 |
if(mosaic[i][j] != null) |
307 |
s[i][j] = mosaic[i][j].getDataset(0)[0].getFName(); |
308 |
} |
309 |
} |
310 |
return s;
|
311 |
} |
312 |
|
313 |
/*
|
314 |
* (non-Javadoc)
|
315 |
* @see org.gvsig.raster.dataset.IRasterDataSource#calcSteps(double, double, double, double, double, double, int, int)
|
316 |
*/
|
317 |
public double[] calcSteps(double dWorldTLX, double dWorldTLY, double dWorldBRX, double dWorldBRY, double nWidth, double nHeight, int bufWidth, int bufHeight) { |
318 |
if(mosaic != null) |
319 |
return mosaic[0][0].calcSteps(dWorldTLX, dWorldTLY, dWorldBRX, dWorldBRY, nWidth, nHeight, bufWidth, bufHeight); |
320 |
return null; |
321 |
} |
322 |
|
323 |
/*
|
324 |
* (non-Javadoc)
|
325 |
* @see org.gvsig.raster.dataset.IRasterDataSource#close()
|
326 |
*/
|
327 |
public void close() { |
328 |
int n = mosaic.length;
|
329 |
int m = mosaic[0].length; |
330 |
for (int row = 0; row < n; row++) { |
331 |
for (int col = 0; col < m; col++) { |
332 |
if(mosaic[row][col] != null) |
333 |
mosaic[row][col].close(); |
334 |
} |
335 |
} |
336 |
} |
337 |
|
338 |
/*
|
339 |
* (non-Javadoc)
|
340 |
* @see org.gvsig.raster.dataset.IRasterDataSource#copy()
|
341 |
*/
|
342 |
public IRasterDataSource newDataset() {
|
343 |
int n = mosaic.length;
|
344 |
int m = mosaic[0].length; |
345 |
MultiRasterDataset[][] mrd = new MultiRasterDataset[n][m]; |
346 |
for (int row = 0; row < n; row++) |
347 |
for (int col = 0; col < m; col++) |
348 |
if(mosaic[row][col] != null) |
349 |
mrd[row][col] = (MultiRasterDataset)mosaic[row][col].newDataset(); |
350 |
|
351 |
try {
|
352 |
return new CompositeDataset(mrd); |
353 |
} catch (MosaicNotValidException e) {
|
354 |
return null; |
355 |
} |
356 |
} |
357 |
|
358 |
/*
|
359 |
* (non-Javadoc)
|
360 |
* @see org.gvsig.raster.dataset.IRasterDataSource#getOwnAffineTransform()
|
361 |
*/
|
362 |
public AffineTransform getOwnAffineTransform() { |
363 |
if(mosaic != null && mosaic[0][0] != null) |
364 |
return mosaic[0][0].getOwnAffineTransform(); |
365 |
return new AffineTransform(); |
366 |
} |
367 |
|
368 |
/*
|
369 |
* (non-Javadoc)
|
370 |
* @see org.gvsig.raster.dataset.IRasterDataSource#getAffineTransform()
|
371 |
*/
|
372 |
public AffineTransform getAffineTransform() { |
373 |
if(mosaic != null && mosaic[0][0] != null) |
374 |
return mosaic[0][0].getAffineTransform(); |
375 |
return new AffineTransform(); |
376 |
} |
377 |
|
378 |
/*
|
379 |
* (non-Javadoc)
|
380 |
* @see org.gvsig.raster.dataset.IRasterDataSource#getExtent()
|
381 |
*/
|
382 |
public Extent getExtent() {
|
383 |
int n = mosaic.length;
|
384 |
int m = mosaic[0].length; |
385 |
if(mosaic != null && mosaic[0][0] != null) { |
386 |
double ulx = mosaic[0][0].getExtent().getULX(); |
387 |
double uly = mosaic[0][0].getExtent().getULY(); |
388 |
|
389 |
double urx = mosaic[n - 1][0].getExtent().getURX(); |
390 |
double ury = mosaic[n - 1][0].getExtent().getURY(); |
391 |
|
392 |
double llx = mosaic[0][m - 1].getExtent().getLLX(); |
393 |
double lly = mosaic[0][m - 1].getExtent().getLLY(); |
394 |
|
395 |
double lrx = mosaic[n - 1][m - 1].getExtent().getLRX(); |
396 |
double lry = mosaic[n - 1][m - 1].getExtent().getLRY(); |
397 |
|
398 |
return new Extent( new Point2D.Double(ulx, uly), |
399 |
new Point2D.Double(lrx, lry), |
400 |
new Point2D.Double(urx, ury), |
401 |
new Point2D.Double(llx, lly)); |
402 |
} |
403 |
return null; |
404 |
} |
405 |
|
406 |
/*
|
407 |
* (non-Javadoc)
|
408 |
* @see org.gvsig.raster.dataset.IRasterDataSource#getBandCount()
|
409 |
*/
|
410 |
public int getBandCount() { |
411 |
if(mosaic != null && mosaic[0][0] != null) |
412 |
return mosaic[0][0].getBandCount(); |
413 |
return 0; |
414 |
} |
415 |
|
416 |
/**
|
417 |
* Obtiene el ancho del mosaico completo en p?xeles, esto es la
|
418 |
* suma de todos los raster que componen la extensi?n.
|
419 |
*/
|
420 |
public double getWidth() { |
421 |
double w = 0; |
422 |
if(mosaic != null && mosaic[0][0] != null) { |
423 |
int m = mosaic[0].length; |
424 |
for (int col = 0; col < m; col++) |
425 |
w += mosaic[0][col].getWidth();
|
426 |
} |
427 |
return w;
|
428 |
} |
429 |
|
430 |
/**
|
431 |
* Obtiene el alto del mosaico completo en p?xeles, esto es la
|
432 |
* suma de todos los raster que componen la extensi?n.
|
433 |
*/
|
434 |
public double getHeight() { |
435 |
double h = 0; |
436 |
if(mosaic != null && mosaic[0][0] != null) { |
437 |
int n = mosaic.length;
|
438 |
for (int row = 0; row < n; row++) |
439 |
h += mosaic[row][0].getHeight();
|
440 |
} |
441 |
return h;
|
442 |
} |
443 |
|
444 |
/*
|
445 |
* (non-Javadoc)
|
446 |
* @see org.gvsig.raster.dataset.IRasterDataSource#getCellSize()
|
447 |
*/
|
448 |
public double getCellSize() { |
449 |
try {
|
450 |
Extent e = getExtent(); |
451 |
double dCellsize = (e.getMax().getX() - e.getMin().getX() ) / getWidth();
|
452 |
return dCellsize;
|
453 |
} catch (NullPointerException e) { |
454 |
return 1; |
455 |
} |
456 |
} |
457 |
|
458 |
/*
|
459 |
* (non-Javadoc)
|
460 |
* @see org.gvsig.raster.dataset.IRasterDataSource#getDataType()
|
461 |
*/
|
462 |
public int[] getDataType() { |
463 |
if(mosaic != null && mosaic[0][0] != null) |
464 |
return mosaic[0][0].getDataType(); |
465 |
return null; |
466 |
} |
467 |
|
468 |
/*
|
469 |
* (non-Javadoc)
|
470 |
* @see org.gvsig.raster.dataset.IRasterDataSource#getDatasetCount()
|
471 |
*/
|
472 |
public int getDatasetCount() { |
473 |
if(mosaic != null && mosaic[0][0] != null) |
474 |
return mosaic[0][0].getDatasetCount(); |
475 |
return 0; |
476 |
} |
477 |
|
478 |
/*
|
479 |
* (non-Javadoc)
|
480 |
* @see org.gvsig.raster.dataset.IRasterDataSource#getFileSize()
|
481 |
*/
|
482 |
public long getFileSize() { |
483 |
long size = 0; |
484 |
int n = mosaic.length;
|
485 |
int m = mosaic[0].length; |
486 |
for (int row = 0; row < n; row++) { |
487 |
for (int col = 0; col < m; col++) { |
488 |
if(mosaic[row][col] != null) |
489 |
size += mosaic[row][col].getFileSize(); |
490 |
} |
491 |
} |
492 |
return size;
|
493 |
} |
494 |
|
495 |
/**
|
496 |
* Obtiene el dataset cuyas coordenadas contienen el punto pasado por par?meto
|
497 |
* @param x Coordenada X a comprobar
|
498 |
* @param y Coordenada Y a comprobar
|
499 |
* @return Point2D Posici?n del MultiRasterDataset dentro del mosaico
|
500 |
*/
|
501 |
public Point2D getDatasetByCoords(double x, double y) { |
502 |
int n = mosaic.length;
|
503 |
int m = mosaic[0].length; |
504 |
for (int row = 0; row < n; row++) { |
505 |
for (int col = 0; col < m; col++) { |
506 |
if(mosaic[row][col] != null && |
507 |
RasterUtilities.isInside(new Point2D.Double(x, y), mosaic[row][col].getExtent(), mosaic[row][col].getAffineTransform())) |
508 |
return new Point2D.Double(row, col); |
509 |
} |
510 |
} |
511 |
|
512 |
return null; |
513 |
} |
514 |
|
515 |
/**
|
516 |
* Obtiene la lista de datasets del mosaico que intersectan con el extent proporcionado
|
517 |
* @param ulx Coordenada X superior izquierda
|
518 |
* @param uly Coordenada Y superior izquierda
|
519 |
* @param lrx Coordenada X inferior derecha
|
520 |
* @param lry Coordenada Y inferior derecha
|
521 |
* @return MultiRasterDataset[][][]
|
522 |
* @throws NoninvertibleTransformException
|
523 |
*/
|
524 |
private MultiRasterDataset[][] getDatasetListInArea(double ulx, double uly, double lrx, double lry) throws NoninvertibleTransformException { |
525 |
int n = mosaic.length;
|
526 |
int m = mosaic[0].length; |
527 |
|
528 |
MultiRasterDataset[][] result = new MultiRasterDataset[n][m]; |
529 |
|
530 |
for (int row = 0; row < n; row++) |
531 |
for (int col = 0; col < m; col++) |
532 |
if(mosaic[row][col] != null && |
533 |
RasterUtilities.intersects(new Extent(ulx, uly, lrx, lry), mosaic[row][col].getExtent(), mosaic[row][col].getAffineTransform())) {
|
534 |
for (int k = 0; k < mosaic.length; k++) |
535 |
result[row][col] = mosaic[row][col]; |
536 |
} |
537 |
return result;
|
538 |
} |
539 |
|
540 |
/*
|
541 |
* (non-Javadoc)
|
542 |
* @see org.gvsig.raster.dataset.IRasterDataSource#isInside(java.awt.geom.Point2D)
|
543 |
*/
|
544 |
public boolean isInside(Point2D p) { |
545 |
return RasterUtilities.isInside(p, getExtent(), getAffineTransform());
|
546 |
} |
547 |
|
548 |
/*
|
549 |
* (non-Javadoc)
|
550 |
* @see org.gvsig.raster.dataset.IRasterDataSource#rasterToWorld(java.awt.geom.Point2D)
|
551 |
*/
|
552 |
public Point2D rasterToWorld(Point2D pt) { |
553 |
Point2D p = new Point2D.Double(); |
554 |
getAffineTransform().transform(pt, p); |
555 |
return p;
|
556 |
} |
557 |
|
558 |
/*
|
559 |
* (non-Javadoc)
|
560 |
* @see org.gvsig.raster.dataset.IRasterDataSource#worldToRaster(java.awt.geom.Point2D)
|
561 |
*/
|
562 |
public Point2D worldToRaster(Point2D pt) { |
563 |
Point2D p = new Point2D.Double(); |
564 |
try {
|
565 |
getAffineTransform().inverseTransform(pt, p); |
566 |
} catch (NoninvertibleTransformException e) { |
567 |
return pt;
|
568 |
} |
569 |
return p;
|
570 |
} |
571 |
|
572 |
/*
|
573 |
* (non-Javadoc)
|
574 |
* @see org.gvsig.raster.dataset.IRasterDataSource#isRotated()
|
575 |
*/
|
576 |
public boolean isRotated() { |
577 |
if(getAffineTransform().getShearX() != 0 || getAffineTransform().getShearY() != 0) |
578 |
return true; |
579 |
return false; |
580 |
} |
581 |
|
582 |
/*
|
583 |
* (non-Javadoc)
|
584 |
* @see org.gvsig.raster.dataset.IRasterDataSource#isGeoreferenced()
|
585 |
*/
|
586 |
public boolean isGeoreferenced() { |
587 |
//Este tipo de datasets siempre est? georreferenciado
|
588 |
return true; |
589 |
} |
590 |
|
591 |
/*
|
592 |
* (non-Javadoc)
|
593 |
* @see org.gvsig.raster.dataset.IRasterDataSource#getDataset(int)
|
594 |
*/
|
595 |
public RasterDataset[] getDataset(int i) { |
596 |
RasterDataset[] d = new RasterDataset[mosaic.length * mosaic[0].length]; |
597 |
int count = 0; |
598 |
for (int row = 0; row < mosaic.length; row++) { |
599 |
for (int col = 0; col < mosaic[row].length; col++) { |
600 |
if(mosaic[row][col] != null) |
601 |
d[count] = mosaic[row][col].getDataset(i)[0];
|
602 |
} |
603 |
} |
604 |
return d;
|
605 |
} |
606 |
|
607 |
/*
|
608 |
* (non-Javadoc)
|
609 |
* @see org.gvsig.raster.dataset.IRasterDataSource#getStatistics()
|
610 |
*/
|
611 |
public DatasetListStatistics getStatistics() {
|
612 |
return stats;
|
613 |
} |
614 |
|
615 |
/*
|
616 |
* (non-Javadoc)
|
617 |
* @see org.gvsig.raster.dataset.IRasterDataSource#getBands()
|
618 |
*/
|
619 |
public BandList getBands() {
|
620 |
return bandList;
|
621 |
} |
622 |
|
623 |
/**
|
624 |
* Genera un buffer de datos ?nico a partir de una matriz de buffers donde puede haber
|
625 |
* elementos con valor nulo.
|
626 |
* @return
|
627 |
*/
|
628 |
public IBuffer generateBuffer(IBuffer[][] bufList, int drawableBands) { |
629 |
int n = mosaic.length;
|
630 |
int m = mosaic[0].length; |
631 |
int nCols = 0, nRows = 0; |
632 |
//Contamos el n?mero de filas y columnas del buffer nuevo
|
633 |
for (int row = 0; row < n; row++) { |
634 |
for (int col = 0; col < m; col++) { |
635 |
if(bufList[row][col] != null) |
636 |
nCols += bufList[row][col].getWidth(); |
637 |
|
638 |
} |
639 |
if(nCols != 0) break; |
640 |
} |
641 |
for (int col = 0; col < m; col++) { |
642 |
for (int row = 0; row < n; row++) { |
643 |
if(bufList[row][col] != null) |
644 |
nRows += bufList[row][col].getHeight(); |
645 |
} |
646 |
if(nRows != 0) break; |
647 |
} |
648 |
|
649 |
//Creamos el buffer
|
650 |
IBuffer raster = RasterBuffer.getBuffer(bufList[0][0].getDataType(), nCols, nRows, drawableBands, true); |
651 |
|
652 |
//Hacemos la copia
|
653 |
int[] pos = new int[2]; |
654 |
int validCol = 0; |
655 |
for (int row = 0; row < n; row++) { |
656 |
for (int col = 0; col < m; col++) { |
657 |
pos[1] = (col == 0) ? 0 : pos[1]; |
658 |
if(bufList[row][col] == null) |
659 |
continue;
|
660 |
validCol = col; |
661 |
copyTile(bufList[row][col], raster, pos[0], pos[1]); |
662 |
pos[1] += bufList[row][col].getWidth();
|
663 |
} |
664 |
if(bufList[row][validCol] != null) |
665 |
pos[0] += bufList[row][validCol].getHeight();
|
666 |
} |
667 |
return raster;
|
668 |
} |
669 |
|
670 |
/**
|
671 |
* Copia un tile en el buffer que contendr? todos los tiles
|
672 |
* @param origin Buffer de origen
|
673 |
* @param dest Buffer de destino
|
674 |
* @param col Columna del buffer de destino donde se empieza a escribir
|
675 |
* @param row Fila del buffer de destino donde se empieza a escribir
|
676 |
* @return array con los valores que representan la ?ltima fila y
|
677 |
* ?ltima columna que se escribieron
|
678 |
*/
|
679 |
private void copyTile(IBuffer origin, IBuffer dest, int r, int c) { |
680 |
switch(origin.getDataType()) {
|
681 |
case IBuffer.TYPE_BYTE :
|
682 |
for (int band = 0; band < origin.getBandCount(); band++) |
683 |
for (int row = 0; row < origin.getHeight(); row++) |
684 |
for (int col = 0; col < origin.getWidth(); col++) |
685 |
try {
|
686 |
dest.setElem(row + r, col + c, band, origin.getElemByte(row, col, band)); |
687 |
} catch (ArrayIndexOutOfBoundsException e) {break;} |
688 |
break;
|
689 |
case IBuffer.TYPE_SHORT :
|
690 |
for (int band = 0; band < origin.getBandCount(); band++) |
691 |
for (int row = 0; row < origin.getHeight(); row++) |
692 |
for (int col = 0; col < origin.getWidth(); col++) |
693 |
try {
|
694 |
dest.setElem(row + r, col + c, band, origin.getElemShort(row, col, band)); |
695 |
} catch (ArrayIndexOutOfBoundsException e) {break;} |
696 |
break;
|
697 |
case IBuffer.TYPE_FLOAT :
|
698 |
for (int band = 0; band < origin.getBandCount(); band++) |
699 |
for (int row = 0; row < origin.getHeight(); row++) |
700 |
for (int col = 0; col < origin.getWidth(); col++) |
701 |
try {
|
702 |
dest.setElem(row + r, col + c, band, origin.getElemFloat(row, col, band)); |
703 |
} catch (ArrayIndexOutOfBoundsException e) {break;} |
704 |
break;
|
705 |
case IBuffer.TYPE_DOUBLE:
|
706 |
for (int band = 0; band < origin.getBandCount(); band++) |
707 |
for (int row = 0; row < origin.getHeight(); row++) |
708 |
for (int col = 0; col < origin.getWidth(); col++) |
709 |
try {
|
710 |
dest.setElem(row + r, col + c, band, origin.getElemDouble(row, col, band)); |
711 |
} catch (ArrayIndexOutOfBoundsException e) {break;} |
712 |
break;
|
713 |
} |
714 |
} |
715 |
|
716 |
/*
|
717 |
* (non-Javadoc)
|
718 |
* @see org.gvsig.raster.dataset.IRasterDataSource#getWindowRaster(double, double, double, double)
|
719 |
*/
|
720 |
public IBuffer getWindowRaster(double ulx, double uly, double lrx, double lry) |
721 |
throws InvalidSetViewException, InterruptedException, RasterDriverException { |
722 |
try {
|
723 |
MultiRasterDataset[][] datasetList = getDatasetListInArea(ulx, uly, lrx, lry); |
724 |
int n = mosaic.length;
|
725 |
int m = mosaic[0].length; |
726 |
IBuffer[][] bufferList = new IBuffer[n][m]; |
727 |
for (int row = 0; row < n; row++) |
728 |
for (int col = 0; col < m; col++) |
729 |
if(datasetList[row][col] != null) |
730 |
bufferList[row][col] = datasetList[row][col].getWindowRaster(ulx, uly, lrx, lry); |
731 |
return generateBuffer(bufferList, mosaic[0][0].getBands().getDrawableBandsCount()); |
732 |
} catch (NoninvertibleTransformException e) { |
733 |
throw new InvalidSetViewException("No se ha podido aplicar la transformaci?n inversa para esa vista."); |
734 |
} |
735 |
} |
736 |
|
737 |
public IBuffer getWindowRaster(double ulx, double uly, double w, double h, boolean adjustToExtent) |
738 |
throws InvalidSetViewException, RasterDriverException {
|
739 |
//TODO: FUNCIONALIDAD: getWindowRaster en CompositeDataset sin implementar
|
740 |
return null; |
741 |
} |
742 |
|
743 |
public IBuffer getWindowRaster(double ulx, double uly, double lrx, double lry, int bufWidth, int bufHeight, boolean adjustToExtent) |
744 |
throws InvalidSetViewException, InterruptedException, RasterDriverException { |
745 |
try {
|
746 |
Point2D p1 = new Point2D.Double(ulx, uly); |
747 |
Point2D p2 = new Point2D.Double(lrx, lry); |
748 |
MultiRasterDataset[][] datasetList = getDatasetListInArea(p1.getX(), p1.getY(), p2.getX(), p2.getY()); |
749 |
Point2D px1 = mosaic[0][0].worldToRaster(p1); |
750 |
Point2D px2 = mosaic[0][0].worldToRaster(p2); |
751 |
int n = mosaic.length;
|
752 |
int m = mosaic[0].length; |
753 |
IBuffer[][] bufferList = new IBuffer[n][m]; |
754 |
for (int row = 0; row < n; row++) |
755 |
for (int col = 0; col < m; col++) |
756 |
if(datasetList[row][col] != null) { |
757 |
int[] values = getLocalRequest((int)px1.getX(), (int)px1.getY(), (int)Math.abs(px2.getX() - px1.getX()), (int)Math.abs(px2.getY() - px1.getY()), row, col); |
758 |
if(values != null) { |
759 |
int bW = (int)Math.round((Math.abs(values[2] - values[0]) * bufWidth) / Math.abs(px2.getX() - px1.getX())); |
760 |
int bH = (int)Math.round((Math.abs(values[3] - values[1]) * bufHeight) / Math.abs(px2.getY() - px1.getY())); |
761 |
int wTile = ((int)Math.abs(values[2] - values[0]) > (int)datasetList[row][col].getWidth()) ? (int)datasetList[row][col].getWidth() : (int)Math.abs(values[2] - values[0]); |
762 |
int hTile = ((int)Math.abs(values[3] - values[1]) > (int)datasetList[row][col].getHeight()) ? (int)datasetList[row][col].getHeight() : (int)Math.abs(values[3] - values[1]); |
763 |
bufferList[row][col] = datasetList[row][col].getWindowRaster(values[0], values[1], wTile, hTile, bW, bH); |
764 |
} |
765 |
} |
766 |
return generateBuffer(bufferList, mosaic[0][0].getBands().getDrawableBandsCount()); |
767 |
} catch (NoninvertibleTransformException e) { |
768 |
throw new InvalidSetViewException("No se ha podido aplicar la transformaci?n inversa para esa vista."); |
769 |
} |
770 |
} |
771 |
|
772 |
/*
|
773 |
* (non-Javadoc)
|
774 |
* @see org.gvsig.raster.dataset.IRasterDataSource#getWindowRaster(int, int, int, int)
|
775 |
*/
|
776 |
public IBuffer getWindowRaster(int x, int y, int w, int h) |
777 |
throws InvalidSetViewException, InterruptedException, RasterDriverException { |
778 |
try {
|
779 |
Point2D p1 = mosaic[0][0].rasterToWorld(new Point2D.Double(x, y)); |
780 |
Point2D p2 = mosaic[0][0].rasterToWorld(new Point2D.Double(x + w, y + h)); |
781 |
MultiRasterDataset[][] datasetList = getDatasetListInArea(p1.getX(), p1.getY(), p2.getX(), p2.getY()); |
782 |
int n = mosaic.length;
|
783 |
int m = mosaic[0].length; |
784 |
IBuffer[][] bufferList = new IBuffer[n][m]; |
785 |
for (int row = 0; row < n; row++) |
786 |
for (int col = 0; col < m; col++) |
787 |
if(datasetList[row][col] != null) { |
788 |
int[] values = getLocalRequest(x, y, w, h, row, col); |
789 |
int wTile = ((int)Math.abs(values[2] - values[0]) > (int)datasetList[row][col].getWidth()) ? (int)datasetList[row][col].getWidth() : (int)Math.abs(values[2] - values[0]); |
790 |
int hTile = ((int)Math.abs(values[3] - values[1]) > (int)datasetList[row][col].getHeight()) ? (int)datasetList[row][col].getHeight() : (int)Math.abs(values[3] - values[1]); |
791 |
if(values != null) |
792 |
bufferList[row][col] = datasetList[row][col].getWindowRaster(values[0], values[1], wTile, hTile); |
793 |
} |
794 |
return generateBuffer(bufferList, mosaic[0][0].getBands().getDrawableBandsCount()); |
795 |
} catch (NoninvertibleTransformException e) { |
796 |
throw new InvalidSetViewException("No se ha podido aplicar la transformaci?n inversa para esa vista."); |
797 |
} |
798 |
} |
799 |
|
800 |
/*
|
801 |
* (non-Javadoc)
|
802 |
* @see org.gvsig.raster.dataset.IRasterDataSource#getWindowRaster(int, int, int, int, int, int)
|
803 |
*/
|
804 |
public IBuffer getWindowRaster(int x, int y, int w, int h, int bufWidth, int bufHeight) |
805 |
throws InvalidSetViewException, InterruptedException, RasterDriverException { |
806 |
try {
|
807 |
Point2D p1 = mosaic[0][0].rasterToWorld(new Point2D.Double(x, y)); |
808 |
Point2D p2 = mosaic[0][0].rasterToWorld(new Point2D.Double(x + w, y + h)); |
809 |
MultiRasterDataset[][] datasetList = getDatasetListInArea(p1.getX(), p1.getY(), p2.getX(), p2.getY()); |
810 |
int n = mosaic.length;
|
811 |
int m = mosaic[0].length; |
812 |
IBuffer[][] bufferList = new IBuffer[n][m]; |
813 |
for (int row = 0; row < n; row++) { |
814 |
for (int col = 0; col < m; col++) { |
815 |
if(datasetList[row][col] != null) { |
816 |
int[] values = getLocalRequest(x, y, w, h, row, col); |
817 |
if(values != null) { |
818 |
int bW = Math.round((Math.abs(values[2] - values[0]) * bufWidth) / w); |
819 |
int bH = Math.round((Math.abs(values[3] - values[1]) * bufHeight) / h); |
820 |
int wTile = ((int)Math.abs(values[2] - values[0]) > (int)datasetList[row][col].getWidth()) ? (int)datasetList[row][col].getWidth() : (int)Math.abs(values[2] - values[0]); |
821 |
int hTile = ((int)Math.abs(values[3] - values[1]) > (int)datasetList[row][col].getHeight()) ? (int)datasetList[row][col].getHeight() : (int)Math.abs(values[3] - values[1]); |
822 |
bufferList[row][col] = datasetList[row][col].getWindowRaster(values[0], values[1], wTile, hTile, bW, bH); |
823 |
} |
824 |
} |
825 |
} |
826 |
} |
827 |
return generateBuffer(bufferList, mosaic[0][0].getBands().getDrawableBandsCount()); |
828 |
} catch (NoninvertibleTransformException e) { |
829 |
throw new InvalidSetViewException("No se ha podido aplicar la transformaci?n inversa para esa vista."); |
830 |
} |
831 |
} |
832 |
|
833 |
/**
|
834 |
* Convierte una petici?n global del mosaico en coordenadas pixel a una local al tile
|
835 |
* concreto que se est? tratando
|
836 |
* @param x Posici?n X de la petici?n a comprobar
|
837 |
* @param y Posici?n Y de la petici?n a comprobar
|
838 |
* @param w Ancho de la petici?n a comprobar
|
839 |
* @param h Alto de la petici?n a comprobar
|
840 |
* @param r File del tile
|
841 |
* @param c Columna del tile
|
842 |
* @return cuatro valores correspondientes a la x1, y1, x2, y2 de la petici?n referente al tile.
|
843 |
*/
|
844 |
private int[] getLocalRequest(int x, int y, int w, int h, int r, int c) { |
845 |
Point2D p1 = null, p2 = null; |
846 |
|
847 |
if(!requestGoThroughTile(x, y, w, h, r, c))
|
848 |
return null; |
849 |
|
850 |
if(isInside(x, y, r, c))
|
851 |
p1 = getLocalPixel(x, y); |
852 |
else {
|
853 |
if(getTileFromPixelPoint(x, y)[0] == r) //Est? en la misma fila |
854 |
p1 = new Point2D.Double(0, getLocalPixel(x, y).getY()); |
855 |
else if(getTileFromPixelPoint(x, y)[1] == c) //Est? en la misma columna |
856 |
p1 = new Point2D.Double(getLocalPixel(x, y).getX(), 0); |
857 |
else
|
858 |
p1 = new Point2D.Double(0, 0); |
859 |
} |
860 |
int fx = x + w;
|
861 |
int fy = y + h;
|
862 |
if(isInside(fx, fy, r, c))
|
863 |
p2 = getLocalPixel(fx, fy); |
864 |
else {
|
865 |
if(getTileFromPixelPoint(fx, fy)[0] == r) |
866 |
p2 = new Point2D.Double(mosaic[r][c].getWidth(), getLocalPixel(fx, fy).getY()); |
867 |
else if(getTileFromPixelPoint(fx, fy)[1] == c) |
868 |
p2 = new Point2D.Double(getLocalPixel(fx, fy).getX(), mosaic[r][c].getHeight()); |
869 |
else
|
870 |
p2 = new Point2D.Double(mosaic[r][c].getWidth(), mosaic[r][c].getHeight()); |
871 |
} |
872 |
if(p1 != null && p2 != null) |
873 |
return new int[]{(int)p1.getX(), (int)p1.getY(), (int)p2.getX(), (int)p2.getY()}; |
874 |
return null; |
875 |
} |
876 |
|
877 |
/**
|
878 |
* Consulta si una petici?n en coordenadas pixel de la imagen completa pasa a trav?s de un
|
879 |
* tile de posici?n r, c
|
880 |
* @param x Posici?n X de la petici?n a comprobar
|
881 |
* @param y Posici?n Y de la petici?n a comprobar
|
882 |
* @param w Ancho de la petici?n a comprobar
|
883 |
* @param h Alto de la petici?n a comprobar
|
884 |
* @param r File del tile
|
885 |
* @param c Columna del tile
|
886 |
* @return true si la petici?n pasa a trav?s del tile y false si no pasa.
|
887 |
*/
|
888 |
private boolean requestGoThroughTile(int x, int y, int w, int h, int r, int c) { |
889 |
if(isInside(x, y, r, c) || isInside(w, h, r, c))
|
890 |
return true; |
891 |
Point2D p1 = getGlobalPixel(x, y, r, c);
|
892 |
Point2D p2 = getGlobalPixel(w, h, r, c);
|
893 |
|
894 |
//Intersecci?n entre el ?rea pedida y el tile. Si intersectan se devuelve true
|
895 |
if(((x <= p1.getX() && w >= p1.getX()) || (x <= p2.getX() && w >= p2.getX())) &&
|
896 |
((y <= p1.getY() && h >= p1.getY()) || (y <= p2.getY() && h >= p2.getY()))) |
897 |
return true; |
898 |
return false; |
899 |
} |
900 |
|
901 |
/**
|
902 |
* Obtiene el tile correspondiente a un pixel dado
|
903 |
* @param x Posici?n X del punto a comprobar
|
904 |
* @param y Posici?n Y del punto a comprobar
|
905 |
* @return Posici?n en fila-columna
|
906 |
*/
|
907 |
public int[] getTileFromPixelPoint(int x, int y) { |
908 |
int n = mosaic.length;
|
909 |
int m = mosaic[0].length; |
910 |
for (int row = 0; row < n; row++) |
911 |
for (int col = 0; col < m; col++) |
912 |
if(isInside(x, y, row, col))
|
913 |
return new int[]{row, col}; |
914 |
return null; |
915 |
} |
916 |
|
917 |
/**
|
918 |
* Comprueba si un punto (x, y) cae dentro de un Tile (r, c)
|
919 |
* @param x Posici?n X del punto a comprobar
|
920 |
* @param y Posici?n Y del punto a comprobar
|
921 |
* @param r Fila del tile a comprobar
|
922 |
* @param c Columna del tile a comprobar
|
923 |
* @return true si el punto cae dentro del tile y false si no cae
|
924 |
*/
|
925 |
private boolean isInside(int x, int y, int r, int c) { |
926 |
int posR = -1, posC = -1; |
927 |
int sum = 0; |
928 |
for (int row = 0; row < mosaic.length; row++) { |
929 |
sum += mosaic[row][0].getHeight();
|
930 |
if(sum >= y) {
|
931 |
posR = row; |
932 |
break;
|
933 |
} |
934 |
} |
935 |
sum = 0;
|
936 |
for (int col = 0; col < mosaic[0].length; col++) { |
937 |
sum += mosaic[0][col].getWidth();
|
938 |
if(sum >= x) {
|
939 |
posC = col; |
940 |
break;
|
941 |
} |
942 |
} |
943 |
return (posR == r && posC == c) ? true : false; |
944 |
} |
945 |
|
946 |
|
947 |
/**
|
948 |
* Obtiene la coordenada pixel local para un raster dada la coordenada pixel global
|
949 |
* @param x Coordenada X global
|
950 |
* @param y Coordenada Y global
|
951 |
* @return Coordenada local
|
952 |
*/
|
953 |
private Point2D getLocalPixel(int x, int y) { |
954 |
int w = 0, h = 0; |
955 |
int sum = 0; |
956 |
for (int row = 0; row < mosaic.length; row++) { |
957 |
sum += mosaic[row][0].getHeight();
|
958 |
if(sum >= y) {
|
959 |
h = y - ((int)(sum - mosaic[row][0].getHeight())); |
960 |
break;
|
961 |
} |
962 |
} |
963 |
sum = 0;
|
964 |
for (int col = 0; col < mosaic[0].length; col++) { |
965 |
sum += mosaic[0][col].getWidth();
|
966 |
if(sum >= x) {
|
967 |
w = x - ((int)(sum - mosaic[0][col].getWidth())); |
968 |
break;
|
969 |
} |
970 |
} |
971 |
return new Point2D.Double(w, h); |
972 |
} |
973 |
|
974 |
/**
|
975 |
* Obtiene la coordenada pixel global para un raster dada la coordenada pixel local
|
976 |
* @param x Coordenada X local
|
977 |
* @param y Coordenada Y local
|
978 |
* @param r Fila del tile
|
979 |
* @param c Columna del tile
|
980 |
* @return Coordenada global
|
981 |
*/
|
982 |
private Point2D getGlobalPixel(int x, int y, int r, int c) { |
983 |
int sumX = 0, sumY = 0; |
984 |
for (int row = 0; row < (r - 1); row++) |
985 |
sumY += mosaic[row][0].getHeight();
|
986 |
sumY += y; |
987 |
for (int col = 0; col < (c - 1); col++) |
988 |
sumX += mosaic[0][col].getWidth();
|
989 |
sumX += x; |
990 |
return new Point2D.Double(sumX, sumY); |
991 |
} |
992 |
|
993 |
/*
|
994 |
* (non-Javadoc)
|
995 |
* @see org.gvsig.raster.dataset.IRasterDataSource#setDrawableBands(int[])
|
996 |
*/
|
997 |
public void setDrawableBands(int[] db) { |
998 |
int n = mosaic.length;
|
999 |
int m = mosaic[0].length; |
1000 |
for (int row = 0; row < n; row++) |
1001 |
for (int col = 0; col < m; col++) |
1002 |
mosaic[row][col].setDrawableBands(db); |
1003 |
} |
1004 |
|
1005 |
/*
|
1006 |
* (non-Javadoc)
|
1007 |
* @see org.gvsig.raster.dataset.IRasterDataSource#clearDrawableBands()
|
1008 |
*/
|
1009 |
public void clearDrawableBands() { |
1010 |
int n = mosaic.length;
|
1011 |
int m = mosaic[0].length; |
1012 |
for (int row = 0; row < n; row++) |
1013 |
for (int col = 0; col < m; col++) |
1014 |
mosaic[row][col].clearDrawableBands(); |
1015 |
} |
1016 |
|
1017 |
/*
|
1018 |
* (non-Javadoc)
|
1019 |
* @see org.gvsig.raster.dataset.IRasterDataSource#addDrawableBand(int, int)
|
1020 |
*/
|
1021 |
public void addDrawableBand(int posRasterBuf, int imageBand){ |
1022 |
int n = mosaic.length;
|
1023 |
int m = mosaic[0].length; |
1024 |
for (int row = 0; row < n; row++) |
1025 |
for (int col = 0; col < m; col++) |
1026 |
mosaic[row][col].addDrawableBand(posRasterBuf, imageBand); |
1027 |
} |
1028 |
|
1029 |
/*
|
1030 |
* (non-Javadoc)
|
1031 |
* @see org.gvsig.raster.dataset.IRasterDataSource#getTransparencyFilesStatus()
|
1032 |
*/
|
1033 |
public Transparency getTransparencyFilesStatus() { |
1034 |
if(mosaic != null && mosaic[0][0] != null) |
1035 |
return mosaic[0][0].getTransparencyFilesStatus(); |
1036 |
return new Transparency(); |
1037 |
} |
1038 |
|
1039 |
/*
|
1040 |
* (non-Javadoc)
|
1041 |
* @see org.gvsig.raster.dataset.IRasterDataSource#getColorTables()
|
1042 |
*/
|
1043 |
public ColorTable[] getColorTables() { |
1044 |
if(mosaic != null && mosaic[0][0] != null) |
1045 |
return mosaic[0][0].getColorTables(); |
1046 |
return null; |
1047 |
} |
1048 |
|
1049 |
/*
|
1050 |
* (non-Javadoc)
|
1051 |
* @see org.gvsig.raster.hierarchy.IHistogramable#getHistogram()
|
1052 |
*/
|
1053 |
public Histogram getHistogram() throws InterruptedException, HistogramException { |
1054 |
Histogram[][] histogram = new Histogram[mosaic.length][mosaic[0].length]; |
1055 |
|
1056 |
try {
|
1057 |
for (int i = 0; i < histogram.length; i++) { |
1058 |
for (int j = 0; j < histogram[i].length; j++) { |
1059 |
histogram[i][j] = new DatasetListHistogram(mosaic[i][j]).getHistogram();
|
1060 |
if(i != 0 || j != 0) |
1061 |
histogram[0][0].union(histogram[i][j]); |
1062 |
} |
1063 |
} |
1064 |
return histogram[0][0]; |
1065 |
} catch (FileNotOpenException e) {
|
1066 |
throw new HistogramException("FileNotOpenException"); |
1067 |
} catch (RasterDriverException e) {
|
1068 |
throw new HistogramException("RasterDriverException"); |
1069 |
} |
1070 |
} |
1071 |
|
1072 |
/**
|
1073 |
* Obtiene la paleta correspondiente a uno de los ficheros que forman el GeoMultiRasterFile
|
1074 |
* @param i Posici?n del raster
|
1075 |
* @return Paleta asociada a este o null si no tiene
|
1076 |
*/
|
1077 |
public ColorTable getColorTable(int i){ |
1078 |
return (mosaic != null) ? mosaic[0][0].getColorTable(i) : null; |
1079 |
} |
1080 |
|
1081 |
/**
|
1082 |
* Obtiene la paleta correspondiente al nombre del fichero pasado por par?metro.
|
1083 |
* @param fileName Nombre del fichero
|
1084 |
* @return Paleta o null si no la tiene
|
1085 |
*/
|
1086 |
public ColorTable getColorTable(String fileName){ |
1087 |
return (mosaic != null) ? mosaic[0][0].getColorTable(fileName) : null; |
1088 |
} |
1089 |
|
1090 |
public DatasetColorInterpretation getColorInterpretation(int dataset) { |
1091 |
return null; |
1092 |
} |
1093 |
|
1094 |
/*
|
1095 |
* (non-Javadoc)
|
1096 |
* @see org.gvsig.raster.dataset.IRasterDataSource#getData(int, int, int)
|
1097 |
*/
|
1098 |
public Object getData(int x, int y, int band) throws InvalidSetViewException, FileNotOpenException, RasterDriverException { |
1099 |
int[] posTile = getTileFromPixelPoint(x, y); |
1100 |
if(posTile != null) { |
1101 |
RasterDataset dataset = mosaic[posTile[0]][posTile[1]].getDataset(0)[0]; |
1102 |
Point2D localPixel = getLocalPixel(x, y);
|
1103 |
return dataset.getData((int)localPixel.getX(), (int)localPixel.getY(), band); |
1104 |
} |
1105 |
return null; |
1106 |
} |
1107 |
|
1108 |
/*
|
1109 |
* (non-Javadoc)
|
1110 |
* @see org.gvsig.raster.dataset.IRasterDataSource#isReadOnly()
|
1111 |
*/
|
1112 |
public boolean isReadOnly() { |
1113 |
return readOnly;
|
1114 |
} |
1115 |
|
1116 |
/*
|
1117 |
* (non-Javadoc)
|
1118 |
* @see org.gvsig.raster.dataset.IRasterDataSource#setReadOnly(boolean)
|
1119 |
*/
|
1120 |
public void setReadOnly(boolean readOnly) { |
1121 |
this.readOnly = readOnly;
|
1122 |
} |
1123 |
|
1124 |
/*
|
1125 |
* (non-Javadoc)
|
1126 |
* @see org.gvsig.raster.dataset.IRasterDataSource#isMemoryBuffer()
|
1127 |
*/
|
1128 |
public boolean isMemoryBuffer() { |
1129 |
return forceToMemory;
|
1130 |
} |
1131 |
|
1132 |
/*
|
1133 |
* (non-Javadoc)
|
1134 |
* @see org.gvsig.raster.dataset.IRasterDataSource#setMemoryBuffer(boolean)
|
1135 |
*/
|
1136 |
public void setMemoryBuffer(boolean memory) { |
1137 |
this.forceToMemory = memory;
|
1138 |
if(memory)
|
1139 |
this.readOnly = false; |
1140 |
} |
1141 |
|
1142 |
public RasterDataset getDataset(String fileName) { |
1143 |
return null; |
1144 |
} |
1145 |
|
1146 |
public Extent getLastSelectedView() {
|
1147 |
return null; |
1148 |
} |
1149 |
|
1150 |
public String[] getNameDatasetStringList(int i, int j) { |
1151 |
return null; |
1152 |
} |
1153 |
|
1154 |
public String getWktProjection() throws RasterDriverException { |
1155 |
return null; |
1156 |
} |
1157 |
|
1158 |
public void removeDataset(String fileName) { |
1159 |
return;
|
1160 |
} |
1161 |
|
1162 |
public void removeDataset(RasterDataset file) { |
1163 |
return;
|
1164 |
} |
1165 |
|
1166 |
public void saveGeoToRmf() throws IOException { |
1167 |
return;
|
1168 |
} |
1169 |
|
1170 |
public void saveRmfModification() throws IOException { |
1171 |
return;
|
1172 |
} |
1173 |
|
1174 |
public void setAffineTransform(AffineTransform transf) { |
1175 |
return;
|
1176 |
} |
1177 |
|
1178 |
public int getPercent() { |
1179 |
return 0; |
1180 |
} |
1181 |
|
1182 |
public void resetPercent() { |
1183 |
return;
|
1184 |
} |
1185 |
|
1186 |
/*
|
1187 |
* (non-Javadoc)
|
1188 |
* @see org.gvsig.raster.dataset.RasterDataset#getOverviewCount(int)
|
1189 |
*/
|
1190 |
public int getOverviewCount(int band) throws BandAccessException, RasterDriverException { |
1191 |
if(band >= getBandCount())
|
1192 |
throw new BandAccessException("Wrong band"); |
1193 |
return 0; |
1194 |
} |
1195 |
|
1196 |
/*
|
1197 |
* (non-Javadoc)
|
1198 |
* @see org.gvsig.raster.dataset.IRasterDataSource#overviewsSupport()
|
1199 |
*/
|
1200 |
public boolean overviewsSupport() { |
1201 |
return false; |
1202 |
} |
1203 |
|
1204 |
/*
|
1205 |
* (non-Javadoc)
|
1206 |
* @see org.gvsig.raster.dataset.IRasterDataSource#loadGeoPointsFromRmf()
|
1207 |
*/
|
1208 |
public GeoPoint[] loadGeoPointsFromRmf() throws IOException { |
1209 |
throw new IOException("Not implemented yet"); |
1210 |
} |
1211 |
|
1212 |
/*
|
1213 |
* (non-Javadoc)
|
1214 |
* @see org.gvsig.raster.dataset.IRasterDataSource#saveGeoPointsToRmf(org.gvsig.raster.datastruct.GeoPoint[])
|
1215 |
*/
|
1216 |
public void saveGeoPointsToRmf(GeoPoint[] geoPoints) throws IOException { |
1217 |
throw new IOException("Not implemented yet"); |
1218 |
} |
1219 |
|
1220 |
/*
|
1221 |
* (non-Javadoc)
|
1222 |
* @see org.gvsig.raster.dataset.IRasterDataSource#getNoDataValue()
|
1223 |
*/
|
1224 |
public double getNoDataValue() { |
1225 |
int n = mosaic.length;
|
1226 |
int m = mosaic[0].length; |
1227 |
if ((n == 0) || (m == 0)) |
1228 |
return RasterLibrary.defaultNoDataValue;
|
1229 |
return mosaic[0][0].getNoDataValue(); |
1230 |
} |
1231 |
|
1232 |
/*
|
1233 |
* (non-Javadoc)
|
1234 |
* @see org.gvsig.raster.dataset.IRasterDataSource#resetNoDataValue()
|
1235 |
*/
|
1236 |
public void resetNoDataValue() { |
1237 |
int n = mosaic.length;
|
1238 |
int m = mosaic[0].length; |
1239 |
for (int row = 0; row < n; row++) |
1240 |
for (int col = 0; col < m; col++) |
1241 |
mosaic[row][col].resetNoDataValue(); |
1242 |
} |
1243 |
|
1244 |
/*
|
1245 |
* (non-Javadoc)
|
1246 |
* @see org.gvsig.raster.dataset.IRasterDataSource#setNoDataValue(double)
|
1247 |
*/
|
1248 |
public void setNoDataValue(double value) { |
1249 |
int n = mosaic.length;
|
1250 |
int m = mosaic[0].length; |
1251 |
for (int row = 0; row < n; row++) |
1252 |
for (int col = 0; col < m; col++) |
1253 |
mosaic[row][col].setNoDataValue(value); |
1254 |
} |
1255 |
|
1256 |
/*
|
1257 |
* (non-Javadoc)
|
1258 |
* @see org.gvsig.raster.dataset.IRasterDataSource#isNoDataEnabled()
|
1259 |
*/
|
1260 |
public boolean isNoDataEnabled() { |
1261 |
int n = mosaic.length;
|
1262 |
int m = mosaic[0].length; |
1263 |
if ((n == 0) || (m == 0)) |
1264 |
return false; |
1265 |
return mosaic[0][0].isNoDataEnabled(); |
1266 |
} |
1267 |
|
1268 |
/*
|
1269 |
* (non-Javadoc)
|
1270 |
* @see org.gvsig.raster.dataset.IRasterDataSource#setNoDataEnabled(boolean)
|
1271 |
*/
|
1272 |
public void setNoDataEnabled(boolean enabled) { |
1273 |
int n = mosaic.length;
|
1274 |
int m = mosaic[0].length; |
1275 |
for (int row = 0; row < n; row++) |
1276 |
for (int col = 0; col < m; col++) |
1277 |
mosaic[row][col].setNoDataEnabled(enabled); |
1278 |
} |
1279 |
} |