Statistics
| Revision:

gvsig-raster / org.gvsig.raster.wms / trunk / org.gvsig.raster.wms / org.gvsig.raster.wms.io / src / main / java / org / gvsig / raster / wms / io / WMSProvider.java @ 3200

History | View | Annotate | Download (39.4 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.List;
34
import java.util.Vector;
35

    
36
import javax.swing.ImageIcon;
37

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

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

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

    
358
        public Rectangle2D getLayerExtent(String layerName, String srs) throws RemoteServiceException {
359
                return getConnector().getLayersExtent(new String[]{layerName}, srs);
360
        }
361

    
362
        public RasterProvider load() {
363
                return this;
364
        }
365
        
366
        public boolean isOpen() {
367
                return open;
368
        }
369

    
370
        public void close() {
371
                open = false;
372
        }
373
        
374
        public Transparency getTransparency() {
375
                if(fileTransparency == null)
376
                        fileTransparency = new DataStoreTransparency(getColorInterpretation());
377
                return fileTransparency;
378
        }
379

    
380
        public String translateFileName(String fileName) {
381
                return fileName;
382
        }
383

    
384
        public void setView(Extent e) {
385
                viewRequest = e;
386
        }
387

    
388
        public Extent getView() {
389
                return viewRequest;
390
        }
391
        
392
        public double getWidth() {
393
                WMSDataParameters p = (WMSDataParameters)parameters;
394
                return p.getWidth();
395
        }
396

    
397
        public double getHeight() {
398
                WMSDataParameters p = (WMSDataParameters)parameters;
399
                return p.getHeight();
400
        }
401
        
402
        /**
403
         * Gets WMS parameters
404
         * @return
405
         */
406
        public WMSDataParameters getParameters() {
407
                return (WMSDataParameters)parameters;
408
        }
409

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

    
451
        /**
452
         * Reads a complete block of data and returns an tridimensional array of the right type. This function is useful
453
         * 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
         * 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
         * 
457
         * @param pos Posici?n donde se empieza  a leer
458
         * @param blockHeight Altura m?xima del bloque leido
459
         * @return Object que es un array tridimendional del tipo de datos del raster. (Bandas X Filas X Columnas)
460
         * @throws InvalidSetViewException
461
         * @throws FileNotOpenException
462
         * @throws RasterDriverException
463
         */
464
        public Object readBlock(int pos, int blockHeight, double scale) 
465
        throws InvalidSetViewException, FileNotOpenException, RasterDriverException, ProcessInterruptedException {
466
                File lastFile = getFileLayer();
467
                BandList bandList = new BandListImpl();
468
                for (int i = 0; i < 3; i++) {
469
                        try {
470
                                bandList.addBand(new DatasetBandImpl(lastFile.getPath(), pos, Buffer.TYPE_BYTE, 3));
471
                        } catch (BandNotFoundInListException e1) {
472
                        }
473
                }
474
                bandList.setDrawableBands(new int[]{0, 1, 2});
475

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

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

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

    
686
                RasterQuery q = RasterLocator.getManager().createQuery();
687
                q.setAreaOfInterest();
688
                if(getColorInterpretation() != null)
689
                        q.setDrawableBands(getColorInterpretation().buildRenderBands());
690
                if(store.getBandCount() > 3)
691
                        q.forceARGBRequest();
692
                else 
693
                        q.forceRGBRequest();
694
                
695
                Buffer buf = store.query(q);
696

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

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

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

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

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

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

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

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

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

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

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

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

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

    
993
        public int getBlockSize() {
994
                return 0;
995
        }
996

    
997
        public void setAffineTransform(AffineTransform t){
998
                
999
        }
1000

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

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

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

    
1013
        public boolean isOverviewsSupported() {
1014
                return false;
1015
        }
1016

    
1017
        public boolean isReproyectable() {
1018
                return false;
1019
        }
1020

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

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