Revision 4181 org.gvsig.raster.wms/trunk/org.gvsig.raster.wms/org.gvsig.raster.wms.io/src/main/java/org/gvsig/raster/wms/io/WMSProvider.java

View differences:

WMSProvider.java
28 28
import java.awt.geom.Rectangle2D;
29 29
import java.io.File;
30 30
import java.io.IOException;
31
import java.net.URI;
32
import java.net.URISyntaxException;
31 33
import java.net.URL;
32 34
import java.util.Hashtable;
33 35
import java.util.List;
......
35 37

  
36 38
import javax.swing.ImageIcon;
37 39

  
40
import org.apache.commons.io.FilenameUtils;
38 41
import org.cresques.cts.ICoordTrans;
39 42
import org.cresques.cts.IProjection;
43

  
40 44
import org.gvsig.compat.net.ICancellable;
41 45
import org.gvsig.fmap.crs.CRSFactory;
42 46
import org.gvsig.fmap.dal.DALLocator;
......
51 55
import org.gvsig.fmap.dal.coverage.exception.FileNotOpenException;
52 56
import org.gvsig.fmap.dal.coverage.exception.InfoByPointException;
53 57
import org.gvsig.fmap.dal.coverage.exception.InvalidSetViewException;
58
import org.gvsig.fmap.dal.coverage.exception.InvalidSourceException;
54 59
import org.gvsig.fmap.dal.coverage.exception.NotSupportedExtensionException;
55 60
import org.gvsig.fmap.dal.coverage.exception.ProcessInterruptedException;
56 61
import org.gvsig.fmap.dal.coverage.exception.QueryException;
......
61 66
import org.gvsig.fmap.dal.coverage.store.props.HistogramComputer;
62 67
import org.gvsig.fmap.dal.coverage.store.props.Transparency;
63 68
import org.gvsig.fmap.dal.exception.InitializeException;
69
import org.gvsig.fmap.dal.exception.OpenException;
64 70
import org.gvsig.fmap.dal.exception.ProviderNotRegisteredException;
65 71
import org.gvsig.fmap.dal.spi.DataManagerProviderServices;
66 72
import org.gvsig.fmap.dal.spi.DataStoreProviderServices;
......
83 89
import org.gvsig.remoteclient.utils.Utilities;
84 90
import org.gvsig.remoteclient.wms.WMSStatus;
85 91
import org.gvsig.tools.ToolsLocator;
92

  
86 93
import org.slf4j.Logger;
87 94
import org.slf4j.LoggerFactory;
88 95
/**
......
97 104
	private static final Logger         logger                    = LoggerFactory.getLogger(WMSProvider.class);
98 105
	private static final int            FIXED_SIZE               = 800;
99 106
	private Extent                      viewRequest              = null;
100
	private static Hashtable<String, WMSConnector>    
107
	private static Hashtable<String, WMSConnector>
101 108
	                                    drivers                  = new Hashtable<String, WMSConnector> ();
102 109
	private boolean                     open                     = false;
103 110
	private DataStoreTransparency       fileTransparency         = null;
......
110 117
	private File                        fileLayerPixelSize       = null;
111 118
	private File                        lastRequest              = null;
112 119
	private AbstractRasterProvider       lastRequestProvider      = null;
113
	
120

  
114 121
	public static void register() {
115 122
		DataManagerProviderServices dataman = (DataManagerProviderServices) DALLocator.getDataManager();
116 123
		if (dataman != null && !dataman.getStoreProviders().contains(NAME)) {
......
123 130
		}
124 131
		dataman.registerStoreFactory(NAME, DefaultStoreFactory.class);
125 132
	}
126
	
133

  
127 134
	public WMSProvider() throws NotSupportedExtensionException {
128 135
		super();
129 136
	}
130
	
137

  
131 138
	public void registerTileProviderFormats(Class<RasterProvider> c) {
132 139

  
133 140
	}
134
	
141

  
135 142
	/**
136 143
	 * Constructor. Abre el dataset.
137 144
	 * @param proj Proyecci?n
138 145
	 * @param fName Nombre del fichero
146
	 * @throws OpenException
139 147
	 * @throws NotSupportedExtensionException
148
     * @deprecated use {@link #WMSProvider(URI)}, this constructor will be removed in gvSIG 2.5
140 149
	 */
141
	public WMSProvider(String params) throws InitializeException {
142
		super(params);
143
		if(params instanceof String) {
144
			WMSDataParameters p = new WMSDataParametersImpl();
145
			p.setURI((String)params);
146
			super.init(p, null, ToolsLocator.getDynObjectManager()
147
					.createDynObject(
148
							MetadataLocator.getMetadataManager().getDefinition(
149
									DataStore.METADATA_DEFINITION_NAME)));
150
			init(p, null);
151
		}
152
	}
153
	
