Revision 186

View differences:

org.gvsig.raster.app/trunk/org.gvsig.raster.app/org.gvsig.raster.app.wmsclient/src/main/java/org/gvsig/raster/app/extension/wmsclient/layer/FLyrWMS.java
46 46

  
47 47
import org.cresques.cts.ICoordTrans;
48 48
import org.cresques.cts.IProjection;
49
import org.exolab.castor.xml.ValidationException;
50
import org.gvsig.andami.messages.NotificationManager;
49 51
import org.gvsig.fmap.crs.CRSFactory;
50 52
import org.gvsig.fmap.dal.DALLocator;
53
import org.gvsig.fmap.dal.DataManager;
51 54
import org.gvsig.fmap.dal.DataStore;
52 55
import org.gvsig.fmap.dal.DataTypes;
53 56
import org.gvsig.fmap.dal.coverage.RasterLocator;
57
import org.gvsig.fmap.dal.coverage.RasterManager;
58
import org.gvsig.fmap.dal.coverage.datastruct.Extent;
54 59
import org.gvsig.fmap.dal.coverage.datastruct.RemoteStyle;
55
import org.gvsig.fmap.dal.coverage.store.MosaicRasterStore;
60
import org.gvsig.fmap.dal.coverage.datastruct.ViewPortData;
61
import org.gvsig.fmap.dal.coverage.exception.FilterTypeException;
62
import org.gvsig.fmap.dal.coverage.exception.InvalidSetViewException;
63
import org.gvsig.fmap.dal.coverage.exception.ProcessInterruptedException;
64
import org.gvsig.fmap.dal.coverage.exception.RasterDriverException;
65
import org.gvsig.fmap.dal.coverage.exception.WMSException;
66
import org.gvsig.fmap.dal.coverage.store.ListRasterStore;
56 67
import org.gvsig.fmap.dal.coverage.store.RasterDataStore;
57 68
import org.gvsig.fmap.dal.coverage.store.RasterStoreParameters;
58 69
import org.gvsig.fmap.dal.coverage.store.remote.RemoteRasterServiceStore;
59 70
import org.gvsig.fmap.dal.coverage.store.remote.RemoteServerExplorerProvider;
60 71
import org.gvsig.fmap.dal.coverage.util.ProviderServices;
72
import org.gvsig.fmap.dal.exception.CloseException;
61 73
import org.gvsig.fmap.dal.exception.DataException;
62 74
import org.gvsig.fmap.dal.exception.InitializeException;
63 75
import org.gvsig.fmap.dal.exception.ProviderNotRegisteredException;
......
70 82
import org.gvsig.fmap.geom.exception.CreateEnvelopeException;
71 83
import org.gvsig.fmap.geom.primitive.Envelope;
72 84
import org.gvsig.fmap.mapcontext.ViewPort;
85
import org.gvsig.fmap.mapcontext.exceptions.ConnectionErrorLayerException;
73 86
import org.gvsig.fmap.mapcontext.exceptions.LoadLayerException;
74 87
import org.gvsig.fmap.mapcontext.exceptions.UnsupportedVersionLayerException;
75 88
import org.gvsig.fmap.mapcontext.layers.FLayer;
76 89
import org.gvsig.fmap.mapcontext.layers.operations.ComposedLayer;
77 90
import org.gvsig.fmap.mapcontext.layers.operations.IHasImageLegend;
78 91
import org.gvsig.fmap.mapcontext.rendering.legend.ILegend;
92
import org.gvsig.raster.app.extension.wmsclient.exception.WMSDriverExceptionType;
79 93
import org.gvsig.raster.fmap.layers.DefaultFLyrRaster;
80 94
import org.gvsig.raster.fmap.layers.IRasterLayerActions;
81 95
import org.gvsig.raster.fmap.layers.NotAvailableStateException;
96
import org.gvsig.raster.impl.store.DefaultListRasterStore;
82 97
import org.gvsig.raster.util.RasterToolsUtil;
98
import org.gvsig.remoteclient.utils.Utilities;
83 99
import org.gvsig.remoteclient.wms.WMSStatus;
84 100
import org.gvsig.tools.ToolsLocator;
85 101
import org.gvsig.tools.dynobject.DynClass;
......
93 109
import org.slf4j.LoggerFactory;
94 110

  
95 111

  
96

  
97

  
98 112
/**
99 113
 * FMap's WMS Layer class.
100 114
 *
......
132 146
	private boolean 					 mustTileDraw           = true;
133 147
	private final int 					 maxTileDrawWidth       = 1023;
134 148
	private final int 					 maxTileDrawHeight      = 1023;
149
	private final int 					 maxTilePrintWidth      = 1023;
150
	private final int 					 maxTilePrintHeight     = 1023;
151
	private final int					 minTilePrintWidth      = 12;
152
	private final int					 minTilePrintHeight     = 12;
135 153
	public URL 							 host;
136 154
	public String 						 m_Format;
137 155
	private String 						 m_SRS;
......
151 169
	private int                         lastNRows               = 0;
152 170
	private int                         callCount;
153 171
	private boolean						firstLoad               = false;
154
	private MosaicRasterStore           mosaic                  = null;
172
	private ListRasterStore             listStore               = null;
173
	private RasterManager               rManager                = RasterLocator.getManager();
174
	private Rectangle2D 				fullExtent              = null;
155 175

  
156 176
	public FLyrWMS() {
157 177
		super();
......
394 414
	 * (non-Javadoc)
395 415
	 * @see org.gvsig.raster.fmap.layers.DefaultFLyrRaster#draw(java.awt.image.BufferedImage, java.awt.Graphics2D, org.gvsig.fmap.mapcontext.ViewPort, org.gvsig.tools.task.Cancellable, double)
396 416
	 */
417
	@SuppressWarnings("deprecation")
397 418
	public void draw(BufferedImage image, Graphics2D g, ViewPort viewPort,
398 419
			Cancellable cancel, double scale) throws ReadException {
399
		/*callCount = 0;  
420
		callCount = 0;  
400 421
		lastNRows = 0;
401 422
		lastNColumns = 0;
402

  
423
		
424
		if(listStore == null) {
425
			listStore = new DefaultListRasterStore();
426
			listStore.setRender(getRender());
427
		} else
428
			try {
429
				listStore.close();
430
			} catch (CloseException e1) {
431
			}
432
		
403 433
		enableStopped();
404 434

  
405
		if (isWithinScale(scale)){
435
		if (isWithinScale(scale)) {
406 436
			Point2D p = viewPort.getOffset();
407 437
			// p will be (0, 0) when drawing a view or other when painting onto
408 438
			// the Layout.
......
413 443
			visualStatus.maxY = vpEnvelope.getMaximum(1);
414 444

  
415 445

  
416
			if (isSizeFixed()) {
446
			//if (isSizeFixed()) {
417 447
				// This condition handles those situations in which the server can
418 448
				// only give static extent and resolution maps despite we need
419 449
				// a specific BBOX and pixel WIDTH and HEIGHT
420 450
				try {
421 451
					visualStatus.fileNames = new String[1];
422
					layerRaster = new FLyrRasterSE[1];
423
					drawFixedSize(g, viewPort, cancel, scale);
424
					if(layerRaster != null && layerRaster[0] != null) {
452
					//drawFixedSize(g, viewPort, cancel, scale);
453
					drawTile(g, viewPort, cancel, scale);
454
					/*if(layerRaster != null && layerRaster[0] != null) {
425 455
						dataset = layerRaster[0].getDataSource();
426 456
						initializeRasterLayer(null, new IBuffer[][]{{layerRaster[0].getRender().getLastRenderBuffer()}});
427 457
						getRender().setLastRenderBuffer(layerRaster[0].getRender().getLastRenderBuffer());
428
					}
458
					}*/
429 459
				} catch (LoadLayerException e) {
430 460
					throw new ReadException("Error cargando la capa.", e);
431 461
				} 
432 462

  
433
			} else {
463
			/*} else {
434 464
				if(mustTileDraw){
435 465
					Rectangle r = new Rectangle((int) p.getX(), (int) p.getY(), viewPort.getImageWidth(), viewPort.getImageHeight());
436 466
					Tiling tiles = new Tiling(maxTileDrawWidth, maxTileDrawHeight, r);
......
487 517
						e.printStackTrace();
488 518
					}
489 519
				}
490
			}
520
			}*/
491 521
		}
492
		disableStopped();*/
