Revision 2236 org.gvsig.raster/branches/org.gvsig.raster_dataaccess_refactoring/org.gvsig.raster.lib/org.gvsig.raster.lib.impl/src/main/java/org/gvsig/raster/impl/store/DefaultRasterStore.java

View differences:

DefaultRasterStore.java
1
/* gvSIG. Geographic Information System of the Valencian Government
2
 *
3
 * Copyright (C) 2007-2008 Infrastructures and Transports Department
4
 * of the Valencian Government (CIT)
5
 *
6
 * This program is free software; you can redistribute it and/or
7
 * modify it under the terms of the GNU General Public License
8
 * as published by the Free Software Foundation; either version 2
9
 * of the License, or (at your option) any later version.
10
 *
11
 * This program is distributed in the hope that it will be useful,
12
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
 * GNU General Public License for more details.
15
 *
16
 * You should have received a copy of the GNU General Public License
17
 * along with this program; if not, write to the Free Software
18
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
19
 * MA  02110-1301, USA.
20
 *
21
 */
22 1
package org.gvsig.raster.impl.store;
23 2

  
24 3
import java.awt.Image;
......
35 14
import org.gvsig.fmap.crs.CRSFactory;
36 15
import org.gvsig.fmap.dal.DALLocator;
37 16
import org.gvsig.fmap.dal.DataStoreParameters;
38
import org.gvsig.fmap.dal.coverage.RasterLibrary;
39 17
import org.gvsig.fmap.dal.coverage.RasterLocator;
40 18
import org.gvsig.fmap.dal.coverage.RasterManager;
41
import org.gvsig.fmap.dal.coverage.dataset.Buffer;
42 19
import org.gvsig.fmap.dal.coverage.datastruct.BandList;
43 20
import org.gvsig.fmap.dal.coverage.datastruct.Extent;
44 21
import org.gvsig.fmap.dal.coverage.datastruct.GeoPointList;
......
83 60
import org.gvsig.raster.cache.tile.Tile;
84 61
import org.gvsig.raster.cache.tile.exception.TileGettingException;
85 62
import org.gvsig.raster.impl.DefaultRasterManager;
86
import org.gvsig.raster.impl.buffer.DefaultRasterQuery;
63
import org.gvsig.raster.impl.buffer.SpiRasterQuery;
87 64
import org.gvsig.raster.impl.datastruct.BandListImpl;
88 65
import org.gvsig.raster.impl.grid.roi.VectorialROIsReader;
89 66
import org.gvsig.raster.impl.provider.AbstractRasterProvider;
......
112 89
	public static final String              PERSISTENT_NAME        = "DefaultRasterStore_Persistent";
113 90
    public static final String              PERSISTENT_DESCRIPTION = "DefaultRasterStore Persistent";
114 91
    private static final Logger             logger                 = LoggerFactory.getLogger(DefaultRasterStore.class);
115
    
116
	private RasterManager                   rManager               = RasterLocator.getManager();
117 92
	
118 93
	/*
119 94
	 * TODO: Refactoring de ROIS 
......
166 141
		return false;
167 142
	}
168 143

  
169
	/**
170
	 * Inicializa el buffer a valores NoData
171
	 * @param raster Buffer a inicializar
172
	 * @param bandList Lista de bandas
173
	 */
174
	private void initBufferToNoData(Buffer buf, BandList bandList) {
175
		for(int i = 0; i < bandList.getDrawableBandsCount(); i++) {
176
			switch(getDataType()[0]) {
177
			case Buffer.TYPE_BYTE:buf.assign(i, 
178
					buf.getNoDataValue().isDefined() ? buf.getNoDataValue().getValue().byteValue() : RasterLibrary.defaultByteNoDataValue);
179
			break;
180
			case Buffer.TYPE_SHORT:buf.assign(i, 
181
					buf.getNoDataValue().isDefined() ? buf.getNoDataValue().getValue().shortValue() : RasterLibrary.defaultShortNoDataValue);
182
			break;
183
			case Buffer.TYPE_INT:buf.assign(i, 
184
					buf.getNoDataValue().isDefined() ? buf.getNoDataValue().getValue().intValue() : RasterLibrary.defaultIntegerNoDataValue);
185
			break;
186
			case Buffer.TYPE_FLOAT:buf.assign(i, 
187
					buf.getNoDataValue().isDefined() ? buf.getNoDataValue().getValue().floatValue() : RasterLibrary.defaultFloatNoDataValue);
188
			break;
189
			case Buffer.TYPE_DOUBLE:buf.assign(i, 
190
					buf.getNoDataValue().isDefined() ? buf.getNoDataValue().getValue().doubleValue() : RasterLibrary.defaultDoubleNoDataValue);
191
			break;
192
			}
193
		}
194
	}
