Revision 11396 trunk/libraries/libRaster/src/org/gvsig/raster/dataset/RasterMultiDataset.java

View differences:

RasterMultiDataset.java
24 24

  
25 25
import org.cresques.cts.IProjection;
26 26
import org.gvsig.raster.buffer.RasterBuffer;
27
import org.gvsig.raster.buffer.cache.RasterReadOnlyHugeBuffer;
27 28
import org.gvsig.raster.dataset.properties.DatasetColorInterpretation;
28 29
import org.gvsig.raster.dataset.properties.DatasetListHistogram;
29 30
import org.gvsig.raster.dataset.properties.DatasetListStatistics;
......
80 81
			for (int dataset = 0; dataset < param.length; dataset++)
81 82
				try {
82 83
					rmd.addDataset(RasterDataset.open(proj, param[dataset]));
83
				} catch (FileFoundInListException e) {
84
				} catch (FileNotFoundInListException e) {
84 85
					//No lo a?adimos en el dataset pq ya existe
85 86
				} 	
86 87
		} else if(datasetOpenParam instanceof IBuffer[]) {
......
88 89
			for (int dataset = 0; dataset < param.length; dataset++)
89 90
				try {
90 91
					rmd.addDataset(RasterDataset.open(proj, param[dataset]));
91
				} catch (FileFoundInListException e) {
92
				} catch (FileNotFoundInListException e) {
92 93
					//No lo a?adimos en el dataset pq ya existe
93 94
				} 	
94 95
		} else {
95 96
			RasterDataset rd = RasterDataset.open(proj, datasetOpenParam);
96 97
			try {
97 98
				rmd.addDataset(rd);
98
			} catch (FileFoundInListException e) {
99
			} catch (FileNotFoundInListException e) {
99 100
				//No lo a?adimos en el dataset pq ya existe
100 101
			}
101 102
		}
......
106 107
	 * Add a file to the list.
107 108
	 * @param f file to add.
108 109
	 */