522
		disableStopped();
493 523
	}
494 524
	
495
	/*private void drawFixedSize(Graphics2D g, ViewPort vp, Cancellable cancel,
525
	/**
526
	 * This is the method used to draw a tile in a WMS mosaic layer.
527
	 * @throws LoadLayerException
528
	 * @throws ReadDriverException
529
	 * @return true when a tile has been painted
530
	 */
531
	private boolean drawTile(Graphics2D g, ViewPort vp, Cancellable cancel, double scale) throws LoadLayerException, ReadException {
532
		callCount++;
533
		// Compute the query geometry
534
		// 1. Check if it is within borders
535
		Envelope envelope = getFullEnvelope();
536
		Envelope vpEnv = vp.getAdjustedExtent();
537
		if (!vpEnv.intersects(envelope)) {
538
			return false;
539
		}
540

  
541

  
542
		// 2. Compute extent to be requested.
543
		Rectangle2D bBox = new Rectangle2D.Double();
544
		Rectangle2D.intersect(getRectable2DFromEnvelope(vpEnv),
545
				getRectable2DFromEnvelope(envelope), bBox);
546

  
547
		// 3. Compute size in pixels
548
		double scalex = vp.getAffineTransform().getScaleX();
549
		double scaley = vp.getAffineTransform().getScaleY();
550
		int wImg = (int) Math.ceil(Math.abs(bBox.getWidth() * scalex) + 1);
551
		int hImg = (int) Math.ceil(Math.abs(bBox.getHeight() * scaley) + 1);
552

  
553
		Dimension sz = new Dimension(wImg, hImg);
554

  
555
		if ((wImg <= 0) || (hImg <= 0)) {
556
			return false;
557
		}
558

  
559
		try {
560
			sz = new Dimension(wImg, hImg);
561

  
562
			wmsStatus.setExtent( bBox );
563
			wmsStatus.setFormat(m_Format);
564
			wmsStatus.setHeight( hImg );
565
			wmsStatus.setWidth( wImg );
566
			wmsStatus.setLayerNames(Utilities.createVector(layerQuery,","));
567
			wmsStatus.setSrs(m_SRS);
568
			wmsStatus.setStyles(styles);
569
			wmsStatus.setDimensions(dimensions);
570
			wmsStatus.setTransparency(wmsTransparency);
571
			wmsStatus.setOnlineResource((String) onlineResources.get("GetMap"));
572

  
573
			// begin patch; Avoid to request too small tiles.
574
			// This generally occurs when printing
575

  
576
			if (wImg < minTilePrintWidth) {
577
				double wScale = (double) minTilePrintWidth / wImg;
578
				wmsStatus.setWidth(minTilePrintWidth);
579
				Rectangle2D sExtent = wmsStatus.getExtent();
580
				Point2D initialPoint = new Point2D.Double(sExtent.getX(), sExtent.getY());
581
				sExtent.setRect(sExtent.getX()*wScale, sExtent.getY(), sExtent.getWidth()*wScale, sExtent.getHeight());
582
				if (!bBox.contains(initialPoint)) {
583
					sExtent.setRect(sExtent.getX() - initialPoint.getX(), sExtent.getY(), sExtent.getWidth(), sExtent.getHeight());
584
				}
585
			}
586

  
587
			if (hImg < minTilePrintHeight) {
588
				double hScale = (double) minTilePrintHeight / hImg;
589
				wmsStatus.setHeight(minTilePrintHeight);
590
				Rectangle2D sExtent = wmsStatus.getExtent();
591
				Point2D initialPoint = new Point2D.Double(sExtent.getX(), sExtent.getY());
592
				sExtent.setRect(sExtent.getX(), sExtent.getY()*hScale, sExtent.getWidth(), sExtent.getHeight()*hScale);
593
				if (!bBox.contains(initialPoint)) {
594
					sExtent.setRect(sExtent.getX(), sExtent.getY() - initialPoint.getY(), sExtent.getWidth(), sExtent.getHeight());
595
				}
596
			}
597

  
598
			// end patch
599
			File f = ((RemoteRasterServiceStore)getDataStore()).getMap(wmsStatus, cancel);
600
			if (f == null) {
601
				return false;
602
			}
603
			String nameWordFile = getWorldFile(f.getPath());
604
			org.gvsig.andami.Utilities.createTemp(nameWordFile, this.getDataWorldFile(bBox, sz));
605

  
606
			//Crea el RasterDataStore y lo a?ade a la lista
607
			ProviderServices provServ = RasterLocator.getManager().getProviderServices();
608
			RasterStoreParameters storeParameters = provServ.createParameters(f.getPath(), -1);
609
			storeParameters.setURI(f.getPath());
610
			storeParameters.setSRS(getProjection());
611
			
612
			DataManager dataManager = DALLocator.getDataManager();
613
			DataStore dataStore = null;
614
			try {
615
				dataStore = dataManager.createStore(storeParameters);
616
			} catch (ValidateDataParametersException e) {
617
				throw new LoadLayerException("Error al cargar la capa.");
618
			} catch (InitializeException e) {
619
				throw new LoadLayerException("Error al cargar la capa.");
620
			} catch (ProviderNotRegisteredException e) {
621
				throw new LoadLayerException("Error al cargar la capa.");
622
			}
623
			
624
			String nameWorldFile = getWorldFile(f.getPath());
625
			org.gvsig.andami.Utilities.createTemp(nameWorldFile, this.getDataWorldFile(bBox, sz));
626
			listStore.addTile((RasterDataStore)dataStore);
627
			
628
			Rectangle2D extent = new Rectangle2D.Double();
629
			Rectangle2D.Double vpExtent = this.getRectable2DFromEnvelope(vpEnv);
630
			Rectangle2D.intersect(vpExtent, bBox, extent);
631
			
632
			ViewPortData vpData = rManager.createViewPortData(vp.getProjection(),
633
					rManager.getDataStructFactory().createExtent(extent), sz );
634
			vpData.setMat(vp.getAffineTransform());
635

  
636
			String filePath = f.getAbsolutePath();
637
			visualStatus.fileNames[0] = filePath;
638
			try {
639
				RasterDataStore ds = listStore.getRender().getDataStore();
640
				listStore.getRender().setDataStore(listStore);
641
				listStore.getRender().draw(g, vpData);
642
				listStore.getRender().setDataStore(ds);
643
				//this.updateDrawVersion();
644
			} catch (RasterDriverException e) {
645
			} catch (InvalidSetViewException e) {
646
			} catch (ProcessInterruptedException e) {
647
			}
648

  
649
		} catch (IOException e) {
650
			if (!cancel.isCanceled()){
651
				if (callCount<MAX_RETRY_TIMES) { // mess code
652
					NotificationManager.addWarning("\n[ FLyrWMS.drawFixedSize() ]  Failed in trying " + callCount + "/" + MAX_RETRY_TIMES + ")\n", null); // mess code
653
					// I'll try again requesting up to MAX_RETRY_TIMES times before throw an error // mess code
654
					// (this is mess code, should be replaced by a layer status handler which is scheduled for version > 1.0) // mess code
655

  
656
					drawFixedSize(g, vp, cancel, scale); // mess code
657
				} // mess code
658
			}
659
			if (callCount == 1) { // mess code
660
				throw new ConnectionErrorLayerException(getName(),e);
661
			}//if
662
		} catch (WMSException e) {
663
			if (!cancel.isCanceled()) {
664
				if (callCount<MAX_RETRY_TIMES) { // mess code
665
					logger.warn("\n[ FLyrWMS.drawFixedSize() ]  Failed in trying " + callCount + "/" + MAX_RETRY_TIMES + ")\n"); // mess code
666
					// I'll try again requesting up to MAX_RETRY_TIMES times before throw an error // mess code
667
					// (this is mess code, should be replaced by a layer status handler which is scheduled for version > 1.0) // mess code
668
					drawTile(g, vp, cancel, scale);
669
				} // mess code
670
				if (callCount == 1) { // mess code
671
					//		azabala			JOptionPane.showMessageDialog((Component)PluginServices.getMainFrame(), e.getMessage());
672
					WMSDriverExceptionType type = new WMSDriverExceptionType();
673
					type.setLayerName(getName());
674
					try {
675
						type.setDriverName("WMS Driver");
676
					} catch (Exception e1) {
677
					}
678
					type.setWcsStatus(this.wmsStatus);
679
					if (!isPrinting) {
680
						this.setVisible(false);
681
					}
682
					throw new LoadLayerException(getName(),e);
683

  
684

  
685
				} //if
686
			}//if
687
		}//catch
688
		callCount--;
689
		return true;
690
	}