195
	
196 144
	public boolean isTiled() {
197 145
		return provider.isTiled();
198 146
	}
......
201 149
		return provider.isMosaic();
202 150
	}
203 151
	
204
	/*public Buffer getWindowWithoutResampling(DefaultRasterQuery q)
205
		throws InvalidSetViewException, ProcessInterruptedException, RasterDriverException {
206
		
207
		//El incremento o decremento de las X e Y depende de los signos de rotaci?n y escala en la matriz de transformaci?n. Por esto
208
		//tenemos que averiguar si lrx es x + w o x -w, asi como si lry es y + h o y - h
209
		Extent ext = getExtent();
210
		Point2D pInit = provider.rasterToWorld(new Point2D.Double(0, 0));
211
		Point2D pEnd = provider.rasterToWorld(new Point2D.Double((int)getWidth(), (int)getHeight()));
212
		double wRaster = Math.abs(pEnd.getX() - pInit.getX());
213
		double hRaster = Math.abs(pEnd.getY() - pInit.getY());
214
		double lrx = (((int)(ext.getULX() - wRaster)) == ((int)ext.getLRX())) ? (q.getX() - q.getW()) : (q.getX() + q.getW());
215
		double lry = (((int)(ext.getULY() - hRaster)) == ((int)ext.getLRY())) ? (q.getY() - q.getH()) : (q.getY() + q.getH());
216

  
217
		//Extent selectedExtent = new Extent(ulx, uly, lrx, lry);
218

  
219
		//Leemos pixels completos aunque el valor obtenido sea decimal. Esto se consigue redondeando
220
		//por arriba el m?s alto y por abajo el menor y luego restandolos
221

  
222
		Point2D p1 = provider.worldToRaster(new Point2D.Double(q.getX(), q.getY()));
223
		Point2D p2 = provider.worldToRaster(new Point2D.Double(lrx, lry));
224
		adjustPoints(p1, p2);
225
		int width = (int)Math.abs(Math.ceil(p2.getX()) - Math.floor(p1.getX()));
226
		int height = (int)Math.abs(Math.floor(p1.getY()) - Math.ceil(p2.getY()));
227

  
228
		//Ajustamos por si nos hemos salido del raster
229
		if(((int)(p1.getX() + width)) > getWidth())
230
			width = (int)(getWidth() - p1.getX());
231
		if(((int)(p1.getY() + height)) > getHeight())
232
			height = (int)(getHeight() - p1.getY());
233

  
234
		if (p1.getX() < 0)
235
			p1.setLocation(0, p1.getY());
236
		if (p1.getY() < 0)
237
			p1.setLocation(p1.getX(), 0);
238
		if (p2.getX() > getWidth())
239
			p2.setLocation(getWidth(), p2.getY());
240
		if (p2.getY() > getHeight())
241
			p2.setLocation(p2.getX(), getHeight());
242

  
243
		int mallocNBands = 0;
244
		if(storeBandList.getDrawableBands() != null)
245
			mallocNBands = storeBandList.getDrawableBands().length;
246
		else
247
			mallocNBands = storeBandList.getDrawableBandsCount();
248

  
249
		//Buffer ReadOnly
250

  
251
		if(isReadOnly()) {
252
			Buffer rb = DefaultRasterManager.getInstance().createReadOnlyBuffer(getDataType()[0], width, height, getBandCount());
253
			if(rb instanceof RasterReadOnlyBuffer) {
254
				try {
255
					((RasterReadOnlyBuffer)rb).setBufferParams(this, 
256
							(int)p1.getX(), (int)p1.getY(), (int)p2.getX(), (int)p2.getY(), storeBandList);
257
				} catch (FileNotExistsException e) {
258
					//Esto no debe darse ya que se comprueba al hacer el open.
259
					return null;
260
				} catch (NotSupportedExtensionException e) {
261
					//Esto no debe darse ya que se comprueba al hacer el open
262
					return null;
263
				}
264
				return rb;
265
			}
266
		}
267
		
268
		//Si hemos redondeado los pixeles de la petici?n (p1 y p2) por arriba y por abajo deberemos calcular un extent mayor
269
		//equivalente a los pixeles redondeados.
270
		Point2D wc1 = provider.rasterToWorld(new Point2D.Double(Math.floor(p1.getX()), Math.floor(p1.getY())));
271
		Point2D wc2 = provider.rasterToWorld(new Point2D.Double(Math.ceil(p2.getX()), Math.ceil(p2.getY())));
272

  
273
		//Buffer RW
274
		Buffer raster = null;
275
		
276
		if(forceToMemory) //Fuerza siempre buffer en memoria
277
			raster = DefaultRasterManager.getInstance().createMemoryBuffer(getDataType()[0], width, height, mallocNBands, true);
278
		else
279
			raster = DefaultRasterManager.getInstance().createBuffer(getDataType()[0], width, height, mallocNBands, true);
280

  
281
		if(!q.isAdjustToExtent())
282
			 initBufferToNoData(raster, storeBandList);
283
		
284
		q.setAreaOfInterest(wc1.getX(), wc1.getY(), Math.abs(wc2.getX() - wc1.getX()), Math.abs(wc2.getY() - wc1.getY()));
285
		q.setBandList(storeBandList);
286
		q.setOutputBuffer(raster);
287
		raster = ((DefaultRasterProvider)provider).getDataSet(q);
288

  
289
		return raster;
290
	}*/
