Statistics
| Revision:

gvsig-raster / org.gvsig.raster.wcs / trunk / org.gvsig.raster.wcs / org.gvsig.raster.wcs.io / src / main / java / org / gvsig / raster / wcs / io / downloader / WCSTileServer.java @ 1137

History | View | Annotate | Download (4.93 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.wcs.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.wcs.io.WCSProvider;
35
import org.slf4j.Logger;
36
import org.slf4j.LoggerFactory;
37

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

    
72
        public CacheStruct getStruct() {
73
                if(struct == null) {
74
                        TileCacheManager  manager = TileCacheLocator.getManager();
75
                        
76
                        int coordinates = CacheStruct.FLAT;
77
                        if(provider.getProjection() != null)
78
                                coordinates = (provider.getProjection() != null && provider.getProjection().isProjected()) ? CacheStruct.FLAT : CacheStruct.GEOGRAFIC;
79
                        else {
80
                                Extent e = provider.getExtent();
81
                                if(e.getULX() >= -180 && e.getULX() <= 180 && e.getLRX() >= -180 && e.getLRX() <= 180 && 
82
                                        e.getULY() >= -90 && e.getULY() <= 90 && e.getLRY() >= -90 && e.getLRY() <= 90) {
83
                                        coordinates = CacheStruct.GEOGRAFIC;
84
                                }
85
                        }
86
                        
87
                        String epsg = null;
88
                        IProjection proj = provider.getProjection();
89
                        if(proj != null)
90
                                epsg = proj.getAbrev();
91
                        
92
                        struct = manager.createCacheStructure(coordinates, 
93
                                        TileCacheLibrary.DEFAULT_LEVELS, 
94
                                        provider.getExtent().toRectangle2D(), 
95
                                        provider.getCellSize(), 
96
                                        TileCacheLibrary.ALTERNATIVE_TILESIZE, 
97
                                        TileCacheLibrary.ALTERNATIVE_TILESIZE,
98
                                        provider.getURIOfFirstProvider(),
99
                                        provider.getParameters().getCoverageName(),
100
                                        TileCacheLibrary.DEFAULT_STRUCTURE,
101
                                        RasterLibrary.pathTileCache,
102
                                        getFileSuffix(),
103
                                        epsg,
104
                                        0);
105
                }
106
                return struct;
107
        }
108
        
109
        /*
110
         * (non-Javadoc)
111
         * @see org.gvsig.raster.cache.tile.provider.TileServer#setStruct(org.gvsig.raster.cache.tile.provider.CacheStruct)
112
         */
113
        public void setStruct(CacheStruct struct) {
114
                if(struct != null) {
115
                        this.struct = struct;
116
                        if(struct.getTileSizeByLevel(0) != null) {
117
                                try {
118
                                        downloader = new TileDownloaderForWCS(provider, 
119
                                                        struct.getTileSizeByLevel(0)[0], 
120
                                                        struct.getTileSizeByLevel(0)[1],
121
                                                        provider.getConnector());
122
                                } catch (RemoteServiceException ex) {
123
                                        logger.error("Constructing TileDownloaderForWCS: " + ex.getMessage());
124
                                }
125
                        }
126
                }
127
        }
128
        
129
        /*
130
         * (non-Javadoc)
131
         * @see org.gvsig.raster.cache.tile.provider.TileServer#getFileSuffix()
132
         */
133
        public String getFileSuffix() {
134
                return suffix;
135
        }
136
        
137
        /*
138
         * (non-Javadoc)
139
         * @see org.gvsig.raster.cache.tile.provider.TileServer#setFileExtension(java.lang.String)
140
         */
141
        public void setFileSuffix(String extension) {
142
                this.suffix = extension;
143
        }
144
}