691
	
692
	private void drawFixedSize(Graphics2D g, ViewPort vp, Cancellable cancel,
496 693
			double scale) throws ReadException, LoadLayerException {
497 694
		callCount++; // mess code, it is not unusual a wms server to response an error which is completely
498 695
		// temporal and the response is available if we retry requesting.
......
511 708
			wmsStatus.setDimensions(dimensions);
512 709
			wmsStatus.setTransparency(wmsTransparency);
513 710
			wmsStatus.setOnlineResource((String) onlineResources.get("GetMap"));
711
			
712
			//Descarga del fichero
514 713
			File f = ((RemoteRasterServiceStore)getDataStore()).getMap(wmsStatus, cancel);
515 714
			if (f == null) {
516 715
				return;
517 716
			}
717
			
718
			//Crea el RasterDataStore y lo a?ade a la lista
719
			ProviderServices provServ = RasterLocator.getManager().getProviderServices();
720
			RasterStoreParameters storeParameters = provServ.createParameters(f.getName(), -1);
721
			storeParameters.setURI(f.getName());
722
			
723
			DataManager dataManager = DALLocator.getDataManager();
724
			DataStore dataStore = null;
725
			try {
726
				dataStore = dataManager.createStore(storeParameters);
727
			} catch (ValidateDataParametersException e) {
728
				throw new LoadLayerException("Error al cargar la capa.");
729
			} catch (InitializeException e) {
730
				throw new LoadLayerException("Error al cargar la capa.");
731
			} catch (ProviderNotRegisteredException e) {
732
				throw new LoadLayerException("Error al cargar la capa.");
733
			}
734
			
518 735
			String nameWorldFile = getWorldFile(f.getPath());
519 736
			org.gvsig.andami.Utilities.createTemp(nameWorldFile, this.getDataWorldFile(bBox, fixedSize));
737
			listStore.addTile((RasterDataStore)dataStore);
520 738

  
521
			IStatusRaster status = getStatus();
522
			if(status!=null && firstLoad){
523
				try {
524
					status.applyStatus(this);
525
				} catch (NotSupportedExtensionException e) {
526
					throw new ReadException("", e);
527
				} catch (RasterDriverException e) {
528
					throw new ReadException("", e);
529
				} catch (FilterTypeException e) {
530
					throw new ReadException("", e);
531
				}
532
				firstLoad = false;
533
			}
534

  
535 739
			// And finally, obtain the extent intersecting the view and the BBox
536 740
			// to draw to.
537 741
			Rectangle2D extent = new Rectangle2D.Double();
......
540 744

  
541 745
			Rectangle2D.intersect(vpExtent, bBox, extent);
542 746

  
543
			ViewPortData vpData = new ViewPortData(
544
					vp.getProjection(), new Extent(extent), fixedSize );
747
			
748
			ViewPortData vpData = rManager.createViewPortData(vp.getProjection(),
749
					rManager.getDataStructFactory().createExtent(extent), fixedSize );
545 750
			vpData.setMat(vp.getAffineTransform());
546 751

  
547 752
			String filePath = f.getAbsolutePath();
548 753
			visualStatus.fileNames[0] = filePath;
549 754

  
550 755
			try {
551
				rasterProcess(filePath, g, vp, scale, cancel, 0);
756
				Envelope adjustedExtent = vp.getAdjustedExtent();
757
				if (adjustedExtent == null)
758
					return;
759
				Extent e = rManager.getDataStructFactory().createExtent(adjustedExtent.getLowerCorner().getX(),
760
						adjustedExtent.getUpperCorner().getY(), adjustedExtent
761
								.getUpperCorner().getX(),
762
						adjustedExtent
763
								.getLowerCorner().getY());
764
				Dimension imgSz = vp.getImageSize();
765
				ViewPortData vp2 = rManager.createViewPortData(vp.getProjection(), e, imgSz );
766
				vp2.setMat(vp.getAffineTransform());
767
				
768
				listStore.getRender().draw(g, vp2);
552 769
				this.updateDrawVersion();
553
			} catch (FilterTypeException e) {
770
			} catch (RasterDriverException e) {
771
			} catch (InvalidSetViewException e) {
772
			} catch (ProcessInterruptedException e) {
773
				return;
554 774
			}
555
		} catch (ValidationException e) {
556
			if (!cancel.isCanceled())
557
			{
558
				LoadLayerException exception = new LoadLayerException(getName(),e);
559
				throw exception;
560
			}
561 775
		} catch (IOException e) {
562 776
			if (!cancel.isCanceled()) {
563 777
				if (callCount < MAX_RETRY_TIMES) { // mess code
......
589 803
			}
590 804
		}
591 805
		callCount--;
592
	}*/
806
	}
593 807
	
594 808
	/**
595 809
	 * Carga y dibuja el raster usando la librer?a
org.gvsig.raster.app/trunk/org.gvsig.raster.app/org.gvsig.raster.app.wmsclient/src/main/java/org/gvsig/raster/app/extension/wmsclient/exception/WMSDriverExceptionType.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
package org.gvsig.raster.app.extension.wmsclient.exception;
23

  
24
import org.gvsig.remoteclient.wms.WMSStatus;
25
import org.gvsig.utils.ExceptionDescription;
26

  
27

  
28
public class WMSDriverExceptionType extends ExceptionDescription {
29

  
30
	WMSStatus status;
31
	
32
	public WMSDriverExceptionType(){
33
		super(65, "Error al acceder a un servicio WMS");
34
		
35
	}
36
	
37
	public String getHtmlErrorMessage() {
38
		String message = "<p><b>Error en una petici?n a servidor WMS</b></p>";
39
		message += "Informaci?n adicional:<br>";
40
		message += "Direcci?n: " + status.getOnlineResource();
41
		message += "<br> Formato: "+status.getFormat();
42
		return message;
43
	}
44

  
45
	public WMSStatus getWcsStatus() {
46
		return status;
47
	}
48

  
49
	public void setWcsStatus(WMSStatus wcsStatus) {
50
		this.status = wcsStatus;
51
	}
52

  
53

  
54
}
55

  
0 56

  
org.gvsig.raster/trunk/org.gvsig.raster/org.gvsig.raster.lib/org.gvsig.raster.lib.impl/src/main/java/org/gvsig/raster/impl/store/QueryableRaster.java
136 136
	public Extent getExtent();
137 137
	
138 138
	/**
139
	 * Gets an extent adjusted to the bounding box of this raster
140
	 * @param e
141
	 * @return
142
	 */
143
	public Extent adjustToExtent(Extent e);
144
	
145
	/**
139 146
	 * Obtiene la altura del raster en p?xeles.
140 147
	 * @return altura
141 148
	 */
org.gvsig.raster/trunk/org.gvsig.raster/org.gvsig.raster.lib/org.gvsig.raster.lib.impl/src/main/java/org/gvsig/raster/impl/store/properties/MosaicDataStoreHistogram.java
26 26
import org.gvsig.fmap.dal.coverage.exception.HistogramException;
27 27
import org.gvsig.fmap.dal.coverage.exception.ProcessInterruptedException;
28 28
import org.gvsig.fmap.dal.coverage.exception.RasterDriverException;
29
import org.gvsig.fmap.dal.coverage.store.MosaicRasterStore;
30 29
import org.gvsig.fmap.dal.coverage.store.RasterDataStore;
31 30
import org.gvsig.fmap.dal.coverage.store.props.Histogram;
32 31
import org.gvsig.fmap.dal.coverage.store.props.Statistics;
......
45 44
	 */
46 45
	private BufferHistogram                       histogram   = null;
47 46
	private Histogram[]                           multihistog = null;
48
	private MosaicRasterStore                     dataset     = null;
47
	private RasterDataStore                       dataset     = null;
49 48
	
50 49
	/**
51 50
	 * Constructor
52 51
	 * @param dataset
53 52
	 */