150
    public WMSProvider(String params) throws InitializeException, OpenException {
151
        super(params);
152
        logger.info("Deprecated use of WMSProvider constructor");
153
        if (params instanceof String) {
154
            WMSDataParameters p = new WMSDataParametersImpl();
155
            try {
156
                p.setURI(new URI((String) params));
157
            } catch (URISyntaxException e) {
158
                throw new OpenException("Can't create URI from" + (String) params, e);
159
            }
160
            super.init(
161
                p,
162
                null,
163
                ToolsLocator.getDynObjectManager().createDynObject(
164
                    MetadataLocator.getMetadataManager().getDefinition(DataStore.METADATA_DEFINITION_NAME)));
165
            init(p, null);
166
        }
167
    }
168

  
169
    /**
170
     * Constructor. Abre el dataset.
171
     * @param fName Nombre del fichero
172
     * @throws OpenException
173
     * @throws NotSupportedExtensionException
174
     * @deprecated use {@link #WMSProvider(URI)}, this constructor will be removed in gvSIG 2.5
175
     */
176
    public WMSProvider(URI uri) throws InitializeException {
177
        super(uri);
178
        logger.info("Deprecated use of ErmapperProvider constructor");
179
        WMSDataParameters p = new WMSDataParametersImpl();
180
        p.setURI(uri);
181
        super.init(
182
            p,
183
            null,
184
            ToolsLocator.getDynObjectManager().createDynObject(
185
                MetadataLocator.getMetadataManager().getDefinition(DataStore.METADATA_DEFINITION_NAME)));
186
        init(p, null);
187
    }
188

  
154 189
	public WMSProvider(WMSDataParameters params,
155 190
			DataStoreProviderServices storeServices) throws InitializeException {
156 191
		super(params, storeServices, ToolsLocator.getDynObjectManager()
......
159 194
								DataStore.METADATA_DEFINITION_NAME)));
160 195
		init(params, storeServices);
161 196
	}
162
	
197

  
163 198
	/**
164 199
	 * Gets the connector from the URL
165 200
	 * @return
......
169 204
		WMSDataParameters p = (WMSDataParameters)parameters;
170 205
		URL url = null;
171 206
		try {
172
			url = new URL(p.getURI());
207
			url =p.getURI().toURL();
173 208
		} catch (Exception e) {
174 209
			throw new RemoteServiceException("Malformed URL",e);
175 210
		}
......
179 214
			throw new RemoteServiceException("Error getting the connector",e);
180 215
		}
181 216
	}
182
	
217

  
183 218
	/**
184 219
	 * Crea las referencias al fichero y carga
185 220
	 * las estructuras con la informaci?n y los metadatos.
......
199 234
			throw new InitializeException(e.getMessage(), e);
200 235
		}
201 236
	}
202
	
237

  
203 238
	/**
204
	 * When a WMS provider is opened the information of data type, number of bands and transparency 
239
	 * When a WMS provider is opened the information of data type, number of bands and transparency
205 240
	 * is not available. Only after the first time a raster has been downloaded it can be know.
206 241
	 * @param newDataType
207 242
	 * @param buf
208 243
	 * @param bandList
209 244
	 * @return
210
	 * @throws RasterDriverException 
245
	 * @throws RasterDriverException
211 246
	 */
212 247
	private void loadInitialInfo() throws RasterDriverException {
213 248
		WMSDataParametersImpl p = (WMSDataParametersImpl)parameters;
......
233 268
			}
234 269
		}
235 270
		WMSStatus wmsStatus = loadWMSStatus(bBox);
236
		
271

  
237 272
		lastRequest = downloadFile(wmsStatus, ext.getULX(), ext.getULY(), ext.getLRX(), ext.getLRY(), w, h);
238 273
		AbstractRasterProvider driver;
239 274
		try {
......
252 287
			throw new RasterDriverException("", e);
253 288
		}
254 289
	}
255
	
290

  
256 291
	public static final WMSConnector getConnectorFromURL(URL url, boolean updating) throws IOException {
257 292
		WMSConnector drv = null;
258 293
		if(!updating) {
......
261 296
			if(drivers.get(url.toString()) != null)
262 297
				drivers.remove(url.toString());
263 298
		}
264
		
299

  
265 300
		if (drv == null) {
266 301
			drv = new WMSConnector(url);
267 302
			drivers.put(url.toString(), drv);
268 303
		}
269
		
304

  
270 305
		return drv;
271 306
	}
272
	
