Statistics
| Revision:

gvsig-raster / org.gvsig.raster / branches / org.gvsig.raster_dataaccess_refactoring / org.gvsig.raster.lib / org.gvsig.raster.lib.impl / src / main / java / org / gvsig / raster / impl / provider / tile / FileTileServer.java @ 2303

History | View | Annotate | Download (4.59 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.impl.provider.tile;
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.store.RasterDataStore;
28
import org.gvsig.fmap.dal.coverage.store.parameter.RasterDataParameters;
29
import org.gvsig.raster.cache.tile.TileCacheLibrary;
30
import org.gvsig.raster.cache.tile.TileCacheLocator;
31
import org.gvsig.raster.cache.tile.TileCacheManager;
32
import org.gvsig.raster.cache.tile.provider.CacheStruct;
33
import org.gvsig.raster.cache.tile.provider.Downloader;
34
import org.gvsig.raster.cache.tile.provider.TileServer;
35

    
36
/** 
37
* Data server for the tile cache in a GdalProvider 
38
* @author Nacho Brodin (nachobrodin@gmail.com)
39
*/
40
public class FileTileServer implements TileServer {
41
        protected   CacheStruct                struct         = null;
42
        protected   Downloader                 downloader     = null;
43
        protected   RasterDataStore            store          = null;
44
        protected   String                     suffix         = "tif";
45
        protected   boolean                    externalStruct = false;
46
        
47
        public FileTileServer(RasterDataStore store) {
48
                this.store = store;
49
        }
50
        
51
        public Downloader getDownloader() {
52
                //The downloader is built the first time or if the structure is assigned from the client. 
53
                boolean firstLoad = (downloader == null);
54
                
55
                if(firstLoad || externalStruct) {
56
                        downloader = new TileDownloaderForFiles(store, getStruct(), 
57
                                        getStruct().getTileSizeByLevel(0)[0], 
58
                                        getStruct().getTileSizeByLevel(0)[1], 
59
                                        getFileSuffix());
60
                        externalStruct = false;
61
                        return downloader;
62
                }
63
                
64
                //If the tile size has changed. 
65
                if(((TileDownloaderForFiles)downloader).getTileSize()[0] != TileCacheLibrary.DEFAULT_TILEWIDTH ||
66
                   ((TileDownloaderForFiles)downloader).getTileSize()[1] != TileCacheLibrary.DEFAULT_TILEHEIGHT) {
67
                        downloader = new TileDownloaderForFiles(store, getStruct(), 
68
                                        TileCacheLibrary.DEFAULT_TILEWIDTH, 
69
                                        TileCacheLibrary.DEFAULT_TILEHEIGHT, 
70
                                        getFileSuffix());
71
                }
72
                return downloader;
73
        }
74

    
75
        public CacheStruct getStruct() {
76
                if(struct == null) {
77
                        TileCacheManager  manager = TileCacheLocator.getManager();
78
                        
79
                        int coordinates = CacheStruct.FLAT;
80
                        if(store.getProjection() != null)
81
                                coordinates = (store.getProjection() != null && store.getProjection().isProjected()) ? CacheStruct.FLAT : CacheStruct.GEOGRAFIC;
82
                        else {
83
                                Extent e = store.getExtent();
84
                                if(e.getULX() >= -180 && e.getULX() <= 180 && e.getLRX() >= -180 && e.getLRX() <= 180 && 
85
                                        e.getULY() >= -90 && e.getULY() <= 90 && e.getLRY() >= -90 && e.getLRY() <= 90) {
86
                                        coordinates = CacheStruct.GEOGRAFIC;
87
                                }
88
                        }
89
                        
90
                        String epsg = null;
91
                        IProjection proj = store.getProjection();
92
                        if(proj != null)
93
                                epsg = proj.getAbrev();
94
                        
95
                        String uri = ((RasterDataParameters)store.getParameters()).getURI();
96
                        struct = manager.createCacheStructure(coordinates, 
97
                                        TileCacheLibrary.DEFAULT_LEVELS, 
98
                                        store.getExtent().toRectangle2D(), 
99
                                        store.getCellSize(), 
100
                                        TileCacheLibrary.DEFAULT_TILEWIDTH, 
101
                                        TileCacheLibrary.DEFAULT_TILEHEIGHT,
102
                                        uri,
103
                                        TileCacheLibrary.DEFAULT_STRUCTURE,
104
                                        RasterLibrary.pathTileCache,
105
                                        getFileSuffix(),
106
                                        epsg,
107
                                        store.getFileSize());
108
                }
109
                return struct;
110
        }
111
        
112
        public void setStruct(CacheStruct struct) {
113
                if(struct != null) {
114
                        this.struct = struct;
115
                        if(struct.getTileSizeByLevel(0) != null) {
116
                                downloader = new TileDownloaderForFiles(store, 
117
                                                struct, 
118
                                                struct.getTileSizeByLevel(0)[0], 
119
                                                struct.getTileSizeByLevel(0)[1], 
120
                                                getFileSuffix());
121
                                externalStruct = true;
122
                        }
123
                }
124
        }
125
        
126
        public String getFileSuffix() {
127
                return suffix;
128
        }
129

    
130
        public void setFileSuffix(String extension) {
131
                this.suffix = extension;
132
        }
133
}