291
	
292
	/*private void adjustPoints(Point2D ul, Point2D lr) {
293
		double a = (ul.getX() - (int)ul.getX());
294
		double b = (ul.getY() - (int)ul.getY());
295
		ul.setLocation(	(a > 0.99 || a < 0.005) ? Math.round(ul.getX()) : ul.getX(), 
296
						(b > 0.99 || b < 0.005) ? Math.round(ul.getY()) : ul.getY());
297
		lr.setLocation(	(a > 0.99 || a < 0.005) ? Math.round(lr.getX()) : lr.getX(), 
298
						(b > 0.99 || b < 0.005) ? Math.round(lr.getY()) : lr.getY());
299
	}*/
300
	
301
	/*public Buffer getWindowWithResampling(DefaultRasterQuery q)
302
		throws InvalidSetViewException, ProcessInterruptedException, RasterDriverException {
303

  
304
		Point2D p1 = worldToRaster(new Point2D.Double(q.getRequestBoundingBox().getULX(), q.getRequestBoundingBox().getULY()));
305
		Point2D p2 = worldToRaster(new Point2D.Double(q.getRequestBoundingBox().getLRX(), q.getRequestBoundingBox().getLRY()));;
306
		
307
		if(p1.getX() > p2.getX())
308
			p1.setLocation(p1.getX() - 1, p1.getY());
309
		else
310
			p2.setLocation(p2.getX() - 1, p2.getY());
311
		
312
		if(p1.getY() > p2.getY())
313
			p1.setLocation(p1.getX(), p1.getY() - 1);
314
		else
315
			p2.setLocation(p2.getX(), p2.getY() - 1);
316
		
317
		if(	((int)p1.getX()) < 0 || ((int)p2.getX()) > getWidth() ||
318
				((int)p2.getY()) > getHeight() || ((int)p2.getY()) < 0)
319
				throw new InvalidSetViewException("");
320

  
321
		int mallocNBands = 0;
322
		if(storeBandList.getDrawableBands() != null)
323
			mallocNBands = storeBandList.getDrawableBands().length;
324
		else
325
			mallocNBands = storeBandList.getDrawableBandsCount();
326

  
327
		//Buffer ReadOnly
328

  
329
		if(isReadOnly()) {
330
			Buffer rb = DefaultRasterManager.getInstance().createReadOnlyBuffer(getDataType()[0], q.getBufWidth(), q.getBufHeight(), getBandCount());
331
			if(rb instanceof RasterReadOnlyBuffer) {
332
				try {
333
					((RasterReadOnlyBuffer)rb).setBufferParams(this, 
334
							(int)p1.getX(), (int)p1.getY(), (int)p2.getX(), (int)p2.getY(), storeBandList);
335
				} catch (FileNotExistsException e) {
336
					//Esto no debe darse ya que se comprueba al hacer el open.
337
					return null;
338
				} catch (NotSupportedExtensionException e) {
339
					//Esto no debe darse ya que se comprueba al hacer el open
340
					return null;
341
				}
342
				return rb;
343
			}
344
		}
345

  
346
		double ulx = q.getRequestBoundingBox().getULX();
347
		double uly = q.getRequestBoundingBox().getULY();
348
		double lrx = q.getRequestBoundingBox().getLRX();
349
		double lry = q.getRequestBoundingBox().getLRY();
350
		
351
		//Buffer RW
352
		Buffer raster = null;
353
		
354
		if(forceToMemory) //Fuerza siempre buffer en memoria
355
			raster = DefaultRasterManager.getInstance().createMemoryBuffer(getDataType()[0], q.getBufWidth(), q.getBufHeight(), mallocNBands, true);
356
		else
357
			raster = DefaultRasterManager.getInstance().createBuffer(getDataType()[0], q.getBufWidth(), q.getBufHeight(), mallocNBands, true);
358
		
359
		Extent ex = rManager.getDataStructFactory().createExtent(ulx, uly, lrx, lry);
360
		 
361
		q.setRequestBoundingBox(ex);
362
		q.setBandList(storeBandList);
363
		q.setOutputBuffer(raster);
364
		raster = ((DefaultRasterProvider)provider).getDataSet(q);
365

  
366
		return raster;
367
	}*/
