Statistics
| Revision:

gvsig-raster / org.gvsig.raster.wms / branches / org.gvsig.raster.wms_dataaccess_refactoring / org.gvsig.raster.wms.io / src / main / java / org / gvsig / raster / wms / io / WMSProvider.java @ 2241

History | View | Annotate | Download (39.1 KB)

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.wms.io;
23

    
24
import java.awt.Image;
25
import java.awt.geom.AffineTransform;
26
import java.awt.geom.NoninvertibleTransformException;
27
import java.awt.geom.Point2D;
28
import java.awt.geom.Rectangle2D;
29
import java.io.File;
30
import java.io.IOException;
31
import java.net.URL;
32
import java.util.Hashtable;
33
import java.util.Vector;
34

    
35
import javax.swing.ImageIcon;
36

    
37
import org.cresques.cts.ICoordTrans;
38
import org.cresques.cts.IProjection;
39
import org.gvsig.compat.net.ICancellable;
40
import org.gvsig.fmap.crs.CRSFactory;
41
import org.gvsig.fmap.dal.DALLocator;
42
import org.gvsig.fmap.dal.DataStore;
43
import org.gvsig.fmap.dal.DataStoreParameters;
44
import org.gvsig.fmap.dal.coverage.RasterLocator;
45
import org.gvsig.fmap.dal.coverage.dataset.Buffer;
46
import org.gvsig.fmap.dal.coverage.datastruct.BandList;
47
import org.gvsig.fmap.dal.coverage.datastruct.Extent;
48
import org.gvsig.fmap.dal.coverage.exception.BandAccessException;
49
import org.gvsig.fmap.dal.coverage.exception.BandNotFoundInListException;
50
import org.gvsig.fmap.dal.coverage.exception.FileNotOpenException;
51
import org.gvsig.fmap.dal.coverage.exception.InfoByPointException;
52
import org.gvsig.fmap.dal.coverage.exception.InvalidSetViewException;
53
import org.gvsig.fmap.dal.coverage.exception.NotSupportedExtensionException;
54
import org.gvsig.fmap.dal.coverage.exception.ProcessInterruptedException;
55
import org.gvsig.fmap.dal.coverage.exception.QueryException;
56
import org.gvsig.fmap.dal.coverage.exception.RasterDriverException;
57
import org.gvsig.fmap.dal.coverage.exception.RemoteServiceException;
58
import org.gvsig.fmap.dal.coverage.store.RasterQuery;
59
import org.gvsig.fmap.dal.coverage.store.props.ColorInterpretation;
60
import org.gvsig.fmap.dal.coverage.store.props.HistogramComputer;
61
import org.gvsig.fmap.dal.coverage.store.props.Transparency;
62
import org.gvsig.fmap.dal.exception.InitializeException;
63
import org.gvsig.fmap.dal.exception.ProviderNotRegisteredException;
64
import org.gvsig.fmap.dal.spi.DataManagerProviderServices;
65
import org.gvsig.fmap.dal.spi.DataStoreProviderServices;
66
import org.gvsig.metadata.MetadataLocator;
67
import org.gvsig.raster.cache.tile.provider.TileServer;
68
import org.gvsig.raster.impl.buffer.SpiRasterQuery;
69
import org.gvsig.raster.impl.datastruct.BandListImpl;
70
import org.gvsig.raster.impl.datastruct.DatasetBandImpl;
71
import org.gvsig.raster.impl.datastruct.ExtentImpl;
72
import org.gvsig.raster.impl.provider.AbstractRasterProvider;
73
import org.gvsig.raster.impl.provider.RasterProvider;
74
import org.gvsig.raster.impl.provider.RemoteRasterProvider;
75
import org.gvsig.raster.impl.store.DefaultRasterStore;
76
import org.gvsig.raster.impl.store.DefaultStoreFactory;
77
import org.gvsig.raster.impl.store.properties.DataStoreColorInterpretation;
78
import org.gvsig.raster.impl.store.properties.DataStoreTransparency;
79
import org.gvsig.raster.impl.store.properties.RemoteStoreHistogram;
80
import org.gvsig.raster.util.DefaultProviderServices;
81
import org.gvsig.raster.wms.io.downloader.WMSTileServer;
82
import org.gvsig.remoteclient.utils.Utilities;
83
import org.gvsig.remoteclient.wms.WMSStatus;
84
import org.gvsig.tools.ToolsLocator;
85
import org.slf4j.Logger;
86
import org.slf4j.LoggerFactory;
87
/**
88
 * Clase que representa al driver de acceso a datos de wms.
89
 *
90
 * @author Nacho Brodin (nachobrodin@gmail.com)
91
 */
