gvsig-raster / org.gvsig.raster.wmts / trunk / org.gvsig.raster.wmts / org.gvsig.raster.wmts.io / src / main / java / org / gvsig / raster / wmts / io / downloader / TileDownloaderForWMTS.java @ 1961
History | View | Annotate | Download (3.75 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.wmts.io.downloader; |
23 |
|
24 |
import java.io.File; |
25 |
import java.io.IOException; |
26 |
import java.net.ConnectException; |
27 |
import java.net.URL; |
28 |
|
29 |
import org.gvsig.compat.net.ICancellable; |
30 |
import org.gvsig.fmap.dal.coverage.exception.RemoteServiceException; |
31 |
import org.gvsig.raster.cache.tile.Tile; |
32 |
import org.gvsig.raster.cache.tile.exception.TileGettingException; |
33 |
import org.gvsig.raster.impl.provider.tile.BaseTileDownloader; |
34 |
import org.gvsig.raster.wmts.io.WMTSConnector; |
35 |
import org.gvsig.raster.wmts.io.WMTSDataParameters; |
36 |
import org.gvsig.raster.wmts.io.WMTSProvider; |
37 |
import org.gvsig.raster.wmts.ogc.WMTSStatus; |
38 |
import org.gvsig.raster.wmts.ogc.exception.ServerErrorException; |
39 |
import org.gvsig.raster.wmts.ogc.exception.WMTSException; |
40 |
|
41 |
/**
|
42 |
* Tile getter
|
43 |
* @author Nacho Brodin (nachobrodin@gmail.com)
|
44 |
*/
|
45 |
public class TileDownloaderForWMTS extends BaseTileDownloader { |
46 |
private WMTSConnector connector = null; |
47 |
|
48 |
public TileDownloaderForWMTS(WMTSProvider prov,
|
49 |
int tilePxWidth,
|
50 |
int tilePxHeight) {
|
51 |
super(prov, tilePxWidth, tilePxHeight);
|
52 |
} |
53 |
|
54 |
/**
|
55 |
* Gets the connector from the URL
|
56 |
* @return
|
57 |
* @throws RemoteServiceException
|
58 |
*/
|
59 |
public WMTSConnector getConnector() throws WMTSException { |
60 |
if(connector == null) { |
61 |
WMTSDataParameters p = (WMTSDataParameters)prov.getDataParameters(); |
62 |
connector = p.getConnector(); |
63 |
if(connector != null) |
64 |
return connector;
|
65 |
|
66 |
URL url = null; |
67 |
try {
|
68 |
url = new URL(p.getURI()); |
69 |
} catch (Exception e) { |
70 |
throw new WMTSException("Malformed URL",e); |
71 |
} |
72 |
try {
|
73 |
connector = new WMTSConnector(url);
|
74 |
connector.connect(new ICancellable() {
|
75 |
public boolean isCanceled() { |
76 |
return false; |
77 |
} |
78 |
|
79 |
public Object getID() { |
80 |
return null; |
81 |
} |
82 |
}); |
83 |
} catch (ConnectException e) { |
84 |
throw new WMTSException("Connect exception",e); |
85 |
} catch (IOException e) { |
86 |
throw new WMTSException("Connect exception",e); |
87 |
} |
88 |
} |
89 |
return connector;
|
90 |
} |
91 |
|
92 |
/*
|
93 |
* (non-Javadoc)
|
94 |
* @see org.gvsig.raster.cache.tile.provider.Downloader#getTile(org.gvsig.raster.cache.tile.Tile)
|
95 |
*/
|
96 |
public synchronized Tile downloadTile(Tile tile) throws TileGettingException { |
97 |
try {
|
98 |
WMTSStatus status = (WMTSStatus)tile.getDownloaderParams("WMTSStatus");
|
99 |
status.setTileRow(tile.getRow()); |
100 |
status.setTileCol(tile.getCol()); |
101 |
File f = getConnector().getTile(status, tile.getCancelled(), tile.getFile());
|
102 |
tile.setFile(f); |
103 |
//Si borramos el rmf no se puede leer la etiqueta Alpha. En caso de que se modifique jgdal para
|
104 |
//poder guardar esta etiqueta deberiamos borrar el rmf para ahorrar ficheros
|
105 |
//File rmf = new File(tile.getFile().getAbsolutePath() + ".rmf");
|
106 |
//if(rmf.exists())
|
107 |
//rmf.delete();
|
108 |
} catch (WMTSException e) {
|
109 |
throw new TileGettingException(e); |
110 |
} catch (ServerErrorException e) {
|
111 |
throw new TileGettingException(e); |
112 |
} |
113 |
readTileFromDisk(tile); |
114 |
return tile;
|
115 |
} |
116 |
|
117 |
} |