368

  
369
	/*public Buffer getWindowWC(DefaultRasterQuery q)
370
		throws InvalidSetViewException, ProcessInterruptedException, RasterDriverException {
371
		
372
		if(q.getBufWidth() > 0 && q.getBufHeight() > 0)
373
			return getWindowWithResampling(q);
374
		
375
		//Leemos pixels completos aunque el valor obtenido sea decimal. Esto se consigue redondeando
376
		//por arriba el m?s alto y por abajo el menor y luego restandolos
377

  
378
		Point2D p1 = provider.worldToRaster(new Point2D.Double(q.getRequestBoundingBox().getULX(), q.getRequestBoundingBox().getULY()));
379
		Point2D p2 = provider.worldToRaster(new Point2D.Double(q.getRequestBoundingBox().getLRX(), q.getRequestBoundingBox().getLRY()));
380

  
381
		//Para el valor mayor redondeamos por arriba. Para el valor menor redondeamos por abajo.
382
		double p1X = (p1.getX() > p2.getX()) ? Math.ceil(p1.getX()) : Math.floor(p1.getX());
383
		double p1Y = (p1.getY() > p2.getY()) ? Math.ceil(p1.getY()) : Math.floor(p1.getY());
384
		double p2X = (p2.getX() > p1.getX()) ? Math.ceil(p2.getX()) : Math.floor(p2.getX());
385
		double p2Y = (p2.getY() > p1.getY()) ? Math.ceil(p2.getY()) : Math.floor(p2.getY());
386

  
387
		int width = (int)Math.abs(p1X - p2X);
388
		int height = (int)Math.abs(p1Y - p2Y);
389

  
390
		//Ajustamos por si nos hemos salido del raster
391
		if(((int)(Math.min(p1X, p2X) + width)) > getWidth())
392
			width = (int)(getWidth() - Math.min(p1X, p2X));
393
		if(((int)(Math.min(p1Y, p2Y) + height)) > getHeight())
394
			height = (int)(getHeight() - Math.min(p1Y, p2Y));
395

  
396
		if (p1X < 0)
397
			p1X = 0;
398
		if (p1Y < 0)
399
			p1Y = 0;
400
		if (p2X > getWidth())
401
			p2X = getWidth();
402
		if (p2Y > getHeight())
403
			p2Y = getHeight();
404

  
405
		int mallocNBands = 0;
406
		if(storeBandList.getDrawableBands() != null)
407
			mallocNBands = storeBandList.getDrawableBands().length;
408
		else
409
			mallocNBands = storeBandList.getDrawableBandsCount();
410

  
411
		//Buffer ReadOnly
412

  
413
		if(isReadOnly()) {
414
			Buffer rb = DefaultRasterManager.getInstance().createReadOnlyBuffer(getDataType()[0], width, height, getBandCount());
415
			if(rb instanceof RasterReadOnlyBuffer) {
416
				try {
417
					((RasterReadOnlyBuffer)rb).setBufferParams(this, 
418
							(int)p1.getX(), (int)p1.getY(), (int)p2.getX(), (int)p2.getY(), storeBandList);
419
				} catch (FileNotExistsException e) {
420
					//Esto no debe darse ya que se comprueba al hacer el open.
421
					return null;
422
				} catch (NotSupportedExtensionException e) {
423
					//Esto no debe darse ya que se comprueba al hacer el open
424
					return null;
425
				}
426
				return rb;
427
			}
428
		}
429

  
430
		//Buffer RW
431
		Buffer raster = null;
432
		
433
		//Si hemos redondeado los pixeles de la petici?n (p1 y p2) por arriba y por abajo deberemos calcular un extent mayor
434
		//equivalente a los pixeles redondeados.
435
		Point2D wc1 = provider.rasterToWorld(new Point2D.Double(p1X, p1Y));
436
		Point2D wc2 = provider.rasterToWorld(new Point2D.Double(p2X, p2Y));
437
		
438
		if(forceToMemory) //Fuerza siempre buffer en memoria
439
			raster = DefaultRasterManager.getInstance().createMemoryBuffer(getDataType()[0], width, height, mallocNBands, true);
440
		else
441
			raster = DefaultRasterManager.getInstance().createBuffer(getDataType()[0], width, height, mallocNBands, true);
442
		
443
		Extent ex = rManager.getDataStructFactory().createExtent(wc1.getX(), wc1.getY(), wc2.getX(), wc2.getY());
444
		q.setType(DefaultRasterQuery.TYPE_WCOORDS);
445
		q.setRequestBoundingBox(ex);
446
		q.setBandList(storeBandList);
447
		q.setOutputBuffer(raster);
448
		raster = ((DefaultRasterProvider)provider).getDataSet(q);
449
		//raster = ((DefaultRasterProvider)provider).getWindow(ex, bandList, raster);
450

  
451
		return raster;
452
	}*/
