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