92
public class WMSProvider extends AbstractRasterProvider implements RemoteRasterProvider {
93
        public static String                NAME                     = "Wms Store";
94
        public static String                DESCRIPTION              = "Wms Raster file";
95
        public static final String          METADATA_DEFINITION_NAME = "WmsStore";
96
        private static final Logger         logger                    = LoggerFactory.getLogger(WMSProvider.class);
97
        private static final int            FIXED_SIZE               = 800;
98
        private Extent                      viewRequest              = null;
99
        private static Hashtable<String, WMSConnector>    
100
                                            drivers                  = new Hashtable<String, WMSConnector> ();
101
        private boolean                     open                     = false;
102
        private DataStoreTransparency       fileTransparency         = null;
103
        private final int                                        minTilePrintWidth        = 12;
104
        private final int                                        minTilePrintHeight       = 12;
105
        //The out size depends on the last request
106
        private int                         lastWidthRequest         = 0;
107
        private int                         lastHeightRequest        = 0;
108
        //Only for fixed size. Complete extent and FIXED_SIZE in long side
109
        private File                        fileLayerPixelSize       = null;
110
        private File                        lastRequest              = null;
111
        private AbstractRasterProvider       lastRequestProvider      = null; 
112
        
113
        public static void register() {
114
                DataManagerProviderServices dataman = (DataManagerProviderServices) DALLocator.getDataManager();
115
                if (dataman != null && !dataman.getStoreProviders().contains(NAME)) {
116
                        dataman.registerStoreProvider(NAME,
117
                                        WMSProvider.class, WMSDataParametersImpl.class);
118
                }
119

    
120
                if (!dataman.getExplorerProviders().contains(WMSServerExplorer.NAME)) {
121
                        dataman.registerExplorerProvider(WMSServerExplorer.NAME, WMSServerExplorer.class, WMSServerExplorerParameters.class);
122
                }
123
                dataman.registerStoreFactory(NAME, DefaultStoreFactory.class);
124
        }
125
        
126
        public WMSProvider() throws NotSupportedExtensionException {
127
                super();
128
        }
129
        
130
        public void registerTileProviderFormats(Class<RasterProvider> c) {
131

    
132
        }
133
        
134
        /**
135
         * Constructor. Abre el dataset.
136
         * @param proj Proyecci?n
137
         * @param fName Nombre del fichero
138
         * @throws NotSupportedExtensionException
139
         */
140
        public WMSProvider(String params) throws InitializeException {
141
                super(params);
142
                if(params instanceof String) {
143
                        WMSDataParameters p = new WMSDataParametersImpl();
144
                        p.setURI((String)params);
145
                        super.init(p, null, ToolsLocator.getDynObjectManager()
146
                                        .createDynObject(
147
                                                        MetadataLocator.getMetadataManager().getDefinition(
148
                                                                        DataStore.METADATA_DEFINITION_NAME)));
149
                        init(p, null);
150
                }
151
        }
152
        
153
        public WMSProvider(WMSDataParameters params,
154
                        DataStoreProviderServices storeServices) throws InitializeException {
155
                super(params, storeServices, ToolsLocator.getDynObjectManager()
156
                                .createDynObject(
157
                                                MetadataLocator.getMetadataManager().getDefinition(
158
                                                                DataStore.METADATA_DEFINITION_NAME)));
159
                init(params, storeServices);
160
        }
161
        
162
        /**
163
         * Gets the connector from the URL
164
         * @return
165
         * @throws RemoteServiceException
166
         */
167
        public WMSConnector getConnector() throws RemoteServiceException {
168
                WMSDataParameters p = (WMSDataParameters)parameters;
169
                URL url = null;
170
                try {
171
                        url = new URL(p.getURI());
172
                } catch (Exception e) {
173
                        throw new RemoteServiceException("Malformed URL",e);
174
                }
175
                try {
176
                        return WMSProvider.getConnectorFromURL(url, false);
177
                } catch (IOException e) {
178
                        throw new RemoteServiceException("Error getting the connector",e);
179
                }
180
        }
181
        
182
        /**
183
         * Crea las referencias al fichero y carga
184
         * las estructuras con la informaci?n y los metadatos.
185
         * @param proj Proyecci?n
186
         * @param param Parametros de carga
187
         * @throws NotSupportedExtensionException
188
         */
189
        public void init (DataStoreParameters params,
190
                        DataStoreProviderServices storeServices) throws InitializeException {
191
                setParam(storeServices, params);
192
                setDataType(new int[]{Buffer.TYPE_BYTE, Buffer.TYPE_BYTE, Buffer.TYPE_BYTE});
193
                bandCount = 3;
194
                open = true;
195
                try {
196
                        loadInitialInfo();
197
                } catch (RasterDriverException e) {
198
                        throw new InitializeException(e.getMessage(), e);
199
                }
200
        }
201
        
202
        /**
203
         * When a WMS provider is opened the information of data type, number of bands and transparency 
204
         * is not available. Only after the first time a raster has been downloaded it can be know.
205
         * @param newDataType
206
         * @param buf
207
         * @param bandList
208
         * @return
209
         * @throws RasterDriverException 
210
         */
211
        private void loadInitialInfo() throws RasterDriverException {
212
                WMSDataParametersImpl p = (WMSDataParametersImpl)parameters;
213
                Extent ext = getExtent();
214
                Rectangle2D bBox = ext.toRectangle2D();
215
                int w = 0;
216
                int h = 0;
217
                if(ext.width() > ext.height()) {
218
                        w = 200;
219
                        h = (int)((ext.height() * w) / ext.width());
220
                } else {
221
                        h = 200;
222
                        w = (int)((ext.width() * h) / ext.height());
223
                }
224
                p.setWidth(w);
225
                p.setHeight(h);
226
                p.setExtent(bBox);
227
                WMSStatus wmsStatus = loadWMSStatus(bBox);
228
                
229
                lastRequest = downloadFile(wmsStatus, ext.getULX(), ext.getULY(), ext.getLRX(), ext.getLRY(), w, h);
230
                AbstractRasterProvider driver;
231
                try {
232
                        driver = DefaultProviderServices.loadProvider(lastRequest);
233
                        setDataType(driver.getDataType());
234
                        bandCount = driver.getBandCount();
235
                        if(bandCount > 3) {
236
                                getColorInterpretation().setColorInterpValue(3, DataStoreColorInterpretation.ALPHA_BAND);
237
                                getTransparency().setTransparencyBand(3);
238
                        }
239
                        setColorTable(driver.getColorTable());
240
                        driver.close();
241
                } catch (ProviderNotRegisteredException e) {
242
                        throw new RasterDriverException("", e);
243
                } catch (InitializeException e) {
244
                        throw new RasterDriverException("", e);
245
                }
246
        }
247
        
248
        public static final WMSConnector getConnectorFromURL(URL url, boolean updating) throws IOException {
249
                WMSConnector drv = null;
250
                if(!updating) {
251
                        drv = (WMSConnector) drivers.get(url.toString());
252
                } else {
253
                        if(drivers.get(url.toString()) != null)
254
                                drivers.remove(url.toString());
255
                }
256
                
257
                if (drv == null) {
258
                        drv = new WMSConnector(url);
259
                        drivers.put(url.toString(), drv);
260
                }
261
                
262
                return drv;
263
        }
264
        
265
        /**
266
         * Obtiene el objeto que contiene que contiene la interpretaci?n de
267
         * color por banda
268
         * @return
269
         */
270
        public ColorInterpretation getColorInterpretation() {
271
                if(super.getColorInterpretation() == null) {
272
                        ColorInterpretation colorInterpretation = new DataStoreColorInterpretation();
273
                        colorInterpretation.initColorInterpretation(getBandCount());
274
                        colorInterpretation.setColorInterpValue(0, DataStoreColorInterpretation.RED_BAND);
275
                        colorInterpretation.setColorInterpValue(1, DataStoreColorInterpretation.GREEN_BAND);
276
                        colorInterpretation.setColorInterpValue(2, DataStoreColorInterpretation.BLUE_BAND);
277
                        setColorInterpretation(colorInterpretation);
278
                }
279
                return super.getColorInterpretation();
280
        }
281
        
282
        public AffineTransform getAffineTransform() {
283
                WMSDataParameters p = (WMSDataParameters)parameters;
284
                Extent e = getExtent();
285
                if(p.isSizeFixed()) {
286
                        double psX = e.width() / (p.getWidth() - 1);
287
                        double psY = -(e.height() / (p.getHeight() - 1));
288
                        ownTransformation = new AffineTransform(
289
                                        psX , 
290
                                        0, 
291
                                        0, 
292
                                        psY, 
293
                                        e.getULX() - (psX / 2),
294
                                        e.getULY() - (psY / 2));
295
                } else {
296
                        double psX = e.width() / (lastWidthRequest <= 0 ? p.getWidth() : lastWidthRequest);
297
                        double psY = -(e.height() / (lastHeightRequest <= 0 ? p.getHeight() : lastHeightRequest));
298
                        ownTransformation = new AffineTransform(
299
                                        psX, 
300
                                        0, 
301
                                        0, 
302
                                        psY, 
303
                                        e.getULX() - (psX / 2),
304
                                        e.getULY() - (psY / 2));
305
                        /*ownTransformation = new AffineTransform(
306
                                        p.getExtent().getWidth() / (lastWidthRequest <= 0 ? p.getWidth() : lastWidthRequest) , 
307
                                        0, 
308
                                        0, 
309
                                        -(p.getExtent().getHeight() / (lastHeightRequest <= 0 ? p.getHeight() : lastHeightRequest)), 
310
                                        p.getExtent().getMinX(),
311
                                        p.getExtent().getMinY());*/
312
                }
313
                externalTransformation = (AffineTransform) ownTransformation.clone();
314
                return ownTransformation;
315
        }
316
        
317
        /**
318
         * Calcula el extent en coordenadas del mundo real
319
         * @return Extent
320
         */
321
        public Extent getExtent() {
322
                WMSDataParameters p = (WMSDataParameters)parameters;
323
                Vector<?> layerNames = Utilities.createVector(p.getLayerQuery(), ",");
324
                
325
                String[] ln = new String[layerNames.size()];
326
                for (int i = 0; i < ln.length; i++) {
327
                        ln[i] = (String)layerNames.get(i);
328
                }
329
                Rectangle2D r = null;
330
                try {
331
                        r = getConnector().getLayersExtent(ln, p.getSRSCode());
332
                        if (r == null) {
333
                                String latLonID = "EPSG:4326";
334
                                r = getConnector().getLayersExtent(ln, latLonID);
335
                                if (r == null) {
336
                                        r = getConnector().getLayersExtent(ln, "CRS:84");
337
                                }
338
                                
339
                                IProjection reqProj = CRSFactory.getCRS(p.getSRSCode());
340
                                IProjection latLonProj = CRSFactory.getCRS(latLonID);
341
                                if ((reqProj != null) && (latLonProj != null)) {
342
                                        ICoordTrans ct = latLonProj.getCT(reqProj);
343
                                        Rectangle2D reprojectedRect = ct.convert(r);
344
                                        r = reprojectedRect;
345
                                }
346
                        }
347
                } catch (RemoteServiceException e) {
348
                }
349
                if(r == null)
350
                        return null;
351
                return new ExtentImpl(r.getMinX(), r.getMaxY(), r.getMaxX(), r.getMinY());
352
        }
353

    
354
        public Rectangle2D getLayerExtent(String layerName, String srs) throws RemoteServiceException {
355
                return getConnector().getLayersExtent(new String[]{layerName}, srs);
356
        }
357

    
358
        public RasterProvider load() {
359
                return this;
360
        }
361
        
362
        public boolean isOpen() {
363
                return open;
364
        }
365

    
366
        public void close() {
367
                open = false;
368
        }
369
        
370
        public Transparency getTransparency() {
371
                if(fileTransparency == null)
372
                        fileTransparency = new DataStoreTransparency();
373
                return fileTransparency;
374
        }
375

    
376
        public String translateFileName(String fileName) {
377
                return fileName;
378
        }
379

    
380
        public void setView(Extent e) {
381
                viewRequest = e;
382
        }
383

    
384
        public Extent getView() {
385
                return viewRequest;
386
        }
387
        
388
        public double getWidth() {
389
                WMSDataParameters p = (WMSDataParameters)parameters;
390
                if(p.isSizeFixed()) {
391
                        return p.getWidth();
392
                }
393
                if (lastWidthRequest <= 0) 
394
                        return p.getWidth();
395
                if (lastWidthRequest < minTilePrintWidth) 
396
                        return minTilePrintWidth;
397
                return lastWidthRequest;
398
        }
399

    
400
        public double getHeight() {
401
                WMSDataParameters p = (WMSDataParameters)parameters;
402
                if(p.isSizeFixed()) {
403
                        return p.getHeight();
404
                }
405
                if (lastHeightRequest <= 0) 
406
                        return p.getHeight();
407
                if (lastHeightRequest < minTilePrintHeight) 
408
                        return minTilePrintHeight;
409
                return lastHeightRequest;
410
        }
411
        
412
        /**
413
         * Gets WMS parameters
414
         * @return
415
         */
416
        public WMSDataParameters getParameters() {
417
                return (WMSDataParameters)parameters;
418
        }
419

    
420
        public Object readCompleteLine(int line, int band)
421
                throws InvalidSetViewException, FileNotOpenException, RasterDriverException {
422
                return null;
423
        }
424
        
425
        /**
426
         * When the remote layer has fixed size this method downloads the file and return its reference. 
427
         * File layer has in the long side FIXED_SIZE pixels and the bounding box is complete. This file could be
428
         * useful to build an histogram or calculate statistics. This represents a sample of data.
429
         * @return
430
         * @throws RasterDriverException
431
         */
432
        public File getFileLayer() throws RasterDriverException {
433
                if(fileLayerPixelSize != null)
434
                        return fileLayerPixelSize;
435
                
436
                WMSDataParameters p = (WMSDataParameters)parameters;
437
                Extent e = getExtent();
438
                Rectangle2D bBox = new Rectangle2D.Double(e.getULX(), e.getLRY(), e.width(), e.height());
439
                WMSStatus wmsStatus = loadWMSStatus(bBox);
440
                
441
                if(!p.isSizeFixed()) {
442
                        int w = 0;
443
                        int h = 0;
444
                        if(e.width() > e.height()) {
445
                                w = FIXED_SIZE;
446
                                h = (int)((e.height() * FIXED_SIZE) / e.width());
447
                        } else {
448
                                h = FIXED_SIZE;
449
                                w = (int)((e.width() * FIXED_SIZE) / e.height());
450
                        }
451
                        wmsStatus.setWidth(w);
452
                        wmsStatus.setHeight(h);
453
                        fileLayerPixelSize = downloadFile(wmsStatus, e.getULX(), e.getULY(), e.getLRX(), e.getLRY(), w, h);
454
                } else {
455
                        fileLayerPixelSize = downloadFile(wmsStatus, e.getULX(), e.getULY(), e.getLRX(), e.getLRY(), 
456
                                        p.getFixedSize().width, p.getFixedSize().height);
457
                }
458
                return fileLayerPixelSize;
459
        }
460

    
461
        /**
462
         * Reads a complete block of data and returns an tridimensional array of the right type. This function is useful
463
         * to read a file very fast without setting a view. In a WMS service when the size is fixed then it will read the
464
         * entire image but when the source hasn't pixel size it will read a sample of data. This set of data will have
465
         * the size defined in FIXED_SIZE. 
466
         * 
467
         * @param pos Posici?n donde se empieza  a leer
468
         * @param blockHeight Altura m?xima del bloque leido
469
         * @return Object que es un array tridimendional del tipo de datos del raster. (Bandas X Filas X Columnas)
470
         * @throws InvalidSetViewException
471
         * @throws FileNotOpenException
472
         * @throws RasterDriverException
473
         */
474
        public Object readBlock(int pos, int blockHeight, double scale) 
475
        throws InvalidSetViewException, FileNotOpenException, RasterDriverException, ProcessInterruptedException {
476
                File lastFile = getFileLayer();
477
                BandList bandList = new BandListImpl();
478
                for (int i = 0; i < 3; i++) {
479
                        try {
480
                                bandList.addBand(new DatasetBandImpl(lastFile.getPath(), pos, Buffer.TYPE_BYTE, 3));
481
                        } catch (BandNotFoundInListException e1) {
482
                        }
483
                }
484
                bandList.setDrawableBands(new int[]{0, 1, 2});
485

    
486
                try {
487
                        lastRequestProvider = openLastRequest();
488
                        return lastRequestProvider.readBlock(pos, blockHeight, scale);
489
                } catch (ProviderNotRegisteredException exc) {
490
                        throw new RasterDriverException("Error building GdalDriver", exc);
491
                } catch (InitializeException exc) {
492
                        throw new RasterDriverException("Error building GdalDriver", exc);
493
                }
494
        }
495
        
496
        public double getLastRequestHeight() throws RasterDriverException {
497
                if(lastRequestProvider == null) {
498
                        try {
499
                                lastRequestProvider = openLastRequest();
500
                        } catch (ProviderNotRegisteredException e) {
501
                                throw new RasterDriverException("Error building GdalDriver", e);
502
                        } catch (InitializeException e) {
503
                                throw new RasterDriverException("Error building GdalDriver", e);
504
                        }
505
                }
506
                return lastRequestProvider.getHeight();
507
        }
508
        
509
        public double getLastRequestWidth() throws RasterDriverException {
510
                if(lastRequestProvider == null) {
511
                        try {
512
                                lastRequestProvider = openLastRequest();
513
                        } catch (ProviderNotRegisteredException e) {
514
                                throw new RasterDriverException("Error building GdalDriver", e);
515
                        } catch (InitializeException e) {
516
                                throw new RasterDriverException("Error building GdalDriver", e);
517
                        }
518
                }
519
                return lastRequestProvider.getWidth();
520
        }
521
        
522
        public File getLastRequest() {
523
                return lastRequest;
524
        }
525
        
526
        public Buffer getBufferLastRequest() throws ProcessInterruptedException, RasterDriverException {
527
                try {
528
                        lastRequestProvider = openLastRequest();
529
                        return getDownloadedRaster(lastRequestProvider);
530
                } catch (ProviderNotRegisteredException e) {
531
                        throw new RasterDriverException("Error building GdalDriver", e);
532
                } catch (InitializeException e) {
533
                        throw new RasterDriverException("Error building GdalDriver", e);
534
                } catch (QueryException e) {
535
                        throw new RasterDriverException("Error building GdalDriver", e);
536
                }
537
        }
538
        
539
        /**
540
         * Opens the last request downloaded
541
         * @return
542
         * @throws ProviderNotRegisteredException
543
         * @throws InitializeException
544
         * @throws RasterDriverException
545
         */
546
        private AbstractRasterProvider openLastRequest() throws ProviderNotRegisteredException, InitializeException, RasterDriverException {
547
                if(lastRequestProvider != null)
548
                        lastRequestProvider.close();
549
                File lastFile = getFileLayer();
550
                lastRequestProvider = DefaultProviderServices.loadProvider(new File(lastFile.getPath()));
551
                setColorTable(lastRequestProvider.getColorTable());
552
                return lastRequestProvider;
553
        }
554

    
555
        public Object getData(int x, int y, int band)
556
                throws InvalidSetViewException, FileNotOpenException, RasterDriverException {
557
                return null;
558
        }
559
        
560
        /**
561
         * Gets the georeferencing file name form a raster file
562
         * @param file
563
         * a raster file
564
         * @return
565
         * a georeferencing file
566
         */
567
        private String getWorldFile(String file){                
568
                String worldFile = file;
569
                int index = file.lastIndexOf(".");
570
                if (index > 0){                        
571
                        worldFile = file.substring(0, index) + getExtensionWorldFile();
572
                }
573
                return worldFile;
574
        }
575
        
576
        /**
577
         * Obtiene la extensi?n del fichero de georreferenciaci?n
578
         * @return String con la extensi?n del fichero de georreferenciaci?n dependiendo
579
         * del valor del formato obtenido del servidor. Por defecto asignaremos un .wld
580
         */
581
        private String getExtensionWorldFile() {
582
                WMSDataParameters p = (WMSDataParameters)parameters;
583
                String extWorldFile = ".wld";
584
                if(p.getFormat().equals("image/tif") || p.getFormat().equals("image/tiff")) {
585
                        extWorldFile = ".tfw";
586
                }
587
                return extWorldFile;
588
        }
589
        
590
        public WMSStatus loadWMSStatus(Rectangle2D bBox) {
591
                WMSDataParameters p = (WMSDataParameters)parameters;
592
                WMSStatus wmsStatus = new WMSStatus();
593
                wmsStatus.setLayerNames(Utilities.createVector(p.getLayerQuery(), ","));
594
                wmsStatus.setSrs(p.getSRSCode());
595
                wmsStatus.setFormat(p.getFormat());
596
                wmsStatus.setInfoFormat(p.getInfoFormat());
597
                wmsStatus.setStyles(p.getStyles());
598
                wmsStatus.setDimensions(p.getDimensions());
599
                wmsStatus.setTransparency(p.isWmsTransparent());
600
                wmsStatus.setOnlineResource((String) p.getOnlineResource().get("GetMap"));
601
                if(p.isSizeFixed()) {
602
                        wmsStatus.setExtent(getExtent().toRectangle2D());
603
                } else
604
                        wmsStatus.setExtent(bBox);
605
                wmsStatus.setHeight(p.getHeight());
606
                wmsStatus.setWidth(p.getWidth());
607
                IProjection proj = (IProjection)p.getSRS();
608
                if(proj != null)
609
                        wmsStatus.setProjected(proj.isProjected());
610
                return wmsStatus;
611
        }
612
        
613
        /**
614
         * This function downloads the file and creates the georeferencing file
615
         * @param wmsStatus
616
         * @param ulx
617
         * @param uly
618
         * @param lrx
619
         * @param lry
620
         * @param w
621
         * @param h
622
         * @return
623
         * @throws RasterDriverException
624
         */
625
        private File downloadFile(WMSStatus wmsStatus, double ulx, double uly, double lrx, double lry, int w, int h) throws RasterDriverException {
626
                WMSDataParameters p = (WMSDataParameters)parameters;
627
                try {
628
                        lastRequest = getConnector().getMap(wmsStatus, ((WMSDataParameters)parameters).getCancellable());
629
                } catch (RemoteServiceException e) {
630
                        throw new RasterDriverException(e.getMessage(), e);
631
                }
632
                
633
                if(lastRequest == null)
634
                        return null;
635
                
636
                String nameWorldFile = getWorldFile(lastRequest.getPath());
637
                try {
638
                        if(p.isSizeFixed()) {
639
                                Extent e = getExtent();
640
                                fileUtil.createWorldFile(nameWorldFile, e, p.getWidth(), p.getHeight());
641
                        } else {
642
                                fileUtil.createWorldFile(nameWorldFile, new ExtentImpl(ulx, uly, lrx, lry), w, h);
643
                        }
644
                } catch (IOException e) {
645
                        throw new RasterDriverException("Error creating world file", e);
646
                }
647

    
648
                return lastRequest;
649
        }
650
        
651
        @Override
652
        public void loadBuffer(SpiRasterQuery q) 
653
                        throws ProcessInterruptedException, RasterDriverException {
654
                Extent bbox = q.getRequestBoundingBox();
655
                lastWidthRequest = q.getBufWidth();
656
                lastHeightRequest = q.getBufHeight();
657
                WMSStatus wmsStatus = loadWMSStatus(bbox.toRectangle2D());
658
                
659
                lastRequest = downloadFile(wmsStatus, 
660
                                bbox.getULX(), 
661
                                bbox.getULY(), 
662
                                bbox.getLRX(), 
663
                                bbox.getLRY(), 
664
                                q.getBufWidth(), 
665
                                q.getBufHeight());
666
                
667
                if (lastRequest == null) {
668
                        return;
669
                }
670
                
671
                Buffer b = null;
672
                try {
673
                        b = getDownloadedRaster(lastRequest);
674
                } catch (QueryException e) {
675
                        throw new RasterDriverException("Error building GdalDriver", e);
676
                } catch (ProviderNotRegisteredException e) {
677
                        throw new RasterDriverException("Error building GdalDriver", e);
678
                } catch (InitializeException e) {
679
                        throw new RasterDriverException("Error building GdalDriver", e);
680
                }
681
                q.setBufferResult(b);
682
        }
683
        
684
        private Buffer getDownloadedRaster(File f) throws ProcessInterruptedException, QueryException, ProviderNotRegisteredException, InitializeException {
685
                AbstractRasterProvider provider = DefaultProviderServices.loadProvider(new File(f.getPath()));
686
                setColorTable(provider.getColorTable());
687
                return getDownloadedRaster(provider);
688
        }
689
        
690
        private Buffer getDownloadedRaster(AbstractRasterProvider provider) throws ProcessInterruptedException, QueryException, ProviderNotRegisteredException, InitializeException {
691
                DefaultRasterStore store = new DefaultRasterStore();
692
                store.setProvider(provider);
693

    
694
                RasterQuery q = RasterLocator.getManager().createQuery();
695
                q.setAreaOfInterest();
696
                q.setAllDrawableBands();
697
                Buffer buf = store.query(q);
698

    
699
                store.close();
700
                return buf;
701
        }
702
        
703
        /**
704
         * Assigns the list of bands RGB and read a window of data
705
         * @param rasterBuf
706
         * @param bandList
707
         * @param lastFile
708
         * @param ulx
709
         * @param uly
710
         * @param lrx
711
         * @param lry
712
         * @return
713
         * @throws RasterDriverException
714
         * @throws ProcessInterruptedException
715
         */
716
        /*public Buffer getBuffer(Buffer rasterBuf, BandList bandList, File lastFile, 
717
                        double ulx, double uly, double lrx, double lry) throws RasterDriverException, ProcessInterruptedException {
718
                try {
719
                        //El nombre de fichero que ha puesto en el bandList es el del servidor y no el del fichero en disco
720
                        String serverName = bandList.getBand(0).getFileName();
721
                        for (int i = 0; i < bandList.getBandCount(); i++) {
722
                                bandList.getBand(i).setFileName(lastFile.getPath());
723
                        }
724
                        
725
                        AbstractRasterProvider driver = DefaultProviderServices.loadProvider(new File(lastFile.getPath()));
726
                        setColorTable(driver.getColorTable());
727
                        
728
                        DefaultRasterQuery q = (DefaultRasterQuery)RasterLocator.getManager().createQuery();
729
                        q.setAreaOfInterest(new ExtentImpl(ulx, uly, lrx, lry));
730
                        q.setBandList(bandList);
731
                        q.setBuffer(rasterBuf);
732
                        Buffer buf = driver.getDataSet(q);
733
                        
734
                        for (int i = 0; i < bandList.getBandCount(); i++) {
735
                                bandList.getBand(i).setFileName(serverName);
736
                        }
737
                        
738
                        return buf;
739
                } catch (ProviderNotRegisteredException e) {
740
                        throw new RasterDriverException("Error building GdalDriver", e);
741
                } catch (InitializeException e) {
742
                        throw new RasterDriverException("Error building GdalDriver", e);
743
                }
744
        }*/
745
        
746
        /*public void getWindow(Extent ex, int bufWidth, int bufHeight, 
747
                        BandList bandList, TileListener listener, TaskStatus status) throws ProcessInterruptedException, RasterDriverException {
748

749
                Buffer raster = DefaultRasterManager.getInstance().createBuffer(getDataType()[0], bufWidth, bufHeight, 3, true);
750
                getWindow(ex, bufWidth, bufHeight, bandList, raster, true, null);
751
                raster.setDataExtent(ex.toRectangle2D());
752

753
                TileCacheManager m = TileCacheLocator.getManager();
754
                org.gvsig.raster.cache.tile.Tile t = m.createTile(-1, 0, 0);
755
                t.setData(new Object[]{raster});
756
                t.setUl(new Point2D.Double(ex.getULX(), ex.getULY()));
757
                t.setLr(new Point2D.Double(ex.getLRX(), ex.getLRY()));
758
                t.setDownloaderParams("AffineTransform", getAffineTransform());
759
                t.setDownloaderParams("Tiling", new Boolean(false));
760
                try {
761
                        listener.tileReady(t);
762
                } catch (TileGettingException e) {
763
                        throw new RasterDriverException("Error throwing a tile", e);
764
                }
765

766
                //listener.nextBuffer(raster, null, new ExtentImpl(minX, minY, maxX, maxY), getAffineTransform(), null, false);
767
                listener.endReading();
768
        }*/
769

    
770
        /*public Buffer getWindow(Extent ex, BandList bandList, Buffer rasterBuf, TaskStatus status) 
771
                throws ProcessInterruptedException, RasterDriverException {
772
                Rectangle2D bBox = ex.toRectangle2D();
773
                lastWidthRequest = rasterBuf.getWidth();
774
                lastHeightRequest = rasterBuf.getHeight();
775
                WMSStatus wmsStatus = loadWMSStatus(bBox);
776
                
777
                lastRequest = downloadFile(wmsStatus, ex.getULX(), ex.getULY(), ex.getLRX(), ex.getLRY(), rasterBuf.getWidth(), rasterBuf.getHeight());
778
                
779
                if (lastRequest == null) {
780
                        return rasterBuf;
781
                }
782
                
783
                try {
784
                        //El nombre de fichero que ha puesto en el bandList es el del servidor y no el del fichero en disco
785
                        String serverName = bandList.getBand(0).getFileName();
786
                        for (int i = 0; i < bandList.getBandCount(); i++) {
787
                                bandList.getBand(i).setFileName(lastRequest.getPath());
788
                        }
789
                        
790
                        AbstractRasterProvider driver = DefaultProviderServices.loadProvider(new File(lastRequest.getPath()));
791
                        setColorTable(driver.getColorTable());
792
                        
793
                        DefaultRasterQuery q = (DefaultRasterQuery)RasterLocator.getManager().createQuery();
794
                        q.setAreaOfInterest(ex);
795
                        q.setBandList(bandList);
796
                        q.setBuffer(rasterBuf);
797
                        Buffer buf = driver.getDataSet(q);
798
                        
799
                        for (int i = 0; i < bandList.getBandCount(); i++) {
800
                                bandList.getBand(i).setFileName(serverName);
801
                        }
802
                        driver.close();
803
                        return buf;
804
                } catch (ProviderNotRegisteredException e) {
805
                        throw new RasterDriverException("Error building GdalDriver", e);
806
                } catch (InitializeException e) {
807
                        throw new RasterDriverException("Error building GdalDriver", e);
808
                }
809
        }*/
810

    
811
        /*public Buffer getWindow(double ulx, double uly, double w, double h, 
812
                        BandList bandList, Buffer rasterBuf, boolean adjustToExtent, TaskStatus status) throws ProcessInterruptedException, RasterDriverException {
813
                Rectangle2D bBox = new Rectangle2D.Double(ulx, uly, w, h);
814
                lastWidthRequest = rasterBuf.getWidth();
815
                lastHeightRequest = rasterBuf.getHeight();
816
                WMSStatus wmsStatus = loadWMSStatus(bBox);
817
                
818
                lastRequest = downloadFile(wmsStatus, ulx, uly, ulx + w, uly - h, rasterBuf.getWidth(), rasterBuf.getHeight());
819
                
820
                if (lastRequest == null) {
821
                        return rasterBuf;
822
                }
823
                
824
                try {
825
                        //El nombre de fichero que ha puesto en el bandList es el del servidor y no el del fichero en disco
826
                        String serverName = bandList.getBand(0).getFileName();
827
                        for (int i = 0; i < bandList.getBandCount(); i++) {
828
                                bandList.getBand(i).setFileName(lastRequest.getPath());
829
                        }
830
                        
831
                        AbstractRasterProvider driver = DefaultProviderServices.loadProvider(new File(lastRequest.getPath()));
832
                        setColorTable(driver.getColorTable());
833
                        
834
                        DefaultRasterQuery q = (DefaultRasterQuery)RasterLocator.getManager().createQuery();
835
                        q.setAreaOfInterest(ulx, uly, w, h);
836
                        q.setBandList(bandList);
837
                        q.setBuffer(rasterBuf);
838
                        q.setAdjustToExtent(adjustToExtent);
839
                        
840
                        Buffer buf = driver.getDataSet(q);
841
                        
842
                        for (int i = 0; i < bandList.getBandCount(); i++) {
843
                                bandList.getBand(i).setFileName(serverName);
844
                        }
845
                        
846
                        return buf;
847
                } catch (ProviderNotRegisteredException e) {
848
                        throw new RasterDriverException("Error building GdalDriver", e);
849
                } catch (InitializeException e) {
850
                        throw new RasterDriverException("Error building GdalDriver", e);
851
                }
852
        }*/
853

    
854
        /*public Buffer getWindow(Extent extent, int bufWidth, int bufHeight, 
855
                        BandList bandList, Buffer rasterBuf, boolean adjustToExtent, TaskStatus status) throws ProcessInterruptedException, RasterDriverException {
856
                Rectangle2D bBox = extent.toRectangle2D();//new Rectangle2D.Double(ulx, lry, Math.abs(lrx - ulx), Math.abs(lry - uly));
857
                lastWidthRequest = rasterBuf.getWidth();
858
                lastHeightRequest = rasterBuf.getHeight();
859
                WMSStatus wmsStatus = loadWMSStatus(bBox);
860
                lastRequest = downloadFile(wmsStatus, extent.getULX(), extent.getULY(), extent.getLRX(), extent.getLRY(), rasterBuf.getWidth(), rasterBuf.getHeight());
861
                
862
                if (lastRequest == null) {
863
                        return rasterBuf;
864
                }
865
                
866
                try {
867
                        //El nombre de fichero que ha puesto en el bandList es el del servidor y no el del fichero en disco
868
                        String serverName = bandList.getBand(0).getFileName();
869
                        for (int i = 0; i < bandList.getBandCount(); i++) {
870
                                bandList.getBand(i).setFileName(lastRequest.getPath());
871
                        }
872
                        
873
                        AbstractRasterProvider driver = DefaultProviderServices.loadProvider(new File(lastRequest.getPath()));
874
                        setColorTable(driver.getColorTable());
875
                        
876
                        DefaultRasterQuery q = (DefaultRasterQuery)RasterLocator.getManager().createQuery();
877
                        q.setAreaOfInterest(extent, bufWidth, bufHeight);
878
                        q.setBandList(bandList);
879
                        q.setBuffer(rasterBuf);
880
                        q.setAdjustToExtent(adjustToExtent);
881
                        Buffer buf = driver.getDataSet(q);
882

883
                        for (int i = 0; i < bandList.getBandCount(); i++) {
884
                                bandList.getBand(i).setFileName(serverName);
885
                        }
886
                        
887
                        return buf;
888
                } catch (ProviderNotRegisteredException e) {
889
                        throw new RasterDriverException("Error building GdalDriver", e);
890
                } catch (InitializeException e) {
891
                        throw new RasterDriverException("Error building GdalDriver", e);
892
                }
893
        }*/
894

    
895
//        public Buffer getWindow(int x, int y, 
896
//                        BandList bandList, Buffer rasterBuf) throws ProcessInterruptedException, RasterDriverException {
897
//                int w = rasterBuf.getWidth();
898
//                int h = rasterBuf.getHeight();
899
//                Point2D p1 = rasterToWorld(new Point2D.Double(x, y));
900
//                Point2D p2 = rasterToWorld(new Point2D.Double(x + w, y + h));
901
//                lastWidthRequest = rasterBuf.getWidth();
902
//                lastHeightRequest = rasterBuf.getHeight();
903
//                Rectangle2D bBox = new Rectangle2D.Double(p1.getX(), p1.getY(), Math.abs(p1.getX() - p1.getX()), Math.abs(p1.getY() - p2.getY()));
904
//                WMSStatus wmsStatus = loadWMSStatus(bBox);
905
//                
906
//                lastRequest = downloadFile(wmsStatus, p1.getX(), p1.getY(), p2.getX(), p2.getY(), rasterBuf.getWidth(), rasterBuf.getHeight());
907
//                
908
//                if (lastRequest == null) {
909
//                        return rasterBuf;
910
//                }
911
//
912
//                AbstractRasterProvider driver = null;
913
//                try {
914
//                        //El nombre de fichero que ha puesto en el bandList es el del servidor y no el del fichero en disco
915
//                        String serverName = bandList.getBand(0).getFileName();
916
//                        for (int i = 0; i < bandList.getBandCount(); i++) {
917
//                                bandList.getBand(i).setFileName(lastRequest.getPath());
918
//                        }
919
//                        
920
//                        driver = DefaultProviderServices.loadProvider(new File(lastRequest.getPath()));
921
//                        Buffer buf = driver.getWindow(0, 0, w, h, bandList, rasterBuf);
922
//
923
//                        for (int i = 0; i < bandList.getBandCount(); i++) {
924
//                                bandList.getBand(i).setFileName(serverName);
925
//                        }
926
//                        
927
//                        return buf;
928
//                } catch (ProviderNotRegisteredException e) {
929
//                        throw new RasterDriverException("Error building GdalDriver", e);
930
//                } catch (InitializeException e) {
931
//                        throw new RasterDriverException("Error building GdalDriver", e);
932
//                }
933
//        }
934

    
935
        /*public Buffer getWindow(int x, int y, int w, int h, 
936
                        BandList bandList, Buffer rasterBuf, TaskStatus status) throws ProcessInterruptedException, RasterDriverException {
937
                Point2D p1 = rasterToWorld(new Point2D.Double(x, y));
938
                Point2D p2 = rasterToWorld(new Point2D.Double(x + w, y + h));
939
                lastWidthRequest = rasterBuf.getWidth();
940
                lastHeightRequest = rasterBuf.getHeight();
941
                Rectangle2D bBox = new Rectangle2D.Double(p1.getX(), p1.getY(), Math.abs(p1.getX() - p1.getX()), Math.abs(p1.getY() - p2.getY()));
942
                WMSStatus wmsStatus = loadWMSStatus(bBox);
943
                
944
                lastRequest = downloadFile(wmsStatus, p1.getX(), p1.getY(), p2.getX(), p2.getY(), rasterBuf.getWidth(), rasterBuf.getHeight());
945
                
946
                if (lastRequest == null) {
947
                        return rasterBuf;
948
                }
949

950
                AbstractRasterProvider driver = null;
951
                try {
952
                        //El nombre de fichero que ha puesto en el bandList es el del servidor y no el del fichero en disco
953
                        String serverName = bandList.getBand(0).getFileName();
954
                        for (int i = 0; i < bandList.getBandCount(); i++) {
955
                                bandList.getBand(i).setFileName(lastRequest.getPath());
956
                        }
957
                        
958
                        driver = DefaultProviderServices.loadProvider(new File(lastRequest.getPath()));
959
                        setColorTable(driver.getColorTable());
960
                        
961
                        DefaultRasterQuery q = (DefaultRasterQuery)RasterLocator.getManager().createQuery();
962
                        q.setAreaOfInterest(0, 0, w, h);
963
                        q.setBandList(bandList);
964
                        q.setBuffer(rasterBuf);
965
                        Buffer buf = driver.getDataSet(q);
966

967
                        for (int i = 0; i < bandList.getBandCount(); i++) {
968
                                bandList.getBand(i).setFileName(serverName);
969
                        }
970
                        
971
                        return buf;
972
                } catch (ProviderNotRegisteredException e) {
973
                        throw new RasterDriverException("Error building GdalDriver", e);
974
                } catch (InitializeException e) {
975
                        throw new RasterDriverException("Error building GdalDriver", e);
976
                }
977
        }*/
978

    
979
        public Image getImageLegend() {
980
                try {
981
                        WMSStatus wmsStatus = loadWMSStatus(getExtent().toRectangle2D());
982
                        wmsStatus.setOnlineResource((String) getParameters().getOnlineResource().get("GetCapabilities"));
983
                        File file = getConnector().getLegendGraphic(wmsStatus, getParameters().getLayerQuery(), null);
984
                        Image img = null;
985
                        if ((file != null) && (file.length() > 0)) {
986
                                img = new ImageIcon(file.getAbsolutePath()).getImage();
987
                        }
988
                        return img;
989
                } catch (Exception e) {
990
                        logger.info("Problems in GetLegendGraphic", e);
991
                }
992
                return null;
993
        }
994

    
995
        public int getBlockSize() {
996
                return 0;
997
        }
998

    
999
        public void setAffineTransform(AffineTransform t){
1000
                
1001
        }
1002

    
1003
        public int getOverviewCount(int band) throws BandAccessException, RasterDriverException {
1004
                return 0;
1005
        }
1006

    
1007
        public int getOverviewWidth(int band, int overview) throws BandAccessException, RasterDriverException {
1008
                return 0;
1009
        }
1010

    
1011
        public int getOverviewHeight(int band, int overview) throws BandAccessException, RasterDriverException {
1012
                return 0;
1013
        }
1014

    
1015
        public boolean isOverviewsSupported() {
1016
                return false;
1017
        }
1018

    
1019
        public boolean isReproyectable() {
1020
                return false;
1021
        }
1022

    
1023
        public String getName() {
1024
                return NAME;
1025
        }
1026
        
1027
        /**
1028
         * Convierte un punto desde coordenadas pixel a coordenadas del mundo.
1029
         * @param pt Punto a transformar
1030
         * @return punto transformado en coordenadas del mundo
1031
         */
1032
        public Point2D rasterToWorld(Point2D pt) {
1033
                Point2D p = new Point2D.Double();
1034
                getAffineTransform().transform(pt, p);
1035
                return p;
1036
        }
1037

    
1038
        /**
1039
         * Convierte un punto desde del mundo a coordenadas pixel.
1040
         * @param pt Punto a transformar
1041
         * @return punto transformado en coordenadas pixel
1042
         */
1043
        public Point2D worldToRaster(Point2D pt) {
1044
                Point2D p = new Point2D.Double();
1045
                try {
1046
                        getAffineTransform().inverseTransform(pt, p);
1047
                } catch (NoninvertibleTransformException e) {
1048
                        return pt;
1049
                }
1050
                return p;
1051
        }
1052
        
1053
        public void setStatus(RasterProvider provider) {
1054
                if(provider instanceof WMSProvider) {
1055
                }
1056
        }
1057
        
1058
        /**
1059
         * ASigna el par?metro de inicializaci?n del driver.
1060
         */
1061
        public void setParam(DataStoreProviderServices storeServices, DataStoreParameters param) {
1062
                if(param instanceof WMSDataParameters)
1063
                        this.uri = ((WMSDataParameters)param).getURI();
1064
                this.param = param;
1065
        }
1066
        
1067
        public String getInfoByPoint(int x, int y, Extent bbox, int w, int h, ICancellable cancellable) throws InfoByPointException {
1068
                WMSDataParameters p = (WMSDataParameters)parameters;
1069
                WMSStatus wmsStatus = new WMSStatus();
1070
                wmsStatus.setLayerNames(Utilities.createVector(p.getLayerQuery(), ","));
1071
                wmsStatus.setSrs(p.getSRSCode());
1072
                wmsStatus.setFormat(p.getFormat());
1073
                wmsStatus.setInfoFormat(p.getInfoFormat());
1074
                wmsStatus.setStyles(p.getStyles());
1075
                wmsStatus.setDimensions(p.getDimensions());
1076
                wmsStatus.setTransparency(p.isWmsTransparent());
1077
                wmsStatus.setOnlineResource((String) p.getOnlineResource().get("GetMap"));
1078
                wmsStatus.setExtent(bbox.toRectangle2D());
1079
                wmsStatus.setHeight(h);
1080
                wmsStatus.setWidth(w);
1081
                try {
1082
                        return getConnector().getFeatureInfo(wmsStatus, x, y, Integer.MAX_VALUE, cancellable);
1083
                } catch (RemoteServiceException e) {
1084
                        throw new InfoByPointException("Error in getFeatureInfo", e);
1085
                }
1086
        }
1087
        
1088
        /**
1089
         * Gets the suffix of the downloaded image
1090
         * @return
1091
         */
1092
        public String getFileSuffix() {
1093
                WMSDataParameters p = (WMSDataParameters)parameters;
1094
                String format = p.getFormat();
1095
                if (format == null){
1096
                        return "xml";
1097
                }
1098
                if (format.indexOf("png") >= 0){
1099
                return "png";
1100
                }        
1101
            if (format.indexOf("xml") >= 0){
1102
                return "xml";
1103
            }        
1104
            if (format.indexOf("gif") >= 0){
1105
                return "gif";
1106
            }
1107
            if (format.indexOf("tif") >= 0){
1108
                return "tif";
1109
            }
1110
            if (format.indexOf("bmp") >= 0){
1111
                return "bmp";
1112
            }
1113
            if (format.indexOf("jpg") >= 0
1114
                || format.indexOf("jpeg") >= 0){
1115
                return "jpg";                         
1116
            }
1117
                return "xml";
1118
        }
1119
        
1120
        public TileServer getTileServer() {
1121
                if(tileServer == null) {
1122
                        DefaultRasterStore store = new DefaultRasterStore();
1123
                        store.setProvider(this);
1124
                        tileServer = new WMSTileServer(store);
1125
                }
1126
                return tileServer;
1127
        }
1128
        
1129
        public boolean isRasterEnclosed() {
1130
                WMSDataParameters p = (WMSDataParameters)parameters;
1131
                if(p.isSizeFixed()) {
1132
                        return false;
1133
                }
1134
                return true;
1135
        }
1136
        
1137
        public String getRMFFile() {
1138
                if(lastRequest != null)
1139
                        return fileUtil.getNameWithoutExtension(lastRequest.getAbsolutePath()) + ".rmf";
1140
                return null;
1141
        }
1142
        
1143
        public HistogramComputer getHistogramComputer() {
1144
                if (histogram == null)
1145
                        histogram = new RemoteStoreHistogram(this);
1146
                return histogram;
1147
        }
1148
}