453

  
454
	/*public void getWindowTiled(DefaultRasterQuery q)
455
		throws InvalidSetViewException, ProcessInterruptedException, RasterDriverException {
456
		if(isTiled()) { 
457
			//Extent ex = q.getBBox();//new ExtentImpl(ulx, uly, lrx, lry);
458
			q.setBandList(storeBandList);
459
			((DefaultRasterProvider)provider).getDataSet(q);
460
			//((DefaultRasterProvider)provider).getWindow(ex, q.getBufWidth(), q.getBufHeight(), bandList, listener);
461
			return;
462
		}
463
				
464
		double[] step = null;
465
		Buffer buf = null;
466
		
467
		double ulx = q.getRequestBoundingBox().getULX();
468
		double uly = q.getRequestBoundingBox().getULY();
469
		double lrx = q.getRequestBoundingBox().getLRX();
470
		double lry = q.getRequestBoundingBox().getLRY();
471
		
472
		//Esta secci?n es para que no supersamplee el driver y pueda hacerse en el cliente
473
		if(!currentQuery.isSupersamplingLoadingBuffer()) {
474
			//nWidth = ((adjustedDataExtent.width() * mDataset.getDataset(0).getWidth()) / mDataset.getExtentForRequest().width());
475
			//nHeight = ((adjustedDataExtent.height() * mDataset.getDataset(0).getHeight()) / mDataset.getExtentForRequest().height());
476
			Point2D p1 = worldToRaster(new Point2D.Double(ulx, uly));
477
			Point2D p2 = worldToRaster(new Point2D.Double(lrx, lry));
478
			nWidth = Math.abs(p1.getX() - p2.getX());
479
			nHeight = Math.abs(p1.getY() - p2.getY());
480

  
481
			if(q.getBufWidth() > Math.ceil(nWidth) && q.getBufHeight() > Math.ceil(nHeight)) {
482
				step = calcSteps(ulx, uly, lrx, lry, nWidth, nHeight, q.getBufWidth(), q.getBufHeight());
483
				buf = getWindowWC(q);
484
			}
485
		} 
486
		
487
		if(buf == null) {
488
			q.setAdjustToExtent(true);
489
			buf = getWindowWithResampling(q);
490
		}
491
		
492
		buf.setDataExtent(new Rectangle2D.Double(ulx, uly, Math.abs(ulx - lrx), Math.abs(uly - lry)));
493
		
494
		Buffer alphaBand = null;
495
		if(currentQuery.getAlphaBandNumber() != -1) {
496
			int[] drawableBands = storeBandList.getDrawableBands();
497
			storeBandList.setDrawableBands(new int[]{currentQuery.getAlphaBandNumber(), -1, -1});
498
			for(int i = 0; i < provider.getInternalProviderCount(); i++)
499
				((AbstractRasterDataParameters)((DefaultRasterProvider)provider.getInternalProvider(i)).getDataParameters()).setAlphaBand(currentQuery.getAlphaBandNumber());
500
			q.setAdjustToExtent(true);
501
			alphaBand = getWindowWithResampling(q);
502
			storeBandList.setDrawableBands(drawableBands);
503
		}
504
		
505
		TileCacheManager m = TileCacheLocator.getManager();
506
		org.gvsig.raster.cache.tile.Tile t = m.createTile(-1, 0, 0);
507
		t.setData(new Object[]{buf, alphaBand});
508
		t.setUl(new Point2D.Double(ulx, uly));
509
		t.setLr(new Point2D.Double(lrx, lry));
510
		if(provider.getDataParameters() instanceof MultiDimensionalStoreParameters) {
511
			MultiDimensionalStoreParameters par = (MultiDimensionalStoreParameters)provider.getDataParameters();
512
			t.setVariable(par.getStringVariable());
513
			t.setZ(par.getStringLevel());
514
			t.setTimeInstant(par.getStringTime());
515
		}
516
		t.setDownloaderParams("AffineTransform", getAffineTransform());
517
		t.setDownloaderParams("Tiling", new Boolean(true));
518
		t.setDownloaderParams("Step", step);
519
		try {
520
			q.getTileListener().tileReady(t);
521
		} catch (TileGettingException e) {
522
			throw new RasterDriverException("Error getting a tile", e);
523
		}
524
		
525
		//listener.nextBuffer(buf, alphaBand, new ExtentImpl(ulx, uly, lrx, lry), this.getAffineTransform(), step, false);
526
		q.getTileListener().endReading();
527
	}*/
