Revision 851
trunk/libraries/libFMap/src/com/iver/cit/gvsig/fmap/layers/FLyrWMS.java | ||
---|---|---|
1 |
package com.iver.cit.gvsig.fmap.layers; |
|
2 |
|
|
3 |
import com.hardcode.gdbms.engine.instruction.FieldNotFoundException; |
|
4 |
import com.iver.cit.gvsig.fmap.DriverException; |
|
5 |
import com.iver.cit.gvsig.fmap.ViewPort; |
|
6 |
import com.iver.cit.gvsig.fmap.drivers.WMSException; |
|
7 |
import com.iver.cit.gvsig.fmap.layers.layerOperations.InfoByPoint; |
|
8 |
import com.iver.cit.gvsig.fmap.operations.Cancellable; |
|
9 |
import com.iver.cit.gvsig.fmap.operations.QueriedPoint; |
|
10 |
import com.iver.cit.gvsig.fmap.rendering.LegendFactory; |
|
11 |
|
|
12 |
import com.iver.utiles.StringUtilities; |
|
13 |
import com.iver.utiles.XMLEntity; |
|
14 |
import com.iver.wmsclient.FeatureInfoQuery; |
|
15 |
import com.iver.wmsclient.MapQuery; |
|
16 |
import com.iver.wmsclient.UnsupportedVersionException; |
|
17 |
import com.iver.wmsclient.WMSClient; |
|
18 |
import com.iver.wmsclient.WMSClientFactory; |
|
19 |
|
|
20 |
import org.exolab.castor.xml.ValidationException; |
|
21 |
|
|
22 |
import java.awt.Graphics2D; |
|
23 |
import java.awt.Image; |
|
24 |
import java.awt.geom.Rectangle2D; |
|
25 |
import java.awt.image.BufferedImage; |
|
26 |
|
|
27 |
import java.io.ByteArrayInputStream; |
|
28 |
import java.io.IOException; |
|
29 |
|
|
30 |
import java.net.MalformedURLException; |
|
31 |
import java.net.URL; |
|
32 |
|
|
33 |
import javax.imageio.ImageIO; |
|
34 |
|
|
35 |
|
|
36 |
/** |
|
37 |
* DOCUMENT ME! |
|
38 |
* |
|
39 |
* @author Fernando Gonz?lez Cort?s |
|
40 |
*/ |
|
41 |
public class FLyrWMS extends FLyrDefault implements InfoByPoint { |
|
42 |
private String m_SRS; |
|
43 |
private String m_Format; |
|
44 |
private String layerQuery; |
|
45 |
private String infoLayerQuery; |
|
46 |
private URL host; |
|
47 |
private WMSClient wmsClient; |
|
48 |
private MapQuery lastMapQuery; |
|
49 |
private Rectangle2D fullExtent; |
|
50 |
|
|
51 |
/** |
|
52 |
* DOCUMENT ME! |
|
53 |
* |
|
54 |
* @return DOCUMENT ME! |
|
55 |
* |
|
56 |
* @throws WMSException |
|
57 |
* @throws IllegalStateException |
|
58 |
* @throws ValidationException |
|
59 |
* @throws UnsupportedVersionException |
|
60 |
* @throws IOException |
|
61 |
*/ |
|
62 |
private String selectFormat() |
|
63 |
throws WMSException, IllegalStateException, ValidationException, |
|
64 |
UnsupportedVersionException, IOException { |
|
65 |
String[] formats; |
|
66 |
formats = getWmsClient().getInfoFormats(); |
|
67 |
|
|
68 |
for (int i = 0; i < formats.length; i++) { |
|
69 |
if (formats[i].equals("GML.1")) { |
|
70 |
return formats[i]; |
|
71 |
} |
|
72 |
|
|
73 |
if (formats[i].equals("GML.2")) { |
|
74 |
return formats[i]; |
|
75 |
} |
|
76 |
|
|
77 |
if (formats[i].equals("GML.3")) { |
|
78 |
return formats[i]; |
|
79 |
} |
|
80 |
|
|
81 |
if (formats[i].equals("application/vnd.ogc.gml")) { |
|
82 |
return formats[i]; |
|
83 |
} |
|
84 |
|
|
85 |
if (formats[i].indexOf("XML") != -1) { |
|
86 |
return formats[i]; |
|
87 |
} |
|
88 |
} |
|
89 |
|
|
90 |
throw new WMSException("No format supported"); |
|
91 |
} |
|
92 |
|
|
93 |
public XMLEntity getXMLEntity() { |
|
94 |
XMLEntity xml = super.getXMLEntity(); |
|
95 |
|
|
96 |
xml.putProperty("fullExtent", StringUtilities.rect2String(fullExtent)); |
|
97 |
xml.putProperty("host", host.toExternalForm()); |
|
98 |
xml.putProperty("infoLayerQuery", infoLayerQuery); |
|
99 |
xml.putProperty("layerQuery", layerQuery); |
|
100 |
xml.putProperty("format", m_Format); |
|
101 |
xml.putProperty("srs", m_SRS); |
|
102 |
|
|
103 |
return xml; |
|
104 |
} |
|
105 |
public void setXMLEntity(XMLEntity xml) throws XMLException, |
|
106 |
DriverException { |
|
107 |
super.setXMLEntity(xml); |
|
108 |
fullExtent = StringUtilities.string2Rect(xml.getStringProperty("fullExtent")); |
|
109 |
try { |
|
110 |
host = new URL(xml.getStringProperty("host")); |
|
111 |
} catch (MalformedURLException e) { |
|
112 |
throw new XMLException(e); |
|
113 |
} |
|
114 |
|
|
115 |
infoLayerQuery = xml.getStringProperty("infoLayerQuery"); |
|
116 |
layerQuery = xml.getStringProperty("layerQuery"); |
|
117 |
m_Format = xml.getStringProperty("format"); |
|
118 |
m_SRS = xml.getStringProperty("srs"); |
|
119 |
} |
|
120 |
/* |
|
121 |
* DOCUMENT ME! |
|
122 |
* |
|
123 |
* @return |
|
124 |
* |
|
125 |
public String getFormat() { |
|
126 |
return m_Format; |
|
127 |
} |
|
128 |
|
|
129 |
/* |
|
130 |
* DOCUMENT ME! |
|
131 |
* |
|
132 |
* @return |
|
133 |
* |
|
134 |
public String getSRS() { |
|
135 |
return m_SRS; |
|
136 |
} |
|
137 |
|
|
138 |
/* |
|
139 |
* DOCUMENT ME! |
|
140 |
* |
|
141 |
* @param string |
|
142 |
* |
|
143 |
public void setFormat(String string) { |
|
144 |
m_Format = string; |
|
145 |
} |
|
146 |
|
|
147 |
/* |
|
148 |
* DOCUMENT ME! |
|
149 |
* |
|
150 |
* @param string |
|
151 |
* |
|
152 |
public void setQuery(String string) { |
|
153 |
layerQuery = string; |
|
154 |
} |
|
155 |
|
|
156 |
/* |
|
157 |
* DOCUMENT ME! |
|
158 |
* |
|
159 |
* @param string |
|
160 |
* |
|
161 |
public void setSRS(String string) { |
|
162 |
m_SRS = string; |
|
163 |
} |
|
164 |
|
|
165 |
/* |
|
166 |
* @see com.iver.cit.gvsig.fmap.FLyrDefault#isEditable() |
|
167 |
* |
|
168 |
public boolean isEditable() { |
|
169 |
return false; |
|
170 |
} |
|
171 |
|
|
172 |
/* |
|
173 |
* DOCUMENT ME! |
|
174 |
* |
|
175 |
* @return |
|
176 |
* |
|
177 |
public URL getHost() { |
|
178 |
return host; |
|
179 |
} |
|
180 |
|
|
181 |
/* |
|
182 |
* DOCUMENT ME! |
|
183 |
* |
|
184 |
* @param url |
|
185 |
* |
|
186 |
public void setHost(URL url) { |
|
187 |
host = url; |
|
188 |
} |
|
189 |
|
|
190 |
/* |
|
191 |
public static FLyrWMS createFLyrWMS(XMLEntity entity) throws Exception{ |
|
192 |
String srs = entity.getStringProperty("srs"); |
|
193 |
String format = entity.getStringProperty("format"); |
|
194 |
String layerQuery = entity.getStringProperty("layerQuery"); |
|
195 |
String infoLayerQuery = entity.getStringProperty("infoLayerQuery"); |
|
196 |
String host = entity.getStringProperty("host"); |
|
197 |
Rectangle2D.Double r = (Rectangle2D.Double) StringUtilities.string2Rect(entity.getStringProperty("rect")); |
|
198 |
return new FLyrWMS(new URL(host), r, format, layerQuery, infoLayerQuery, srs); |
|
199 |
} |
|
200 |
|
|
201 |
public XMLEntity getXMLEntity(){ |
|
202 |
XMLEntity xml = new XMLEntity(); |
|
203 |
xml.putProperty("srs", m_SRS); |
|
204 |
xml.putProperty("format", m_Format); |
|
205 |
xml.putProperty("layerQuery", layerQuery); |
|
206 |
xml.putProperty("infoLayerQuery", infoLayerQuery); |
|
207 |
xml.putProperty("host", host.toExternalForm()); |
|
208 |
xml.putProperty("bbox", StringUtilities.rect2String(this.getLayerExtent())); |
|
209 |
|
|
210 |
return xml; |
|
211 |
} |
|
212 |
*/ |
|
213 |
|
|
214 |
/* |
|
215 |
* DOCUMENT ME! |
|
216 |
* |
|
217 |
* @return |
|
218 |
* |
|
219 |
public String getInfoLayerQuery() { |
|
220 |
return infoLayerQuery; |
|
221 |
} |
|
222 |
|
|
223 |
/* |
|
224 |
* DOCUMENT ME! |
|
225 |
* |
|
226 |
* @return |
|
227 |
* |
|
228 |
public String getLayerQuery() { |
|
229 |
return layerQuery; |
|
230 |
} |
|
231 |
|
|
232 |
/* |
|
233 |
* DOCUMENT ME! |
|
234 |
* |
|
235 |
* @param string |
|
236 |
* |
|
237 |
public void setInfoLayerQuery(String string) { |
|
238 |
infoLayerQuery = string; |
|
239 |
} |
|
240 |
|
|
241 |
/* |
|
242 |
* DOCUMENT ME! |
|
243 |
* |
|
244 |
* @param string |
|
245 |
* |
|
246 |
public void setLayerQuery(String string) { |
|
247 |
layerQuery = string; |
|
248 |
} |
|
249 |
*/ |
|
250 |
/** |
|
251 |
* @see com.iver.cit.gvsig.fmap.layers.layerOperations.InfoByPoint#queryByPoint(com.iver.cit.gvsig.fmap.operations.QueriedPoint) |
|
252 |
*/ |
|
253 |
public String queryByPoint(QueriedPoint p) throws DriverException { |
|
254 |
FeatureInfoQuery query = new FeatureInfoQuery(lastMapQuery); |
|
255 |
query.setFeatureCount(Integer.MAX_VALUE); |
|
256 |
query.setX((int) p.getX()); |
|
257 |
query.setY((int) p.getY()); |
|
258 |
query.setInfoQuery(infoLayerQuery); |
|
259 |
|
|
260 |
try { |
|
261 |
query.setInfoFormat(selectFormat()); |
|
262 |
|
|
263 |
return new String(getWmsClient().doFeatureInfo(query)); |
|
264 |
} catch (WMSException e) { |
|
265 |
return "<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?><exception>" + |
|
266 |
e.getMessage() + "</exception>"; |
|
267 |
} catch (ValidationException e) { |
|
268 |
/* |
|
269 |
* TODO Las traducciones en este m?todo han de ser |
|
270 |
* las mismas que en el m?todo de dibujado |
|
271 |
*/ |
|
272 |
|
|
273 |
throw new DriverException("No se reconoce el formato de la respuesta", |
|
274 |
e); |
|
275 |
} catch (UnsupportedVersionException e) { |
|
276 |
throw new DriverException("Conflicto de versiones", e); |
|
277 |
} catch (IOException e) { |
|
278 |
throw new DriverException("Error en la conexi?n", e); |
|
279 |
} catch (com.iver.wmsclient.WMSException e) { |
|
280 |
throw new DriverException(e.getMessage(), e); |
|
281 |
} catch (NoSuchFieldException e) { |
|
282 |
throw new RuntimeException( |
|
283 |
"No se rellenaron todos los campos de la petici?n"); |
|
284 |
} |
|
285 |
} |
|
286 |
|
|
287 |
/** |
|
288 |
* @see com.iver.cit.gvsig.fmap.layers.FLayer#getFullExtent() |
|
289 |
*/ |
|
290 |
public Rectangle2D getFullExtent() throws DriverException { |
|
291 |
return fullExtent; |
|
292 |
} |
|
293 |
|
|
294 |
/** |
|
295 |
* @see com.iver.cit.gvsig.fmap.layers.FLayer#draw(java.awt.image.BufferedImage, |
|
296 |
* java.awt.Graphics2D, com.iver.cit.gvsig.fmap.ViewPort, |
|
297 |
* com.iver.cit.gvsig.fmap.operations.Cancellable) |
|
298 |
*/ |
|
299 |
public void draw(BufferedImage image, Graphics2D g, ViewPort viewPort, |
|
300 |
Cancellable cancel) throws DriverException { |
|
301 |
try { |
|
302 |
lastMapQuery = getWmsClient().createQuery(); |
|
303 |
lastMapQuery.setBBOX(viewPort.getAdjustedExtent()); |
|
304 |
lastMapQuery.setFormat(m_Format); |
|
305 |
lastMapQuery.setHeight(viewPort.getImageHeight()); |
|
306 |
|
|
307 |
// System.err.println("m_Mapa.getHeight() = " + m_Mapa.getHeight()); |
|
308 |
lastMapQuery.setLayers(layerQuery); |
|
309 |
lastMapQuery.setSRS(m_SRS); |
|
310 |
lastMapQuery.setStyles(""); |
|
311 |
lastMapQuery.setWidth(viewPort.getImageWidth()); |
|
312 |
lastMapQuery.setExceptions("application/vnd.ogc.se_xml"); |
|
313 |
|
|
314 |
byte[] bytes; |
|
315 |
|
|
316 |
bytes = getWmsClient().doMapQuery(lastMapQuery); |
|
317 |
|
|
318 |
ByteArrayInputStream inbytes = new ByteArrayInputStream(bytes); |
|
319 |
BufferedImage tempImg = ImageIO.read(inbytes); |
|
320 |
g.drawImage(tempImg, 0, 0, null); |
|
321 |
} catch (ValidationException e) { |
|
322 |
throw new DriverException("No se reconoce el formato de la respuesta", |
|
323 |
e); |
|
324 |
} catch (UnsupportedVersionException e) { |
|
325 |
throw new DriverException("Conflicto de versiones", e); |
|
326 |
} catch (IOException e) { |
|
327 |
throw new DriverException("Error en la conexi?n", e); |
|
328 |
} catch (com.iver.wmsclient.WMSException e) { |
|
329 |
throw new DriverException(e.getMessage(), e); |
|
330 |
} catch (NoSuchFieldException e) { |
|
331 |
throw new RuntimeException( |
|
332 |
"No se rellenaron todos los campos de la petici?n"); |
|
333 |
} |
|
334 |
} |
|
335 |
|
|
336 |
/** |
|
337 |
* @see com.iver.cit.gvsig.fmap.layers.FLayer#print(java.awt.Graphics2D, |
|
338 |
* com.iver.cit.gvsig.fmap.ViewPort, |
|
339 |
* com.iver.cit.gvsig.fmap.operations.Cancellable) |
|
340 |
*/ |
|
341 |
public void print(Graphics2D g, ViewPort viewPort, Cancellable cancel) |
|
342 |
throws DriverException { |
|
343 |
draw(null, g, viewPort, cancel); |
|
344 |
} |
|
345 |
|
|
346 |
/** |
|
347 |
* DOCUMENT ME! |
|
348 |
* |
|
349 |
* @return |
|
350 |
* |
|
351 |
* @throws IllegalStateException DOCUMENT ME! |
|
352 |
* @throws ValidationException DOCUMENT ME! |
|
353 |
* @throws UnsupportedVersionException DOCUMENT ME! |
|
354 |
* @throws IOException DOCUMENT ME! |
|
355 |
*/ |
|
356 |
private WMSClient getWmsClient() |
|
357 |
throws IllegalStateException, ValidationException, |
|
358 |
UnsupportedVersionException, IOException { |
|
359 |
if (wmsClient == null) { |
|
360 |
wmsClient = WMSClientFactory.getClient(host); |
|
361 |
} |
|
362 |
|
|
363 |
return wmsClient; |
|
364 |
} |
|
365 |
|
|
366 |
public URL getHost() { |
|
367 |
return host; |
|
368 |
} |
|
369 |
public void setHost(URL host) { |
|
370 |
this.host = host; |
|
371 |
} |
|
372 |
public String getInfoLayerQuery() { |
|
373 |
return infoLayerQuery; |
|
374 |
} |
|
375 |
public void setInfoLayerQuery(String infoLayerQuery) { |
|
376 |
this.infoLayerQuery = infoLayerQuery; |
|
377 |
} |
|
378 |
public String getLayerQuery() { |
|
379 |
return layerQuery; |
|
380 |
} |
|
381 |
public void setLayerQuery(String layerQuery) { |
|
382 |
this.layerQuery = layerQuery; |
|
383 |
} |
|
384 |
public String getFormat() { |
|
385 |
return m_Format; |
|
386 |
} |
|
387 |
public void setFormat(String format) { |
|
388 |
m_Format = format; |
|
389 |
} |
|
390 |
public String getSRS() { |
|
391 |
return m_SRS; |
|
392 |
} |
|
393 |
public void setSRS(String m_srs) { |
|
394 |
m_SRS = m_srs; |
|
395 |
} |
|
396 |
public void setFullExtent(Rectangle2D fullExtent) { |
|
397 |
this.fullExtent = fullExtent; |
|
398 |
} |
|
399 |
} |
|
0 | 400 |
trunk/libraries/libFMap/src/com/iver/cit/gvsig/fmap/layers/LayerFactory.java | ||
---|---|---|
14 | 14 |
import com.iver.cit.gvsig.fmap.drivers.VectorialDatabaseDriver; |
15 | 15 |
import com.iver.cit.gvsig.fmap.drivers.VectorialDriver; |
16 | 16 |
import com.iver.cit.gvsig.fmap.drivers.VectorialFileDriver; |
17 |
import com.iver.cit.gvsig.fmap.drivers.WMSDriver; |
|
17 | 18 |
import com.iver.cit.gvsig.fmap.drivers.WithDefaultLegend; |
18 | 19 |
import com.iver.cit.gvsig.fmap.drivers.wfs.WFSDriver; |
19 | 20 |
import com.iver.cit.gvsig.fmap.rendering.LegendFactory; |
... | ... | |
23 | 24 |
|
24 | 25 |
import org.cresques.cts.IProjection; |
25 | 26 |
|
27 |
import java.awt.geom.Rectangle2D; |
|
26 | 28 |
import java.io.File; |
27 | 29 |
|
28 | 30 |
import java.net.URL; |
... | ... | |
137 | 139 |
return capa; |
138 | 140 |
} |
139 | 141 |
|
142 |
public static FLayer createLayer(String layerName, Rectangle2D rect, |
|
143 |
URL host, String format, String query, String infoQuery, String srs){ |
|
144 |
|
|
145 |
FLyrWMS layer = new FLyrWMS(); |
|
146 |
layer.setHost(host); |
|
147 |
layer.setFullExtent(rect); |
|
148 |
layer.setFormat(format); |
|
149 |
layer.setLayerQuery(query); |
|
150 |
layer.setInfoLayerQuery(infoQuery); |
|
151 |
layer.setSRS(srs); |
|
152 |
layer.setName(layerName); |
|
153 |
|
|
154 |
return layer; |
|
155 |
} |
|
156 |
|
|
140 | 157 |
/** |
141 | 158 |
* DOCUMENT ME! |
142 | 159 |
* |
trunk/libraries/libFMap/src/com/iver/cit/gvsig/fmap/drivers/WMSDriver.java | ||
---|---|---|
1 |
/* Generated by Together */ |
|
2 |
|
|
3 |
package com.iver.cit.gvsig.fmap.drivers; |
|
4 |
|
|
5 |
import java.awt.Image; |
|
6 |
import java.io.IOException; |
|
7 |
import java.net.ProtocolException; |
|
8 |
import java.net.URL; |
|
9 |
|
|
10 |
public interface WMSDriver { |
|
11 |
void getCapabilities(URL servidor) throws WMSException, IOException, ProtocolException; |
|
12 |
|
|
13 |
Image getMap(com.iver.wmsclient.MapQuery mapQuery) throws WMSException, IOException, ProtocolException; |
|
14 |
|
|
15 |
// String getFeatureInfo(InfoQuery infoQuery) throws WMSException, IOException, ProtocolException; |
|
16 |
} |
|
0 | 17 |
trunk/libraries/libFMap/src/com/iver/cit/gvsig/fmap/drivers/WMSException.java | ||
---|---|---|
1 |
package com.iver.cit.gvsig.fmap.drivers; |
|
2 |
|
|
3 |
|
|
4 |
public class WMSException extends Exception { |
|
5 |
|
|
6 |
/** |
|
7 |
* |
|
8 |
*/ |
|
9 |
public WMSException() { |
|
10 |
super(); |
|
11 |
|
|
12 |
} |
|
13 |
/** |
|
14 |
* @param message |
|
15 |
*/ |
|
16 |
public WMSException(String message) { |
|
17 |
super(message); |
|
18 |
|
|
19 |
} |
|
20 |
/** |
|
21 |
* @param message |
|
22 |
* @param cause |
|
23 |
*/ |
|
24 |
public WMSException(String message, Throwable cause) { |
|
25 |
super(message, cause); |
|
26 |
|
|
27 |
} |
|
28 |
/** |
|
29 |
* @param cause |
|
30 |
*/ |
|
31 |
public WMSException(Throwable cause) { |
|
32 |
super(cause); |
|
33 |
|
|
34 |
} |
|
35 |
} |
|
0 | 36 |
trunk/libraries/libFMap/src/com/iver/cit/gvsig/fmap/drivers/wms/InfoQuery.java | ||
---|---|---|
1 |
package com.iver.cit.gvsig.fmap.drivers.wms; |
|
2 |
|
|
3 |
/** |
|
4 |
* Petici?n de informaci?n al servidor WMS |
|
5 |
*/ |
|
6 |
public class InfoQuery { |
|
7 |
} |
trunk/libraries/libFMap/src/com/iver/cit/gvsig/fmap/drivers/wms/WMSDriver.java | ||
---|---|---|
1 |
/* Generated by Together */ |
|
2 |
|
|
3 |
package com.iver.cit.gvsig.fmap.drivers.wms; |
|
4 |
|
|
5 |
import java.awt.Image; |
|
6 |
import java.io.IOException; |
|
7 |
import java.net.ProtocolException; |
|
8 |
import java.net.URL; |
|
9 |
|
|
10 |
public interface WMSDriver { |
|
11 |
void getCapabilities(URL servidor) throws WMSException, IOException, ProtocolException; |
|
12 |
|
|
13 |
Image getMap(MapQuery mapQuery) throws WMSException, IOException, ProtocolException; |
|
14 |
|
|
15 |
String getFeatureInfo(InfoQuery infoQuery) throws WMSException, IOException, ProtocolException; |
|
16 |
} |
trunk/libraries/libFMap/src/com/iver/cit/gvsig/fmap/drivers/wms/MapQuery.java | ||
---|---|---|
1 |
package com.iver.cit.gvsig.fmap.drivers.wms; |
|
2 |
|
|
3 |
/** |
|
4 |
* Petici?n de Map para el servidor WMS |
|
5 |
*/ |
|
6 |
public class MapQuery { |
|
7 |
} |
trunk/libraries/libFMap/src/com/iver/cit/gvsig/fmap/drivers/wms/WMSException.java | ||
---|---|---|
1 |
package com.iver.cit.gvsig.fmap.drivers.wms; |
|
2 |
|
|
3 |
|
|
4 |
public class WMSException extends Exception { |
|
5 |
|
|
6 |
/** |
|
7 |
* |
|
8 |
*/ |
|
9 |
public WMSException() { |
|
10 |
super(); |
|
11 |
|
|
12 |
} |
|
13 |
/** |
|
14 |
* @param message |
|
15 |
*/ |
|
16 |
public WMSException(String message) { |
|
17 |
super(message); |
|
18 |
|
|
19 |
} |
|
20 |
/** |
|
21 |
* @param message |
|
22 |
* @param cause |
|
23 |
*/ |
|
24 |
public WMSException(String message, Throwable cause) { |
|
25 |
super(message, cause); |
|
26 |
|
|
27 |
} |
|
28 |
/** |
|
29 |
* @param cause |
|
30 |
*/ |
|
31 |
public WMSException(Throwable cause) { |
|
32 |
super(cause); |
|
33 |
|
|
34 |
} |
|
35 |
} |
trunk/libraries/libFMap/src/com/iver/cit/gvsig/fmap/drivers/wms/FMapWMSDriver.java | ||
---|---|---|
1 |
package com.iver.cit.gvsig.fmap.drivers.wms; |
|
2 |
|
|
3 |
import java.awt.Image; |
|
4 |
import java.awt.image.BufferedImage; |
|
5 |
import java.io.ByteArrayInputStream; |
|
6 |
import java.io.IOException; |
|
7 |
import java.net.ProtocolException; |
|
8 |
import java.net.URL; |
|
9 |
|
|
10 |
import javax.imageio.ImageIO; |
|
11 |
|
|
12 |
import org.exolab.castor.xml.ValidationException; |
|
13 |
|
|
14 |
import com.iver.cit.gvsig.fmap.drivers.WMSDriver; |
|
15 |
import com.iver.cit.gvsig.fmap.drivers.WMSException; |
|
16 |
import com.iver.wmsclient.Capabilities; |
|
17 |
import com.iver.wmsclient.FeatureInfoQuery; |
|
18 |
import com.iver.wmsclient.MapQuery; |
|
19 |
import com.iver.wmsclient.UnsupportedVersionException; |
|
20 |
import com.iver.wmsclient.WMSClient; |
|
21 |
import com.iver.wmsclient.WMSClientFactory; |
|
22 |
|
|
23 |
|
|
24 |
public class FMapWMSDriver implements WMSDriver{ |
|
25 |
private MapQuery lastMapQuery; |
|
26 |
private WMSClient client; |
|
27 |
|
|
28 |
/** |
|
29 |
* @see com.iver.cit.gvsig.fmap.drivers.WMSDriver#getCapabilities(java.net.URL) |
|
30 |
*/ |
|
31 |
public void getCapabilities(URL servidor) throws WMSException, IOException, ProtocolException { |
|
32 |
try { |
|
33 |
Capabilities c = getClient(servidor).getCapabilities(servidor); |
|
34 |
} catch (UnsupportedVersionException e) { |
|
35 |
throw new WMSException(e); |
|
36 |
} |
|
37 |
} |
|
38 |
|
|
39 |
/** |
|
40 |
* @see com.iver.cit.gvsig.fmap.drivers.WMSDriver#getMap(com.iver.cit.gvsig.fmap.drivers.wms.MapQuery) |
|
41 |
*/ |
|
42 |
public Image getMap(MapQuery mapQuery) throws WMSException, IOException, ProtocolException { |
|
43 |
BufferedImage image = new BufferedImage(mapQuery.getWidth(), mapQuery.getHeight(), BufferedImage.TYPE_INT_ARGB); |
|
44 |
try { |
|
45 |
byte[] res = client.doMapQuery(mapQuery); |
|
46 |
ByteArrayInputStream inbytes = new ByteArrayInputStream(res); |
|
47 |
image = ImageIO.read(inbytes); |
|
48 |
return image; |
|
49 |
} catch (ValidationException e) { |
|
50 |
throw new ProtocolException(); |
|
51 |
} catch (com.iver.wmsclient.WMSException e) { |
|
52 |
throw new WMSException(e); |
|
53 |
} catch (NoSuchFieldException e) { |
|
54 |
throw new RuntimeException("No se incluyeron todos los campos necesarios de la petici?n"); |
|
55 |
} |
|
56 |
} |
|
57 |
|
|
58 |
/** |
|
59 |
* @see com.iver.cit.gvsig.fmap.drivers.WMSDriver#getFeatureInfo(com.iver.cit.gvsig.fmap.drivers.wms.InfoQuery) |
|
60 |
*/ |
|
61 |
public String getFeatureInfo(FeatureInfoQuery infoQuery) throws WMSException, IOException, ProtocolException { |
|
62 |
return null; |
|
63 |
} |
|
64 |
|
|
65 |
private WMSClient getClient(URL url) throws UnsupportedVersionException, IOException { |
|
66 |
if (client == null) { |
|
67 |
client = WMSClientFactory.getClient(url); |
|
68 |
} |
|
69 |
return client; |
|
70 |
} |
|
71 |
} |
|
0 | 72 |
Also available in: Unified diff