307

  
273 308
	/**
274 309
	 * Obtiene el objeto que contiene que contiene la interpretaci?n de
275 310
	 * color por banda
......
288 323
		}
289 324
		return super.getColorInterpretation();
290 325
	}
291
	
326

  
292 327
	public AffineTransform getAffineTransform() {
293 328
		WMSDataParameters p = (WMSDataParameters)parameters;
294 329
		if(p.isSizeFixed()) {
......
296 331
			double psX = e.width() / (p.getWidth() - 1);
297 332
			double psY = -(e.height() / (p.getHeight() - 1));
298 333
			ownTransformation = new AffineTransform(
299
					psX , 
300
					0, 
301
					0, 
302
					psY, 
334
					psX ,
335
					0,
336
					0,
337
					psY,
303 338
					e.getULX() - (psX / 2),
304 339
					e.getULY() - (psY / 2));
305 340
		} else {
......
307 342
			double psX = bbox.getWidth() / p.getWidth();
308 343
			double psY = -(bbox.getHeight() / p.getHeight());
309 344
			ownTransformation = new AffineTransform(
310
					psX, 
311
					0, 
312
					0, 
345
					psX,
346
					0,
347
					0,
313 348
					psY,
314 349
					bbox.getX(),
315 350
					(bbox.getY()+bbox.getHeight())); // FIXME: check for other CRSs such as 4326
......
317 352
		externalTransformation = (AffineTransform) ownTransformation.clone();
318 353
		return ownTransformation;
319 354
	}
320
	
355

  
321 356
	/**
322 357
	 * Calcula el extent en coordenadas del mundo real
323 358
	 * @return Extent
......
325 360
	public Extent getExtent() {
326 361
		WMSDataParameters p = (WMSDataParameters)parameters;
327 362
		Vector<?> layerNames = Utilities.createVector(p.getLayerQuery(), ",");
328
		
363

  
329 364
		String[] ln = new String[layerNames.size()];
330 365
		for (int i = 0; i < ln.length; i++) {
331 366
			ln[i] = (String)layerNames.get(i);
......
339 374
				if (r == null) {
340 375
					r = getConnector().getLayersExtent(ln, "CRS:84");
341 376
				}
342
				
377

  
343 378
				IProjection reqProj = CRSFactory.getCRS(p.getSRSCode());
344 379
				IProjection latLonProj = CRSFactory.getCRS(latLonID);
345 380
				if ((reqProj != null) && (latLonProj != null)) {
......
362 397
	public RasterProvider load() {
363 398
		return this;
364 399
	}
365
	
400

  
366 401
	public boolean isOpen() {
367 402
		return open;
368 403
	}
......
370 405
	public void close() {
371 406
		open = false;
372 407
	}
373
	
408

  
374 409
	public Transparency getTransparency() {
375 410
		if(fileTransparency == null)
376 411
			fileTransparency = new DataStoreTransparency(getColorInterpretation());
377 412
		return fileTransparency;
378 413
	}
379 414

  
380
	public String translateFileName(String fileName) {
381
		return fileName;
415
	public URI translateURI(URI uri) {
416
		return uri;
382 417
	}
383 418

  
384 419
	public void setView(Extent e) {
......
388 423
	public Extent getView() {
389 424
		return viewRequest;
390 425
	}
391
	
426

  
392 427
	public double getWidth() {
393 428
		WMSDataParameters p = (WMSDataParameters)parameters;
394 429
		return p.getWidth();
......
398 433
		WMSDataParameters p = (WMSDataParameters)parameters;
399 434
		return p.getHeight();
400 435
	}
401
	
436

  
402 437
	/**
403 438
	 * Gets WMS parameters
404 439
	 * @return
......
411 446
		throws InvalidSetViewException, FileNotOpenException, RasterDriverException {
412 447
		return null;
413 448
	}
414
	
449

  
415 450
	/**
416
	 * When the remote layer has fixed size this method downloads the file and return its reference. 
451
	 * When the remote layer has fixed size this method downloads the file and return its reference.
417 452
	 * File layer has in the long side FIXED_SIZE pixels and the bounding box is complete. This file could be
418 453
	 * useful to build an histogram or calculate statistics. This represents a sample of data.
419 454
	 * @return
......
422 457
	public File getFileLayer() throws RasterDriverException {
423 458
		if(fileLayerPixelSize != null)
424 459
			return fileLayerPixelSize;
425
		
460

  
426 461
		WMSDataParameters p = (WMSDataParameters)parameters;
427 462
		Extent e = getExtent();
428 463
		Rectangle2D bBox = new Rectangle2D.Double(e.getULX(), e.getLRY(), e.width(), e.height());
429 464
		WMSStatus wmsStatus = loadWMSStatus(bBox);
430
		
465

  
431 466
		if(!p.isSizeFixed()) {
432 467
			int w = 0;
433 468
			int h = 0;
......
442 477
			wmsStatus.setHeight(h);
443 478
			fileLayerPixelSize = downloadFile(wmsStatus, e.getULX(), e.getULY(), e.getLRX(), e.getLRY(), w, h);
444 479
		} else {
445
			fileLayerPixelSize = downloadFile(wmsStatus, e.getULX(), e.getULY(), e.getLRX(), e.getLRY(), 
480
			fileLayerPixelSize = downloadFile(wmsStatus, e.getULX(), e.getULY(), e.getLRX(), e.getLRY(),
446 481
					p.getFixedSize().width, p.getFixedSize().height);
447 482
		}
448 483
		return fileLayerPixelSize;
......
452 487
	 * Reads a complete block of data and returns an tridimensional array of the right type. This function is useful
453 488
	 * to read a file very fast without setting a view. In a WMS service when the size is fixed then it will read the
454 489
	 * entire image but when the source hasn't pixel size it will read a sample of data. This set of data will have
455
	 * the size defined in FIXED_SIZE. 
456
	 * 
490
	 * the size defined in FIXED_SIZE.
491
	 *
457 492
	 * @param pos Posici?n donde se empieza  a leer
458 493
	 * @param blockHeight Altura m?xima del bloque leido
459 494
	 * @return Object que es un array tridimendional del tipo de datos del raster. (Bandas X Filas X Columnas)
......
461 496
	 * @throws FileNotOpenException
462 497
	 * @throws RasterDriverException
463 498
	 */