528
	
529
	public Tile getTile(DefaultRasterQuery q) throws TileGettingException {
152
	public Tile getTile(SpiRasterQuery q) throws TileGettingException {
530 153
		TiledRasterProvider tiledProv = ((TiledRasterProvider)provider);
531 154
		return tiledProv.getTile(q);
532 155
	}
533 156

  
534
	/*public Buffer getWindowPx(DefaultRasterQuery q)
535
		throws InvalidSetViewException, ProcessInterruptedException, RasterDriverException {
536
		step = null;
537
		if(q.getPixelX() < 0 || q.getPixelY() < 0 || q.getPixelW() > getWidth() || q.getPixelH() > getHeight())
538
			throw new InvalidSetViewException("Out of image");
539
		
540
		q.setPixelX((q.getPixelX() < 0) ? 0 : q.getPixelX());
541
		q.setPixelY((q.getPixelY() < 0) ? 0 : q.getPixelY());
542
		q.setPixelW((q.getPixelW() > getWidth()) ? (int)getWidth() : q.getPixelW());
543
		q.setPixelH((q.getPixelH() > getHeight()) ? (int)getHeight() : q.getPixelH());
544

  
545
		dataExtent = new ExtentImpl(rasterToWorld(new Point2D.Double(q.getPixelX(), q.getPixelY())),
546
				rasterToWorld(new Point2D.Double(q.getPixelX() + q.getPixelW(), q.getPixelY() + q.getPixelH())));
547
		
548
		if(	q.getType() == DefaultRasterQuery.TYPE_PX || 
549
			q.getType() == DefaultRasterQuery.TYPE_ENTIRE || 
550
			q.getBufWidth() <= 0 || q.getBufHeight() <= 0) {
551
			q.setBufWidth(q.getPixelW());
552
			q.setBufHeight(q.getPixelH());
553
		}
554

  
555
		//Buffer ReadOnly
556

  
557
		if(isReadOnly()) {
558
			Buffer rb = DefaultRasterManager.getInstance().createReadOnlyBuffer(getDataType()[0], 
559
					q.getBufWidth(), q.getBufHeight(), getBandCount());
560
			if(rb instanceof RasterReadOnlyBuffer) {
561
				try {
562
					((RasterReadOnlyBuffer)rb).setBufferParams((QueryableRaster)this, 
563
							q.getPixelX(), 
564
							q.getPixelY(), 
565
							q.getPixelX() + q.getPixelW() - 1, 
566
							q.getPixelY() + q.getPixelH() - 1, 
567
							storeBandList);
568
				} catch (FileNotExistsException e) {
569
					//Esto no debe darse ya que se comprueba al hacer el open.
570
					return null;
571
				} catch (NotSupportedExtensionException e) {
572
					//Esto no debe darse ya que se comprueba al hacer el open
573
					return null;
574
				}
575
				return rb;
576
			}
577
		}
578

  
579
		//Buffer RW
580
		Buffer raster = null;
581
		
582
		if(forceToMemory) //Fuerza siempre buffer en memoria
583
			raster = DefaultRasterManager.getInstance().createMemoryBuffer(getDataType()[0], q.getBufWidth(), q.getBufHeight(), storeBandList.getDrawableBandsCount(), true);
584
		else
585
			raster = DefaultRasterManager.getInstance().createBuffer(getDataType()[0], q.getBufWidth(), q.getBufHeight(), storeBandList.getDrawableBandsCount(), true);
586
		
587
		q.setBandList(storeBandList);
588
		q.setOutputBuffer(raster);
589
		raster = ((DefaultRasterProvider)provider).getDataSet(q);
590
		//raster = ((DefaultRasterProvider)provider).getWindow(q.getPixelX(), q.getPixelY(), q.getPixelW(), q.getPixelH(), bandList, raster);
591

  
592
		return raster;
593
	}*/
594

  
595 157
	//******************************
596 158
	//Setters and Getters
597 159
	//******************************
......
750 312
		return provider.worldToRaster(pt);
751 313
	}
