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 / downloader / WMSTileServer.java @ 867

History | View | Annotate | Download (4.12 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.downloader;
23

    
24
import org.cresques.cts.IProjection;
25
import org.gvsig.fmap.dal.coverage.RasterLibrary;
26
import org.gvsig.fmap.dal.coverage.datastruct.Extent;
27
import org.gvsig.fmap.dal.coverage.exception.RemoteServiceException;
28
import org.gvsig.raster.cache.tile.TileCacheLibrary;
29
import org.gvsig.raster.cache.tile.TileCacheLocator;
30
import org.gvsig.raster.cache.tile.TileCacheManager;
31
import org.gvsig.raster.cache.tile.provider.CacheStruct;
32
import org.gvsig.raster.cache.tile.provider.Downloader;
33
import org.gvsig.raster.cache.tile.provider.TileServer;
34
import org.gvsig.raster.wms.io.WMSProvider;
35

    
36
/** 
37
* Data server for the tile cache in a WMSProvider 
38
* @author Nacho Brodin (nachobrodin@gmail.com)
39
*/
40
public class WMSTileServer implements TileServer {
41
        private CacheStruct                struct               = null;
42
        private Downloader                 downloader           = null;
43
        private WMSProvider                provider             = null;
44
        private String                     suffix               = ".tif";
45
        
46
        public WMSTileServer(WMSProvider prov) {
47
                this.provider = prov;
48
                this.suffix = prov.getFileSuffix();
49
        }
50
        
51
        /*
52
         * (non-Javadoc)
53
         * @see org.gvsig.raster.cache.tile.provider.TileServer#getDownloader()
54
         */
55
        public Downloader getDownloader() {
56
                if(downloader == null ||
57
                   ((TileDownloaderForWMS)downloader).getTileSize()[0] != TileCacheLibrary.DEFAULT_TILEWIDTH ||
58
                   ((TileDownloaderForWMS)downloader).getTileSize()[1] != TileCacheLibrary.DEFAULT_TILEHEIGHT) {
59
                        try {
60
                                downloader = new TileDownloaderForWMS(provider, TileCacheLibrary.DEFAULT_TILEWIDTH, TileCacheLibrary.DEFAULT_TILEHEIGHT, provider.getConnector());
61
                        } catch (RemoteServiceException e) {
62
                                return null;
63
                        }
64
                }
65
                return downloader;
66
        }
67

    
68
        public CacheStruct getStruct() {
69
                if(struct == null) {
70
                        TileCacheManager  manager = TileCacheLocator.getManager();
71
                        
72
                        int coordinates = CacheStruct.FLAT;
73
                        if(provider.getProjection() != null)
74
                                coordinates = (provider.getProjection() != null && provider.getProjection().isProjected()) ? CacheStruct.FLAT : CacheStruct.GEOGRAFIC;
75
                        else {
76
                                Extent e = provider.getExtent();
77
                                if(e.getULX() >= -180 && e.getULX() <= 180 && e.getLRX() >= -180 && e.getLRX() <= 180 && 
78
                                        e.getULY() >= -90 && e.getULY() <= 90 && e.getLRY() >= -90 && e.getLRY() <= 90) {
79
                                        coordinates = CacheStruct.GEOGRAFIC;
80
                                }
81
                        }
82
                        
83
                        String epsg = null;
84
                        IProjection proj = provider.getProjection();
85
                        if(proj != null)
86
                                epsg = proj.getAbrev();
87
                        
88
                        struct = manager.createCacheStructure(coordinates, 
89
                                        TileCacheLibrary.DEFAULT_LEVELS, 
90
                                        provider.getExtent().toRectangle2D(), 
91
                                        provider.getCellSize(), 
92
                                        TileCacheLibrary.DEFAULT_TILEWIDTH, 
93
                                        TileCacheLibrary.DEFAULT_TILEHEIGHT,
94
                                        provider.getURIOfFirstProvider(),
95
                                        TileCacheLibrary.DEFAULT_STRUCTURE,
96
                                        RasterLibrary.pathTileCache,
97
                                        getFileSuffix(),
98
                                        epsg,
99
                                        0);
100
                }
101
                return struct;
102
        }
103
        
104
        /*
105
         * (non-Javadoc)
106
         * @see org.gvsig.raster.cache.tile.provider.TileServer#getFileSuffix()
107
         */
108
        public String getFileSuffix() {
109
                return suffix;
110
        }
111
        
112
        /*
113
         * (non-Javadoc)
114
         * @see org.gvsig.raster.cache.tile.provider.TileServer#setFileExtension(java.lang.String)
115
         */
116
        public void setFileSuffix(String extension) {
117
                this.suffix = extension;
118
        }
119
}