54
	public MosaicDataStoreHistogram(Histogram[] h, MosaicRasterStore dataset){
53
	public MosaicDataStoreHistogram(Histogram[] h, RasterDataStore dataset){
55 54
		this.multihistog = h;
56 55
		this.dataset = dataset;
57 56
	}
org.gvsig.raster/trunk/org.gvsig.raster/org.gvsig.raster.lib/org.gvsig.raster.lib.impl/src/main/java/org/gvsig/raster/impl/store/DefaultListRasterStore.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
package org.gvsig.raster.impl.store;
23

  
24
import java.awt.geom.AffineTransform;
25
import java.awt.geom.NoninvertibleTransformException;
26
import java.awt.geom.Point2D;
27
import java.io.IOException;
28
import java.util.ArrayList;
29

  
30
import org.cresques.cts.IProjection;
31
import org.gvsig.fmap.dal.coverage.RasterLibrary;
32
import org.gvsig.fmap.dal.coverage.RasterLocator;
33
import org.gvsig.fmap.dal.coverage.dataset.Buffer;
34
import org.gvsig.fmap.dal.coverage.datastruct.BandList;
35
import org.gvsig.fmap.dal.coverage.datastruct.Extent;
36
import org.gvsig.fmap.dal.coverage.exception.BandAccessException;
37
import org.gvsig.fmap.dal.coverage.exception.FileNotOpenException;
38
import org.gvsig.fmap.dal.coverage.exception.HistogramException;
39
import org.gvsig.fmap.dal.coverage.exception.InvalidSetViewException;
40
import org.gvsig.fmap.dal.coverage.exception.MosaicNotValidException;
41
import org.gvsig.fmap.dal.coverage.exception.ProcessInterruptedException;
42
import org.gvsig.fmap.dal.coverage.exception.RasterDriverException;
43
import org.gvsig.fmap.dal.coverage.exception.RmfSerializerException;
44
import org.gvsig.fmap.dal.coverage.store.ListRasterStore;
45
import org.gvsig.fmap.dal.coverage.store.RasterDataStore;
46
import org.gvsig.fmap.dal.coverage.store.RasterStoreParameters;
47
import org.gvsig.fmap.dal.coverage.store.props.ColorTable;
48
import org.gvsig.fmap.dal.coverage.store.props.Histogram;
49
import org.gvsig.fmap.dal.coverage.store.props.Metadata;
50
import org.gvsig.fmap.dal.coverage.store.props.SerialInfo;
51
import org.gvsig.fmap.dal.coverage.store.props.Statistics;
52
import org.gvsig.fmap.dal.coverage.store.props.Transparency;
53
import org.gvsig.fmap.dal.coverage.util.RasterUtils;
54
import org.gvsig.fmap.dal.exception.CloseException;
55
import org.gvsig.fmap.dal.raster.spi.CoverageStoreProvider;
56
import org.gvsig.metadata.exceptions.MetadataException;
57
import org.gvsig.raster.impl.DefaultRasterManager;
58
import org.gvsig.raster.impl.datastruct.BandListImpl;
59
import org.gvsig.raster.impl.datastruct.ExtentImpl;
60
import org.gvsig.raster.impl.provider.RasterProvider;
61
import org.gvsig.raster.impl.store.properties.DataStoreColorInterpretation;
62
import org.gvsig.raster.impl.store.properties.DataStoreTransparency;
63
import org.gvsig.raster.impl.store.properties.MosaicDataStoreHistogram;
64
/**
65
 * Esta clase est? compuestas de multiples datasets formando una rejilla de NxM
66
 * rasters. Un cliente de esta clase debe tener una visi?n de la rejilla como si
67
 * fuese un solo raster, gestionando esta el acceso la imagen que corresponda en
68
 * cada petici?n de usuario.
69
 *
70
 * @version 29/08/2007
71
 * @author Nacho Brodin (nachobrodin@gmail.com)
72
 */
73
public class DefaultListRasterStore extends AbstractRasterDataStore implements ListRasterStore {
74
	private ArrayList<RasterDataStore>    list          = null;
75
	private Statistics                    stats         = null;
76
	private BandListImpl                  bandList      = null;
77
	private boolean                       readOnly      = false;
78
	/**
79
	 * Flag que fuerza al buffer en memoria
80
	 */            
81
	private boolean                       forceToMemory = false;
82
	private int                           percent       = 0;
83

  
84
	/**
85
	 * Constructor. Genera la estructura de n filas por n columnas de rasters.
86
	 */
87
	public DefaultListRasterStore() {
88
		bandList = new BandListImpl();
89
		list = new ArrayList<RasterDataStore>();
90
	}
91

  
92
	/**
93
	 * Constructor. Genera la estructura de n filas por n columnas de rasters y
94
	 * las asigna a los raster que se le pasan por par?metro.
95
	 * @param n N?mero de filas
96
	 * @param m N?mero de columnas
97
	 */
98
	public DefaultListRasterStore(RasterDataStore mos) throws MosaicNotValidException {
99
		bandList = (BandListImpl)mos.getBands();
100
		
101
		list = new ArrayList<RasterDataStore>();
102
		list.add(mos);
103
	}
104
	
105
	/**
106
	 * Constructor. Genera la estructura de n filas por n columnas de rasters y
107
	 * las asigna a los raster que se le pasan por par?metro.
108
	 * @param n N?mero de filas
109
	 * @param m N?mero de columnas
110
	 */
111
	public DefaultListRasterStore(ArrayList<RasterDataStore> mos) throws MosaicNotValidException {
112
		bandList = (BandListImpl)mos.get(0).getBands();
113
		list = mos;
114
	}
115
	
116
	/*
117
	 * (non-Javadoc)
118
	 * @see org.gvsig.fmap.dal.coverage.store.RasterDataStore#newDataStore()
119
	 */
120
	public RasterDataStore newDataStore() {
121
		DefaultListRasterStore newList = new DefaultListRasterStore();
122
		for (int i = 0; i < list.size(); i++) {
123
			newList.addTile(list.get(i).newDataStore());
124
		}
125
		return newList;
126
	}
127

  
128
	/*
129
	 * (non-Javadoc)
130
	 * @see org.gvsig.fmap.dal.DataStore#getName()
131
	 */
132
	public String getName() {
133
		if(list.size() >= 1) 
134
			return list.get(0).getName();
135
		return null;
136
	}
137
	
138
	/*
139
	 * (non-Javadoc)
140
	 * @see org.gvsig.raster.impl.dataset.QueryableRaster#getProviders()
141
	 */
142
	public ArrayList<RasterProvider> getProviders() {
143
		ArrayList<RasterProvider> provList = new ArrayList<RasterProvider>();
144
		for (int i = 0; i < list.size(); i++) {
145
			provList.add(((QueryableRaster)list.get(0)).getProviders().get(0));
146
		}
147
		return provList;
148
	}
149
	
150
	/*
151
	 * (non-Javadoc)
152
	 * @see org.gvsig.raster.impl.dataset.QueryableRaster#getProvider(int)
153
	 */
154
	public RasterProvider getProvider(int i) {
155
		if(list == null)
156
			return null;
157
		return (RasterProvider)list.get(i).getProvider();
158
	}
159
	
160
	/*
161
	 * (non-Javadoc)
162
	 * @see org.gvsig.raster.impl.dataset.QueryableRaster#getDrawableBands()
163
	 */
164
	public int[] getDrawableBands() {
165
		return getBands().getDrawableBands();
166
	}
167

  
168
	/*
169
	 * (non-Javadoc)
170
	 * @see org.gvsig.fmap.dal.coverage.store.ListRasterStore#addTile(org.gvsig.fmap.dal.coverage.store.RasterDataStore)
171
	 */
172
	public void addTile(RasterDataStore store) {
173
		this.bandList = (BandListImpl)store.getBands();
174
		list.add(store);
175
	}
176

  
177
	/**
178
	 * Obtiene la lista de nombres de los dataset
179
	 * @return
180
	 */
181
	public String[] getFileNames() {
182
		String[] s = new String[list.size()];
183
		for (int i = 0; i < s.length; i++)
184
				if(list.get(i) != null)
185
					s[i] = ((RasterStoreParameters)list.get(i).getParameters()).getURI();
186
		return s;
187
	}
188

  
189
	/*
190
	 * (non-Javadoc)
191
	 * @see org.gvsig.raster.impl.dataset.QueryableRaster#calcSteps(double, double, double, double, double, double, int, int)
192
	 */
193
	public double[] calcSteps(double dWorldTLX, double dWorldTLY, double dWorldBRX, double dWorldBRY, double nWidth, double nHeight, int bufWidth, int bufHeight) {
194
		return ((QueryableRaster)list.get(0)).calcSteps(dWorldTLX, dWorldTLY, dWorldBRX, dWorldBRY, nWidth, nHeight, bufWidth, bufHeight);
195
	}
196

  
197
	/*
198
	 * (non-Javadoc)
199
	 * @see org.gvsig.fmap.dal.raster.impl.DefaultCoverageStore#close()
200
	 */
201
	public void close() throws CloseException {
202
		for (int i = 0; i < list.size(); i++) {
203
			list.get(i).close();
204
		}
205
		list.clear();
206
		bandList.clear();
207
	}
208

  
209

  
210
	/*
211
	 * (non-Javadoc)
212
	 * @see org.gvsig.raster.dataset.IRasterDataSource#getOwnAffineTransform()
213
	 */
214
	public AffineTransform getOwnAffineTransform() {
215
		return list.get(0).getOwnAffineTransform();
216
	}
217

  
218
	/*
219
	 * (non-Javadoc)
220
	 * @see org.gvsig.raster.dataset.IRasterDataSource#getAffineTransform()
221
	 */
222
	public AffineTransform getAffineTransform() {
223
		return list.get(0).getAffineTransform();
224
	}
225

  
226
	/*
227
	 * (non-Javadoc)
228
	 * @see org.gvsig.raster.dataset.IRasterDataSource#getExtent()
229
	 */
230
	public Extent getExtent() {
231
		//Ojo! no es rotable
232
		double ulx = 0;
233
		double uly = 0;
234
		double urx = 0;
235
		double ury = 0;
236
		double llx = 0;
237
		double lly = 0;
238
		double lrx = 0;
239
		double lry = 0;
240

  
241
		for (int i = 0; i < list.size(); i++) {
242
			ulx = list.get(i).getExtent().getULX() < ulx ? list.get(i).getExtent().getULX() : ulx;
243
			uly = list.get(i).getExtent().getULY() > uly ? list.get(i).getExtent().getULY() : uly;
244
			urx = list.get(i).getExtent().getURX() > urx ? list.get(i).getExtent().getURX() : urx;
245
			ury = list.get(i).getExtent().getURY() > ury ? list.get(i).getExtent().getURY() : ury;
246
			llx = list.get(i).getExtent().getLLX() > llx ? list.get(i).getExtent().getLLX() : llx;
247
			lly = list.get(i).getExtent().getLLY() < lly ? list.get(i).getExtent().getLLY() : lly;
248
			lrx = list.get(i).getExtent().getLRX() < lrx ? list.get(i).getExtent().getLRX() : lrx;
249
			lry = list.get(i).getExtent().getLRY() < lry ? list.get(i).getExtent().getLRY() : lry;
250
		}
251

  
252
		return new ExtentImpl(	new Point2D.Double(ulx, uly),
253
				new Point2D.Double(lrx, lry),
254
				new Point2D.Double(urx, ury),
255
				new Point2D.Double(llx, lly));
256
	}
257

  
258
	/*
259
	 * (non-Javadoc)
260
	 * @see org.gvsig.raster.dataset.IRasterDataSource#getBandCount()
261
	 */
262
	public int getBandCount() {
263
		return list.get(0).getBandCount();
264
	}
265

  
266
	/*
267
	 * (non-Javadoc)
268
	 * @see org.gvsig.fmap.dal.coverage.store.RasterDataStore#getWidth()
269
	 */
270
	public double getWidth() {
271
		double wReal = (getExtent().getMax().getX() - getExtent().getMin().getX());
272
		return Math.abs(wReal / getPixelSizeY());
273
	}
274

  
275
	/*
276
	 * (non-Javadoc)
277
	 * @see org.gvsig.fmap.dal.coverage.store.RasterDataStore#getHeight()
278
	 */
279
	public double getHeight() {
280
		double hReal = (getExtent().getMax().getY() - getExtent().getMin().getY());
281
		return Math.abs(hReal / getPixelSizeX());
282
	}
283

  
284
	/*
285
	 * (non-Javadoc)
286
	 * @see org.gvsig.fmap.dal.coverage.store.RasterDataStore#getCellSize()
287
	 */
288
	public double getCellSize() {
289
		try {
290
			Extent e = getExtent();
291
			double dCellsize = (e.getMax().getX() - e.getMin().getX() ) / getWidth();
292
			return dCellsize;
293
		} catch (NullPointerException e) {
294
			return 1;
295
		}
296
	}
297

  
298
	/*
299
	 * (non-Javadoc)
300
	 * @see org.gvsig.fmap.dal.coverage.store.RasterDataStore#getDataType()
301
	 */
302
	public int[] getDataType() {
303
		return list.get(0).getDataType();
304
	}
305

  
306
	/*
307
	 * (non-Javadoc)
308
	 * @see org.gvsig.fmap.dal.coverage.store.RasterDataStore#getDataStoreCount()
309
	 */
310
	public int getDataStoreCount() {
311
		return list.get(0).getDataStoreCount();
312
	}
313

  
314
	/*
315
	 * (non-Javadoc)
316
	 * @see org.gvsig.fmap.dal.coverage.store.RasterDataStore#getFileSize()
317
	 */
318
	public long getFileSize() {
319
		long size = 0;
320
		for (int i = 0; i < list.size(); i++) {
321
			size += list.get(i).getFileSize();
322
		}
323
		return size;
324
	}
325

  
326
	/**
327
	 * Obtiene el dataset cuyas coordenadas contienen el punto pasado por par?meto
328
	 * @param x Coordenada X a comprobar
329
	 * @param y Coordenada Y a comprobar
330
	 * @return Point2D Posici?n del MultiRasterDataset dentro del mosaico
331
	 */
332
	public int getDatasetByCoords(double x, double y) {
333
		RasterUtils util = RasterLocator.getManager().getRasterUtils();
334
		for (int i = 0; i < list.size(); i++) {
335
			if(util.isInside(new Point2D.Double(x, y), list.get(i).getExtent(), list.get(i).getAffineTransform()))
336
				return i;
337
		}
338
		return -1;
339
	}
340

  
341
	/**
342
	 * Obtiene la lista de datasets del mosaico que intersectan con el extent proporcionado
343
	 * @param ulx Coordenada X superior izquierda
344
	 * @param uly Coordenada Y superior izquierda
345
	 * @param lrx Coordenada X inferior derecha
346
	 * @param lry Coordenada Y inferior derecha
347
	 * @return QueryableRaster[][][]
348
	 * @throws NoninvertibleTransformException
349
	 */
350
	private ArrayList<QueryableRaster> getDatasetListInArea(double ulx, double uly, double lrx, double lry) throws NoninvertibleTransformException {
351
		RasterUtils util = RasterLocator.getManager().getRasterUtils();
352

  
353
		ArrayList<QueryableRaster> result = new ArrayList<QueryableRaster>();
354

  
355
		for (int i = 0; i < list.size(); i++) {
356
			if(util.intersects(new ExtentImpl(ulx, uly, lrx, lry), list.get(i).getExtent(), list.get(i).getAffineTransform()))
357
				result.add((QueryableRaster)list.get(i));
358
		}
359
		return result;
360
	}
361

  
362
	/*
363
	 * (non-Javadoc)
364
	 * @see org.gvsig.fmap.dal.coverage.store.RasterDataStore#isInside(java.awt.geom.Point2D)
365
	 */
366
	public boolean isInside(Point2D p) {
367
		return RasterLocator.getManager().getRasterUtils().isInside(p, getExtent(), getAffineTransform());
368
	}
369

  
370
	/*
371
	 * (non-Javadoc)
372
	 * @see org.gvsig.fmap.dal.coverage.store.RasterDataStore#rasterToWorld(java.awt.geom.Point2D)
373
	 */
374
	public Point2D rasterToWorld(Point2D pt) {
375
		Point2D p = new Point2D.Double();
376
		getAffineTransform().transform(pt, p);
377
		return p;
378
	}
379

  
380
	/*
381
	 * (non-Javadoc)
382
	 * @see org.gvsig.fmap.dal.coverage.store.RasterDataStore#worldToRaster(java.awt.geom.Point2D)
383
	 */
384
	public Point2D worldToRaster(Point2D pt) {
385
		Point2D p = new Point2D.Double();
386
		try {
387
			getAffineTransform().inverseTransform(pt, p);
388
		} catch (NoninvertibleTransformException e) {
389
			return pt;
390
		}
391
		return p;
392
	}
393

  
394
	/*
395
	 * (non-Javadoc)
396
	 * @see org.gvsig.fmap.dal.coverage.store.RasterDataStore#isRotated()
397
	 */
398
	public boolean isRotated() {
399
		if(getAffineTransform().getShearX() != 0 || getAffineTransform().getShearY() != 0)
400
			return true;
401
		return false;
402
	}
403

  
404
	/*
405
	 * (non-Javadoc)
406
	 * @see org.gvsig.fmap.dal.coverage.store.RasterDataStore#isGeoreferenced()
407
	 */
408
	public boolean isGeoreferenced() {
409
		//Este tipo de datasets siempre est? georreferenciado
410
		return true;
411
	}
412

  
413
	/*
414
	 * (non-Javadoc)
415
	 * @see org.gvsig.fmap.dal.coverage.store.RasterDataStore#getBands()
416
	 */
417
	public BandList getBands() {
418
		return bandList;
419
	}
420

  
421
	/**
422
	 * Copia un tile en el buffer que contendr? todos los tiles
423
	 * @param origin Buffer de origen
424
	 * @param dest Buffer de destino
425
	 * @param col Columna del buffer de destino donde se empieza a escribir
426
	 * @param row Fila del buffer de destino donde se empieza a escribir
427
	 * @return array con los valores que representan la ?ltima fila y
428
	 * ?ltima columna que se escribieron
429
	 */
430
	@SuppressWarnings("unused")
431
	private void copyTile(Buffer origin, Buffer dest, int r, int c) {
432
		switch(origin.getDataType()) {
433
		case Buffer.TYPE_BYTE :
434
			for (int band = 0; band < origin.getBandCount(); band++)
435
				for (int row = 0; row < origin.getHeight(); row++)
436
					for (int col = 0; col < origin.getWidth(); col++)
437
						try {
438
								dest.setElem(row + r, col + c, band, origin.getElemByte(row, col, band));
439
							} catch (ArrayIndexOutOfBoundsException e) {break;}
440
			break;
441
		case Buffer.TYPE_SHORT :
442
			for (int band = 0; band < origin.getBandCount(); band++)
443
				for (int row = 0; row < origin.getHeight(); row++)
444
					for (int col = 0; col < origin.getWidth(); col++)
445
						try {
446
								dest.setElem(row + r, col + c, band, origin.getElemShort(row, col, band));
447
							} catch (ArrayIndexOutOfBoundsException e) {break;}
448
			break;
449
		case Buffer.TYPE_FLOAT :
450
			for (int band = 0; band < origin.getBandCount(); band++)
451
				for (int row = 0; row < origin.getHeight(); row++)
452
					for (int col = 0; col < origin.getWidth(); col++)
453
						try {
454
								dest.setElem(row + r, col + c, band, origin.getElemFloat(row, col, band));
455
							} catch (ArrayIndexOutOfBoundsException e) {break;}
456
			break;
457
		case Buffer.TYPE_DOUBLE:
458
			for (int band = 0; band < origin.getBandCount(); band++)
459
				for (int row = 0; row < origin.getHeight(); row++)
460
					for (int col = 0; col < origin.getWidth(); col++)
461
						try {
462
								dest.setElem(row + r, col + c, band, origin.getElemDouble(row, col, band));
463
							} catch (ArrayIndexOutOfBoundsException e) {break;}
464
			break;
465
		}
466
	}
467

  
468
	/*
469
	 * (non-Javadoc)
470
	 * @see org.gvsig.raster.dataset.IRasterDataSource#getWindowRaster(double, double, double, double)
471
	 */
472
	public Buffer getWindowRaster(double ulx, double uly, double lrx, double lry)
473
		throws InvalidSetViewException, ProcessInterruptedException, RasterDriverException {
474
		try {
475
			Point2D p1 = new Point2D.Double(ulx, uly);
476
			Point2D p2 = new Point2D.Double(lrx, lry);
477
			
478
			//Para el valor mayor redondeamos por arriba. Para el valor menor redondeamos por abajo.
479
			double p1X = (p1.getX() > p2.getX()) ? Math.ceil(p1.getX()) : Math.floor(p1.getX());
480
			double p1Y = (p1.getY() > p2.getY()) ? Math.ceil(p1.getY()) : Math.floor(p1.getY());
481
			double p2X = (p2.getX() > p1.getX()) ? Math.ceil(p2.getX()) : Math.floor(p2.getX());
482
			double p2Y = (p2.getY() > p1.getY()) ? Math.ceil(p2.getY()) : Math.floor(p2.getY());
483

  
484
			int width = (int)Math.abs(p1X - p2X);
485
			int height = (int)Math.abs(p1Y - p2Y);
486

  
487
			//Ajustamos por si nos hemos salido del raster
488
			if(((int)(Math.min(p1X, p2X) + width)) > getWidth())
489
				width = (int)(getWidth() - Math.min(p1X, p2X));
490
			if(((int)(Math.min(p1Y, p2Y) + height)) > getHeight())
491
				height = (int)(getHeight() - Math.min(p1Y, p2Y));
492
			
493
			ArrayList<QueryableRaster> datasetList = getDatasetListInArea(p1.getX(), p1.getY(), p2.getX(), p2.getY());
494
			Buffer endBuffer = DefaultRasterManager.getInstance().createBuffer(getDataType()[0], width, height, bandList.getDrawableBandsCount(), true);
495
			
496
			for (int i = 0; i < list.size(); i++) {
497
				Extent e = datasetList.get(i).adjustToExtent(new ExtentImpl(ulx, uly, lrx, lry));
498
				Buffer buf = datasetList.get(i).getWindowRaster(e.getULX(), e.getULY(), e.getLRX(), e.getLRY());
499
				Point2D pa = datasetList.get(i).worldToRaster(new Point2D.Double(e.getULX(), e.getULY()));
500
				double ulPixX = (ulx * pa.getX()) / e.getULX();
501
				double ulPixY = (uly * pa.getY()) / e.getULY();
502
				copyBuffer(buf, endBuffer, pa, new Point2D.Double(ulPixX, ulPixY), buf.getWidth(), buf.getHeight());
503
				buf.free();
504
			}
505
			return endBuffer;
506
		} catch (NoninvertibleTransformException e) {
507
			throw new InvalidSetViewException("No se ha podido aplicar la transformaci?n inversa para esa vista.");
508
		}
509
	}
510

  
511
	/*
512
	 * (non-Javadoc)
513
	 * @see org.gvsig.raster.impl.dataset.QueryableRaster#getWindowRaster(double, double, double, double, boolean)
514
	 */
515
	public Buffer getWindowRaster(double ulx, double uly, double w, double h, boolean adjustToExtent)
516
		throws InvalidSetViewException, RasterDriverException {
517
		//TODO: FUNCIONALIDAD: getWindowRaster en CompositeDataset sin implementar
518
		return null;
519
	}
520

  
521
	private void copyBuffer(Buffer orBuf, Buffer dstBuf, Point2D orUL, Point2D dstUL, int width, int height) {
522
		if(getDataType()[0] == Buffer.TYPE_BYTE) {
523
			for (int iBand = 0; iBand < getBandCount(); iBand++) {
524
				for (int j = 0; j < height; j++) {
525
					for (int i = 0; i < width; i++) {
526
						dstBuf.setElem((int)(dstUL.getY() + j), (int)(dstUL.getX() + i), iBand, 
527
								orBuf.getElemByte((int)orUL.getY() + j, (int)orUL.getX() + i, iBand));
528
					}
529
				}
530
			}
531

  
532
		}
533
		if(getDataType()[0] == Buffer.TYPE_SHORT) {
534
			for (int iBand = 0; iBand < getBandCount(); iBand++) {
535
				for (int j = 0; j < height; j++) {
536
					for (int i = 0; i < width; i++) {
537
						dstBuf.setElem((int)(dstUL.getY() + j), (int)(dstUL.getX() + i), iBand, 
538
								orBuf.getElemShort((int)orUL.getY() + j, (int)orUL.getX() + i, iBand));
539
					}
540
				}
541
			}
542

  
543
		}
544
		if(getDataType()[0] == Buffer.TYPE_INT) {
545
			for (int iBand = 0; iBand < getBandCount(); iBand++) {
546
				for (int j = 0; j < height; j++) {
547
					for (int i = 0; i < width; i++) {
548
						dstBuf.setElem((int)(dstUL.getY() + j), (int)(dstUL.getX() + i), iBand, 
549
								orBuf.getElemInt((int)orUL.getY() + j, (int)orUL.getX() + i, iBand));
550
					}
551
				}
552
			}
553

  
554
		}
555
		if(getDataType()[0] == Buffer.TYPE_FLOAT) {
556
			for (int iBand = 0; iBand < getBandCount(); iBand++) {
557
				for (int j = 0; j < height; j++) {
558
					for (int i = 0; i < width; i++) {
559
						dstBuf.setElem((int)(dstUL.getY() + j), (int)(dstUL.getX() + i), iBand, 
560
								orBuf.getElemFloat((int)orUL.getY() + j, (int)orUL.getX() + i, iBand));
561
					}
562
				}
563
			}
564

  
565
		}
566
		if(getDataType()[0] == Buffer.TYPE_DOUBLE) {
567
			for (int iBand = 0; iBand < getBandCount(); iBand++) {
568
				for (int j = 0; j < height; j++) {
569
					for (int i = 0; i < width; i++) {
570
						dstBuf.setElem((int)(dstUL.getY() + j), (int)(dstUL.getX() + i), iBand, 
571
								orBuf.getElemDouble((int)orUL.getY() + j, (int)orUL.getX() + i, iBand));
572
					}
573
				}
574
			}
575

  
576
		}
577
	}
578

  
579
	/*
580
	 * (non-Javadoc)
581
	 * @see org.gvsig.raster.dataset.IRasterDataSource#getWindowRaster(double, double, double, double, int, int, boolean)
582
	 */
583
	public Buffer getWindowRaster(double ulx, double uly, double lrx, double lry, int bufWidth, int bufHeight, boolean adjustToExtent)
584
		throws InvalidSetViewException, ProcessInterruptedException, RasterDriverException {
585
		try {
586
			Point2D p1 = new Point2D.Double(ulx, uly);
587
			Point2D p2 = new Point2D.Double(lrx, lry);
588
			ArrayList<QueryableRaster> datasetList = getDatasetListInArea(p1.getX(), p1.getY(), p2.getX(), p2.getY());
589
			Buffer endBuffer = DefaultRasterManager.getInstance().createBuffer(getDataType()[0], bufWidth, bufHeight, bandList.getDrawableBandsCount(), true);
590
			
591
			for (int i = 0; i < list.size(); i++) {
592
				Extent e = datasetList.get(i).adjustToExtent(new ExtentImpl(ulx, uly, lrx, lry));
593
				int w = (int)Math.ceil((e.width() * bufWidth) / (Math.abs(lrx - ulx)));
594
				int h = (int)Math.ceil((e.height() * bufHeight) / (Math.abs(lry - uly)));
595
				Buffer buf = datasetList.get(i).getWindowRaster(e.getULX(), e.getULY(), e.getLRX(), e.getLRY(), w, h, true);
596
				Point2D pa = datasetList.get(i).worldToRaster(new Point2D.Double(e.getULX(), e.getULY()));
597
				double ulPixX = (ulx * pa.getX()) / e.getULX();
598
				double ulPixY = (uly * pa.getY()) / e.getULY();
599
				copyBuffer(buf, endBuffer, pa, new Point2D.Double(ulPixX, ulPixY), w, h);
600
				buf.free();
601
			}
602
			
603
			return endBuffer;
604
		} catch (NoninvertibleTransformException e) {
605
			throw new InvalidSetViewException("No se ha podido aplicar la transformaci?n inversa para esa vista.");
606
		}
607
	}
608

  
609
	/*
610
	 * (non-Javadoc)
611
	 * @see org.gvsig.raster.dataset.IRasterDataSource#getWindowRaster(int, int, int, int)
612
	 */
613
	public Buffer getWindowRaster(int x, int y, int w, int h)
614
		throws InvalidSetViewException, ProcessInterruptedException, RasterDriverException {
615
		return null;
616
	}
617

  
618
	/*
619
	 * (non-Javadoc)
620
	 * @see org.gvsig.raster.dataset.IRasterDataSource#getWindowRaster(int, int, int, int, int, int)
621
	 */
622
	public Buffer getWindowRaster(int x, int y, int w, int h, int bufWidth, int bufHeight)
623
		throws InvalidSetViewException, ProcessInterruptedException, RasterDriverException {
624
		return null;
625
	}
626
	
627
	/*
628
	 * (non-Javadoc)
629
	 * @see org.gvsig.fmap.dal.coverage.dataset.RasterDataSet#getPixelSizeX()
630
	 */
631
	public double getPixelSizeX() {
632
		if(list == null || list.size() <= 0)
633
			return 0;
634
		return list.get(0).getPixelSizeX();
635
	}
636

  
637
	/*
638
	 * (non-Javadoc)
639
	 * @see org.gvsig.fmap.dal.coverage.dataset.RasterDataSet#getPixelSizeY()
640
	 */
641
	public double getPixelSizeY() {
642
		if(list == null || list.size() <= 0)
643
			return 0;
644
		return list.get(0).getPixelSizeY();
645
	}
646

  
647
	/*
648
	 * (non-Javadoc)
649
	 * @see org.gvsig.raster.impl.store.QueryableRaster#setDrawableBands(int[])
650
	 */
651
	public void setDrawableBands(int[] db) {
652
		for (int i = 0; i < list.size(); i++) {
653
			((QueryableRaster)list.get(i)).setDrawableBands(db);
654
		}
655
	}
656

  
657
	/*
658
	 * (non-Javadoc)
659
	 * @see org.gvsig.raster.impl.dataset.QueryableRaster#clearDrawableBands()
660
	 */
661
	public void clearDrawableBands() {
662
		for (int i = 0; i < list.size(); i++) {
663
			((QueryableRaster)list.get(i)).clearDrawableBands();
664
		}
665
	}
666

  
667
	/*
668
	 * (non-Javadoc)
669
	 * @see org.gvsig.raster.impl.store.QueryableRaster#addDrawableBand(int, int)
670
	 */
671
	public void addDrawableBand(int posRasterBuf, int imageBand) {
672
		for (int i = 0; i < list.size(); i++) {
673
			((QueryableRaster)list.get(i)).addDrawableBand(posRasterBuf, imageBand);
674
		}
675
	}
676

  
677
	/*
678
	 * (non-Javadoc)
679
	 * @see org.gvsig.fmap.dal.coverage.store.RasterDataStore#getTransparency()
680
	 */
681
	public Transparency getTransparency() {
682
		if(list != null && list.size() > 0)
683
			return list.get(0).getTransparency();
684
		return new DataStoreTransparency();
685
	}
686

  
687
	/*
688
	 * (non-Javadoc)
689
	 * @see org.gvsig.fmap.dal.coverage.store.RasterDataStore#getColorTable()
690
	 */
691
	public ColorTable getColorTable() {
692
		if(list != null && list.size() > 0)
693
			return list.get(0).getColorTable();
694
		return null;
695
	}
696

  
697
	/*
698
	 * (non-Javadoc)
699
	 * @see org.gvsig.fmap.dal.coverage.store.RasterDataStore#getHistogram()
700
	 */
701
	public Histogram getHistogram() throws HistogramException {
702
		percent = 0;
703
		Histogram[] histogram = new Histogram[list.size()];
704
		double parc = 100 / (double)(list.size());
705
		int cont = 0;
706
		for (int i = 0; i < list.size(); i++) {
707
			histogram[cont] = list.get(i).getHistogram();
708
			percent += cont * parc; 
709
			cont ++;
710
		}
711
		MosaicDataStoreHistogram histRes = new MosaicDataStoreHistogram(histogram, this);
712
		return histRes;
713
	}
714

  
715
	/*
716
	 * (non-Javadoc)
717
	 * @see org.gvsig.raster.impl.store.QueryableRaster#getColorTable(int)
718
	 */
719
	public ColorTable getColorTable(int i){
720
		return (list != null && list.size() > 0) ? ((QueryableRaster)list.get(0)).getColorTable(i) : null;
721
	}
722

  
723
	/*
724
	 * (non-Javadoc)
725
	 * @see org.gvsig.raster.impl.store.QueryableRaster#getColorTable(java.lang.String)
726
	 */
727
	public ColorTable getColorTable(String fileName){
728
		return (list != null && list.size() > 0) ? ((QueryableRaster)list.get(0)).getColorTable(fileName) : null;
729
	}
730

  
731
	/*
732
	 * (non-Javadoc)
733
	 * @see org.gvsig.raster.dataset.MultiRasterStore#getData(int, int, int)
734
	 */
735
	public Object getData(int x, int y, int band) throws InvalidSetViewException, FileNotOpenException, RasterDriverException {
736
		return null;
737
	}
738

  
739
	/*
740
	 * (non-Javadoc)
741
	 * @see org.gvsig.raster.dataset.IRasterDataSource#isReadOnly()
742
	 */
743
	public boolean isReadOnly() {
744
		return readOnly;
745
	}
746

  
747
	/*
748
	 * (non-Javadoc)
749
	 * @see org.gvsig.raster.dataset.IRasterDataSource#setReadOnly(boolean)
750
	 */
751
	public void setReadOnly(boolean readOnly) {
752
		this.readOnly = readOnly;
753
	}
754

  
755
	/*
756
	 * (non-Javadoc)
757
	 * @see org.gvsig.raster.dataset.IRasterDataSource#isMemoryBuffer()
758
	 */
759
	public boolean isMemoryBuffer() {
760
		return forceToMemory;
761
	}
762

  
763
	/*
764
	 * (non-Javadoc)
765
	 * @see org.gvsig.raster.impl.store.QueryableRaster#setMemoryBuffer(boolean)
766
	 */
767
	public void setMemoryBuffer(boolean memory) {
768
		this.forceToMemory = memory;
769
		if(memory)
770
			this.readOnly = false;
771
	}
772

  
773
	/*
774
	 * (non-Javadoc)
775
	 * @see org.gvsig.raster.dataset.RasterDataset#getOverviewCount(int)
776
	 */
777
	public int getOverviewCount(int band) throws BandAccessException, RasterDriverException {
778
		if(band >= getBandCount())
779
			throw new BandAccessException("Wrong band");
780
		return 0;
781
	}
782

  
783
	/*
784
	 * (non-Javadoc)
785
	 * @see org.gvsig.fmap.dal.coverage.store.RasterDataStore#overviewsSupport()
786
	 */
787
	public boolean overviewsSupport() {
788
		return false;
789
	}
790
	
791
	/*
792
	 * (non-Javadoc)
793
	 * @see org.gvsig.fmap.dal.coverage.store.RasterDataStore#getOverviewWidth(int, int)
794
	 */
795
	public int getOverviewWidth(int band, int overview) throws BandAccessException, RasterDriverException {
796
		if(list == null || list.size() <= 0)
797
			return 0;
798
		int[] providerBand = ((DefaultMultiRasterStore)list.get(0)).getProviderFromBandNumber(band);
799
		RasterProvider prov = ((DefaultMultiRasterStore)list.get(0)).getProvider(providerBand[0]);
800
		return prov.getOverviewWidth(providerBand[1], overview);
801
	}
802

  
803
	/*
804
	 * (non-Javadoc)
805
	 * @see org.gvsig.fmap.dal.coverage.store.RasterDataStore#getOverviewHeight(int, int)
806
	 */
807
	public int getOverviewHeight(int band, int overview) throws BandAccessException, RasterDriverException {
808
		if(list == null || list.size() <= 0)
809
			return 0;
810
		int[] providerBand = ((DefaultMultiRasterStore)list.get(0)).getProviderFromBandNumber(band);
811
		RasterProvider prov = ((DefaultMultiRasterStore)list.get(0)).getProvider(providerBand[0]);
812
		return prov.getOverviewHeight(providerBand[1], overview);
813
	}
814

  
815
	/*
816
	 * (non-Javadoc)
817
	 * @see org.gvsig.fmap.dal.coverage.store.RasterDataStore#getNoDataValue()
818
	 */
819
	public double getNoDataValue() {
820
		if (list.size() <= 0)
821
			return RasterLibrary.defaultNoDataValue;
822
		return list.get(0).getNoDataValue();
823
	}
824

  
825
	/*
826
	 * (non-Javadoc)
827
	 * @see org.gvsig.fmap.dal.coverage.store.RasterDataStore#resetNoDataValue()
828
	 */
829
	public void resetNoDataValue() {
830
		for (int i = 0; i < list.size(); i++) {
831
			list.get(i).resetNoDataValue();
832
		}
833
	}
834

  
835
	/*
836
	 * (non-Javadoc)
837
	 * @see org.gvsig.fmap.dal.coverage.store.RasterDataStore#setNoDataValue(double)
838
	 */
839
	public void setNoDataValue(double value) {
840
		for (int i = 0; i < list.size(); i++) {
841
			list.get(i).setNoDataValue(value);
842
		}
843
	}
844

  
845
	/*
846
	 * (non-Javadoc)
847
	 * @see org.gvsig.fmap.dal.coverage.store.RasterDataStore#isNoDataEnabled()
848
	 */
849
	public boolean isNoDataEnabled() {
850
		return list.get(0).isNoDataEnabled();
851
	}
852

  
853
	/*
854
	 * (non-Javadoc)
855
	 * @see org.gvsig.fmap.dal.coverage.store.RasterDataStore#setNoDataEnabled(boolean)
856
	 */
857
	public void setNoDataEnabled(boolean enabled) {
858
		for (int i = 0; i < list.size(); i++) {
859
			list.get(i).setNoDataEnabled(enabled);
860
		}
861
	}
862

  
863
	/*
864
	 * (non-Javadoc)
865
	 * @see org.gvsig.raster.impl.store.QueryableRaster#getDataStore()
866
	 */
867
	public RasterDataStore getDataStore() {
868
		return this;
869
	}
870
	
871
	/*
872
	 * (non-Javadoc)
873
	 * @see org.gvsig.fmap.dal.coverage.store.RasterDataStore#getProjection()
874
	 */
875
	public IProjection getProjection() {
876
		if(list == null && list.size() <= 0)
877
			return null;
878
		return list.get(0).getProjection();
879
	}
880
	
881
	/*
882
	 * (non-Javadoc)
883
	 * @see org.gvsig.fmap.dal.coverage.store.RasterDataStore#getView()
884
	 */
885
	public Extent getView() {
886
		//TODO:Sin implementar
887
		return null;
888
	}
889
	
890
	/*
891
	 * (non-Javadoc)
892
	 * @see org.gvsig.fmap.dal.coverage.store.RasterDataStore#getExtentWithoutRot()
893
	 */
894
	public Extent getExtentWithoutRot() {
895
		//TODO:Sin implementar
896
		return null;
897
	}
898
	
899
	/*
900
	 * (non-Javadoc)
901
	 * @see org.gvsig.fmap.dal.coverage.store.RasterDataStore#getMetadata()
902
	 */
903
	public Metadata getMetadata() {
904
		//TODO:Sin implementar
905
		return null;
906
	}
907
	
908
	/*
909
	 * (non-Javadoc)
910
	 * @see org.gvsig.fmap.dal.coverage.dataset.RasterDataSet#getWktProjection()
911
	 */
912
	public String getWktProjection() throws RasterDriverException {
913
		return null;
914
	}
915

  
916
	/*
917
	 * (non-Javadoc)
918
	 * @see org.gvsig.fmap.dal.coverage.dataset.RasterDataSet#getColorInterpretation()
919
	 */
920
	public DataStoreColorInterpretation getColorInterpretation() {
921
		return null;
922
	}
923
	
924
	/*
925
	 * (non-Javadoc)
926
	 * @see org.gvsig.fmap.dal.coverage.dataset.RasterDataSet#getStatistics()
927
	 */
928
	public Statistics getStatistics() {
929
		return stats;
930
	}
931
	
932
	/*
933
	 * (non-Javadoc)
934
	 * @see org.gvsig.fmap.dal.coverage.store.MosaicRasterStore#getTile(int)
935
	 */
936
	public RasterDataStore getTile(int i) {
937
		return (RasterDataStore)list.get(i);
938
	}
939
	
940
	/*
941
	 * (non-Javadoc)
942
	 * @see org.gvsig.fmap.dal.coverage.store.MosaicRasterStore#getNumberOfTiles()
943
	 */
944
	public int getNumberOfTiles() {
945
		return list.size();
946
	}
947
	
948
	/*
949
	 * (non-Javadoc)
950
	 * @see org.gvsig.fmap.dal.coverage.store.RasterDataStore#isReproyectable()
... This diff was truncated because it exceeds the maximum size that can be displayed.

Also available in: Unified diff