464
	public Object readBlock(int pos, int blockHeight, double scale) 
499
	public Object readBlock(int pos, int blockHeight, double scale)
465 500
	throws InvalidSetViewException, FileNotOpenException, RasterDriverException, ProcessInterruptedException {
466 501
		File lastFile = getFileLayer();
467 502
		BandList bandList = new BandListImpl();
......
482 517
			throw new RasterDriverException("Error building GdalDriver", exc);
483 518
		}
484 519
	}
485
	
520

  
486 521
	public double getLastRequestHeight() throws RasterDriverException {
487 522
		if(lastRequestProvider == null) {
488 523
			try {
......
495 530
		}
496 531
		return lastRequestProvider.getHeight();
497 532
	}
498
	
533

  
499 534
	public double getLastRequestWidth() throws RasterDriverException {
500 535
		if(lastRequestProvider == null) {
501 536
			try {
......
508 543
		}
509 544
		return lastRequestProvider.getWidth();
510 545
	}
511
	
546

  
512 547
	public File getLastRequest() {
513 548
		return lastRequest;
514 549
	}
515
	
550

  
516 551
	public Buffer getBufferLastRequest() throws ProcessInterruptedException, RasterDriverException {
517 552
		try {
518 553
			lastRequestProvider = openLastRequest();
......
525 560
			throw new RasterDriverException("Error building GdalDriver", e);
526 561
		}
527 562
	}
528
	
563

  
529 564
	/**
530 565
	 * Opens the last request downloaded
531 566
	 * @return
......
546 581
		throws InvalidSetViewException, FileNotOpenException, RasterDriverException {
547 582
		return null;
548 583
	}
549
	
584

  
550 585
	/**
551 586
	 * Gets the georeferencing file name form a raster file
552 587
	 * @param file
......
554 589
	 * @return
555 590
	 * a georeferencing file
556 591
	 */
557
	private String getWorldFile(String file){		
592
	private String getWorldFile(String file){
558 593
		String worldFile = file;
559 594
		int index = file.lastIndexOf(".");
560
		if (index > 0){			
595
		if (index > 0){
561 596
			worldFile = file.substring(0, index) + getExtensionWorldFile();
562 597
		}
563 598
		return worldFile;
564 599
	}
565
	
600

  
566 601
	/**
567 602
	 * Obtiene la extensi?n del fichero de georreferenciaci?n
568 603
	 * @return String con la extensi?n del fichero de georreferenciaci?n dependiendo
......
576 611
		}
577 612
		return extWorldFile;
578 613
	}
579
	
614

  
580 615
	public WMSStatus loadWMSStatus(Rectangle2D bBox) {
581 616
		WMSDataParameters p = (WMSDataParameters)parameters;
582 617
		WMSStatus wmsStatus = new WMSStatus();
......
585 620
		wmsStatus.setFormat(p.getFormat());
586 621
		wmsStatus.setInfoFormat(p.getInfoFormat());
587 622
		List<RemoteWMSStyle> listStyles = p.getStyles();
588
		Vector<?> v = listStyles != null ? new Vector<RemoteWMSStyle>(listStyles) : null; 
623
		Vector<?> v = listStyles != null ? new Vector<RemoteWMSStyle>(listStyles) : null;
589 624
		wmsStatus.setStyles(v);
590 625
		wmsStatus.setDimensions(p.getDimensions());
591 626
		wmsStatus.setTransparency(p.isWmsTransparent());
......
602 637
			wmsStatus.setProjected(proj.isProjected());
603 638
		return wmsStatus;
604 639
	}
605
	
640

  
606 641
	/**
607 642
	 * This function downloads the file and creates the georeferencing file
608 643
	 * @param wmsStatus
......
622 657
		} catch (RemoteServiceException e) {
623 658
			throw new RasterDriverException(e.getMessage(), e);
624 659
		}
625
		
660

  
626 661
		if(lastRequest == null)
627 662
			return null;
628
		
663

  
629 664
		String nameWorldFile = getWorldFile(lastRequest.getPath());
630 665
		try {
631 666
			if(p.isSizeFixed()) {
......
640 675

  
641 676
		return lastRequest;
642 677
	}
643
	
678

  
644 679
	@Override
645
	public void loadBuffer(SpiRasterQuery q) 
680
	public void loadBuffer(SpiRasterQuery q)
646 681
			throws ProcessInterruptedException, RasterDriverException {
647 682
		Extent bbox = q.getRequestBoundingBox();
648 683
		lastWidthRequest = q.getBufWidth();
649 684
		lastHeightRequest = q.getBufHeight();
650 685
		WMSStatus wmsStatus = loadWMSStatus(bbox.toRectangle2D());
651
		
652
		lastRequest = downloadFile(wmsStatus, 
653
				bbox.getULX(), 
654
				bbox.getULY(), 
655
				bbox.getLRX(), 
656
				bbox.getLRY(), 
657
				q.getBufWidth(), 
686

  
687
		lastRequest = downloadFile(wmsStatus,
688
				bbox.getULX(),
689
				bbox.getULY(),
690
				bbox.getLRX(),
691
				bbox.getLRY(),
692
				q.getBufWidth(),
658 693
				q.getBufHeight());
659
		
694

  
660 695
		if (lastRequest == null) {
661 696
			return;
662 697
		}
663
		
698

  
664 699
		Buffer b = null;
665 700
		try {
666 701
			b = getDownloadedRaster(lastRequest);
......
673 708
		}
674 709
		q.setBufferResult(b);
675 710
	}
676
	
711

  
677 712
	private Buffer getDownloadedRaster(File f) throws ProcessInterruptedException, QueryException, ProviderNotRegisteredException, InitializeException {
678 713
		AbstractRasterProvider provider = DefaultProviderServices.loadProvider(new File(f.getPath()));
679 714
		setColorTable(provider.getColorTable());
680 715
		return getDownloadedRaster(provider);
681 716
	}
682
	
717

  
683 718
	private Buffer getDownloadedRaster(AbstractRasterProvider provider) throws ProcessInterruptedException, QueryException, ProviderNotRegisteredException, InitializeException {
684 719
		DefaultRasterStore store = new DefaultRasterStore();
685 720
		store.setProvider(provider);
......
690 725
			q.setDrawableBands(getColorInterpretation().buildRenderBands());
691 726
		if(store.getBandCount() > 3)
692 727
			q.forceARGBRequest();
693
		else 
728
		else
694 729
			q.forceRGBRequest();
695
		
730

  
696 731
		Buffer buf = store.query(q);
697 732

  
698 733
		store.close();
699 734
		return buf;
700 735
	}
701
	
736

  
702 737
	/**
703 738
	 * Assigns the list of bands RGB and read a window of data
704 739
	 * @param rasterBuf
......
712 747
	 * @throws RasterDriverException
713 748
	 * @throws ProcessInterruptedException
714 749
	 */
715
	/*public Buffer getBuffer(Buffer rasterBuf, BandList bandList, File lastFile, 
750
	/*public Buffer getBuffer(Buffer rasterBuf, BandList bandList, File lastFile,
716 751
			double ulx, double uly, double lrx, double lry) throws RasterDriverException, ProcessInterruptedException {
717 752
		try {
718 753
			//El nombre de fichero que ha puesto en el bandList es el del servidor y no el del fichero en disco
......
720 755
			for (int i = 0; i < bandList.getBandCount(); i++) {
721 756
				bandList.getBand(i).setFileName(lastFile.getPath());
722 757
			}
723
			
758

  
724 759
			AbstractRasterProvider driver = DefaultProviderServices.loadProvider(new File(lastFile.getPath()));
725 760
			setColorTable(driver.getColorTable());
726
			
761

  
727 762
			DefaultRasterQuery q = (DefaultRasterQuery)RasterLocator.getManager().createQuery();
728 763
			q.setAreaOfInterest(new ExtentImpl(ulx, uly, lrx, lry));
729 764
			q.setBandList(bandList);
730 765
			q.setBuffer(rasterBuf);
731 766
			Buffer buf = driver.getDataSet(q);
732
			
767

  
733 768
			for (int i = 0; i < bandList.getBandCount(); i++) {
734 769
				bandList.getBand(i).setFileName(serverName);
735 770
			}
736
			
771

  
737 772
			return buf;
738 773
		} catch (ProviderNotRegisteredException e) {
739 774
			throw new RasterDriverException("Error building GdalDriver", e);
......
741 776
			throw new RasterDriverException("Error building GdalDriver", e);
742 777
		}
743 778
	}*/
744
	
745
	/*public void getWindow(Extent ex, int bufWidth, int bufHeight, 
779

  
780
	/*public void getWindow(Extent ex, int bufWidth, int bufHeight,
746 781
			BandList bandList, TileListener listener, TaskStatus status) throws ProcessInterruptedException, RasterDriverException {
747 782

  
748 783
		Buffer raster = DefaultRasterManager.getInstance().createBuffer(getDataType()[0], bufWidth, bufHeight, 3, true);
......
766 801
		listener.endReading();
767 802
	}*/
768 803

  
769
	/*public Buffer getWindow(Extent ex, BandList bandList, Buffer rasterBuf, TaskStatus status) 
804
	/*public Buffer getWindow(Extent ex, BandList bandList, Buffer rasterBuf, TaskStatus status)
770 805
		throws ProcessInterruptedException, RasterDriverException {
771 806
		Rectangle2D bBox = ex.toRectangle2D();
772 807
		lastWidthRequest = rasterBuf.getWidth();
773 808
		lastHeightRequest = rasterBuf.getHeight();
774 809
		WMSStatus wmsStatus = loadWMSStatus(bBox);
775
		
810

  
776 811
		lastRequest = downloadFile(wmsStatus, ex.getULX(), ex.getULY(), ex.getLRX(), ex.getLRY(), rasterBuf.getWidth(), rasterBuf.getHeight());
777
		
812

  
778 813
		if (lastRequest == null) {
779 814
			return rasterBuf;
780 815
		}
781
		
816

  
782 817
		try {
783 818
			//El nombre de fichero que ha puesto en el bandList es el del servidor y no el del fichero en disco
784 819
			String serverName = bandList.getBand(0).getFileName();
785 820
			for (int i = 0; i < bandList.getBandCount(); i++) {
786 821
				bandList.getBand(i).setFileName(lastRequest.getPath());
787 822
			}
788
			
823

  
789 824
			AbstractRasterProvider driver = DefaultProviderServices.loadProvider(new File(lastRequest.getPath()));
790 825
			setColorTable(driver.getColorTable());
791
			
826

  
792 827
			DefaultRasterQuery q = (DefaultRasterQuery)RasterLocator.getManager().createQuery();
793 828
			q.setAreaOfInterest(ex);
794 829
			q.setBandList(bandList);
795 830
			q.setBuffer(rasterBuf);
796 831
			Buffer buf = driver.getDataSet(q);
797
			
832

  
798 833
			for (int i = 0; i < bandList.getBandCount(); i++) {
799 834
				bandList.getBand(i).setFileName(serverName);
800 835
			}
......
807 842
		}
808 843
	}*/
809 844

  
810
	/*public Buffer getWindow(double ulx, double uly, double w, double h, 
845
	/*public Buffer getWindow(double ulx, double uly, double w, double h,
811 846
			BandList bandList, Buffer rasterBuf, boolean adjustToExtent, TaskStatus status) throws ProcessInterruptedException, RasterDriverException {
812 847
		Rectangle2D bBox = new Rectangle2D.Double(ulx, uly, w, h);
813 848
		lastWidthRequest = rasterBuf.getWidth();
814 849
		lastHeightRequest = rasterBuf.getHeight();
815 850
		WMSStatus wmsStatus = loadWMSStatus(bBox);
816
		
851

  
817 852
		lastRequest = downloadFile(wmsStatus, ulx, uly, ulx + w, uly - h, rasterBuf.getWidth(), rasterBuf.getHeight());
818
		
853

  
819 854
		if (lastRequest == null) {
820 855
			return rasterBuf;
821 856
		}
822
		
857

  
823 858
		try {
824 859
			//El nombre de fichero que ha puesto en el bandList es el del servidor y no el del fichero en disco
825 860
			String serverName = bandList.getBand(0).getFileName();
826 861
			for (int i = 0; i < bandList.getBandCount(); i++) {
827 862
				bandList.getBand(i).setFileName(lastRequest.getPath());
828 863
			}
829
			
864

  
830 865
			AbstractRasterProvider driver = DefaultProviderServices.loadProvider(new File(lastRequest.getPath()));
831 866
			setColorTable(driver.getColorTable());
832
			
867

  
833 868
			DefaultRasterQuery q = (DefaultRasterQuery)RasterLocator.getManager().createQuery();
834 869
			q.setAreaOfInterest(ulx, uly, w, h);
835 870
			q.setBandList(bandList);
836 871
			q.setBuffer(rasterBuf);
837 872
			q.setAdjustToExtent(adjustToExtent);
838
			
873

  
839 874
			Buffer buf = driver.getDataSet(q);
840
			
875

  
841 876
			for (int i = 0; i < bandList.getBandCount(); i++) {
842 877
				bandList.getBand(i).setFileName(serverName);
843 878
			}
844
			
879

  
845 880
			return buf;
846 881
		} catch (ProviderNotRegisteredException e) {
847 882
			throw new RasterDriverException("Error building GdalDriver", e);
......
850 885
		}
851 886
	}*/
852 887

  
853
	/*public Buffer getWindow(Extent extent, int bufWidth, int bufHeight, 
888
	/*public Buffer getWindow(Extent extent, int bufWidth, int bufHeight,
854 889
			BandList bandList, Buffer rasterBuf, boolean adjustToExtent, TaskStatus status) throws ProcessInterruptedException, RasterDriverException {
855 890
		Rectangle2D bBox = extent.toRectangle2D();//new Rectangle2D.Double(ulx, lry, Math.abs(lrx - ulx), Math.abs(lry - uly));
856 891
		lastWidthRequest = rasterBuf.getWidth();
857 892
		lastHeightRequest = rasterBuf.getHeight();
858 893
		WMSStatus wmsStatus = loadWMSStatus(bBox);
859 894
		lastRequest = downloadFile(wmsStatus, extent.getULX(), extent.getULY(), extent.getLRX(), extent.getLRY(), rasterBuf.getWidth(), rasterBuf.getHeight());
860
		
895

  
861 896
		if (lastRequest == null) {
862 897
			return rasterBuf;
863 898
		}
864
		
899

  
865 900
		try {
866 901
			//El nombre de fichero que ha puesto en el bandList es el del servidor y no el del fichero en disco
867 902
			String serverName = bandList.getBand(0).getFileName();
868 903
			for (int i = 0; i < bandList.getBandCount(); i++) {
869 904
				bandList.getBand(i).setFileName(lastRequest.getPath());
870 905
			}
871
			
906

  
872 907
			AbstractRasterProvider driver = DefaultProviderServices.loadProvider(new File(lastRequest.getPath()));
873 908
			setColorTable(driver.getColorTable());
874
			
909

  
875 910
			DefaultRasterQuery q = (DefaultRasterQuery)RasterLocator.getManager().createQuery();
876 911
			q.setAreaOfInterest(extent, bufWidth, bufHeight);
877 912
			q.setBandList(bandList);
......
882 917
			for (int i = 0; i < bandList.getBandCount(); i++) {
883 918
				bandList.getBand(i).setFileName(serverName);
884 919
			}
885
			
920

  
886 921
			return buf;
887 922
		} catch (ProviderNotRegisteredException e) {
888 923
			throw new RasterDriverException("Error building GdalDriver", e);
......
891 926
		}
892 927
	}*/
893 928

  
894
//	public Buffer getWindow(int x, int y, 
929
//	public Buffer getWindow(int x, int y,
895 930
//			BandList bandList, Buffer rasterBuf) throws ProcessInterruptedException, RasterDriverException {
896 931
//		int w = rasterBuf.getWidth();
897 932
//		int h = rasterBuf.getHeight();
......
901 936
//		lastHeightRequest = rasterBuf.getHeight();
902 937
//		Rectangle2D bBox = new Rectangle2D.Double(p1.getX(), p1.getY(), Math.abs(p1.getX() - p1.getX()), Math.abs(p1.getY() - p2.getY()));
903 938
//		WMSStatus wmsStatus = loadWMSStatus(bBox);
904
//		
939
//
905 940
//		lastRequest = downloadFile(wmsStatus, p1.getX(), p1.getY(), p2.getX(), p2.getY(), rasterBuf.getWidth(), rasterBuf.getHeight());
906
//		
941
//
907 942
//		if (lastRequest == null) {
908 943
//			return rasterBuf;
909 944
//		}
......
915 950
//			for (int i = 0; i < bandList.getBandCount(); i++) {
916 951
//				bandList.getBand(i).setFileName(lastRequest.getPath());
917 952
//			}
918
//			
953
//
919 954
//			driver = DefaultProviderServices.loadProvider(new File(lastRequest.getPath()));
920 955
//			Buffer buf = driver.getWindow(0, 0, w, h, bandList, rasterBuf);
921 956
//
922 957
//			for (int i = 0; i < bandList.getBandCount(); i++) {
923 958
//				bandList.getBand(i).setFileName(serverName);
924 959
//			}
925
//			
960
//
926 961
//			return buf;
927 962
//		} catch (ProviderNotRegisteredException e) {
928 963
//			throw new RasterDriverException("Error building GdalDriver", e);
......
931 966
//		}
932 967
//	}
933 968

  
934
	/*public Buffer getWindow(int x, int y, int w, int h, 
969
	/*public Buffer getWindow(int x, int y, int w, int h,
935 970
			BandList bandList, Buffer rasterBuf, TaskStatus status) throws ProcessInterruptedException, RasterDriverException {
936 971
		Point2D p1 = rasterToWorld(new Point2D.Double(x, y));
937 972
		Point2D p2 = rasterToWorld(new Point2D.Double(x + w, y + h));
......
939 974
		lastHeightRequest = rasterBuf.getHeight();
940 975
		Rectangle2D bBox = new Rectangle2D.Double(p1.getX(), p1.getY(), Math.abs(p1.getX() - p1.getX()), Math.abs(p1.getY() - p2.getY()));
941 976
		WMSStatus wmsStatus = loadWMSStatus(bBox);
942
		
977

  
943 978
		lastRequest = downloadFile(wmsStatus, p1.getX(), p1.getY(), p2.getX(), p2.getY(), rasterBuf.getWidth(), rasterBuf.getHeight());
944
		
979

  
945 980
		if (lastRequest == null) {
946 981
			return rasterBuf;
947 982
		}
......
953 988
			for (int i = 0; i < bandList.getBandCount(); i++) {
954 989
				bandList.getBand(i).setFileName(lastRequest.getPath());
955 990
			}
956
			
991

  
957 992
			driver = DefaultProviderServices.loadProvider(new File(lastRequest.getPath()));
958 993
			setColorTable(driver.getColorTable());
959
			
994

  
960 995
			DefaultRasterQuery q = (DefaultRasterQuery)RasterLocator.getManager().createQuery();
961 996
			q.setAreaOfInterest(0, 0, w, h);
962 997
			q.setBandList(bandList);
......
966 1001
			for (int i = 0; i < bandList.getBandCount(); i++) {
967 1002
				bandList.getBand(i).setFileName(serverName);
968 1003
			}
969
			
1004

  
970 1005
			return buf;
971 1006
		} catch (ProviderNotRegisteredException e) {
972 1007
			throw new RasterDriverException("Error building GdalDriver", e);
......
996 1031
	}
997 1032

  
998 1033
	public void setAffineTransform(AffineTransform t){
999
		
1034

  
1000 1035
	}
1001 1036

  
1002 1037
	public int getOverviewCount(int band) throws BandAccessException, RasterDriverException {
......
1022 1057
	public String getProviderName() {
1023 1058
		return NAME;
1024 1059
	}
1025
        
1060

  
1026 1061
	public String getName() {
1027 1062
		return this.getParameters().getName();
1028 1063
	}
1029
        
1064

  
1030 1065
	public String getFullName() {
1031
		return this.uri;
1066
		return getURI().getPath();
1032 1067
	}
1033
	
1068

  
1034 1069
	/**
1035 1070
	 * Convierte un punto desde coordenadas pixel a coordenadas del mundo.
1036 1071
	 * @param pt Punto a transformar
......
1056 1091
		}
1057 1092
		return p;
1058 1093
	}
1059
	
1094

  
1060 1095
	public void setStatus(RasterProvider provider) {
1061 1096
		if(provider instanceof WMSProvider) {
1062 1097
		}
1063 1098
	}
1064
	
1099

  
1065 1100
	/**
1066 1101
	 * ASigna el par?metro de inicializaci?n del driver.
1067 1102
	 */
......
1070 1105
			this.uri = ((WMSDataParameters)param).getURI();
1071 1106
		this.param = param;
1072 1107
	}
1073
        
1074
        
1075
	
1108

  
1109

  
1110

  
1076 1111
	public String getInfoByPoint(int x, int y, Extent bbox, int w, int h, ICancellable cancellable) throws InfoByPointException {
1077 1112
		WMSDataParameters p = (WMSDataParameters)parameters;
1078 1113
		WMSStatus wmsStatus = new WMSStatus();
......
1097 1132
			throw new InfoByPointException("Error in getFeatureInfo", e);
1098 1133
		}
1099 1134
	}
1100
	
1135

  
1101 1136
	/**
1102 1137
	 * Gets the suffix of the downloaded image
1103 1138
	 * @return
......
1110 1145
		}
1111 1146
		if (format.indexOf("png") >= 0){
1112 1147
	        return "png";
1113
		}	
1148
		}
1114 1149
	    if (format.indexOf("xml") >= 0){
1115 1150
	        return "xml";
1116
	    }	
1151
	    }
1117 1152
	    if (format.indexOf("gif") >= 0){
1118 1153
	        return "gif";
1119 1154
	    }
......
1125 1160
	    }
1126 1161
	    if (format.indexOf("jpg") >= 0
1127 1162
	        || format.indexOf("jpeg") >= 0){
1128
	        return "jpg";			 
1163
	        return "jpg";
1129 1164
	    }
1130 1165
		return "xml";
1131 1166
	}
1132
	
1167

  
1133 1168
	public TileServer getTileServer() {
1134 1169
		if(tileServer == null) {
1135 1170
			DefaultRasterStore store = new DefaultRasterStore();
......
1138 1173
		}
1139 1174
		return tileServer;
1140 1175
	}
1141
	
1176

  
1142 1177
	public boolean isRasterEnclosed() {
1143 1178
		WMSDataParameters p = (WMSDataParameters)parameters;
1144 1179
		if(p.isSizeFixed()) {
......
1146 1181
		}
1147 1182
		return true;
1148 1183
	}
1149
	
1150
	public String getRMFFile() {
1184

  
1185
	public File getRMFFile() {
1151 1186
		if(lastRequest != null)
1152
			return fileUtil.getNameWithoutExtension(lastRequest.getAbsolutePath()) + ".rmf";
1187
		    return new File(FilenameUtils.removeExtension(lastRequest.getAbsolutePath()) + ".rmf");
1153 1188
		return null;
1154 1189
	}
1155
	
1190

  
1156 1191
	public HistogramComputer getHistogramComputer() {
1157 1192
		if (histogram == null)
1158 1193
			histogram = new RemoteStoreHistogram(this);
1159 1194
		return histogram;
1160 1195
	}
1196

  
1197
    /* (non-Javadoc)
1198
     * @see org.gvsig.raster.impl.provider.RasterProvider#addFile(java.io.File)
1199
     */
1200
    @Override
1201
    public void addFile(File file) throws InvalidSourceException {
1202
        //do nothing
1203
    }
1204

  
1205
    /* (non-Javadoc)
1206
     * @see org.gvsig.raster.impl.provider.RasterProvider#removeFile(java.io.File)
1207
     */
1208
    @Override
1209
    public void removeFile(File file) {
1210
        //do nothing
1211
    }
1161 1212
}

Also available in: Unified diff