109
	public void addDataset(RasterDataset f)throws FileFoundInListException {
110
	public void addDataset(RasterDataset f)throws FileNotFoundInListException {
110 111
		if(findDataset(f))
111
			throw new FileFoundInListException("The file already is in list.");
112
			throw new FileNotFoundInListException("The file already is in list.");
112 113
		files.add(f);
113 114
		addBands(f);
114 115
		stats = new DatasetListStatistics(files);
......
119 120
	 * @param f fichero a a?adir.
120 121
	 * @throws RasterDriverException 
121 122
	 */
122
	public void addDataset(String fileName)throws FileFoundInListException, NotSupportedExtensionException, RasterDriverException{
123
	public void addDataset(String fileName)throws FileNotFoundInListException, NotSupportedExtensionException, RasterDriverException{
123 124
		if(findDataset(fileName))
124
			throw new FileFoundInListException("The file already is in list.");
125
			throw new FileNotFoundInListException("The file already is in list.");
125 126
		RasterDataset f = RasterDataset.open(null, fileName);
126 127
		files.add(f);
127 128
		addBands(f);
......
141 142
			try {
142 143
				Band band = new Band(grf.getFName(), i, dataType);
143 144
				bandList.addBand(band, i);
144
			} catch(BandFoundInListException ex) {
145
			} catch(BandNotFoundInListException ex) {
145 146
				//No a?adimos la banda
146 147
			}
147 148
		}
......
260 261
	private IBuffer[] mallocBuffersDatasets(BandList bl, int width, int height){
261 262
		IBuffer[] buffers = new IBuffer[getDatasetCount()];
262 263
		for(int i = 0; i < getDatasetCount(); i++){
263
			buffers[i] =  RasterBuffer.getBuffer(getDataset(i).getDataType(), width, height, getDataset(i).getBandCount(), false, null);
264
			buffers[i] =  RasterBuffer.getBuffer(getDataset(i).getDataType(), width, height, getDataset(i).getBandCount(), false);
264 265
			
265 266
			//Asignamos las bandas de cada fichero que no se pintan a null y las que se pintan se reserva memoria
266 267
			String name = getDataset(i).getFName();
......
315 316
	 * @param bandList
316 317
	 * @return Buffer de datos
317 318
	 */
318
	public IBuffer getWindowRaster(double x, double y, double w, double h, boolean adjustToExtent) {
319
	public IBuffer getWindowRaster(double x, double y, double w, double h, boolean adjustToExtent) 
320
		throws InvalidSetViewException {
319 321
		
320 322
		Extent selectedExtent = new Extent(x, y, x + w, y - h);
321 323

  
......
333 335
		else
334 336
			bandList.getDrawableBandsCount();
335 337
		
336
		IBuffer raster = RasterBuffer.getBuffer(getDataType()[0], width, height, mallocNBands, false, null);
338
		IBuffer raster = RasterBuffer.getBuffer(getDataType()[0], width, height, mallocNBands, false);
337 339
		
338 340
		//Caso en el que un buffer no se puedan conmutar las bandas (t?picamente RasterReadOnlyHugeBuffer)
339
		if(!raster.isBandSwitchable())
340
			return RasterBuffer.getBuffer(getDataType()[0], width, height, getDataset(0).getBandCount(), false, getDataset(0).getFName());
341
		if(!raster.isBandSwitchable()) {
342
			RasterBuffer rb = RasterBuffer.getBuffer(getDataType()[0], width, height, getDataset(0).getBandCount(), false);
343
			if(rb instanceof RasterReadOnlyHugeBuffer) {
344
				try {
345
					((RasterReadOnlyHugeBuffer)rb).setBufferParams(getDataset(0).getFName(), selectedExtent);
346
				} catch (FileNotExistsException e) {
347
					//Esto no debe darse ya que se comprueba al hacer el open
348
				} catch (NotSupportedExtensionException e) {
349
					//Esto no debe darse ya que se comprueba al hacer el open
350
				}
351
				return rb;
352
			}
353
				
354
		}
341 355
					
342 356
		for(int iBand = 0; iBand < raster.getBandCount(); iBand ++)
343 357
			raster.assignBandToNotValid(iBand);
......
373 387
	 * @return Buffer de datos
374 388
	 */
375 389
	public IBuffer getWindowRaster(double minX, double minY, double maxX, double maxY, 
376
									int bufWidth, int bufHeight, boolean adjustToExtent) {
390
									int bufWidth, int bufHeight, boolean adjustToExtent) throws InvalidSetViewException {
391
		
392
		if(	minX < ((RasterDataset)files.get(0)).getExtent().minX() || minY < ((RasterDataset)files.get(0)).getExtent().minY() ||
393
			maxX > ((RasterDataset)files.get(0)).getExtent().maxX() || maxY > ((RasterDataset)files.get(0)).getExtent().maxY())
394
				throw new InvalidSetViewException("");
395
		
377 396
		int mallocNBands = 0;
378 397
		if(bandList.getDrawableArray() != null)
379 398
			mallocNBands = bandList.getDrawableArray().length;
380 399
		else
381 400
			bandList.getDrawableBandsCount();
382 401
		
383
		IBuffer raster = RasterBuffer.getBuffer(getDataType()[0], bufWidth, bufHeight, mallocNBands, false, null);
402
		IBuffer raster = RasterBuffer.getBuffer(getDataType()[0], bufWidth, bufHeight, mallocNBands, false);
384 403
		
385
		//Caso en el que un buffer no se puedan conmutar las bandas (t?picamente RasterReadOnlyHugeBuffer)
386
		if(!raster.isBandSwitchable())
387
			return RasterBuffer.getBuffer(getDataType()[0], bufWidth, bufHeight, getDataset(0).getBandCount(), false, getDataset(0).getFName());
404
		//TODO: FUNCIONALIDAD: Si la petici?n es muy grande en solo lectura y con resampleo de buffer
405
		//Este caso no deberia darse en una petici?n con resampleo ya que RasterReadOnlyHugeBuffer hace referencia a la imagen en disco
406
		/*if(!raster.isBandSwitchable()) {
407
			RasterBuffer rb = RasterBuffer.getBuffer(getDataType()[0], bufWidth, bufHeight, getDataset(0).getBandCount(), false);
408
			if(rb instanceof RasterReadOnlyHugeBuffer) {
409
				try {
410
					((RasterReadOnlyHugeBuffer)rb).setBufferParams(getDataset(0).getFName(), selectedExtent);
411
				} catch (FileNotExistsException e) {
412
					//Esto no debe darse ya que se comprueba al hacer el open
413
				} catch (NotSupportedExtensionException e) {
414
					//Esto no debe darse ya que se comprueba al hacer el open
415
				}
416
				return rb;
417
			}
418
		}*/
388 419
			
389 420
		for(int iBand = 0; iBand < raster.getBandCount(); iBand ++)
390 421
			raster.assignBandToNotValid(iBand);
......
416 447
	 * @param bandList
417 448
	 * @return Buffer de datos
418 449
	 */
419
	public IBuffer getWindowRaster(int x, int y, int w, int h) {
420
		IBuffer raster = RasterBuffer.getBuffer(getDataType()[0], w, h, bandList.getDrawableBandsCount(), false, null);
450
	public IBuffer getWindowRaster(int x, int y, int w, int h) throws InvalidSetViewException {
451
		if(x < 0 || y < 0 || w > ((RasterDataset)files.get(0)).getWidth() || h > ((RasterDataset)files.get(0)).getHeight())
452
			throw new InvalidSetViewException("Out of image");
421 453
		
454
		IBuffer raster = RasterBuffer.getBuffer(getDataType()[0], w, h, bandList.getDrawableBandsCount(), false);
455
		
422 456
		//Caso en el que un buffer no se puedan conmutar las bandas (t?picamente RasterReadOnlyHugeBuffer)
423
		if(!raster.isBandSwitchable())
424
			return RasterBuffer.getBuffer(getDataType()[0], w, h, getDataset(0).getBandCount(), false, getDataset(0).getFName());
457
		if(!raster.isBandSwitchable()) {
458
			RasterBuffer rb = RasterBuffer.getBuffer(getDataType()[0], w, h, getDataset(0).getBandCount(), false);
459
			if(rb instanceof RasterReadOnlyHugeBuffer) {
460
				try {
461
					((RasterReadOnlyHugeBuffer)rb).setBufferParams(getDataset(0).getFName(), x, y, x + w, y + h);
462
				} catch (FileNotExistsException e) {
463
					//Esto no debe darse ya que se comprueba al hacer el open
464
				} catch (NotSupportedExtensionException e) {
465
					//Esto no debe darse ya que se comprueba al hacer el open
466
				}
467
				return rb;
468
			}
469
		}
425 470
				
426 471
		for(int iBand = 0; iBand < raster.getBandCount(); iBand ++)
427 472
			raster.assignBandToNotValid(iBand);
......
449 494
	 * @param bandList
450 495
	 * @return Buffer de datos
451 496
	 */
452
	public IBuffer getWindowRaster(int x, int y, int w, int h, int bufWidth, int bufHeight) {
453
		IBuffer raster = RasterBuffer.getBuffer(getDataType()[0], bufWidth, bufHeight, bandList.getDrawableBandsCount(), false, null);
497
	public IBuffer getWindowRaster(int x, int y, int w, int h, int bufWidth, int bufHeight)  
498
		throws InvalidSetViewException {
499
		if(x < 0 || y < 0 || w > ((RasterDataset)files.get(0)).getWidth() || h > ((RasterDataset)files.get(0)).getHeight())
500
			throw new InvalidSetViewException("Out of image");
501
		
502
		IBuffer raster = RasterBuffer.getBuffer(getDataType()[0], bufWidth, bufHeight, bandList.getDrawableBandsCount(), false);
454 503
		for(int iBand = 0; iBand < raster.getBandCount(); iBand ++)
455 504
			raster.assignBandToNotValid(iBand);
456 505
		
457 506
		//Reservamos memoria para los buffers por dataset
458 507
		IBuffer[] bufferDatasets = mallocBuffersDatasets(bandList, bufWidth, bufHeight);
459 508
		
460
		//Caso en el que un buffer no se puedan conmutar las bandas (t?picamente RasterReadOnlyHugeBuffer)
461
		if(!raster.isBandSwitchable())
462
			return RasterBuffer.getBuffer(getDataType()[0], bufWidth, bufHeight, getDataset(0).getBandCount(), false, getDataset(0).getFName());
509
		//TODO: FUNCIONALIDAD: Si la petici?n es muy grande en solo lectura y con resampleo de buffer
510
		//Este caso no deberia darse en una petici?n con resampleo ya que RasterReadOnlyHugeBuffer hace referencia a la imagen en disco
511
		/*if(!raster.isBandSwitchable()) {
512
			RasterBuffer rb = RasterBuffer.getBuffer(getDataType()[0], bufWidth, bufHeight, getDataset(0).getBandCount(), false);
513
			if(rb instanceof RasterReadOnlyHugeBuffer) {
514
				try {
515
					((RasterReadOnlyHugeBuffer)rb).setBufferParams(getDataset(0).getFName(), x, y, x + w, y + h);
516
				} catch (FileNotExistsException e) {
517
					//Esto no debe darse ya que se comprueba al hacer el open
518
				} catch (NotSupportedExtensionException e) {
519
					//Esto no debe darse ya que se comprueba al hacer el open
520
				}
521
				return rb;
522
			}
523
		}*/
463 524
				
464 525
		for(int i = 0; i < getDatasetCount(); i++)
465 526
			bufferDatasets[i] = ((RasterDataset)files.get(i)).getWindowRaster(x, y, w, h, bufWidth, bufHeight, bandList, bufferDatasets[i]);

Also available in: Unified diff