752 314

  
753
	public double[] calcSteps(double dWorldTLX, double dWorldTLY, double dWorldBRX, double dWorldBRY,
754
			double nWidth, double nHeight, int bufWidth, int bufHeight){
755
		return provider.calcSteps(dWorldTLX, dWorldTLY, dWorldBRX, dWorldBRY, nWidth, nHeight, bufWidth, bufHeight);
756
	}
757

  
758 315
	public boolean isGeoreferenced() {
759 316
		return provider.isGeoreferenced();
760 317
	}
......
1401 958
		
1402 959
	}
1403 960
	
1404
	/*private void loadROIFromProject(PersistentState state) throws PersistenceException {
1405
		List<ROI> rois = state.getList("rois");
1406
		if(rois != null) {
1407
			this.rois = new ArrayList<ROI>();
1408
			this.rois.addAll(rois);
1409
		}
1410
	}*/
1411
	
1412 961
	@SuppressWarnings("unchecked")
1413 962
	private void loadFiltersFromProject(PersistentState state) throws PersistenceException {
1414 963
		RasterFilterList fList = (RasterFilterList)state.get("filterList");
......
1504 1053
		provider               = null;
1505 1054
		storeBandList               = null;
1506 1055
		metadata               = null;
1507
		rManager               = null;
1508 1056
		if(rois != null) {
1509 1057
			rois.clear();
1510 1058
			rois = null;

Also available in: Unified diff