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 @ 2887

History | View | Annotate | Download (40 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.exception.RmfSerializerException;
60
import org.gvsig.fmap.dal.coverage.store.RasterQuery;
61
import org.gvsig.fmap.dal.coverage.store.props.ColorInterpretation;
62
import org.gvsig.fmap.dal.coverage.store.props.HistogramComputer;
63
import org.gvsig.fmap.dal.coverage.store.props.Transparency;
64
import org.gvsig.fmap.dal.exception.InitializeException;
65
import org.gvsig.fmap.dal.exception.ProviderNotRegisteredException;
66
import org.gvsig.fmap.dal.spi.DataManagerProviderServices;
67
import org.gvsig.fmap.dal.spi.DataStoreProviderServices;
68
import org.gvsig.metadata.MetadataLocator;
69
import org.gvsig.raster.cache.tile.provider.TileServer;
70
import org.gvsig.raster.impl.buffer.SpiRasterQuery;
71
import org.gvsig.raster.impl.datastruct.BandListImpl;
72
import org.gvsig.raster.impl.datastruct.DatasetBandImpl;
73
import org.gvsig.raster.impl.datastruct.ExtentImpl;
74
import org.gvsig.raster.impl.provider.AbstractRasterProvider;
75
import org.gvsig.raster.impl.provider.RasterProvider;
76
import org.gvsig.raster.impl.provider.RemoteRasterProvider;
77
import org.gvsig.raster.impl.store.DefaultRasterStore;
78
import org.gvsig.raster.impl.store.DefaultStoreFactory;
79
import org.gvsig.raster.impl.store.properties.DataStoreColorInterpretation;
80
import org.gvsig.raster.impl.store.properties.DataStoreTransparency;
81
import org.gvsig.raster.impl.store.properties.RemoteStoreHistogram;
82
import org.gvsig.raster.util.DefaultProviderServices;
83
import org.gvsig.raster.wms.io.downloader.WMSTileServer;
84
import org.gvsig.remoteclient.utils.Utilities;
85
import org.gvsig.remoteclient.wms.WMSStatus;
86
import org.gvsig.tools.ToolsLocator;
87
import org.slf4j.Logger;
88
import org.slf4j.LoggerFactory;
89
/**
90
 * Clase que representa al driver de acceso a datos de wms.
91
 *
92
 * @author Nacho Brodin (nachobrodin@gmail.com)
93
 */
94
public class WMSProvider extends AbstractRasterProvider implements RemoteRasterProvider {
95
        public static String                NAME                     = "Wms Store";
96
        public static String                DESCRIPTION              = "Wms Raster file";
97
        public static final String          METADATA_DEFINITION_NAME = "WmsStore";
98
        private static final Logger         logger                    = LoggerFactory.getLogger(WMSProvider.class);
99
        private static final int            FIXED_SIZE               = 800;
100
        private Extent                      viewRequest              = null;
101
        private static Hashtable<String, WMSConnector>    
102
                                            drivers                  = new Hashtable<String, WMSConnector> ();
103
        private boolean                     open                     = false;
104
        private DataStoreTransparency       fileTransparency         = null;
105
        private final int                                        minTilePrintWidth        = 12;
106
        private final int                                        minTilePrintHeight       = 12;
107
        //The out size depends on the last request
108
        private int                         lastWidthRequest         = 0;
109
        private int                         lastHeightRequest        = 0;
110
        //Only for fixed size. Complete extent and FIXED_SIZE in long side
111
        private File                        fileLayerPixelSize       = null;
112
        private File                        lastRequest              = null;
113
        private AbstractRasterProvider       lastRequestProvider      = null; 
114
        
115
        public static void register() {
116
                DataManagerProviderServices dataman = (DataManagerProviderServices) DALLocator.getDataManager();
117
                if (dataman != null && !dataman.getStoreProviders().contains(NAME)) {
118
                        dataman.registerStoreProvider(NAME,
119
                                        WMSProvider.class, WMSDataParametersImpl.class);
120
                }
121

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

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

    
365
        public Rectangle2D getLayerExtent(String layerName, String srs) throws RemoteServiceException {
366
                return getConnector().getLayersExtent(new String[]{layerName}, srs);
367
        }
368

    
369
        public RasterProvider load() {
370
                return this;
371
        }
372
        
373
        public boolean isOpen() {
374
                return open;
375
        }
376

    
377
        public void close() {
378
                open = false;
379
        }
380
        
381
        public Transparency getTransparency() {
382
                if(fileTransparency == null)
383
                        fileTransparency = new DataStoreTransparency(getColorInterpretation());
384
                return fileTransparency;
385
        }
386

    
387
        public String translateFileName(String fileName) {
388
                return fileName;
389
        }
390

    
391
        public void setView(Extent e) {
392
                viewRequest = e;
393
        }
394

    
395
        public Extent getView() {
396
                return viewRequest;
397
        }
398
        
399
        public double getWidth() {
400
                WMSDataParameters p = (WMSDataParameters)parameters;
401
                if(p.isSizeFixed()) {
402
                        return p.getWidth();
403
                }
404
                if (lastWidthRequest <= 0) 
405
                        return p.getWidth();
406
                if (lastWidthRequest < minTilePrintWidth) 
407
                        return minTilePrintWidth;
408
                return lastWidthRequest;
409
        }
410

    
411
        public double getHeight() {
412
                WMSDataParameters p = (WMSDataParameters)parameters;
413
                if(p.isSizeFixed()) {
414
                        return p.getHeight();
415
                }
416
                if (lastHeightRequest <= 0) 
417
                        return p.getHeight();
418
                if (lastHeightRequest < minTilePrintHeight) 
419
                        return minTilePrintHeight;
420
                return lastHeightRequest;
421
        }
422
        
423
        /**
424
         * Gets WMS parameters
425
         * @return
426
         */
427
        public WMSDataParameters getParameters() {
428
                return (WMSDataParameters)parameters;
429
        }
430

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

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

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

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

    
661
                return lastRequest;
662
        }
663
        
664
        @Override
665
        public void loadBuffer(SpiRasterQuery q) 
666
                        throws ProcessInterruptedException, RasterDriverException {
667
                Extent bbox = q.getRequestBoundingBox();
668
                lastWidthRequest = q.getBufWidth();
669
                lastHeightRequest = q.getBufHeight();
670
                WMSStatus wmsStatus = loadWMSStatus(bbox.toRectangle2D());
671
                
672
                lastRequest = downloadFile(wmsStatus, 
673
                                bbox.getULX(), 
674
                                bbox.getULY(), 
675
                                bbox.getLRX(), 
676
                                bbox.getLRY(), 
677
                                q.getBufWidth(), 
678
                                q.getBufHeight());
679
                
680
                if (lastRequest == null) {
681
                        return;
682
                }
683
                
684
                Buffer b = null;
685
                try {
686
                        b = getDownloadedRaster(lastRequest);
687
                } catch (QueryException e) {
688
                        throw new RasterDriverException("Error building GdalDriver", e);
689
                } catch (ProviderNotRegisteredException e) {
690
                        throw new RasterDriverException("Error building GdalDriver", e);
691
                } catch (InitializeException e) {
692
                        throw new RasterDriverException("Error building GdalDriver", e);
693
                }
694
                q.setBufferResult(b);
695
        }
696
        
697
        private Buffer getDownloadedRaster(File f) throws ProcessInterruptedException, QueryException, ProviderNotRegisteredException, InitializeException {
698
                AbstractRasterProvider provider = DefaultProviderServices.loadProvider(new File(f.getPath()));
699
                setColorTable(provider.getColorTable());
700
                return getDownloadedRaster(provider);
701
        }
702
        
703
        private Buffer getDownloadedRaster(AbstractRasterProvider provider) throws ProcessInterruptedException, QueryException, ProviderNotRegisteredException, InitializeException {
704
                DefaultRasterStore store = new DefaultRasterStore();
705
                store.setProvider(provider);
706

    
707
                RasterQuery q = RasterLocator.getManager().createQuery();
708
                q.setAreaOfInterest();
709
                if(getColorInterpretation() != null)
710
                        q.setDrawableBands(getColorInterpretation().buildRenderBands());
711
                if(store.getBandCount() > 3)
712
                        q.forceARGBRequest();
713
                else 
714
                        q.forceRGBRequest();
715
                
716
                Buffer buf = store.query(q);
717

    
718
                store.close();
719
                return buf;
720
        }
721
        
722
        /**
723
         * Assigns the list of bands RGB and read a window of data
724
         * @param rasterBuf
725
         * @param bandList
726
         * @param lastFile
727
         * @param ulx
728
         * @param uly
729
         * @param lrx
730
         * @param lry
731
         * @return
732
         * @throws RasterDriverException
733
         * @throws ProcessInterruptedException
734
         */
735
        /*public Buffer getBuffer(Buffer rasterBuf, BandList bandList, File lastFile, 
736
                        double ulx, double uly, double lrx, double lry) throws RasterDriverException, ProcessInterruptedException {
737
                try {
738
                        //El nombre de fichero que ha puesto en el bandList es el del servidor y no el del fichero en disco
739
                        String serverName = bandList.getBand(0).getFileName();
740
                        for (int i = 0; i < bandList.getBandCount(); i++) {
741
                                bandList.getBand(i).setFileName(lastFile.getPath());
742
                        }
743
                        
744
                        AbstractRasterProvider driver = DefaultProviderServices.loadProvider(new File(lastFile.getPath()));
745
                        setColorTable(driver.getColorTable());
746
                        
747
                        DefaultRasterQuery q = (DefaultRasterQuery)RasterLocator.getManager().createQuery();
748
                        q.setAreaOfInterest(new ExtentImpl(ulx, uly, lrx, lry));
749
                        q.setBandList(bandList);
750
                        q.setBuffer(rasterBuf);
751
                        Buffer buf = driver.getDataSet(q);
752
                        
753
                        for (int i = 0; i < bandList.getBandCount(); i++) {
754
                                bandList.getBand(i).setFileName(serverName);
755
                        }
756
                        
757
                        return buf;
758
                } catch (ProviderNotRegisteredException e) {
759
                        throw new RasterDriverException("Error building GdalDriver", e);
760
                } catch (InitializeException e) {
761
                        throw new RasterDriverException("Error building GdalDriver", e);
762
                }
763
        }*/
764
        
765
        /*public void getWindow(Extent ex, int bufWidth, int bufHeight, 
766
                        BandList bandList, TileListener listener, TaskStatus status) throws ProcessInterruptedException, RasterDriverException {
767

768
                Buffer raster = DefaultRasterManager.getInstance().createBuffer(getDataType()[0], bufWidth, bufHeight, 3, true);
769
                getWindow(ex, bufWidth, bufHeight, bandList, raster, true, null);
770
                raster.setDataExtent(ex.toRectangle2D());
771

772
                TileCacheManager m = TileCacheLocator.getManager();
773
                org.gvsig.raster.cache.tile.Tile t = m.createTile(-1, 0, 0);
774
                t.setData(new Object[]{raster});
775
                t.setUl(new Point2D.Double(ex.getULX(), ex.getULY()));
776
                t.setLr(new Point2D.Double(ex.getLRX(), ex.getLRY()));
777
                t.setDownloaderParams("AffineTransform", getAffineTransform());
778
                t.setDownloaderParams("Tiling", new Boolean(false));
779
                try {
780
                        listener.tileReady(t);
781
                } catch (TileGettingException e) {
782
                        throw new RasterDriverException("Error throwing a tile", e);
783
                }
784

785
                //listener.nextBuffer(raster, null, new ExtentImpl(minX, minY, maxX, maxY), getAffineTransform(), null, false);
786
                listener.endReading();
787
        }*/
788

    
789
        /*public Buffer getWindow(Extent ex, BandList bandList, Buffer rasterBuf, TaskStatus status) 
790
                throws ProcessInterruptedException, RasterDriverException {
791
                Rectangle2D bBox = ex.toRectangle2D();
792
                lastWidthRequest = rasterBuf.getWidth();
793
                lastHeightRequest = rasterBuf.getHeight();
794
                WMSStatus wmsStatus = loadWMSStatus(bBox);
795
                
796
                lastRequest = downloadFile(wmsStatus, ex.getULX(), ex.getULY(), ex.getLRX(), ex.getLRY(), rasterBuf.getWidth(), rasterBuf.getHeight());
797
                
798
                if (lastRequest == null) {
799
                        return rasterBuf;
800
                }
801
                
802
                try {
803
                        //El nombre de fichero que ha puesto en el bandList es el del servidor y no el del fichero en disco
804
                        String serverName = bandList.getBand(0).getFileName();
805
                        for (int i = 0; i < bandList.getBandCount(); i++) {
806
                                bandList.getBand(i).setFileName(lastRequest.getPath());
807
                        }
808
                        
809
                        AbstractRasterProvider driver = DefaultProviderServices.loadProvider(new File(lastRequest.getPath()));
810
                        setColorTable(driver.getColorTable());
811
                        
812
                        DefaultRasterQuery q = (DefaultRasterQuery)RasterLocator.getManager().createQuery();
813
                        q.setAreaOfInterest(ex);
814
                        q.setBandList(bandList);
815
                        q.setBuffer(rasterBuf);
816
                        Buffer buf = driver.getDataSet(q);
817
                        
818
                        for (int i = 0; i < bandList.getBandCount(); i++) {
819
                                bandList.getBand(i).setFileName(serverName);
820
                        }
821
                        driver.close();
822
                        return buf;
823
                } catch (ProviderNotRegisteredException e) {
824
                        throw new RasterDriverException("Error building GdalDriver", e);
825
                } catch (InitializeException e) {
826
                        throw new RasterDriverException("Error building GdalDriver", e);
827
                }
828
        }*/
829

    
830
        /*public Buffer getWindow(double ulx, double uly, double w, double h, 
831
                        BandList bandList, Buffer rasterBuf, boolean adjustToExtent, TaskStatus status) throws ProcessInterruptedException, RasterDriverException {
832
                Rectangle2D bBox = new Rectangle2D.Double(ulx, uly, w, h);
833
                lastWidthRequest = rasterBuf.getWidth();
834
                lastHeightRequest = rasterBuf.getHeight();
835
                WMSStatus wmsStatus = loadWMSStatus(bBox);
836
                
837
                lastRequest = downloadFile(wmsStatus, ulx, uly, ulx + w, uly - h, rasterBuf.getWidth(), rasterBuf.getHeight());
838
                
839
                if (lastRequest == null) {
840
                        return rasterBuf;
841
                }
842
                
843
                try {
844
                        //El nombre de fichero que ha puesto en el bandList es el del servidor y no el del fichero en disco
845
                        String serverName = bandList.getBand(0).getFileName();
846
                        for (int i = 0; i < bandList.getBandCount(); i++) {
847
                                bandList.getBand(i).setFileName(lastRequest.getPath());
848
                        }
849
                        
850
                        AbstractRasterProvider driver = DefaultProviderServices.loadProvider(new File(lastRequest.getPath()));
851
                        setColorTable(driver.getColorTable());
852
                        
853
                        DefaultRasterQuery q = (DefaultRasterQuery)RasterLocator.getManager().createQuery();
854
                        q.setAreaOfInterest(ulx, uly, w, h);
855
                        q.setBandList(bandList);
856
                        q.setBuffer(rasterBuf);
857
                        q.setAdjustToExtent(adjustToExtent);
858
                        
859
                        Buffer buf = driver.getDataSet(q);
860
                        
861
                        for (int i = 0; i < bandList.getBandCount(); i++) {
862
                                bandList.getBand(i).setFileName(serverName);
863
                        }
864
                        
865
                        return buf;
866
                } catch (ProviderNotRegisteredException e) {
867
                        throw new RasterDriverException("Error building GdalDriver", e);
868
                } catch (InitializeException e) {
869
                        throw new RasterDriverException("Error building GdalDriver", e);
870
                }
871
        }*/
872

    
873
        /*public Buffer getWindow(Extent extent, int bufWidth, int bufHeight, 
874
                        BandList bandList, Buffer rasterBuf, boolean adjustToExtent, TaskStatus status) throws ProcessInterruptedException, RasterDriverException {
875
                Rectangle2D bBox = extent.toRectangle2D();//new Rectangle2D.Double(ulx, lry, Math.abs(lrx - ulx), Math.abs(lry - uly));
876
                lastWidthRequest = rasterBuf.getWidth();
877
                lastHeightRequest = rasterBuf.getHeight();
878
                WMSStatus wmsStatus = loadWMSStatus(bBox);
879
                lastRequest = downloadFile(wmsStatus, extent.getULX(), extent.getULY(), extent.getLRX(), extent.getLRY(), rasterBuf.getWidth(), rasterBuf.getHeight());
880
                
881
                if (lastRequest == null) {
882
                        return rasterBuf;
883
                }
884
                
885
                try {
886
                        //El nombre de fichero que ha puesto en el bandList es el del servidor y no el del fichero en disco
887
                        String serverName = bandList.getBand(0).getFileName();
888
                        for (int i = 0; i < bandList.getBandCount(); i++) {
889
                                bandList.getBand(i).setFileName(lastRequest.getPath());
890
                        }
891
                        
892
                        AbstractRasterProvider driver = DefaultProviderServices.loadProvider(new File(lastRequest.getPath()));
893
                        setColorTable(driver.getColorTable());
894
                        
895
                        DefaultRasterQuery q = (DefaultRasterQuery)RasterLocator.getManager().createQuery();
896
                        q.setAreaOfInterest(extent, bufWidth, bufHeight);
897
                        q.setBandList(bandList);
898
                        q.setBuffer(rasterBuf);
899
                        q.setAdjustToExtent(adjustToExtent);
900
                        Buffer buf = driver.getDataSet(q);
901

902
                        for (int i = 0; i < bandList.getBandCount(); i++) {
903
                                bandList.getBand(i).setFileName(serverName);
904
                        }
905
                        
906
                        return buf;
907
                } catch (ProviderNotRegisteredException e) {
908
                        throw new RasterDriverException("Error building GdalDriver", e);
909
                } catch (InitializeException e) {
910
                        throw new RasterDriverException("Error building GdalDriver", e);
911
                }
912
        }*/
913

    
914
//        public Buffer getWindow(int x, int y, 
915
//                        BandList bandList, Buffer rasterBuf) throws ProcessInterruptedException, RasterDriverException {
916
//                int w = rasterBuf.getWidth();
917
//                int h = rasterBuf.getHeight();
918
//                Point2D p1 = rasterToWorld(new Point2D.Double(x, y));
919
//                Point2D p2 = rasterToWorld(new Point2D.Double(x + w, y + h));
920
//                lastWidthRequest = rasterBuf.getWidth();
921
//                lastHeightRequest = rasterBuf.getHeight();
922
//                Rectangle2D bBox = new Rectangle2D.Double(p1.getX(), p1.getY(), Math.abs(p1.getX() - p1.getX()), Math.abs(p1.getY() - p2.getY()));
923
//                WMSStatus wmsStatus = loadWMSStatus(bBox);
924
//                
925
//                lastRequest = downloadFile(wmsStatus, p1.getX(), p1.getY(), p2.getX(), p2.getY(), rasterBuf.getWidth(), rasterBuf.getHeight());
926
//                
927
//                if (lastRequest == null) {
928
//                        return rasterBuf;
929
//                }
930
//
931
//                AbstractRasterProvider driver = null;
932
//                try {
933
//                        //El nombre de fichero que ha puesto en el bandList es el del servidor y no el del fichero en disco
934
//                        String serverName = bandList.getBand(0).getFileName();
935
//                        for (int i = 0; i < bandList.getBandCount(); i++) {
936
//                                bandList.getBand(i).setFileName(lastRequest.getPath());
937
//                        }
938
//                        
939
//                        driver = DefaultProviderServices.loadProvider(new File(lastRequest.getPath()));
940
//                        Buffer buf = driver.getWindow(0, 0, w, h, bandList, rasterBuf);
941
//
942
//                        for (int i = 0; i < bandList.getBandCount(); i++) {
943
//                                bandList.getBand(i).setFileName(serverName);
944
//                        }
945
//                        
946
//                        return buf;
947
//                } catch (ProviderNotRegisteredException e) {
948
//                        throw new RasterDriverException("Error building GdalDriver", e);
949
//                } catch (InitializeException e) {
950
//                        throw new RasterDriverException("Error building GdalDriver", e);
951
//                }
952
//        }
953

    
954
        /*public Buffer getWindow(int x, int y, int w, int h, 
955
                        BandList bandList, Buffer rasterBuf, TaskStatus status) throws ProcessInterruptedException, RasterDriverException {
956
                Point2D p1 = rasterToWorld(new Point2D.Double(x, y));
957
                Point2D p2 = rasterToWorld(new Point2D.Double(x + w, y + h));
958
                lastWidthRequest = rasterBuf.getWidth();
959
                lastHeightRequest = rasterBuf.getHeight();
960
                Rectangle2D bBox = new Rectangle2D.Double(p1.getX(), p1.getY(), Math.abs(p1.getX() - p1.getX()), Math.abs(p1.getY() - p2.getY()));
961
                WMSStatus wmsStatus = loadWMSStatus(bBox);
962
                
963
                lastRequest = downloadFile(wmsStatus, p1.getX(), p1.getY(), p2.getX(), p2.getY(), rasterBuf.getWidth(), rasterBuf.getHeight());
964
                
965
                if (lastRequest == null) {
966
                        return rasterBuf;
967
                }
968

969
                AbstractRasterProvider driver = null;
970
                try {
971
                        //El nombre de fichero que ha puesto en el bandList es el del servidor y no el del fichero en disco
972
                        String serverName = bandList.getBand(0).getFileName();
973
                        for (int i = 0; i < bandList.getBandCount(); i++) {
974
                                bandList.getBand(i).setFileName(lastRequest.getPath());
975
                        }
976
                        
977
                        driver = DefaultProviderServices.loadProvider(new File(lastRequest.getPath()));
978
                        setColorTable(driver.getColorTable());
979
                        
980
                        DefaultRasterQuery q = (DefaultRasterQuery)RasterLocator.getManager().createQuery();
981
                        q.setAreaOfInterest(0, 0, w, h);
982
                        q.setBandList(bandList);
983
                        q.setBuffer(rasterBuf);
984
                        Buffer buf = driver.getDataSet(q);
985

986
                        for (int i = 0; i < bandList.getBandCount(); i++) {
987
                                bandList.getBand(i).setFileName(serverName);
988
                        }
989
                        
990
                        return buf;
991
                } catch (ProviderNotRegisteredException e) {
992
                        throw new RasterDriverException("Error building GdalDriver", e);
993
                } catch (InitializeException e) {
994
                        throw new RasterDriverException("Error building GdalDriver", e);
995
                }
996
        }*/
997

    
998
        public Image getImageLegend() {
999
                try {
1000
                        WMSStatus wmsStatus = loadWMSStatus(getExtent().toRectangle2D());
1001
                        wmsStatus.setOnlineResource((String) getParameters().getOnlineResource().get("GetCapabilities"));
1002
                        File file = getConnector().getLegendGraphic(wmsStatus, getParameters().getLayerQuery(), null);
1003
                        Image img = null;
1004
                        if ((file != null) && (file.length() > 0)) {
1005
                                img = new ImageIcon(file.getAbsolutePath()).getImage();
1006
                        }
1007
                        return img;
1008
                } catch (Exception e) {
1009
                        logger.info("Problems in GetLegendGraphic", e);
1010
                }
1011
                return null;
1012
        }
1013

    
1014
        public int getBlockSize() {
1015
                return 0;
1016
        }
1017

    
1018
        public void setAffineTransform(AffineTransform t){
1019
                
1020
        }
1021

    
1022
        public int getOverviewCount(int band) throws BandAccessException, RasterDriverException {
1023
                return 0;
1024
        }
1025

    
1026
        public int getOverviewWidth(int band, int overview) throws BandAccessException, RasterDriverException {
1027
                return 0;
1028
        }
1029

    
1030
        public int getOverviewHeight(int band, int overview) throws BandAccessException, RasterDriverException {
1031
                return 0;
1032
        }
1033

    
1034
        public boolean isOverviewsSupported() {
1035
                return false;
1036
        }
1037

    
1038
        public boolean isReproyectable() {
1039
                return false;
1040
        }
1041

    
1042
        public String getProviderName() {
1043
                return NAME;
1044
        }
1045
        
1046
        public String getName() {
1047
                return this.getParameters().getName();
1048
        }
1049
        
1050
        public String getFullName() {
1051
                return this.uri;
1052
        }
1053
        
1054
        /**
1055
         * Convierte un punto desde coordenadas pixel a coordenadas del mundo.
1056
         * @param pt Punto a transformar
1057
         * @return punto transformado en coordenadas del mundo
1058
         */
1059
        public Point2D rasterToWorld(Point2D pt) {
1060
                Point2D p = new Point2D.Double();
1061
                getAffineTransform().transform(pt, p);
1062
                return p;
1063
        }
1064

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