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 @ 1144
History | View | Annotate | Download (4.97 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.ALTERNATIVE_TILESIZE ||
|
61 |
((TileDownloaderForWMS)downloader).getTileSize()[1] != TileCacheLibrary.ALTERNATIVE_TILESIZE) {
|
62 |
try {
|
63 |
downloader = new TileDownloaderForWMS(
|
64 |
provider, |
65 |
TileCacheLibrary.ALTERNATIVE_TILESIZE, |
66 |
TileCacheLibrary.ALTERNATIVE_TILESIZE, |
67 |
provider.getConnector()); |
68 |
} catch (RemoteServiceException e) {
|
69 |
return null; |
70 |
} |
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(provider.getProjection() != null) |
81 |
coordinates = (provider.getProjection() != null && provider.getProjection().isProjected()) ? CacheStruct.FLAT : CacheStruct.GEOGRAFIC;
|
82 |
else {
|
83 |
Extent e = provider.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 = provider.getProjection(); |
92 |
if(proj != null) |
93 |
epsg = proj.getAbrev(); |
94 |
|
95 |
struct = manager.createCacheStructure(coordinates, |
96 |
TileCacheLibrary.DEFAULT_LEVELS, |
97 |
provider.getExtent().toRectangle2D(), |
98 |
Double.POSITIVE_INFINITY,//provider.getCellSize(), |
99 |
TileCacheLibrary.ALTERNATIVE_TILESIZE, |
100 |
TileCacheLibrary.ALTERNATIVE_TILESIZE, |
101 |
provider.getURIOfFirstProvider(), |
102 |
provider.getParameters().getLayerQuery(), |
103 |
TileCacheLibrary.DEFAULT_STRUCTURE, |
104 |
RasterLibrary.pathTileCache, |
105 |
getFileSuffix(), |
106 |
epsg, |
107 |
0);
|
108 |
} |
109 |
return struct;
|
110 |
} |
111 |
|
112 |
/*
|
113 |
* (non-Javadoc)
|
114 |
* @see org.gvsig.raster.cache.tile.provider.TileServer#setStruct(org.gvsig.raster.cache.tile.provider.CacheStruct)
|
115 |
*/
|
116 |
public void setStruct(CacheStruct struct) { |
117 |
if(struct != null) { |
118 |
this.struct = struct;
|
119 |
if(struct.getTileSizeByLevel(0) != null) { |
120 |
try {
|
121 |
downloader = new TileDownloaderForWMS(provider,
|
122 |
struct.getTileSizeByLevel(0)[0], |
123 |
struct.getTileSizeByLevel(0)[1], |
124 |
provider.getConnector()); |
125 |
} catch (RemoteServiceException ex) {
|
126 |
logger.error("Constructing TileDownloaderForWCS: " + ex.getMessage());
|
127 |
} |
128 |
} |
129 |
} |
130 |
} |
131 |
|
132 |
/*
|
133 |
* (non-Javadoc)
|
134 |
* @see org.gvsig.raster.cache.tile.provider.TileServer#getFileSuffix()
|
135 |
*/
|
136 |
public String getFileSuffix() { |
137 |
return suffix;
|
138 |
} |
139 |
|
140 |
/*
|
141 |
* (non-Javadoc)
|
142 |
* @see org.gvsig.raster.cache.tile.provider.TileServer#setFileExtension(java.lang.String)
|
143 |
*/
|
144 |
public void setFileSuffix(String extension) { |
145 |
this.suffix = extension;
|
146 |
} |
147 |
} |