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

    
36
/** 
37
* Data server for the tile cache in a WMSProvider 
38
* @author Nacho Brodin (nachobrodin@gmail.com)
39
*/
40
public class WCSTileServer implements TileServer {
41
        private CacheStruct                struct               = null;
42
        private Downloader                 downloader           = null;
43
        private WCSProvider                provider             = null;
44
        private String                     suffix               = ".tif";
45
        
46
        public WCSTileServer(WCSProvider 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
                   ((TileDownloaderForWCS)downloader).getTileSize()[0] != TileCacheLibrary.DEFAULT_TILEWIDTH ||
58
                   ((TileDownloaderForWCS)downloader).getTileSize()[1] != TileCacheLibrary.DEFAULT_TILEHEIGHT) {
59
                                                        
60
                        try {
61
                                downloader = new TileDownloaderForWCS(provider, TileCacheLibrary.DEFAULT_TILEWIDTH, TileCacheLibrary.DEFAULT_TILEHEIGHT, provider.getConnector());
62
                        } catch (RemoteServiceException e) {
63
                                return null;
64
                        }
65
                }
66
                return downloader;
67
        }
68

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