root / tags / v1_0_2_Build_916 / libraries / libRemoteServices / src / org / gvsig / remoteClient / wcs / WCSClient.java @ 12327
History | View | Annotate | Download (6.86 KB)
1 | 3483 | jaume | /* 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 org.gvsig.remoteClient.wcs; |
||
42 | |||
43 | 4427 | jaume | import java.awt.geom.Rectangle2D; |
44 | 4493 | jaume | import java.io.File; |
45 | 4293 | jaume | import java.io.IOException; |
46 | import java.net.ConnectException; |
||
47 | 4931 | jaume | import java.util.ArrayList; |
48 | 4427 | jaume | import java.util.Hashtable; |
49 | 7010 | jaume | import java.util.Iterator; |
50 | 4293 | jaume | |
51 | 4493 | jaume | import org.gvsig.remoteClient.exceptions.ServerErrorException; |
52 | import org.gvsig.remoteClient.exceptions.WCSException; |
||
53 | 4427 | jaume | import org.gvsig.remoteClient.utils.BoundaryBox; |
54 | 7010 | jaume | import org.gvsig.remoteClient.wcs.wcs_1_0_0.WCSProtocolHandler1_0_0; |
55 | 5409 | jaume | import org.gvsig.remoteClient.wms.ICancellable; |
56 | 3483 | jaume | |
57 | 4924 | jaume | /**
|
58 | * WCSClient managing the low-level comunication to the server. It is used
|
||
59 | 6422 | jaume | * as a bridge between a standard WCS server and other high-level clients.
|
60 | 4924 | jaume | * @author jaume dominguez faus - jaume.dominguez@iver.es
|
61 | *
|
||
62 | */
|
||
63 | 3483 | jaume | public class WCSClient extends org.gvsig.remoteClient.RasterClient{ |
64 | |||
65 | private WCSProtocolHandler handler;
|
||
66 | 6422 | jaume | private Hashtable layerPool; |
67 | |||
68 | 3483 | jaume | /**
|
69 | * Constructor.
|
||
70 | * the parameter host, indicates the WCS host to connect.
|
||
71 | 6422 | jaume | * @throws IOException
|
72 | 3483 | jaume | *
|
73 | */
|
||
74 | 6442 | jaume | public WCSClient(String host) throws ConnectException, IOException { |
75 | 3483 | jaume | setHost(host); |
76 | 6422 | jaume | try {
|
77 | 4293 | jaume | handler = WCSProtocolHandlerFactory.negotiate(host); |
78 | 6422 | jaume | handler.setHost(host); |
79 | 4293 | jaume | } catch(ConnectException conE) { |
80 | 6422 | jaume | throw conE;
|
81 | 4293 | jaume | } catch(IOException ioE) { |
82 | 6422 | jaume | throw ioE;
|
83 | 4293 | jaume | } catch(Exception e) { |
84 | 6422 | jaume | e.printStackTrace(); |
85 | } |
||
86 | 3483 | jaume | } |
87 | 6422 | jaume | |
88 | 3483 | jaume | /**
|
89 | 9048 | jaume | * @param override
|
90 | 6422 | jaume | *
|
91 | 3483 | jaume | */
|
92 | 9048 | jaume | public boolean connect(boolean override, ICancellable cancel) |
93 | 3483 | jaume | { |
94 | try {
|
||
95 | 4293 | jaume | if (handler == null) { |
96 | 6422 | jaume | if (getHost().trim().length() > 0) { |
97 | 4427 | jaume | handler = WCSProtocolHandlerFactory.negotiate(getHost()); |
98 | 3483 | jaume | handler.setHost(getHost()); |
99 | 4293 | jaume | } else {
|
100 | 4427 | jaume | // must to specify host first!!!!
|
101 | 3483 | jaume | return false; |
102 | } |
||
103 | } |
||
104 | 9048 | jaume | getCapabilities(null, override, cancel);
|
105 | 6422 | jaume | |
106 | 9048 | jaume | describeCoverage(null, override, cancel); //TODO falta posar el onlineresource del describe coverage |
107 | 3483 | jaume | return true; |
108 | 6422 | jaume | |
109 | 3483 | jaume | } catch (Exception e) { |
110 | e.printStackTrace(); |
||
111 | return false; |
||
112 | } |
||
113 | } |
||
114 | 6422 | jaume | |
115 | 3483 | jaume | /**
|
116 | 4924 | jaume | * Sends a GetCapabilities request using the properties contained by
|
117 | * the status. If status is null, then it uses the default configuration.
|
||
118 | 9048 | jaume | * @param override
|
119 | 4924 | jaume | * @param WCSStatus, containing the status properties
|
120 | 3483 | jaume | */
|
121 | 9048 | jaume | private void getCapabilities(WCSStatus status, boolean override, ICancellable cancel) { |
122 | handler.getCapabilities(status, override, cancel); |
||
123 | 3483 | jaume | } |
124 | 6422 | jaume | |
125 | 4427 | jaume | /**
|
126 | 4924 | jaume | * Sends a DescribeCoverage request using the properties contained by
|
127 | * the status.
|
||
128 | 9048 | jaume | * @param override, if true the cache is ignored
|
129 | 4924 | jaume | * @param WCSStatus, containing the status properties
|
130 | 4427 | jaume | */
|
131 | 9048 | jaume | private void describeCoverage(WCSStatus status, boolean override, ICancellable cancel) { |
132 | handler.describeCoverage(status, override, cancel); |
||
133 | 7010 | jaume | // check it was response or if we need to perform a specific DescribeCoverage for each coverage
|
134 | Hashtable layers = handler.getLayers();
|
||
135 | Iterator it = layers.keySet().iterator();
|
||
136 | while (it.hasNext()) {
|
||
137 | Object obj = layers.get(it.next());
|
||
138 | if (obj instanceof CoverageOfferingBrief) { |
||
139 | if (status == null) |
||
140 | status = new WCSStatus();
|
||
141 | status.setCoveraName( ((CoverageOfferingBrief) obj).getName()); |
||
142 | 9048 | jaume | handler.describeCoverage(status, override, cancel); |
143 | 7010 | jaume | } |
144 | } |
||
145 | |||
146 | 4427 | jaume | layerPool = handler.getLayers(); |
147 | } |
||
148 | 3483 | jaume | |
149 | /* (non-Javadoc)
|
||
150 | * @see org.gvsig.remoteClient.RemoteClient#close()
|
||
151 | */
|
||
152 | public void close() { |
||
153 | } |
||
154 | 4427 | jaume | |
155 | 4924 | jaume | /**
|
156 | * Returns the title of the service. The title is a human-readable string format
|
||
157 | * used to label the service connection.
|
||
158 | * @return String
|
||
159 | */
|
||
160 | 4427 | jaume | public String getServiceTitle() { |
161 | return handler.serviceInfo.title;
|
||
162 | } |
||
163 | |||
164 | 4924 | jaume | /**
|
165 | * Returns the service version (1.0.0, 1.1.0, ...).
|
||
166 | * @return String
|
||
167 | */
|
||
168 | 4427 | jaume | public String getVersion() { |
169 | return handler.getVersion();
|
||
170 | } |
||
171 | |||
172 | 4924 | jaume | /**
|
173 | * Returns a brief description of the service, it is a human-readable string.
|
||
174 | * @return String
|
||
175 | */
|
||
176 | 4427 | jaume | public String getDescription() { |
177 | return handler.serviceInfo.abstr;
|
||
178 | } |
||
179 | |||
180 | 4924 | jaume | /**
|
181 | 6422 | jaume | *
|
182 | 4931 | jaume | * @return
|
183 | */
|
||
184 | public ArrayList getFormats() { |
||
185 | return handler.getFormats();
|
||
186 | } |
||
187 | |||
188 | /**
|
||
189 | 4924 | jaume | * Returns a hash table containing the WCSCoverage's produced at parse time using
|
190 | * the coverage names as the Hashtable's keys
|
||
191 | * @return Hashtable.
|
||
192 | */
|
||
193 | 4427 | jaume | public Hashtable getCoverageList() { |
194 | return layerPool;
|
||
195 | } |
||
196 | |||
197 | 4924 | jaume | /**
|
198 | * Given a coverage name, it returns the coverage's title.
|
||
199 | * @param coverageName
|
||
200 | * @return String
|
||
201 | */
|
||
202 | 4427 | jaume | public String getLabel(String coverageName) { |
203 | return ((WCSCoverage) layerPool.get(coverageName)).getTitle();
|
||
204 | } |
||
205 | |||
206 | 4924 | jaume | /**
|
207 | * Given a coverage name and the CRS name, it returns the extent defined by the
|
||
208 | * server in the DescribeCoverage document.
|
||
209 | 6422 | jaume | *
|
210 | 4924 | jaume | * @param coverageName
|
211 | * @param crs
|
||
212 | * @return Rectangle2D
|
||
213 | */
|
||
214 | public Rectangle2D getExtent(String coverageName, String crs) { |
||
215 | BoundaryBox bbox = (BoundaryBox) ((WCSCoverage) layerPool.get(coverageName)).getBbox(crs);; |
||
216 | 4427 | jaume | if (bbox == null) return null; |
217 | double xmin = bbox.getXmin();
|
||
218 | double xmax = bbox.getXmax();
|
||
219 | double ymin = bbox.getYmin();
|
||
220 | double ymax = bbox.getYmax();
|
||
221 | return new Rectangle2D.Double(xmin, ymin, xmax-xmin, ymax-ymin); |
||
222 | } |
||
223 | 4493 | jaume | |
224 | 4924 | jaume | /**
|
225 | * Sends the GetCoverage request according to the settings passed in the status
|
||
226 | * argument.
|
||
227 | * @param status
|
||
228 | * @return File
|
||
229 | * @throws ServerErrorException
|
||
230 | * @throws WCSException
|
||
231 | */
|
||
232 | 5409 | jaume | public File getCoverage(WCSStatus status, ICancellable cancel) throws ServerErrorException, WCSException { |
233 | return handler.getCoverage(status, cancel);
|
||
234 | 4493 | jaume | } |
235 | 3483 | jaume | } |