Revision 12749 trunk/libraries/libRaster/src/org/gvsig/raster/dataset/MultiRasterDataset.java
MultiRasterDataset.java | ||
---|---|---|
331 | 331 |
} |
332 | 332 |
} |
333 | 333 |
} |
334 |
|
|
335 |
/** |
|
336 |
* Obtiene una ventana de datos de la imagen a partir de coordenadas reales. |
|
337 |
* No aplica supersampleo ni subsampleo sino que devuelve una matriz de igual tama?o a los |
|
338 |
* pixeles de disco. |
|
339 |
* @param x Posici?n X superior izquierda |
|
340 |
* @param y Posici?n Y superior izquierda |
|
341 |
* @param w Ancho en coordenadas reales |
|
342 |
* @param h Alto en coordenadas reales |
|
343 |
* @param adjustToExtent Flag que dice si el extent solicitado debe ajustarse al extent del raster o no. |
|
344 |
* @param bandList |
|
345 |
* @return Buffer de datos |
|
346 |
*/ |
|
347 |
public IBuffer getWindowRaster(double ulx, double uly, double lrx, double lry) throws InvalidSetViewException { |
|
348 |
Extent selectedExtent = new Extent(ulx, uly, lrx, lry); |
|
349 |
|
|
350 |
//Leemos pixels completos aunque el valor obtenido sea decimal. Esto se consigue redondeando |
|
351 |
//por arriba el m?s alto y por abajo el menor y luego restandolos |
|
352 |
|
|
353 |
Point2D p1 = ((RasterDataset)files.get(0)).worldToRaster(new Point2D.Double(ulx, uly)); |
|
354 |
Point2D p2 = ((RasterDataset)files.get(0)).worldToRaster(new Point2D.Double(lrx, lry)); |
|
355 |
int width = (int)Math.abs(Math.ceil(p2.getX()) - Math.floor(p1.getX())); |
|
356 |
int height = (int)Math.abs(Math.floor(p1.getY()) - Math.ceil(p2.getY())); |
|
357 |
|
|
358 |
//Ajustamos por si nos hemos salido del raster |
|
359 |
while(((int)(p1.getX() + width)) > getWidth()[0]) |
|
360 |
width --; |
|
361 |
while(((int)(p1.getY() + height)) > getHeight()[0]) |
|
362 |
height --; |
|
363 |
|
|
364 |
if(p1.getX() < 0) |
|
365 |
p1.setLocation(0, p1.getY()); |
|
366 |
if(p1.getY() < 0) |
|
367 |
p1.setLocation(p1.getX(), 0); |
|
368 |
if(p2.getX() > getWidth()[0]) |
|
369 |
p2.setLocation(getWidth()[0], p2.getY()); |
|
370 |
if(p1.getY() > getHeight()[0]) |
|
371 |
p1.setLocation(p2.getX(), getHeight()[0]); |
|
372 |
|
|
373 |
int mallocNBands = 0; |
|
374 |
if(bandList.getDrawableBands() != null) |
|
375 |
mallocNBands = bandList.getDrawableBands().length; |
|
376 |
else |
|
377 |
mallocNBands = bandList.getDrawableBandsCount(); |
|
378 |
|
|
379 |
IBuffer raster = RasterBuffer.getBuffer(getDataType()[0], width, height, mallocNBands, false); |
|
380 |
|
|
381 |
//Caso en el que un buffer no se puedan conmutar las bandas (t?picamente RasterReadOnlyHugeBuffer) |
|
382 |
if(!raster.isBandSwitchable()) { |
|
383 |
RasterBuffer rb = RasterBuffer.getBuffer(getDataType()[0], width, height, getDataset(0).getBandCount(), false); |
|
384 |
if(rb instanceof RasterReadOnlyHugeBuffer) { |
|
385 |
try { |
|
386 |
((RasterReadOnlyHugeBuffer)rb).setBufferParams(getDataset(0).getFName(), selectedExtent); |
|
387 |
} catch (FileNotExistsException e) { |
|
388 |
//Esto no debe darse ya que se comprueba al hacer el open |
|
389 |
} catch (NotSupportedExtensionException e) { |
|
390 |
//Esto no debe darse ya que se comprueba al hacer el open |
|
391 |
} |
|
392 |
return rb; |
|
393 |
} |
|
394 |
} |
|
395 |
|
|
396 |
for(int iBand = 0; iBand < raster.getBandCount(); iBand ++) |
|
397 |
raster.assignBandToNotValid(iBand); |
|
398 |
|
|
399 |
//Reservamos memoria para los buffers por dataset |
|
400 |
IBuffer[] bufferDatasets = mallocBuffersDatasets(bandList, width, height); |
|
401 |
|
|
402 |
//Si hemos redondeado los pixeles de la petici?n (p1 y p2) por arriba y por abajo deberemos calcular un extent mayor |
|
403 |
//equivalente a los pixeles redondeados. |
|
404 |
Point2D wc1 = ((RasterDataset)files.get(0)).rasterToWorld(new Point2D.Double(Math.floor(p1.getX()), Math.floor(p1.getY()))); |
|
405 |
Point2D wc2 = ((RasterDataset)files.get(0)).rasterToWorld(new Point2D.Double(Math.ceil(p2.getX()), Math.ceil(p2.getY()))); |
|
406 |
for(int i = 0; i < getDatasetCount(); i++) |
|
407 |
bufferDatasets[i] = ((RasterDataset)files.get(i)).getWindowRaster(wc1.getX(), wc1.getY(), wc2.getX(), wc2.getY(), bandList, bufferDatasets[i]); |
|
408 |
|
|
409 |
//Mezclamos los buffers de cada dataset en un solo buffer |
|
410 |
mergeBuffers(raster, bufferDatasets, bandList); |
|
411 |
|
|
412 |
return raster; |
|
413 |
} |
|
334 | 414 |
|
335 | 415 |
/** |
336 | 416 |
* Obtiene una ventana de datos de la imagen a partir de coordenadas reales. |
... | ... | |
353 | 433 |
Point2D pEnd = ((RasterDataset)files.get(0)).rasterToWorld(new Point2D.Double((int)getWidth()[0], (int)getHeight()[0])); |
354 | 434 |
double wRaster = Math.abs(pEnd.getX() - pInit.getX()); |
355 | 435 |
double hRaster = Math.abs(pEnd.getY() - pInit.getY()); |
356 |
double lrx = (((ext.getULX() - wRaster) > ext.maxX()) || ((ext.getULX() - wRaster) < ext.minX())) ? (ulx + w) : (ulx - w);
|
|
357 |
double lry = (((ext.getULY() - hRaster) > ext.maxY()) || ((ext.getULY() - hRaster) < ext.minY())) ? (uly + h) : (uly - h);
|
|
436 |
double lrx = (((int)(ext.getULX() - wRaster)) == ((int)ext.getLRX())) ? (ulx - w) : (ulx + w);
|
|
437 |
double lry = (((int)(ext.getULY() - hRaster)) == ((int)ext.getLRY())) ? (uly - h) : (uly + h);
|
|
358 | 438 |
|
359 | 439 |
Extent selectedExtent = new Extent(ulx, uly, lrx, lry); |
360 | 440 |
|
... | ... | |
429 | 509 |
|
430 | 510 |
return raster; |
431 | 511 |
} |
432 |
|
|
512 |
|
|
433 | 513 |
/** |
434 | 514 |
* Obtiene una ventana de datos de la imagen a partir de coordenadas reales. |
435 | 515 |
* Aplica supersampleo o subsampleo en funci?n del tama?o del buffer. Esta operaci?n la gestiona |
Also available in: Unified diff