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 @ 1085
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.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 |
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 WMSTileServer implements TileServer { |
43 |
private static Logger logger = LoggerFactory.getLogger(WMSTileServer.class); |
44 |
private CacheStruct struct = null; |
45 |
private Downloader downloader = null; |
46 |
private WMSProvider provider = null; |
47 |
private String suffix = ".tif"; |
48 |
|
49 |
public WMSTileServer(WMSProvider 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 |
((TileDownloaderForWMS)downloader).getTileSize()[0] != TileCacheLibrary.DEFAULT_TILEWIDTH ||
|
61 |
((TileDownloaderForWMS)downloader).getTileSize()[1] != TileCacheLibrary.DEFAULT_TILEHEIGHT) {
|
62 |
try {
|
63 |
downloader = new TileDownloaderForWMS(provider, TileCacheLibrary.DEFAULT_TILEWIDTH, TileCacheLibrary.DEFAULT_TILEHEIGHT, provider.getConnector());
|
64 |
} catch (RemoteServiceException e) {
|
65 |
return null; |
66 |
} |
67 |
} |
68 |
return downloader;
|
69 |
} |
70 |
|
71 |
public CacheStruct getStruct() {
|
72 |
if(struct == null) { |
73 |
TileCacheManager manager = TileCacheLocator.getManager(); |
74 |
|
75 |
int coordinates = CacheStruct.FLAT;
|
76 |
if(provider.getProjection() != null) |
77 |
coordinates = (provider.getProjection() != null && provider.getProjection().isProjected()) ? CacheStruct.FLAT : CacheStruct.GEOGRAFIC;
|
78 |
else {
|
79 |
Extent e = provider.getExtent(); |
80 |
if(e.getULX() >= -180 && e.getULX() <= 180 && e.getLRX() >= -180 && e.getLRX() <= 180 && |
81 |
e.getULY() >= -90 && e.getULY() <= 90 && e.getLRY() >= -90 && e.getLRY() <= 90) { |
82 |
coordinates = CacheStruct.GEOGRAFIC; |
83 |
} |
84 |
} |
85 |
|
86 |
String epsg = null; |
87 |
IProjection proj = provider.getProjection(); |
88 |
if(proj != null) |
89 |
epsg = proj.getAbrev(); |
90 |
|
91 |
struct = manager.createCacheStructure(coordinates, |
92 |
TileCacheLibrary.DEFAULT_LEVELS, |
93 |
provider.getExtent().toRectangle2D(), |
94 |
Double.POSITIVE_INFINITY,//provider.getCellSize(), |
95 |
TileCacheLibrary.DEFAULT_TILEWIDTH, |
96 |
TileCacheLibrary.DEFAULT_TILEHEIGHT, |
97 |
provider.getURIOfFirstProvider(), |
98 |
provider.getParameters().getLayerQuery(), |
99 |
TileCacheLibrary.DEFAULT_STRUCTURE, |
100 |
RasterLibrary.pathTileCache, |
101 |
getFileSuffix(), |
102 |
epsg, |
103 |
0);
|
104 |
} |
105 |
return struct;
|
106 |
} |
107 |
|
108 |
/*
|
109 |
* (non-Javadoc)
|
110 |
* @see org.gvsig.raster.cache.tile.provider.TileServer#setStruct(org.gvsig.raster.cache.tile.provider.CacheStruct)
|
111 |
*/
|
112 |
public void setStruct(CacheStruct struct) { |
113 |
if(struct != null) { |
114 |
this.struct = struct;
|
115 |
if(struct.getTileSizeByLevel(0) != null) { |
116 |
try {
|
117 |
downloader = new TileDownloaderForWMS(provider,
|
118 |
struct.getTileSizeByLevel(0)[0], |
119 |
struct.getTileSizeByLevel(0)[1], |
120 |
provider.getConnector()); |
121 |
} catch (RemoteServiceException ex) {
|
122 |
logger.error("Constructing TileDownloaderForWCS: " + ex.getMessage());
|
123 |
} |
124 |
} |
125 |
} |
126 |
} |
127 |
|
128 |
/*
|
129 |
* (non-Javadoc)
|
130 |
* @see org.gvsig.raster.cache.tile.provider.TileServer#getFileSuffix()
|
131 |
*/
|
132 |
public String getFileSuffix() { |
133 |
return suffix;
|
134 |
} |
135 |
|
136 |
/*
|
137 |
* (non-Javadoc)
|
138 |
* @see org.gvsig.raster.cache.tile.provider.TileServer#setFileExtension(java.lang.String)
|
139 |
*/
|
140 |
public void setFileSuffix(String extension) { |
141 |
this.suffix = extension;
|
142 |
} |
143 |
} |