root / trunk / extensions / extWMS / src / com / iver / cit / gvsig / fmap / layers / FLyrWMS.java @ 4915
History | View | Annotate | Download (40.1 KB)
1 | 4503 | jaume | /* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
|
---|---|---|---|
2 | 3746 | jaume | *
|
3 | * Copyright (C) 2004 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 | 4503 | jaume | * Av. Blasco Ib??ez, 50
|
24 | 3746 | jaume | * 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.layers; |
||
42 | |||
43 | import java.awt.Component; |
||
44 | 3841 | nacho | import java.awt.Dimension; |
45 | 3746 | jaume | import java.awt.Graphics2D; |
46 | import java.awt.Point; |
||
47 | 3840 | nacho | import java.awt.Rectangle; |
48 | 3746 | jaume | import java.awt.geom.AffineTransform; |
49 | import java.awt.geom.NoninvertibleTransformException; |
||
50 | import java.awt.geom.Point2D; |
||
51 | import java.awt.geom.Rectangle2D; |
||
52 | import java.awt.image.BufferedImage; |
||
53 | 4378 | nacho | import java.awt.image.DataBuffer; |
54 | 3746 | jaume | import java.io.File; |
55 | import java.io.IOException; |
||
56 | import java.lang.reflect.Constructor; |
||
57 | import java.lang.reflect.InvocationTargetException; |
||
58 | import java.net.MalformedURLException; |
||
59 | import java.net.URL; |
||
60 | import java.util.ArrayList; |
||
61 | import java.util.HashMap; |
||
62 | 3841 | nacho | import java.util.Hashtable; |
63 | 4222 | jaume | import java.util.Iterator; |
64 | 4677 | jorpiell | import java.util.Map; |
65 | 3746 | jaume | import java.util.Vector; |
66 | |||
67 | import javax.swing.JOptionPane; |
||
68 | |||
69 | import org.cresques.geo.ViewPortData; |
||
70 | import org.cresques.io.GdalFile; |
||
71 | import org.cresques.io.GeoRasterFile; |
||
72 | import org.cresques.io.raster.RasterFilterStack; |
||
73 | import org.cresques.io.raster.RasterFilterStackManager; |
||
74 | import org.cresques.px.Extent; |
||
75 | import org.cresques.px.PxRaster; |
||
76 | import org.exolab.castor.xml.ValidationException; |
||
77 | import org.gvsig.remoteClient.utils.Utilities; |
||
78 | import org.gvsig.remoteClient.wms.WMSStatus; |
||
79 | |||
80 | import com.iver.andami.PluginServices; |
||
81 | 4222 | jaume | import com.iver.andami.messages.NotificationManager; |
82 | 3746 | jaume | import com.iver.cit.gvsig.fmap.DriverException; |
83 | import com.iver.cit.gvsig.fmap.ViewPort; |
||
84 | import com.iver.cit.gvsig.fmap.drivers.DriverIOException; |
||
85 | import com.iver.cit.gvsig.fmap.drivers.UnsupportedVersionException; |
||
86 | import com.iver.cit.gvsig.fmap.drivers.WMSException; |
||
87 | import com.iver.cit.gvsig.fmap.drivers.wms.FMapWMSDriver; |
||
88 | 4730 | jaume | import com.iver.cit.gvsig.fmap.layers.WMSLayerNode.FMapWMSStyle; |
89 | 3746 | jaume | import com.iver.cit.gvsig.fmap.layers.layerOperations.InfoByPoint; |
90 | import com.iver.cit.gvsig.fmap.operations.Cancellable; |
||
91 | 4730 | jaume | import com.iver.cit.gvsig.fmap.rendering.XmlBuilder; |
92 | 4876 | jaume | import com.iver.cit.gvsig.webmapcontext.WebMapContextTags; |
93 | 3746 | jaume | import com.iver.utiles.StringUtilities; |
94 | import com.iver.utiles.XMLEntity; |
||
95 | |||
96 | |||
97 | /**
|
||
98 | 4222 | jaume | * FMap's WMS Layer class.
|
99 | 3746 | jaume | *
|
100 | 3749 | jaume | * @author Jaume Dominguez Faus
|
101 | * Nacho Brodin
|
||
102 | *
|
||
103 | 3746 | jaume | */
|
104 | public class FLyrWMS extends FLyrDefault implements InfoByPoint, RasterOperations { |
||
105 | 4222 | jaume | private boolean isPrinting = false; |
106 | private boolean mustTileDraw = false; |
||
107 | private boolean mustTilePrint = true; |
||
108 | private final int maxTileDrawWidth = -1; |
||
109 | private final int maxTileDrawHeight = -1; |
||
110 | private final int maxTilePrintWidth = 1200; |
||
111 | private final int maxTilePrintHeight = 1200; |
||
112 | 3746 | jaume | |
113 | 4222 | jaume | public URL host; |
114 | public String m_Format; |
||
115 | 3746 | jaume | |
116 | 4222 | jaume | private String m_SRS; |
117 | private String layerQuery; |
||
118 | private String infoLayerQuery; |
||
119 | private FMapWMSDriver wms;
|
||
120 | private WMSStatus wmsStatus = new WMSStatus(); |
||
121 | private Rectangle2D fullExtent; |
||
122 | private boolean wmsTransparency; |
||
123 | private Vector styles; |
||
124 | private Vector dimensions; |
||
125 | 3746 | jaume | private StatusRasterInterface status = null; |
126 | private int posX = 0, posY = 0; |
||
127 | private double posXWC = 0, posYWC = 0; |
||
128 | private int r = 0, g = 0, b = 0; |
||
129 | private GeoRasterFile rasterFile = null; |
||
130 | private PxRaster raster = null; |
||
131 | private RasterFilterStack filterStack = null; |
||
132 | 3756 | jaume | private boolean firstLoad = false; |
133 | 3746 | jaume | private int transparency = -1; |
134 | private int rband = 0, gband = 1, bband = 2; |
||
135 | private RasterFilterStackManager stackManager = null; |
||
136 | 4222 | jaume | private Hashtable onlineResources = new Hashtable(); |
137 | private Dimension fixedSize; |
||
138 | private boolean queryable = true; |
||
139 | private VisualStatusWMS visualStatus = new VisualStatusWMS(); |
||
140 | |||
141 | 4677 | jorpiell | public FLyrWMS(){
|
142 | super();
|
||
143 | } |
||
144 | |||
145 | public FLyrWMS(Map args) throws DriverIOException{ |
||
146 | FMapWMSDriver drv = null;
|
||
147 | String host = (String)args.get("host"); |
||
148 | String sLayer = (String)args.get("layer"); |
||
149 | Rectangle2D fullExtent = (Rectangle2D)args.get("FullExtent"); |
||
150 | String sSRS = (String)args.get("SRS"); |
||
151 | String sFormat = (String)args.get("Format"); |
||
152 | String[] sLayers = sLayer.split(","); |
||
153 | |||
154 | try {
|
||
155 | this.setHost(new URL(host)); |
||
156 | } catch (MalformedURLException e) { |
||
157 | //e.printStackTrace();
|
||
158 | throw new DriverIOException("Malformed host URL, '" + host + "' (" + e.toString() + ")."); |
||
159 | } |
||
160 | try {
|
||
161 | drv = this.getDriver();
|
||
162 | } catch (Exception e) { |
||
163 | // e.printStackTrace();
|
||
164 | throw new DriverIOException("Can't get driver to host '" + host + "' (" + e.toString() + ")."); |
||
165 | } |
||
166 | if( sFormat == null || sSRS == null || fullExtent == null ) { |
||
167 | if (!drv.connect())
|
||
168 | throw new DriverIOException("Can't connect to host '" + host + "'."); |
||
169 | |||
170 | WMSLayerNode wmsNode = drv.getLayer(sLayer); |
||
171 | |||
172 | if (wmsNode == null){ |
||
173 | throw new DriverIOException("The server '" + host + "' doesn't has the layer '" + sLayer + "'."); |
||
174 | } |
||
175 | if( sFormat == null ) { |
||
176 | sFormat = this.getGreatFormat(drv.getFormats());
|
||
177 | } |
||
178 | if( sSRS == null ) { |
||
179 | sSRS = (String)wmsNode.getAllSrs().get(0); |
||
180 | } |
||
181 | if( fullExtent == null ) { |
||
182 | fullExtent = drv.getLayersExtent(sLayers,(String)wmsNode.getAllSrs().get(0)); |
||
183 | } |
||
184 | } |
||
185 | |||
186 | |||
187 | this.setFullExtent(fullExtent);
|
||
188 | this.setFormat(sFormat);
|
||
189 | this.setLayerQuery(sLayer);
|
||
190 | this.setInfoLayerQuery(""); |
||
191 | this.setSRS(sSRS);
|
||
192 | this.setName(sLayer);
|
||
193 | } |
||
194 | |||
195 | 4222 | jaume | /**
|
196 | 4677 | jorpiell | * It choose the best format to load different maps if the server
|
197 | * supports it. This format could be png, because it supports
|
||
198 | * transparency.
|
||
199 | * @param formats
|
||
200 | * Arraywith all the formats supported by the server
|
||
201 | * @return
|
||
202 | */
|
||
203 | private String getGreatFormat(Vector formats){ |
||
204 | for (int i=0 ; i<formats.size() ; i++){ |
||
205 | String format = (String) formats.get(i); |
||
206 | if (format.equals("image/jpg")){ |
||
207 | return format;
|
||
208 | } |
||
209 | if (format.equals("image/jpeg")){ |
||
210 | return format;
|
||
211 | } |
||
212 | } |
||
213 | |||
214 | return (String)formats.get(0); |
||
215 | } |
||
216 | |||
217 | /**
|
||
218 | 4222 | jaume | * Clase que contiene los datos de visualizaci?n de WMS.
|
219 | * @author Nacho Brodin (brodin_ign@gva.es)
|
||
220 | */
|
||
221 | private class VisualStatusWMS{ |
||
222 | /**
|
||
223 | * Ancho y alto de la imagen o del conjunto de tiles si los tiene. Coincide con
|
||
224 | * el ancho y alto del viewPort
|
||
225 | */
|
||
226 | private int width = 0, height = 0; |
||
227 | private double minX = 0D, minY = 0D, maxX = 0D, maxY = 0D; |
||
228 | 4378 | nacho | private int bandCount = 0; |
229 | private int dataType = DataBuffer.TYPE_UNDEFINED; |
||
230 | 4222 | jaume | } |
231 | |||
232 | 3746 | jaume | |
233 | /**
|
||
234 | * Devuelve el XMLEntity con la informaci?n necesaria para reproducir la
|
||
235 | * capa.
|
||
236 | *
|
||
237 | * @return XMLEntity.
|
||
238 | * @throws XMLException
|
||
239 | */
|
||
240 | public XMLEntity getXMLEntity() throws XMLException { |
||
241 | XMLEntity xml = super.getXMLEntity();
|
||
242 | |||
243 | 4222 | jaume | // Full extent
|
244 | 3746 | jaume | xml.putProperty("fullExtent", StringUtilities.rect2String(fullExtent));
|
245 | 4222 | jaume | |
246 | // Host
|
||
247 | 3746 | jaume | xml.putProperty("host", host.toExternalForm());
|
248 | 4222 | jaume | |
249 | // Part of the query that is not the host, or the
|
||
250 | // layer names, or other not listed bellow
|
||
251 | 3746 | jaume | xml.putProperty("infoLayerQuery", infoLayerQuery);
|
252 | 4222 | jaume | |
253 | // Part of the query containing the layer names
|
||
254 | 3746 | jaume | xml.putProperty("layerQuery", layerQuery);
|
255 | 4222 | jaume | |
256 | // Format
|
||
257 | 3746 | jaume | xml.putProperty("format", m_Format);
|
258 | 4222 | jaume | |
259 | // SRS
|
||
260 | 3746 | jaume | xml.putProperty("srs", m_SRS);
|
261 | if (status!=null) |
||
262 | status.getXMLEntity(xml, true, this); |
||
263 | else{
|
||
264 | status = new StatusLayerRaster();
|
||
265 | status.getXMLEntity(xml, true, this); |
||
266 | } |
||
267 | 4222 | jaume | |
268 | // Transparency
|
||
269 | 3746 | jaume | xml.putProperty("wms_transparency", wmsTransparency);
|
270 | |||
271 | 4222 | jaume | // Styles
|
272 | 3746 | jaume | if (styles!=null){ |
273 | String stylePr = ""; |
||
274 | for (int i = 0; i < styles.size(); i++) { |
||
275 | stylePr += (String) styles.get(i);
|
||
276 | if (i<styles.size()-1) |
||
277 | stylePr += ",";
|
||
278 | } |
||
279 | 4222 | jaume | if (stylePr.endsWith(",")) |
280 | stylePr += " ";
|
||
281 | 3746 | jaume | xml.putProperty("styles", stylePr);
|
282 | } |
||
283 | 4222 | jaume | |
284 | // Dimensions
|
||
285 | 3746 | jaume | if (dimensions!=null){ |
286 | String dim = ""; |
||
287 | for (int i = 0; i < dimensions.size(); i++) { |
||
288 | dim += (String) dimensions.get(i);
|
||
289 | if (i<dimensions.size()-1) |
||
290 | dim += ",";
|
||
291 | } |
||
292 | 4222 | jaume | if (dim.endsWith(",")) |
293 | dim += " ";
|
||
294 | 3746 | jaume | xml.putProperty("dimensions", dim);
|
295 | } |
||
296 | 4222 | jaume | |
297 | // OnlineResources
|
||
298 | Iterator it = onlineResources.keySet().iterator();
|
||
299 | String strOnlines = ""; |
||
300 | while (it.hasNext()) {
|
||
301 | String key = (String) it.next(); |
||
302 | String value = (String) onlineResources.get(key); |
||
303 | strOnlines = key+"~##SEP2##~"+value;
|
||
304 | if (it.hasNext())
|
||
305 | strOnlines += "~##SEP1##~";
|
||
306 | } |
||
307 | xml.putProperty("onlineResources", strOnlines);
|
||
308 | |||
309 | // Queryable
|
||
310 | xml.putProperty("queryable", queryable);
|
||
311 | |||
312 | // fixedSize
|
||
313 | if (isSizeFixed()) {
|
||
314 | xml.putProperty("fixedSize", true); |
||
315 | xml.putProperty("fixedWidth", fixedSize.width);
|
||
316 | xml.putProperty("fixedHeight", fixedSize.height);
|
||
317 | } |
||
318 | 3746 | jaume | return xml;
|
319 | } |
||
320 | |||
321 | /**
|
||
322 | * A partir del XMLEntity reproduce la capa.
|
||
323 | *
|
||
324 | * @param xml XMLEntity
|
||
325 | *
|
||
326 | * @throws XMLException
|
||
327 | * @throws DriverException
|
||
328 | * @throws DriverIOException
|
||
329 | */
|
||
330 | public void setXMLEntity03(XMLEntity xml) |
||
331 | throws XMLException {
|
||
332 | super.setXMLEntity(xml);
|
||
333 | fullExtent = StringUtilities.string2Rect(xml.getStringProperty( |
||
334 | "fullExtent"));
|
||
335 | |||
336 | try {
|
||
337 | host = new URL(xml.getStringProperty("host")); |
||
338 | } catch (MalformedURLException e) { |
||
339 | throw new XMLException(e); |
||
340 | } |
||
341 | |||
342 | infoLayerQuery = xml.getStringProperty("infoLayerQuery");
|
||
343 | layerQuery = xml.getStringProperty("layerQuery");
|
||
344 | m_Format = xml.getStringProperty("format");
|
||
345 | m_SRS = xml.getStringProperty("srs");
|
||
346 | } |
||
347 | |||
348 | /**
|
||
349 | * A partir del XMLEntity reproduce la capa.
|
||
350 | *
|
||
351 | * @param xml XMLEntity
|
||
352 | *
|
||
353 | * @throws XMLException
|
||
354 | * @throws DriverException
|
||
355 | * @throws DriverIOException
|
||
356 | */
|
||
357 | public void setXMLEntity(XMLEntity xml) |
||
358 | throws XMLException {
|
||
359 | super.setXMLEntity(xml);
|
||
360 | fullExtent = StringUtilities.string2Rect(xml.getStringProperty( |
||
361 | "fullExtent"));
|
||
362 | 4222 | jaume | |
363 | // Host
|
||
364 | 3746 | jaume | try {
|
365 | host = new URL(xml.getStringProperty("host")); |
||
366 | } catch (MalformedURLException e) { |
||
367 | throw new XMLException(e); |
||
368 | } |
||
369 | |||
370 | 4222 | jaume | // Part of the query that is not the host, or the
|
371 | // layer names, or other not listed bellow
|
||
372 | 3746 | jaume | infoLayerQuery = xml.getStringProperty("infoLayerQuery");
|
373 | 4222 | jaume | |
374 | // Part of the query containing the layer names
|
||
375 | 3746 | jaume | layerQuery = xml.getStringProperty("layerQuery");
|
376 | 4222 | jaume | |
377 | // Format
|
||
378 | 3746 | jaume | m_Format = xml.getStringProperty("format");
|
379 | 4222 | jaume | |
380 | // SRS
|
||
381 | 3746 | jaume | m_SRS = xml.getStringProperty("srs");
|
382 | |||
383 | 4222 | jaume | String claseStr = StatusLayerRaster.defaultClass;
|
384 | 3746 | jaume | if (xml.contains("raster.class")) { |
385 | claseStr = xml.getStringProperty("raster.class");
|
||
386 | } |
||
387 | 4222 | jaume | |
388 | // Transparency
|
||
389 | 3746 | jaume | if (xml.contains("wms_transparency")) |
390 | wmsTransparency = xml.getBooleanProperty("wms_transparency");
|
||
391 | 4222 | jaume | |
392 | // Styles
|
||
393 | 3746 | jaume | if (xml.contains("styles")){ |
394 | styles = new Vector(); |
||
395 | String[] stl = xml.getStringProperty("styles").split(","); |
||
396 | 4222 | jaume | |
397 | 3746 | jaume | for (int i = 0; i < stl.length; i++) { |
398 | 4222 | jaume | if (stl[i].equals(" ")) |
399 | stl[i]="";
|
||
400 | 3746 | jaume | styles.add(stl[i]); |
401 | } |
||
402 | } |
||
403 | 4222 | jaume | |
404 | // Dimensions
|
||
405 | 3746 | jaume | if (xml.contains("dimensions")){ |
406 | dimensions = new Vector(); |
||
407 | String[] dims = xml.getStringProperty("dimensions").split(","); |
||
408 | for (int i = 0; i < dims.length; i++){ |
||
409 | 4222 | jaume | if (dims[i].equals(" ")) |
410 | dims[i]="";
|
||
411 | |||
412 | 3746 | jaume | dimensions.add(dims[i]); |
413 | } |
||
414 | } |
||
415 | 4222 | jaume | |
416 | // OnlineResources
|
||
417 | if (xml.contains("onlineResources")) { |
||
418 | String[] operations = xml.getStringProperty("onlineResources").split("~##SEP1##~"); |
||
419 | for (int i = 0; i < operations.length; i++) { |
||
420 | String[] resources = operations[i].split("~##SEP2##~"); |
||
421 | if (resources.length==2 && resources[1]!="") |
||
422 | onlineResources.put(resources[0], resources[1]); |
||
423 | } |
||
424 | } |
||
425 | |||
426 | // Queryable
|
||
427 | queryable = true; // let's assume that the layer is queryable by default |
||
428 | if (xml.contains("queryable")) |
||
429 | queryable = xml.getBooleanProperty("queryable");
|
||
430 | |||
431 | // fixedSize
|
||
432 | if (xml.contains("fixedSize")) { |
||
433 | fixedSize = new Dimension(xml.getIntProperty("fixedWidth"), |
||
434 | xml.getIntProperty("fixedHeight"));
|
||
435 | } |
||
436 | |||
437 | 3746 | jaume | if(status!=null) |
438 | status.setXMLEntity(xml, this);
|
||
439 | else{
|
||
440 | if(claseStr!=null && !claseStr.equals("")){ |
||
441 | try{
|
||
442 | Class clase = Class.forName(claseStr); |
||
443 | Constructor constr = clase.getConstructor(null); |
||
444 | status = (StatusRasterInterface)constr.newInstance(null);
|
||
445 | if(status!=null) |
||
446 | status.setXMLEntity(xml, this);
|
||
447 | }catch(ClassNotFoundException exc){ |
||
448 | exc.printStackTrace(); |
||
449 | }catch(InstantiationException exc){ |
||
450 | exc.printStackTrace(); |
||
451 | }catch(IllegalAccessException exc){ |
||
452 | exc.printStackTrace(); |
||
453 | }catch(NoSuchMethodException exc){ |
||
454 | exc.printStackTrace(); |
||
455 | }catch(InvocationTargetException exc){ |
||
456 | exc.printStackTrace(); |
||
457 | } |
||
458 | } |
||
459 | } |
||
460 | firstLoad = true;
|
||
461 | } |
||
462 | |||
463 | /**
|
||
464 | * @see com.iver.cit.gvsig.fmap.layers.layerOperations.InfoByPoint#queryByPoint(com.iver.cit.gvsig.fmap.operations.QueriedPoint)
|
||
465 | */
|
||
466 | public String queryByPoint(Point p) throws DriverException { |
||
467 | try {
|
||
468 | 4222 | jaume | if (queryable)
|
469 | { |
||
470 | //TODO
|
||
471 | // check if there are layers which are not queryable
|
||
472 | ViewPort viewPort = getFMap().getViewPort(); |
||
473 | |||
474 | Point tiledPoint = new Point((int) p.getX() % maxTilePrintWidth, (int) p.getY() % maxTilePrintHeight); |
||
475 | Rectangle rect = new Rectangle(0, 0, viewPort.getImageWidth() - 1, viewPort.getImageHeight() - 1); |
||
476 | Tiling tiles = new Tiling(maxTilePrintWidth, maxTilePrintHeight, rect);
|
||
477 | tiles.setAffineTransform((AffineTransform) viewPort.getAffineTransform().clone());
|
||
478 | int nCols = tiles.getNumCols();
|
||
479 | |||
480 | int col = (int) p.getX() / maxTilePrintWidth; |
||
481 | int row = (int) p.getY() / maxTilePrintHeight; |
||
482 | int tileIndex = (row*nCols) + col;
|
||
483 | |||
484 | ViewPort vp = tiles.getTileViewPort(viewPort, tileIndex); |
||
485 | wmsStatus.setExtent(vp.getExtent()); |
||
486 | wmsStatus.setHeight(vp.getImageHeight()); |
||
487 | wmsStatus.setWidth(vp.getImageWidth()); |
||
488 | wmsStatus.setOnlineResource((String) onlineResources.get("GetFeatureInfo")); |
||
489 | return new String(getDriver() |
||
490 | .getFeatureInfo(wmsStatus, (int) tiledPoint.getX(), (int) tiledPoint.getY(), Integer.MAX_VALUE)); |
||
491 | } |
||
492 | else
|
||
493 | { |
||
494 | JOptionPane.showMessageDialog((Component)PluginServices.getMainFrame(), |
||
495 | PluginServices.getText(this, "wms_not_queryable")); |
||
496 | return "<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?><info></info>"; |
||
497 | } |
||
498 | 3746 | jaume | } catch (WMSException e) {
|
499 | return "<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?><exception>" + |
||
500 | e.getMessage() + "</exception>";
|
||
501 | } catch (ValidationException e) {
|
||
502 | 4222 | jaume | throw new DriverException(PluginServices.getText(this, "unknown_response_format"), e); |
503 | 3746 | jaume | } catch (UnsupportedVersionException e) {
|
504 | 4222 | jaume | throw new DriverException(PluginServices.getText(this, "version_conflict"), e); |
505 | 3746 | jaume | } catch (IOException e) { |
506 | 4222 | jaume | throw new DriverException(PluginServices.getText(this, "connect_error"), e); |
507 | } catch (NoninvertibleTransformException e) { |
||
508 | NotificationManager.addError("NotinvertibleTransform", e);
|
||
509 | 3746 | jaume | } |
510 | 4222 | jaume | return null; |
511 | 3746 | jaume | } |
512 | |||
513 | /**
|
||
514 | * @see com.iver.cit.gvsig.fmap.layers.FLayer#getFullExtent()
|
||
515 | */
|
||
516 | public Rectangle2D getFullExtent() { |
||
517 | return fullExtent;
|
||
518 | } |
||
519 | |||
520 | /**
|
||
521 | 3841 | nacho | *
|
522 | 3746 | jaume | * @see com.iver.cit.gvsig.fmap.layers.FLayer#draw(java.awt.image.BufferedImage,
|
523 | * java.awt.Graphics2D, com.iver.cit.gvsig.fmap.ViewPort,
|
||
524 | * com.iver.cit.gvsig.fmap.operations.Cancellable)
|
||
525 | */
|
||
526 | public void draw(BufferedImage image, Graphics2D g, ViewPort viewPort, |
||
527 | Cancellable cancel,double scale) throws DriverException { |
||
528 | 4222 | jaume | |
529 | if (isWithinScale(scale)){
|
||
530 | Point2D p = viewPort.getOffset();
|
||
531 | // p will be (0, 0) when drawing a view or other when painting onto
|
||
532 | // the Layout.
|
||
533 | visualStatus.width = viewPort.getImageWidth(); |
||
534 | visualStatus.height = viewPort.getImageHeight(); |
||
535 | visualStatus.minX = viewPort.getAdjustedExtent().getMinX(); |
||
536 | visualStatus.minY = viewPort.getAdjustedExtent().getMinY(); |
||
537 | visualStatus.maxX = viewPort.getAdjustedExtent().getMaxX(); |
||
538 | visualStatus.maxY = viewPort.getAdjustedExtent().getMaxY(); |
||
539 | if (isSizeFixed()) {
|
||
540 | // This condition handles those situations in which the server can
|
||
541 | // only give static extent and resolution maps despite we need
|
||
542 | // a specific BBOX and pixel WIDTH and HEIGHT
|
||
543 | drawFixedSize(g, viewPort, cancel); |
||
544 | |||
545 | } else {
|
||
546 | Rectangle r = new Rectangle((int) p.getX(), (int) p.getY(), viewPort.getImageWidth() - 1, viewPort.getImageHeight() - 1); |
||
547 | Tiling tiles = new Tiling(maxTilePrintWidth, maxTilePrintHeight, r);
|
||
548 | tiles.setAffineTransform((AffineTransform) viewPort.getAffineTransform().clone());
|
||
549 | for (int tileNr=0; tileNr < tiles.getNumTiles(); tileNr++) { |
||
550 | // drawing part
|
||
551 | try {
|
||
552 | ViewPort vp = tiles.getTileViewPort(viewPort, tileNr); |
||
553 | drawTile(g, vp, cancel); |
||
554 | } catch (NoninvertibleTransformException e) { |
||
555 | e.printStackTrace(); |
||
556 | } |
||
557 | 3841 | nacho | } |
558 | 4222 | jaume | } |
559 | 3841 | nacho | } |
560 | 4730 | jaume | // Runtime r = Runtime.getRuntime();
|
561 | // long mem = r.totalMemory() - r.freeMemory();
|
||
562 | // System.err.println("Memoria total: " + (mem / 1024) +"KB");
|
||
563 | 3841 | nacho | } |
564 | |||
565 | 4222 | jaume | private void drawFixedSize(Graphics2D g, ViewPort vp, Cancellable cancel) throws DriverException { |
566 | // This is the extent that will be requested
|
||
567 | Rectangle2D bBox = getFullExtent();
|
||
568 | |||
569 | try {
|
||
570 | wmsStatus.setExtent( bBox ); |
||
571 | wmsStatus.setFormat( m_Format ); |
||
572 | wmsStatus.setHeight( fixedSize.height ); |
||
573 | wmsStatus.setWidth( fixedSize.width ); |
||
574 | wmsStatus.setLayerNames(Utilities.createVector(layerQuery,",")); |
||
575 | wmsStatus.setSrs(m_SRS); |
||
576 | wmsStatus.setStyles(styles); |
||
577 | wmsStatus.setDimensions(dimensions); |
||
578 | wmsStatus.setTransparency(wmsTransparency); |
||
579 | wmsStatus.setOnlineResource((String) onlineResources.get("GetMap")); |
||
580 | |||
581 | File f = getDriver().getMap(wmsStatus);
|
||
582 | String nameWorldFile = f.getPath() + getExtensionWorldFile();
|
||
583 | com.iver.andami.Utilities.createTemp(nameWorldFile, this.getDataWorldFile(bBox, fixedSize));
|
||
584 | |||
585 | if(status!=null && firstLoad){ |
||
586 | status.applyStatus(this);
|
||
587 | firstLoad = false;
|
||
588 | } |
||
589 | |||
590 | // And finally, obtain the extent intersecting the view and the BBox
|
||
591 | // to draw to.
|
||
592 | Rectangle2D extent = new Rectangle2D.Double(); |
||
593 | Rectangle2D.intersect(vp.getAdjustedExtent(), bBox, extent);
|
||
594 | |||
595 | ViewPortData vpData = new ViewPortData(
|
||
596 | vp.getProjection(), new Extent(extent), fixedSize );
|
||
597 | vpData.setMat(vp.getAffineTransform()); |
||
598 | |||
599 | rasterProcess(g, vpData, f); |
||
600 | |||
601 | } catch (ValidationException e) {
|
||
602 | throw new DriverException(PluginServices.getText(this, "unknown_response_format"), e); |
||
603 | } catch (UnsupportedVersionException e) {
|
||
604 | throw new DriverException(PluginServices.getText(this, "version_conflict"), e); |
||
605 | } catch (IOException e) { |
||
606 | throw new DriverException(PluginServices.getText(this, "connect_error"), e); |
||
607 | } catch (WMSException e) {
|
||
608 | JOptionPane.showMessageDialog((Component)PluginServices.getMainFrame(), e.getMessage()); |
||
609 | this.setVisible(false); |
||
610 | 3841 | nacho | } |
611 | 4222 | jaume | |
612 | |||
613 | } |
||
614 | 3841 | nacho | |
615 | /**
|
||
616 | 4222 | jaume | * This is the method used to draw a tile in a WMS mosaic layer.
|
617 | 3841 | nacho | */
|
618 | 4222 | jaume | private void drawTile(Graphics2D g, ViewPort vp, Cancellable cancel) throws DriverException { |
619 | |||
620 | // Compute the query geometry
|
||
621 | // 1. Check if it is within borders
|
||
622 | Rectangle2D extent = getFullExtent();
|
||
623 | if ((vp.getExtent().getMinX() > extent.getMaxX()) ||
|
||
624 | (vp.getExtent().getMinY() > extent.getMaxY()) || |
||
625 | (vp.getExtent().getMaxX() < extent.getMinX()) || |
||
626 | (vp.getExtent().getMaxY() < extent.getMinY())) { |
||
627 | return;
|
||
628 | } |
||
629 | |||
630 | // 2. Compute extent to be requested.
|
||
631 | Rectangle2D bBox = new Rectangle2D.Double(); |
||
632 | Rectangle2D.intersect(vp.getExtent(), extent, bBox);
|
||
633 | |||
634 | // 3. Compute size in pixels
|
||
635 | double scalex = vp.getAffineTransform().getScaleX();
|
||
636 | double scaley = vp.getAffineTransform().getScaleY();
|
||
637 | int wImg = (int) Math.ceil(Math.abs(bBox.getWidth() * scalex) + 1); |
||
638 | int hImg = (int) Math.ceil(Math.abs(bBox.getHeight() * scaley) + 1); |
||
639 | Dimension sz = new Dimension(wImg, hImg); |
||
640 | |||
641 | if ((wImg <= 0) || (hImg <= 0)) { |
||
642 | return;
|
||
643 | } |
||
644 | |||
645 | try {
|
||
646 | wmsStatus.setExtent( bBox ); |
||
647 | wmsStatus.setFormat(m_Format); |
||
648 | wmsStatus.setHeight( hImg ); |
||
649 | wmsStatus.setWidth( wImg ); |
||
650 | wmsStatus.setLayerNames(Utilities.createVector(layerQuery,",")); |
||
651 | wmsStatus.setSrs(m_SRS); |
||
652 | wmsStatus.setStyles(styles); |
||
653 | wmsStatus.setDimensions(dimensions); |
||
654 | wmsStatus.setTransparency(wmsTransparency); |
||
655 | wmsStatus.setOnlineResource((String) onlineResources.get("GetMap")); |
||
656 | 3840 | nacho | |
657 | 4222 | jaume | File f = getDriver().getMap(wmsStatus);
|
658 | String nameWordFile = f.getPath() + getExtensionWorldFile();
|
||
659 | com.iver.andami.Utilities.createTemp(nameWordFile, this.getDataWorldFile(bBox, sz));
|
||
660 | |||
661 | if(status!=null && firstLoad){ |
||
662 | status.applyStatus(this);
|
||
663 | firstLoad = false;
|
||
664 | } |
||
665 | ViewPortData vpData = new ViewPortData(
|
||
666 | vp.getProjection(), new Extent(bBox), sz );
|
||
667 | vpData.setMat(vp.getAffineTransform()); |
||
668 | |||
669 | rasterProcess(g, vpData, f); |
||
670 | |||
671 | 3840 | nacho | } catch (ValidationException e) {
|
672 | 4222 | jaume | throw new DriverException(PluginServices.getText(this, "unknown_response_format"), e); |
673 | 3840 | nacho | } catch (UnsupportedVersionException e) {
|
674 | 4222 | jaume | throw new DriverException(PluginServices.getText(this, "version_conflict"), e); |
675 | 3840 | nacho | } catch (IOException e) { |
676 | 4222 | jaume | throw new DriverException(PluginServices.getText(this, "connect_error"), e); |
677 | 3840 | nacho | } catch (WMSException e) {
|
678 | JOptionPane.showMessageDialog((Component)PluginServices.getMainFrame(), e.getMessage()); |
||
679 | this.setVisible(false); |
||
680 | 3746 | jaume | } |
681 | 3840 | nacho | |
682 | 3746 | jaume | } |
683 | 4222 | jaume | |
684 | /**
|
||
685 | * Obtiene la extensi?n del fichero de georreferenciaci?n
|
||
686 | * @return String con la extensi?n del fichero de georreferenciaci?n dependiendo
|
||
687 | * del valor del formato obtenido del servidor. Por defecto asignaremos un .wld
|
||
688 | */
|
||
689 | private String getExtensionWorldFile(){ |
||
690 | String extWorldFile = ".wld"; |
||
691 | if(m_Format.equals("image/tif") || m_Format.equals("image/tiff")) |
||
692 | extWorldFile = ".tfw";
|
||
693 | if(m_Format.equals("image/jpeg")) |
||
694 | extWorldFile = ".jpgw";
|
||
695 | return extWorldFile;
|
||
696 | } |
||
697 | 3746 | jaume | |
698 | /**
|
||
699 | 4222 | jaume | * Calcula el contenido del fichero de georreferenciaci?n de una imagen.
|
700 | * @param bBox Tama?o y posici?n de la imagen (en coordenadas de usuario)
|
||
701 | * @param sz Tama?o de la imagen en pixeles.
|
||
702 | * @return el 'WorldFile', como String.
|
||
703 | 3746 | jaume | * @throws IOException
|
704 | */
|
||
705 | 4222 | jaume | public String getDataWorldFile(Rectangle2D bBox, Dimension sz) throws IOException { |
706 | StringBuffer data = new StringBuffer(); |
||
707 | data.append((bBox.getMaxX() - bBox.getMinX())/(sz.getWidth() - 1)+"\n"); |
||
708 | data.append("0.0\n");
|
||
709 | data.append("0.0\n");
|
||
710 | data.append((bBox.getMaxY() - bBox.getMinY())/(sz.getHeight() - 1)+"\n"); |
||
711 | data.append(""+bBox.getMinX()+"\n"); |
||
712 | data.append(""+bBox.getMinY()+"\n"); |
||
713 | return data.toString();
|
||
714 | 3746 | jaume | } |
715 | 3841 | nacho | |
716 | 3746 | jaume | /**
|
717 | 4222 | jaume | * Dibuja una imagen usando PxRaster
|
718 | * @param g Graphics2D en el que hay que dibujar.
|
||
719 | * @param vpData Par?metros de visualizaci?n
|
||
720 | * @param file La imagen en cuesti?n.
|
||
721 | */
|
||
722 | private void rasterProcess(Graphics2D g, ViewPortData vpData, File file) { |
||
723 | 3746 | jaume | |
724 | //Creamos el PxRaster
|
||
725 | 4222 | jaume | rasterFile = new GdalFile(vpData.getProjection(), file.getAbsolutePath());
|
726 | 3746 | jaume | raster = new PxRaster(rasterFile, null, rasterFile.getExtent()); |
727 | |||
728 | //Recuperamos la pila de filtros si ya hubiese sido cargado antes
|
||
729 | if(this.filterStack!=null) |
||
730 | raster.filterStack = this.filterStack;
|
||
731 | |||
732 | raster.setTransparency(false);
|
||
733 | 4222 | jaume | |
734 | 3746 | jaume | //Asignamos transparencia y orden de bandas
|
735 | if(this.transparency==-1 && !firstLoad); |
||
736 | else
|
||
737 | raster.setTransparency(this.transparency);
|
||
738 | |||
739 | raster.setBand(GeoRasterFile.RED_BAND,rband); |
||
740 | raster.setBand(GeoRasterFile.GREEN_BAND, gband); |
||
741 | raster.setBand(GeoRasterFile.BLUE_BAND, bband); |
||
742 | |||
743 | //Despues del primer pxRaster asignamos el stackManager guardado para los siguientes.
|
||
744 | //Con esto conseguimos asignar los cambios que se hayan producido desde el cuadro de
|
||
745 | //propiedades cuando creamos un nuevo pxRaster
|
||
746 | if(this.stackManager != null) |
||
747 | raster.setStackManager(this.stackManager);
|
||
748 | 4378 | nacho | |
749 | if(visualStatus != null){ |
||
750 | visualStatus.bandCount = raster.getBandCount(); |
||
751 | visualStatus.dataType = raster.getDataType(); |
||
752 | } |
||
753 | 3841 | nacho | |
754 | 3746 | jaume | raster.draw(g, vpData); |
755 | |||
756 | //En el primer pxRaster de una imagen obtenemos el Stack Manager para poder modificarlo
|
||
757 | //si queremos desde las propiedades
|
||
758 | |||
759 | if(this.stackManager == null) |
||
760 | this.stackManager = raster.getStackManager();
|
||
761 | |||
762 | if(this.filterStack == null) |
||
763 | this.filterStack = raster.filterStack;
|
||
764 | 4222 | jaume | |
765 | 4329 | ldiaz | //rasterFile.close();
|
766 | 3746 | jaume | } |
767 | |||
768 | /**
|
||
769 | * @see com.iver.cit.gvsig.fmap.layers.FLayer#print(java.awt.Graphics2D,
|
||
770 | * com.iver.cit.gvsig.fmap.ViewPort,
|
||
771 | * com.iver.cit.gvsig.fmap.operations.Cancellable)
|
||
772 | */
|
||
773 | public void print(Graphics2D g, ViewPort viewPort, Cancellable cancel,double scale) |
||
774 | throws DriverException {
|
||
775 | if (isVisible() && isWithinScale(scale)){
|
||
776 | isPrinting = true;
|
||
777 | if (!mustTilePrint) {
|
||
778 | draw(null, g, viewPort, cancel,scale);
|
||
779 | } else {
|
||
780 | // Para no pedir imagenes demasiado grandes, vamos
|
||
781 | // a hacer lo mismo que hace EcwFile: chunkear.
|
||
782 | 4222 | jaume | // Llamamos a drawView con cuadraditos m?s peque?os
|
783 | 3746 | jaume | // del BufferedImage ni caso, cuando se imprime viene con null
|
784 | 3841 | nacho | |
785 | 3746 | jaume | Tiling tiles = new Tiling(maxTilePrintWidth, maxTilePrintHeight, g.getClipRect());
|
786 | tiles.setAffineTransform((AffineTransform) viewPort.getAffineTransform().clone());
|
||
787 | for (int tileNr=0; tileNr < tiles.getNumTiles(); tileNr++) { |
||
788 | // Parte que dibuja
|
||
789 | try {
|
||
790 | ViewPort vp = tiles.getTileViewPort(viewPort, tileNr); |
||
791 | 4222 | jaume | drawTile(g, vp, cancel); |
792 | 3746 | jaume | } catch (NoninvertibleTransformException e) { |
793 | e.printStackTrace(); |
||
794 | } |
||
795 | } |
||
796 | } |
||
797 | isPrinting = false;
|
||
798 | } |
||
799 | } |
||
800 | |||
801 | public void _print(Graphics2D g, ViewPort viewPort, Cancellable cancel,double scale) |
||
802 | throws DriverException {
|
||
803 | draw(null, g, viewPort, cancel,scale);
|
||
804 | } |
||
805 | |||
806 | /**
|
||
807 | * Devuelve el FMapWMSDriver.
|
||
808 | *
|
||
809 | * @return FMapWMSDriver
|
||
810 | *
|
||
811 | * @throws IllegalStateException
|
||
812 | * @throws ValidationException
|
||
813 | * @throws UnsupportedVersionException
|
||
814 | * @throws IOException
|
||
815 | */
|
||
816 | private FMapWMSDriver getDriver()
|
||
817 | throws IllegalStateException, ValidationException, |
||
818 | UnsupportedVersionException, IOException {
|
||
819 | if (wms == null) { |
||
820 | //wmsClient = WMSClientFactory.getClient(host);
|
||
821 | wms = new FMapWMSDriver();
|
||
822 | wms.createClient(host); |
||
823 | |||
824 | } |
||
825 | |||
826 | return wms;
|
||
827 | } |
||
828 | |||
829 | /**
|
||
830 | * Devuelve el FMapWMSDriver.
|
||
831 | *
|
||
832 | * @return FMapWMSDriver
|
||
833 | *
|
||
834 | * @throws IllegalStateException
|
||
835 | * @throws ValidationException
|
||
836 | * @throws UnsupportedVersionException
|
||
837 | * @throws IOException
|
||
838 | */
|
||
839 | public void setDriver(FMapWMSDriver drv) { |
||
840 | wms = drv; |
||
841 | } |
||
842 | |||
843 | /**
|
||
844 | * Devuelve el URL.
|
||
845 | *
|
||
846 | * @return URL.
|
||
847 | */
|
||
848 | public URL getHost() { |
||
849 | return host;
|
||
850 | } |
||
851 | |||
852 | /**
|
||
853 | * Inserta el URL.
|
||
854 | *
|
||
855 | * @param host URL.
|
||
856 | */
|
||
857 | public void setHost(URL host) { |
||
858 | this.host = host;
|
||
859 | } |
||
860 | |||
861 | /**
|
||
862 | * Devuelve la informaci?n de la consulta.
|
||
863 | *
|
||
864 | * @return String.
|
||
865 | */
|
||
866 | public String getInfoLayerQuery() { |
||
867 | return infoLayerQuery;
|
||
868 | } |
||
869 | |||
870 | /**
|
||
871 | 4222 | jaume | * Inserta la informaci?n de la consulta.
|
872 | 3746 | jaume | *
|
873 | * @param infoLayerQuery String.
|
||
874 | */
|
||
875 | public void setInfoLayerQuery(String infoLayerQuery) { |
||
876 | this.infoLayerQuery = infoLayerQuery;
|
||
877 | } |
||
878 | |||
879 | /**
|
||
880 | * Devuelve la consulta.
|
||
881 | *
|
||
882 | * @return String.
|
||
883 | */
|
||
884 | public String getLayerQuery() { |
||
885 | return layerQuery;
|
||
886 | } |
||
887 | |||
888 | /**
|
||
889 | * Inserta la consulta.
|
||
890 | *
|
||
891 | * @param layerQuery consulta.
|
||
892 | */
|
||
893 | public void setLayerQuery(String layerQuery) { |
||
894 | this.layerQuery = layerQuery;
|
||
895 | } |
||
896 | |||
897 | /**
|
||
898 | * Devuelve el formato.
|
||
899 | *
|
||
900 | * @return Formato.
|
||
901 | */
|
||
902 | public String getFormat() { |
||
903 | return m_Format;
|
||
904 | } |
||
905 | |||
906 | /**
|
||
907 | * Inserta el formato.
|
||
908 | *
|
||
909 | * @param format Formato.
|
||
910 | */
|
||
911 | public void setFormat(String format) { |
||
912 | m_Format = format; |
||
913 | } |
||
914 | |||
915 | /**
|
||
916 | * Devuelve el SRS.
|
||
917 | *
|
||
918 | * @return SRS.
|
||
919 | */
|
||
920 | public String getSRS() { |
||
921 | return m_SRS;
|
||
922 | } |
||
923 | |||
924 | /**
|
||
925 | * Inserta el SRS.
|
||
926 | *
|
||
927 | * @param m_srs SRS.
|
||
928 | */
|
||
929 | public void setSRS(String m_srs) { |
||
930 | m_SRS = m_srs; |
||
931 | } |
||
932 | |||
933 | /**
|
||
934 | 4222 | jaume | * Inserta la extensi?n total de la capa.
|
935 | 3746 | jaume | *
|
936 | 4222 | jaume | * @param fullExtent Rect?ngulo.
|
937 | 3746 | jaume | */
|
938 | public void setFullExtent(Rectangle2D fullExtent) { |
||
939 | this.fullExtent = fullExtent;
|
||
940 | } |
||
941 | |||
942 | public HashMap getProperties() { |
||
943 | HashMap info = new HashMap(); |
||
944 | String[] layerNames = getLayerQuery().split(","); |
||
945 | Vector layers = new Vector(layerNames.length); |
||
946 | try {
|
||
947 | if(getDriver().connect()){
|
||
948 | for (int i = 0; i < layerNames.length; i++) { |
||
949 | layers.add(i, wms.getLayer(layerNames[i])); |
||
950 | } |
||
951 | 4222 | jaume | info.put("name", getName());
|
952 | 3746 | jaume | info.put("selectedLayers", layers);
|
953 | info.put("host", getHost());
|
||
954 | info.put("srs", getSRS());
|
||
955 | info.put("format", getFormat());
|
||
956 | info.put("wmsTransparency", new Boolean(wmsTransparency)); |
||
957 | info.put("styles", styles);
|
||
958 | info.put("dimensions", dimensions);
|
||
959 | 4222 | jaume | info.put("fixedSize", fixedSize);
|
960 | 3746 | jaume | return info;
|
961 | } |
||
962 | } catch (Exception e) { |
||
963 | e.printStackTrace(); |
||
964 | } |
||
965 | return null; |
||
966 | } |
||
967 | |||
968 | /**
|
||
969 | * Asignar el estado del raster
|
||
970 | * @param status
|
||
971 | */
|
||
972 | public void setStatus(StatusRasterInterface status){ |
||
973 | this.status = status;
|
||
974 | } |
||
975 | |||
976 | /**
|
||
977 | * Obtiene el estado del raster
|
||
978 | * @return
|
||
979 | */
|
||
980 | public StatusRasterInterface getStatus(){
|
||
981 | return this.status; |
||
982 | } |
||
983 | |||
984 | /* (non-Javadoc)
|
||
985 | * @see com.iver.cit.gvsig.fmap.layers.RasterOperations#getAttributes()
|
||
986 | */
|
||
987 | public ArrayList getAttributes() { |
||
988 | if(rasterFile != null){ |
||
989 | ArrayList attr = new ArrayList(); |
||
990 | 4378 | nacho | String dataType = "Byte"; |
991 | 3746 | jaume | if (rasterFile.getDataType() == DataBuffer.TYPE_BYTE) dataType = "Byte"; |
992 | 4378 | nacho | else if (visualStatus.dataType == DataBuffer.TYPE_SHORT) |
993 | 3746 | jaume | dataType = "Short";
|
994 | 4378 | nacho | else if (visualStatus.dataType == DataBuffer.TYPE_USHORT) |
995 | 3746 | jaume | dataType = "Unsigned Short";
|
996 | 4378 | nacho | else if (visualStatus.dataType == DataBuffer.TYPE_INT) |
997 | 3746 | jaume | dataType = "Integer";
|
998 | 4378 | nacho | else if (visualStatus.dataType == DataBuffer.TYPE_FLOAT) |
999 | 3746 | jaume | dataType = "Float";
|
1000 | 4378 | nacho | else if (visualStatus.dataType == DataBuffer.TYPE_DOUBLE) |
1001 | 3746 | jaume | dataType = "Double";
|
1002 | else
|
||
1003 | dataType = "Unknown";
|
||
1004 | 4378 | nacho | |
1005 | 3746 | jaume | Object [][] a = { |
1006 | {"Filename",rasterFile.getName().substring(rasterFile.getName().lastIndexOf("/")+1, rasterFile.getName().length())}, |
||
1007 | 4378 | nacho | {"Filesize",new Long(0)}, |
1008 | {"Width",new Integer((int)this.getWidth())}, |
||
1009 | {"Height", new Integer((int)this.getHeight())}, |
||
1010 | {"Bands", new Integer(visualStatus.bandCount)}, |
||
1011 | {"BandDataType", dataType}
|
||
1012 | 3746 | jaume | }; |
1013 | 4378 | nacho | for (int i=0; i<a.length; i++) |
1014 | 3746 | jaume | attr.add(a[i]); |
1015 | 4378 | nacho | |
1016 | 3746 | jaume | return attr;
|
1017 | } |
||
1018 | return null; |
||
1019 | } |
||
1020 | 4222 | jaume | |
1021 | 3746 | jaume | /* (non-Javadoc)
|
1022 | * @see com.iver.cit.gvsig.fmap.layers.RasterOperations#getFilterStack()
|
||
1023 | */
|
||
1024 | public RasterFilterStack getFilterStack() {
|
||
1025 | if(raster!=null) |
||
1026 | return raster.filterStack;
|
||
1027 | return null; |
||
1028 | } |
||
1029 | /* (non-Javadoc)
|
||
1030 | * @see com.iver.cit.gvsig.fmap.layers.RasterOperations#getHeight()
|
||
1031 | */
|
||
1032 | public double getHeight() { |
||
1033 | 4222 | jaume | return visualStatus.height;
|
1034 | 3746 | jaume | } |
1035 | 4222 | jaume | |
1036 | 3746 | jaume | /* (non-Javadoc)
|
1037 | * @see com.iver.cit.gvsig.fmap.layers.RasterOperations#getMaxX()
|
||
1038 | */
|
||
1039 | public double getMaxX() { |
||
1040 | 4222 | jaume | return visualStatus.maxX;
|
1041 | 3746 | jaume | } |
1042 | 4222 | jaume | |
1043 | 3746 | jaume | /* (non-Javadoc)
|
1044 | * @see com.iver.cit.gvsig.fmap.layers.RasterOperations#getMaxY()
|
||
1045 | */
|
||
1046 | public double getMaxY() { |
||
1047 | 4222 | jaume | return visualStatus.maxY;
|
1048 | 3746 | jaume | } |
1049 | 4222 | jaume | |
1050 | 3746 | jaume | /* (non-Javadoc)
|
1051 | * @see com.iver.cit.gvsig.fmap.layers.RasterOperations#getMinX()
|
||
1052 | */
|
||
1053 | public double getMinX() { |
||
1054 | 4222 | jaume | return visualStatus.minX;
|
1055 | 3746 | jaume | } |
1056 | 4222 | jaume | |
1057 | 3746 | jaume | /* (non-Javadoc)
|
1058 | * @see com.iver.cit.gvsig.fmap.layers.RasterOperations#getMinY()
|
||
1059 | */
|
||
1060 | public double getMinY() { |
||
1061 | 4222 | jaume | return visualStatus.minY;
|
1062 | 3746 | jaume | } |
1063 | /* (non-Javadoc)
|
||
1064 | * @see com.iver.cit.gvsig.fmap.layers.RasterOperations#getPixel(double, double)
|
||
1065 | */
|
||
1066 | public int[] getPixel(double wcx, double wcy) { |
||
1067 | if(getPxRaster() != null) |
||
1068 | return getPxRaster().getPixel(wcx, wcy);
|
||
1069 | return null; |
||
1070 | } |
||
1071 | /* (non-Javadoc)
|
||
1072 | * @see com.iver.cit.gvsig.fmap.layers.RasterOperations#getSource()
|
||
1073 | */
|
||
1074 | public RasterAdapter getSource() {
|
||
1075 | return null; |
||
1076 | } |
||
1077 | /* (non-Javadoc)
|
||
1078 | * @see com.iver.cit.gvsig.fmap.layers.RasterOperations#getWidth()
|
||
1079 | */
|
||
1080 | public double getWidth() { |
||
1081 | 4222 | jaume | return visualStatus.width;
|
1082 | 3746 | jaume | } |
1083 | /* (non-Javadoc)
|
||
1084 | * @see com.iver.cit.gvsig.fmap.layers.RasterOperations#setBand(int, int)
|
||
1085 | */
|
||
1086 | public void setBand(int flag, int nBand) { |
||
1087 | switch(flag){
|
||
1088 | case GeoRasterFile.RED_BAND:setBandR(nBand);break; |
||
1089 | case GeoRasterFile.GREEN_BAND:setBandG(nBand);break; |
||
1090 | case GeoRasterFile.BLUE_BAND:setBandB(nBand);break; |
||
1091 | } |
||
1092 | } |
||
1093 | /* (non-Javadoc)
|
||
1094 | * @see com.iver.cit.gvsig.fmap.layers.RasterOperations#setFilterStack(org.cresques.io.raster.RasterFilterStack)
|
||
1095 | */
|
||
1096 | public void setFilterStack(RasterFilterStack stack) { |
||
1097 | this.filterStack = stack;
|
||
1098 | } |
||
1099 | /* (non-Javadoc)
|
||
1100 | * @see com.iver.cit.gvsig.fmap.layers.RasterOperations#setPos(int, int)
|
||
1101 | */
|
||
1102 | public void setPos(int x, int y) { |
||
1103 | this.posX = x;
|
||
1104 | this.posY = y;
|
||
1105 | } |
||
1106 | |||
1107 | /* (non-Javadoc)
|
||
1108 | * @see com.iver.cit.gvsig.fmap.layers.RasterOperations#setPosWC(double, double)
|
||
1109 | */
|
||
1110 | public void setPosWC(double x, double y) { |
||
1111 | this.posXWC = x;
|
||
1112 | this.posYWC = y;
|
||
1113 | } |
||
1114 | |||
1115 | /* (non-Javadoc)
|
||
1116 | * @see com.iver.cit.gvsig.fmap.layers.RasterOperations#setRGB(int, int, int)
|
||
1117 | */
|
||
1118 | public void setRGB(int r, int g, int b) { |
||
1119 | this.r = r;
|
||
1120 | this.g = g;
|
||
1121 | this.b = b;
|
||
1122 | } |
||
1123 | /* (non-Javadoc)
|
||
1124 | * @see com.iver.cit.gvsig.fmap.layers.RasterOperations#setSource(com.iver.cit.gvsig.fmap.layers.RasterAdapter)
|
||
1125 | */
|
||
1126 | public void setSource(RasterAdapter ra) { |
||
1127 | } |
||
1128 | /**
|
||
1129 | * @return Returns the raster.
|
||
1130 | */
|
||
1131 | public PxRaster getPxRaster() {
|
||
1132 | return raster;
|
||
1133 | } |
||
1134 | /**
|
||
1135 | * @return Returns the rasterFile.
|
||
1136 | */
|
||
1137 | public GeoRasterFile getGeoRasterFile() {
|
||
1138 | return rasterFile;
|
||
1139 | } |
||
1140 | |||
1141 | public void setTransparency(int trans) { |
||
1142 | this.transparency = trans;
|
||
1143 | } |
||
1144 | |||
1145 | /**
|
||
1146 | * Sets the R-band.
|
||
1147 | *
|
||
1148 | * Asigna la banda R.
|
||
1149 | * @param r
|
||
1150 | */
|
||
1151 | public void setBandR(int r){ |
||
1152 | this.rband = r;
|
||
1153 | } |
||
1154 | |||
1155 | /**
|
||
1156 | * Sets the G-band.
|
||
1157 | *
|
||
1158 | * Asigna la banda G
|
||
1159 | * @param g
|
||
1160 | */
|
||
1161 | public void setBandG(int g){ |
||
1162 | this.gband = g;
|
||
1163 | } |
||
1164 | |||
1165 | /**
|
||
1166 | * Sets the B-band.
|
||
1167 | *
|
||
1168 | * Asigna la banda B
|
||
1169 | * @param b
|
||
1170 | */
|
||
1171 | public void setBandB(int b){ |
||
1172 | this.bband = b;
|
||
1173 | } |
||
1174 | |||
1175 | /**
|
||
1176 | * @return Returns the wmsTransparency.
|
||
1177 | */
|
||
1178 | 4222 | jaume | public boolean isWmsTransparent() { |
1179 | 3746 | jaume | return wmsTransparency;
|
1180 | } |
||
1181 | |||
1182 | /**
|
||
1183 | * @param wmsTransparency The wmsTransparency to set.
|
||
1184 | */
|
||
1185 | public void setWmsTransparency(boolean wmsTransparency) { |
||
1186 | this.wmsTransparency = wmsTransparency;
|
||
1187 | } |
||
1188 | |||
1189 | 3842 | nacho | /**
|
1190 | 3746 | jaume | * @param styles
|
1191 | */
|
||
1192 | public void setStyles(Vector styles) { |
||
1193 | 3842 | nacho | //laura:
|
1194 | //layer query is built with the layer in reverse order
|
||
1195 | // so here we build the styles upside-down.
|
||
1196 | if (styles != null) |
||
1197 | { |
||
1198 | this.styles = new Vector(); |
||
1199 | for(int i = styles.size()-1; i>=0; i--) |
||
1200 | { |
||
1201 | this.styles.add(styles.elementAt(i));
|
||
1202 | } |
||
1203 | } |
||
1204 | 3746 | jaume | } |
1205 | |||
1206 | /**
|
||
1207 | 4222 | jaume | * Sets the dimension vector that is a list of key-value pairs containing
|
1208 | * the name of the dimension and the value for it
|
||
1209 | 3746 | jaume | * @param dimensions
|
1210 | */
|
||
1211 | public void setDimensions(Vector dimensions) { |
||
1212 | this.dimensions = dimensions;
|
||
1213 | } |
||
1214 | 4222 | jaume | |
1215 | /**
|
||
1216 | * Sets the set of URLs that should be accessed for each operation performed
|
||
1217 | * to the server.
|
||
1218 | *
|
||
1219 | * @param onlineResources
|
||
1220 | */
|
||
1221 | public void setOnlineResources(Hashtable onlineResources) { |
||
1222 | this.onlineResources = onlineResources;
|
||
1223 | } |
||
1224 | 3746 | jaume | |
1225 | 4222 | jaume | /**
|
1226 | * When a server is not fully featured and it only can serve constant map
|
||
1227 | * sizes this value must be set. It expresses the size in pixels (width, height)
|
||
1228 | * that the map will be requested.
|
||
1229 | * @param Dimension sz
|
||
1230 | */
|
||
1231 | public void setFixedSize(Dimension sz) { |
||
1232 | fixedSize = sz; |
||
1233 | } |
||
1234 | |||
1235 | /**
|
||
1236 | * Tells whether if this layer must deal with the server with the constant-size
|
||
1237 | * limitations or not.
|
||
1238 | * @return boolean.
|
||
1239 | */
|
||
1240 | private boolean isSizeFixed() { |
||
1241 | return fixedSize != null && fixedSize.getWidth() > 0 && fixedSize.getHeight() > 0; |
||
1242 | } |
||
1243 | |||
1244 | /**
|
||
1245 | * If it is true, this layer accepts GetFeatureInfo operations. This WMS operations
|
||
1246 | * maps to FMap's infoByPoint(p) operation.
|
||
1247 | * @param b
|
||
1248 | */
|
||
1249 | public void setQueryable(boolean b) { |
||
1250 | queryable = b; |
||
1251 | } |
||
1252 | 4730 | jaume | |
1253 | /**
|
||
1254 | * Creates the part of a OGC's MapContext document that would describe this
|
||
1255 | * layer(s).
|
||
1256 | * @param version, The desired version of the resulting document. (1.1.0)
|
||
1257 | * @return String containing the xml.
|
||
1258 | * @throws UnsupportedVersionException
|
||
1259 | */
|
||
1260 | public String toMapContext(String version) { |
||
1261 | XmlBuilder xml = new XmlBuilder();
|
||
1262 | FMapWMSDriver drv; |
||
1263 | try {
|
||
1264 | drv = getDriver(); |
||
1265 | } catch (Exception e) { |
||
1266 | return xml.toString();
|
||
1267 | } |
||
1268 | String[] layerNames = getLayerQuery().split(","); |
||
1269 | for (int i = 0; i < layerNames.length; i++) { |
||
1270 | WMSLayerNode layer = drv.getLayer(layerNames[i]); |
||
1271 | 4833 | jaume | // <Layer>
|
1272 | 4876 | jaume | xml.openTag(WebMapContextTags.LAYER); |
1273 | 4730 | jaume | HashMap xmlAttrs = new HashMap(); |
1274 | if (version.equals("1.1.0")) { |
||
1275 | // <Server>
|
||
1276 | 4876 | jaume | xmlAttrs.put(WebMapContextTags.SERVICE, WebMapContextTags.WMS); |
1277 | xmlAttrs.put(WebMapContextTags.VERSION, drv.getVersion()); |
||
1278 | xmlAttrs.put(WebMapContextTags.SERVER_TITLE, drv.getServiceTitle()); |
||
1279 | xml.openTag(WebMapContextTags.SERVER, xmlAttrs); |
||
1280 | 4730 | jaume | xmlAttrs.clear(); |
1281 | |||
1282 | // <OnlineResource>
|
||
1283 | 4876 | jaume | xmlAttrs.put(WebMapContextTags.XLINK_TYPE, "simple");
|
1284 | xmlAttrs.put(WebMapContextTags.XLINK_HREF, getHost().toString()); |
||
1285 | xml.writeTag(WebMapContextTags.ONLINE_RESOURCE, xmlAttrs); |
||
1286 | 4730 | jaume | xmlAttrs.clear(); |
1287 | // </OnlineResource>
|
||
1288 | |||
1289 | xml.closeTag(); |
||
1290 | // </Server>
|
||
1291 | |||
1292 | // <Name>
|
||
1293 | 4915 | jaume | xml.writeTag(WebMapContextTags.NAME, layer.getName().trim()); |
1294 | 4730 | jaume | // </Name>
|
1295 | |||
1296 | // <Title>
|
||
1297 | 4915 | jaume | xml.writeTag(WebMapContextTags.TITLE, layer.getTitle().trim()); |
1298 | 4730 | jaume | // </Title>
|
1299 | |||
1300 | // <Abstract>
|
||
1301 | 4915 | jaume | if (layer.getAbstract() != null) |
1302 | xml.writeTag(WebMapContextTags.ABSTRACT, layer.getAbstract()); |
||
1303 | 4730 | jaume | // </Abstract>
|
1304 | |||
1305 | // <SRS> (a list of available SRS for the enclosing layer)
|
||
1306 | String[] strings = (String[]) layer.getAllSrs().toArray(new String[0]); |
||
1307 | String mySRS = strings[0]; |
||
1308 | for (int j = 1; j < strings.length; j++) { |
||
1309 | mySRS += ","+strings[j];
|
||
1310 | } |
||
1311 | 4915 | jaume | xml.writeTag(WebMapContextTags.SRS, mySRS); |
1312 | 4730 | jaume | // </SRS>
|
1313 | |||
1314 | // <FormatList>
|
||
1315 | 4876 | jaume | xml.openTag(WebMapContextTags.FORMAT_LIST); |
1316 | 4730 | jaume | strings = (String[]) drv.getFormats().toArray(new String[0]); |
1317 | for (int j = 0; j < strings.length; j++) { |
||
1318 | // <Format>
|
||
1319 | 4915 | jaume | String str = strings[j].trim();
|
1320 | if (str.equals(getFormat()))
|
||
1321 | xml.writeTag(WebMapContextTags.FORMAT, str, WebMapContextTags.CURRENT, "1");
|
||
1322 | else
|
||
1323 | xml.writeTag(WebMapContextTags.FORMAT, str); |
||
1324 | 4730 | jaume | // </Format>
|
1325 | } |
||
1326 | xml.closeTag(); |
||
1327 | // </FormatList>
|
||
1328 | |||
1329 | // <StyleList>
|
||
1330 | 4915 | jaume | if (layer.getStyles().size()>0) { |
1331 | 4876 | jaume | xml.openTag(WebMapContextTags.STYLE_LIST); |
1332 | 4730 | jaume | for (int j = 0; j < layer.getStyles().size(); j++) { |
1333 | // <Style>
|
||
1334 | FMapWMSStyle st = (FMapWMSStyle) layer.getStyles().get(i); |
||
1335 | if (st.equals(layer.getSelectedStyle()))
|
||
1336 | 4876 | jaume | xmlAttrs.put(WebMapContextTags.CURRENT, "1");
|
1337 | xml.openTag(WebMapContextTags.STYLE, xmlAttrs); |
||
1338 | 4730 | jaume | |
1339 | // <Name>
|
||
1340 | 4915 | jaume | xml.writeTag(WebMapContextTags.NAME, st.name); |
1341 | 4730 | jaume | // </Name>
|
1342 | |||
1343 | // <Title>
|
||
1344 | 4915 | jaume | xml.writeTag(WebMapContextTags.TITLE, st.title); |
1345 | 4730 | jaume | // </Title>
|
1346 | |||
1347 | // <LegendURL width="180" format="image/gif" height="50">
|
||
1348 | // <OnlineResource xlink:type="simple" xlink:href="http://globe.digitalearth.gov/globe/en/icons/colorbars/NATIONAL.gif"/>
|
||
1349 | // </OnlineResource>
|
||
1350 | // </LegendURL>
|
||
1351 | // </Style>
|
||
1352 | xml.closeTag(); |
||
1353 | } |
||
1354 | 4915 | jaume | } |
1355 | 4730 | jaume | // </StyleList>
|
1356 | // <DimensionList>
|
||
1357 | // <Dimension>
|
||
1358 | // </Dimension>
|
||
1359 | // </DimensionList>
|
||
1360 | |||
1361 | |||
1362 | } else if (version.equals("1.0.0")) { |
||
1363 | } else {
|
||
1364 | xml.writeTag("ERROR", PluginServices.getText(this, "unsupported_map_context_version")); |
||
1365 | } |
||
1366 | 4833 | jaume | // </Layer>
|
1367 | xml.closeTag(); |
||
1368 | 4730 | jaume | } |
1369 | 4915 | jaume | return xml.getXML();
|
1370 | 4730 | jaume | } |
1371 | 3746 | jaume | } |