svn-gvsig-desktop / tags / v1_0_2_Build_905 / extensions / extWCS / src / com / iver / cit / gvsig / fmap / drivers / wcs / FMapWCSDriver.java @ 10767
History | View | Annotate | Download (9.54 KB)
1 |
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
|
---|---|
2 |
*
|
3 |
* Copyright (C) 2005 IVER T.I. and Generalitat Valenciana.
|
4 |
*
|
5 |
* This program is free software; you can redistribute it and/or
|
6 |
* modify it under the terms of the GNU General Public License
|
7 |
* as published by the Free Software Foundation; either version 2
|
8 |
* of the License, or (at your option) any later version.
|
9 |
*
|
10 |
* This program is distributed in the hope that it will be useful,
|
11 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
12 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
13 |
* GNU General Public License for more details.
|
14 |
*
|
15 |
* You should have received a copy of the GNU General Public License
|
16 |
* along with this program; if not, write to the Free Software
|
17 |
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,USA.
|
18 |
*
|
19 |
* For more information, contact:
|
20 |
*
|
21 |
* Generalitat Valenciana
|
22 |
* Conselleria d'Infraestructures i Transport
|
23 |
* Av. Blasco Ib??ez, 50
|
24 |
* 46010 VALENCIA
|
25 |
* SPAIN
|
26 |
*
|
27 |
* +34 963862235
|
28 |
* gvsig@gva.es
|
29 |
* www.gvsig.gva.es
|
30 |
*
|
31 |
* or
|
32 |
*
|
33 |
* IVER T.I. S.A
|
34 |
* Salamanca 50
|
35 |
* 46005 Valencia
|
36 |
* Spain
|
37 |
*
|
38 |
* +34 963163400
|
39 |
* dac@iver.es
|
40 |
*/
|
41 |
package com.iver.cit.gvsig.fmap.drivers.wcs; |
42 |
|
43 |
import java.awt.geom.Point2D; |
44 |
import java.awt.geom.Rectangle2D; |
45 |
import java.io.File; |
46 |
import java.io.IOException; |
47 |
import java.net.ConnectException; |
48 |
import java.net.URL; |
49 |
import java.util.ArrayList; |
50 |
import java.util.Hashtable; |
51 |
import java.util.Iterator; |
52 |
import java.util.Set; |
53 |
|
54 |
import org.gvsig.remoteClient.exceptions.ServerErrorException; |
55 |
import org.gvsig.remoteClient.utils.BoundaryBox; |
56 |
import org.gvsig.remoteClient.wcs.WCSClient; |
57 |
import org.gvsig.remoteClient.wcs.WCSCoverage; |
58 |
import org.gvsig.remoteClient.wcs.WCSStatus; |
59 |
import org.gvsig.remoteClient.wcs.WCSCoverage.AxisDescription; |
60 |
import org.gvsig.remoteClient.wms.ICancellable; |
61 |
import org.gvsig.remoteClient.wms.WMSClient; |
62 |
|
63 |
import com.iver.cit.gvsig.fmap.DriverException; |
64 |
import com.iver.cit.gvsig.fmap.layers.FMapWCSParameter; |
65 |
import com.iver.cit.gvsig.fmap.layers.WCSLayer; |
66 |
|
67 |
|
68 |
|
69 |
/**
|
70 |
* Driver between the FMap and WCSClient
|
71 |
*
|
72 |
* Controlador entre FMap y WCSClient
|
73 |
*
|
74 |
* @author jaume
|
75 |
*
|
76 |
*/
|
77 |
public class FMapWCSDriver { |
78 |
private WCSClient client = null; |
79 |
private Hashtable coverages; |
80 |
private WCSLayer[] layerList; |
81 |
|
82 |
|
83 |
|
84 |
/**
|
85 |
* Obtains the host name.
|
86 |
*
|
87 |
* Devuelve el nombre del host.
|
88 |
*/
|
89 |
public String getHost() { |
90 |
return client.getHost();
|
91 |
} |
92 |
|
93 |
private FMapWCSDriver() {}
|
94 |
|
95 |
protected FMapWCSDriver(URL url) throws ConnectException, IOException { |
96 |
client = new WCSClient(url.toString());
|
97 |
} |
98 |
|
99 |
/**
|
100 |
* Returns the string "WCSDriver", which is the driver's name.
|
101 |
*
|
102 |
* Devuelve "WCSDriver", el nombre del driver.
|
103 |
* @return String
|
104 |
*/
|
105 |
public String getName() { return "WCSDriver"; } |
106 |
|
107 |
/**
|
108 |
* Sets the server that we want to connect to.
|
109 |
*
|
110 |
* Establece el servidor al que se quiere conectar.
|
111 |
*
|
112 |
* @param host
|
113 |
* @throws IOException
|
114 |
*/
|
115 |
public void setHost(String host) throws IOException{ |
116 |
client = new WCSClient(host);
|
117 |
} |
118 |
|
119 |
|
120 |
/**
|
121 |
* Returns a human-readable string containing the server's name.
|
122 |
*
|
123 |
* Devuelve el nombre legible del servidor devuelto por ?ste.
|
124 |
*
|
125 |
* @return String
|
126 |
*/
|
127 |
public String getLabel() { |
128 |
return client.getServiceTitle();
|
129 |
} |
130 |
|
131 |
/**
|
132 |
* Returns a string containing the server's WCS version number.
|
133 |
*
|
134 |
* Devuelve el n?mero de versi?n WCS del servidor
|
135 |
*
|
136 |
* @return String
|
137 |
*/
|
138 |
public String getVersion(){ |
139 |
return client.getVersion();
|
140 |
} |
141 |
|
142 |
/**
|
143 |
* <p>
|
144 |
* Returns name and description of the server. It is supposed to be used
|
145 |
* as the source of the abstract field in your application's interface.
|
146 |
* </p>
|
147 |
* <p>
|
148 |
* Devuelve nombre y descripci?n (abstract) del servidor.
|
149 |
* </p>
|
150 |
* @return String
|
151 |
*/
|
152 |
public String getDescription(){ |
153 |
return client.getDescription();
|
154 |
} |
155 |
|
156 |
/**
|
157 |
* Returns the layer descriptor for a given coverage name.
|
158 |
* @param layerName
|
159 |
* @return WCSLayer
|
160 |
*/
|
161 |
public WCSLayer getLayer(String layerName) { |
162 |
getLayerList(); |
163 |
return (WCSLayer) coverages.get(layerName);
|
164 |
} |
165 |
|
166 |
/**
|
167 |
* Returns an array of WCSLayer's with the descriptors of all coverages
|
168 |
* @return WCSLayer[]
|
169 |
*/
|
170 |
public WCSLayer[] getLayerList(){ |
171 |
if (coverages == null || coverages.isEmpty()) { |
172 |
// the WCSLayer collection will be built
|
173 |
coverages = new Hashtable(); |
174 |
Hashtable wcsCoverages = client.getCoverageList();
|
175 |
int sz = wcsCoverages.size();
|
176 |
|
177 |
// Create an array with the WCSCoverages
|
178 |
WCSCoverage[] coverageList = new WCSCoverage[sz]; |
179 |
Iterator it = wcsCoverages.keySet().iterator();
|
180 |
int i = 0; |
181 |
while (it.hasNext()) {
|
182 |
coverageList[i] = (WCSCoverage) wcsCoverages.get(it.next()); |
183 |
i++; |
184 |
} |
185 |
|
186 |
// Create a WCSLayer array from the previous WCSCoverage array
|
187 |
layerList = new WCSLayer[sz];
|
188 |
for (int j = 0; j < layerList.length; j++) { |
189 |
WCSLayer lyr = new WCSLayer();
|
190 |
WCSCoverage cov = coverageList[j]; |
191 |
// name
|
192 |
lyr.setName(cov.getName()); |
193 |
|
194 |
// title
|
195 |
lyr.setTitle(cov.getTitle()); |
196 |
|
197 |
// description
|
198 |
lyr.setDescription(cov.getAbstract()); |
199 |
|
200 |
// srs
|
201 |
lyr.addAllSrs(cov.getAllSrs()); |
202 |
|
203 |
// native srs
|
204 |
lyr.setNativeSRS(cov.getNativeSRS()); |
205 |
|
206 |
// extents
|
207 |
Set k = cov.getBBoxes().keySet();
|
208 |
if (!k.isEmpty()) {
|
209 |
it = k.iterator(); |
210 |
while (it.hasNext()) {
|
211 |
String srs = (String) it.next(); |
212 |
BoundaryBox bBox = cov.getBbox(srs); |
213 |
Rectangle2D r = new Rectangle2D.Double( |
214 |
bBox.getXmin(), |
215 |
bBox.getYmin(), |
216 |
bBox.getXmax()-bBox.getXmin(), |
217 |
bBox.getYmax()-bBox.getYmin() |
218 |
); |
219 |
lyr.addExtent(srs, r); |
220 |
} |
221 |
} |
222 |
|
223 |
// formats
|
224 |
lyr.setFormats(cov.getFormats()); |
225 |
|
226 |
// time positions
|
227 |
lyr.setTimePositions(cov.getTimePositions()); |
228 |
|
229 |
// max res
|
230 |
lyr.setMaxRes(new Point2D.Double(cov.getResX(), cov.getResY())); |
231 |
|
232 |
// interpolations
|
233 |
lyr.setInterpolationMethods(cov.getInterpolationMethods()); |
234 |
|
235 |
// parameters
|
236 |
k = cov.axisPool.keySet(); |
237 |
if (!k.isEmpty()) {
|
238 |
it = k.iterator(); |
239 |
while (it.hasNext()) {
|
240 |
AxisDescription ad = (AxisDescription) cov.axisPool.get(it.next()); |
241 |
FMapWCSParameter p = new FMapWCSParameter();
|
242 |
p.setName(ad.getName()); |
243 |
p.setLabel(ad.getLabel()); |
244 |
p.setType(ad.getInterval()==null? FMapWCSParameter.VALUE_LIST : FMapWCSParameter.INTERVAL);
|
245 |
if (p.getType()==FMapWCSParameter.VALUE_LIST)
|
246 |
p.setValueList(ad.getSingleValues()); |
247 |
else
|
248 |
p.setInterval(ad.getInterval()); |
249 |
lyr.addParameter(p); |
250 |
} |
251 |
} |
252 |
layerList[j] = lyr; |
253 |
coverages.put(lyr.getName(), lyr); |
254 |
} |
255 |
} |
256 |
return layerList;
|
257 |
} |
258 |
|
259 |
/**
|
260 |
* Establishes the connection to the WCS server. Connecting to a WCS is
|
261 |
* an abstraction.<br>
|
262 |
* <p>
|
263 |
* Actually, it sends a GetCapabilities and a general DescribeCoverage
|
264 |
* request (not a coverage-specific DescribeCoverage request) to read the
|
265 |
* necessary data for building further GetCoverage requests.
|
266 |
* </p>
|
267 |
* @param override
|
268 |
* @throws IOException, DriverException.
|
269 |
*/
|
270 |
public boolean connect(boolean override, ICancellable cancel) throws IOException, DriverException { |
271 |
coverages = null;
|
272 |
setHost(client.getHost()); |
273 |
return client.connect(override, cancel);
|
274 |
} |
275 |
|
276 |
/**
|
277 |
* No close operation is needed since WCS service it is a non-session based
|
278 |
* protocol. So, this does nothing and you can omit it.<br>
|
279 |
*/
|
280 |
public void close() { |
281 |
// connected = false;
|
282 |
} |
283 |
|
284 |
/**
|
285 |
* Returns the label of an specific coverage given by the coverage name
|
286 |
* @param coverage name (string)
|
287 |
* @return string
|
288 |
*/
|
289 |
public String getLabel(String coverageName) { |
290 |
return client.getLabel(coverageName);
|
291 |
} |
292 |
|
293 |
/**
|
294 |
* Returns the coverage's MAX extent from the server.
|
295 |
* @return Rectangle2D
|
296 |
* @throws DriverException
|
297 |
* @throws IOException
|
298 |
*/
|
299 |
public Rectangle2D getFullExtent(String coverageName, String srs) throws IOException, DriverException { |
300 |
return client.getExtent(coverageName, srs);
|
301 |
} |
302 |
|
303 |
/**
|
304 |
* Returns the max resolution of a specific coverage given by the coverage's name.
|
305 |
* @param coverage name (string)
|
306 |
* @return double
|
307 |
*/
|
308 |
public Point2D getMaxResolution(String coverageName) { |
309 |
if (coverages.containsKey(coverageName)) {
|
310 |
return ((WCSLayer) coverages.get(coverageName)).getMaxRes();
|
311 |
} |
312 |
return null; |
313 |
} |
314 |
|
315 |
|
316 |
/**
|
317 |
* Returns an ArrayList containing a set of Strings with the coverage's SRSs.
|
318 |
* @param coverage name (string)
|
319 |
* @return ArrayList
|
320 |
*/
|
321 |
public ArrayList getSRSs(String coverageName) { |
322 |
if (coverages.containsKey(coverageName)) {
|
323 |
return ((WCSLayer) coverages.get(coverageName)).getSRSs();
|
324 |
} |
325 |
return null; |
326 |
} |
327 |
|
328 |
/**
|
329 |
* Returns a String containing a description of an specific coverage.
|
330 |
* @param coverage name (string)
|
331 |
* @return string
|
332 |
*/
|
333 |
public String getCoverageDescription(String coverageName) { |
334 |
if (coverages.containsKey(coverageName)) {
|
335 |
return ((WCSLayer) coverages.get(coverageName)).getDescription();
|
336 |
} |
337 |
return null; |
338 |
} |
339 |
|
340 |
/**
|
341 |
* Returns an ArrayList containing strings for the time positions of an
|
342 |
* specific coverage given by the coverage's name.
|
343 |
* @param coverage name (string)
|
344 |
* @return ArrayList
|
345 |
*/
|
346 |
public ArrayList getTimes(String coverageName) { |
347 |
if (coverages.containsKey(coverageName)) {
|
348 |
return ((WCSLayer) coverages.get(coverageName)).getTimePositions();
|
349 |
} |
350 |
return null; |
351 |
} |
352 |
|
353 |
/**
|
354 |
* Sends a GetCoverage request to the client.
|
355 |
* @param status
|
356 |
* @return
|
357 |
* @throws WCSException
|
358 |
*/
|
359 |
public File getCoverage(WCSStatus status, ICancellable cancel) throws WCSException { |
360 |
try {
|
361 |
return client.getCoverage(status, cancel);
|
362 |
} catch (ServerErrorException e) {
|
363 |
throw new WCSException("WCS Unexpected server error."+e.getMessage()); |
364 |
} catch (org.gvsig.remoteClient.exceptions.WCSException e) {
|
365 |
throw new WCSException(e.getMessage()); |
366 |
} |
367 |
} |
368 |
} |