svn-gvsig-desktop / trunk / extensions / extWCS / src / com / iver / cit / gvsig / fmap / layers / FLyrWCS.java @ 2764
History | View | Annotate | Download (23.3 KB)
1 |
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
|
---|---|
2 |
*
|
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 |
* 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.layers; |
42 |
|
43 |
import java.awt.Component; |
44 |
import java.awt.Graphics2D; |
45 |
import java.awt.Point; |
46 |
import java.awt.geom.Point2D; |
47 |
import java.awt.geom.Rectangle2D; |
48 |
import java.awt.image.BufferedImage; |
49 |
import java.io.IOException; |
50 |
import java.lang.reflect.Constructor; |
51 |
import java.lang.reflect.InvocationTargetException; |
52 |
import java.util.ArrayList; |
53 |
import java.util.Hashtable; |
54 |
import java.util.TreeMap; |
55 |
|
56 |
import javax.swing.JOptionPane; |
57 |
|
58 |
import org.cresques.io.GeoRasterFile; |
59 |
import org.cresques.io.raster.RasterFilterStack; |
60 |
|
61 |
import com.iver.andami.PluginServices; |
62 |
import com.iver.cit.gvsig.fmap.DriverException; |
63 |
import com.iver.cit.gvsig.fmap.ViewPort; |
64 |
import com.iver.cit.gvsig.fmap.drivers.DriverIOException; |
65 |
import com.iver.cit.gvsig.fmap.drivers.wcs.FMapWCSDriver; |
66 |
import com.iver.cit.gvsig.fmap.operations.Cancellable; |
67 |
import com.iver.cit.gvsig.fmap.services.OGCWCSService; |
68 |
import com.iver.utiles.StringUtilities; |
69 |
import com.iver.utiles.XMLEntity; |
70 |
|
71 |
import es.uji.lsi.wcs.client.ServerErrorResponseException; |
72 |
|
73 |
/**
|
74 |
* Class for the WCS layer.
|
75 |
*
|
76 |
* Capa para el WCS.
|
77 |
*
|
78 |
* @author jaume - jaume.dominguez@iver.es
|
79 |
*/
|
80 |
public class FLyrWCS extends FLyrDefault implements RasterOperations{ |
81 |
private FMapWCSAdapter wcs = null; |
82 |
|
83 |
private String label; |
84 |
private StatusRasterInterface status = null; |
85 |
private int posX = 0, posY = 0; |
86 |
private double posXWC = 0, posYWC = 0; |
87 |
private int r = 0, g = 0, b = 0; |
88 |
|
89 |
|
90 |
/**
|
91 |
* Returns the XMLEntity containing the necessary info for reproduce
|
92 |
* the layer.
|
93 |
*
|
94 |
* Devuelve el XMLEntity con la informaci?n necesaria para reproducir
|
95 |
* la capa.
|
96 |
*
|
97 |
* @return XMLEntity.
|
98 |
* @throws XMLException
|
99 |
*/
|
100 |
public XMLEntity getXMLEntity() throws XMLException { |
101 |
XMLEntity xml = super.getXMLEntity();
|
102 |
|
103 |
xml.putProperty("wcs.host", getHost());
|
104 |
try {
|
105 |
xml.putProperty("wcs.fullExtent",
|
106 |
StringUtilities.rect2String(wcs.getFullExtent())); |
107 |
} catch (IOException e) { |
108 |
} catch (DriverException e) {
|
109 |
} |
110 |
xml.putProperty("wcs.layerQuery", wcs.getCoverageQuery());
|
111 |
xml.putProperty("wcs.format", getFormat());
|
112 |
xml.putProperty("wcs.srs", getSRS());
|
113 |
xml.putProperty("wcs.time", getTime());
|
114 |
xml.putProperty("wcs.parameter", getParameter());
|
115 |
xml.putProperty("wcs.label", label);
|
116 |
xml.putProperty("wcs.coverageName", getCoverageName());
|
117 |
xml.putProperty("wcs.maxResX", getMaxResolution().getX());
|
118 |
xml.putProperty("wcs.maxResY", getMaxResolution().getY());
|
119 |
if (status!=null) |
120 |
status.getXMLEntity(xml, true, this); |
121 |
else{
|
122 |
status = new StatusLayerRaster();
|
123 |
status.getXMLEntity(xml, true, this); |
124 |
} |
125 |
return xml;
|
126 |
} |
127 |
|
128 |
/**
|
129 |
* Reproduces the layer from an XMLEntity.
|
130 |
*
|
131 |
* A partir del XMLEntity reproduce la capa.
|
132 |
*
|
133 |
* @param xml XMLEntity
|
134 |
*
|
135 |
* @throws XMLException
|
136 |
* @throws DriverException
|
137 |
* @throws DriverIOException
|
138 |
*/
|
139 |
public void setXMLEntity(XMLEntity xml) throws XMLException { |
140 |
super.setXMLEntity(xml);
|
141 |
//System.out.println(" Cargo la capa WCS. ... o no ;-)");
|
142 |
setHost(xml.getStringProperty("wcs.host"));
|
143 |
setFullExtent(StringUtilities.string2Rect( |
144 |
xml.getStringProperty("wcs.fullExtent")));
|
145 |
wcs.setCoverageQuery(xml.getStringProperty("wcs.layerQuery"));
|
146 |
setFormat(xml.getStringProperty("wcs.format"));
|
147 |
setSRS(xml.getStringProperty("wcs.srs"));
|
148 |
setTime(xml.getStringProperty("wcs.time"));
|
149 |
setParameter(xml.getStringProperty("wcs.parameter"));
|
150 |
label = xml.getStringProperty("wcs.label");
|
151 |
setCoverageName(xml.getStringProperty("wcs.coverageName"));
|
152 |
if (xml.contains("wcs.maxRes")) |
153 |
setMaxResolution(new Point2D.Double(xml.getDoubleProperty("wcs.maxRes"), xml.getDoubleProperty("wcs.maxRes"))); |
154 |
else if (xml.contains("wcs.maxResX") && xml.contains("wcs.maxResY")) |
155 |
setMaxResolution(new Point2D.Double(xml.getDoubleProperty("wcs.maxResX"), xml.getDoubleProperty("wcs.maxResY"))); |
156 |
|
157 |
|
158 |
String claseStr = null; |
159 |
if (xml.contains("raster.class")) { |
160 |
claseStr = xml.getStringProperty("raster.class");
|
161 |
} |
162 |
if(status!=null) |
163 |
status.setXMLEntity(xml, this);
|
164 |
else{
|
165 |
|
166 |
//Cuando cargamos un proyecto
|
167 |
|
168 |
if(claseStr!=null && !claseStr.equals("")){ |
169 |
try{
|
170 |
Class clase = Class.forName(claseStr); |
171 |
Constructor constr = clase.getConstructor(null); |
172 |
status = (StatusRasterInterface)constr.newInstance(null);
|
173 |
if(status!=null) |
174 |
status.setXMLEntity(xml, this);
|
175 |
}catch(ClassNotFoundException exc){ |
176 |
exc.printStackTrace(); |
177 |
}catch(InstantiationException exc){ |
178 |
exc.printStackTrace(); |
179 |
}catch(IllegalAccessException exc){ |
180 |
exc.printStackTrace(); |
181 |
}catch(NoSuchMethodException exc){ |
182 |
exc.printStackTrace(); |
183 |
}catch(InvocationTargetException exc){ |
184 |
exc.printStackTrace(); |
185 |
} |
186 |
} |
187 |
} |
188 |
wcs.firstLoad = true;
|
189 |
} |
190 |
|
191 |
/**
|
192 |
* The full extent of the layer.
|
193 |
*
|
194 |
* La extensi?n completa de la layer.
|
195 |
*
|
196 |
* @return Rectangle2D
|
197 |
*/
|
198 |
public Rectangle2D getFullExtent(){// throws DriverException { |
199 |
try {
|
200 |
return getWCSAdaptor().getFullExtent();
|
201 |
} catch (IOException e) { |
202 |
JOptionPane.showMessageDialog((Component)PluginServices.getMainFrame(), |
203 |
"error_comunicacion_servidor", "Error", JOptionPane.ERROR_MESSAGE); |
204 |
} catch (DriverException e) {
|
205 |
JOptionPane.showMessageDialog((Component)PluginServices.getMainFrame(), |
206 |
"servidor_wcs_no_responde", "Error", JOptionPane.ERROR_MESSAGE); |
207 |
} |
208 |
return null; |
209 |
} |
210 |
|
211 |
/**
|
212 |
* Draws the layer on the ViewPort using PxRaster.
|
213 |
*
|
214 |
* Dibuja la capa en el ViewPort con PxRaster.
|
215 |
*/
|
216 |
public void draw(BufferedImage image, Graphics2D g, |
217 |
ViewPort viewPort, Cancellable cancel, double scale) throws DriverException { |
218 |
/* This try loop I've moved here is for show an alert window when it is not
|
219 |
* possible to download the coverage.
|
220 |
*/
|
221 |
try {
|
222 |
if (!isWithinScale(scale))
|
223 |
return;
|
224 |
|
225 |
if(status!=null && wcs.firstLoad){ |
226 |
wcs.draw(image, g, viewPort, cancel); |
227 |
status.applyStatus(this);
|
228 |
wcs.firstLoad = false;
|
229 |
} |
230 |
|
231 |
wcs.draw(image, g, viewPort, cancel); |
232 |
} catch (ServerErrorResponseException e) {
|
233 |
JOptionPane.showMessageDialog((Component)PluginServices.getMainFrame(), e.getMessage(), "Error", |
234 |
JOptionPane.ERROR_MESSAGE);
|
235 |
} |
236 |
} |
237 |
/**
|
238 |
* Prints the layer.
|
239 |
*
|
240 |
* Imprime la cobertura.
|
241 |
*/
|
242 |
public void print(Graphics2D g, ViewPort viewPort, Cancellable cancel, double scale) |
243 |
throws DriverException {
|
244 |
draw(null, g, viewPort, cancel, scale);
|
245 |
} |
246 |
|
247 |
/**
|
248 |
* Sets the layer's label. That what is going to be used at the TOC.
|
249 |
*
|
250 |
* Establece la etiqueta de la cobertura. La que se usar? en el TOC.
|
251 |
*
|
252 |
* @param lbl
|
253 |
*/
|
254 |
public void setLabel(String lbl) { |
255 |
label = lbl; |
256 |
} |
257 |
|
258 |
/**
|
259 |
* Sets the layer's full extent.
|
260 |
*
|
261 |
* Establece la extensi?n m?xima de la capa.
|
262 |
*
|
263 |
* @param rect
|
264 |
*/
|
265 |
public void setFullExtent(Rectangle2D rect) { |
266 |
wcs.setFullExtent(rect); |
267 |
} |
268 |
|
269 |
/**
|
270 |
* Recovers the name of the layer shown on the TOC. The text used for the name
|
271 |
* is not the actual coverage's name but that what appears in the wizard's text
|
272 |
* field which initially correponds with the "label" specified by the server for
|
273 |
* the coverage and may be edited by the user for choose whatever she/he wants.
|
274 |
*
|
275 |
* Recupera el nom de la capa mostrada al TOC. El text per al nom no ?s el
|
276 |
* nom de la cobertura sin? el text que apareix al camp de text del wizard,
|
277 |
* que es correspon amb la "label" que el servidor especifica per a la
|
278 |
* covertura, i pot ser modificat per l'usuari al wizard per a gastar el que
|
279 |
* dessitge.
|
280 |
*
|
281 |
* @return String
|
282 |
*/
|
283 |
public String getLabel() { |
284 |
return this.label; |
285 |
} |
286 |
|
287 |
// /**
|
288 |
// * Sets TabbedPane shown when WCS_Properties is clicked within the TOC.
|
289 |
// *
|
290 |
// * Establece el TabbedPane mostrado cuando se clica en WCS_Properties dentro del TOC.
|
291 |
// *
|
292 |
// * @param panel
|
293 |
// */
|
294 |
// public void setToc(WCSParamsPanel panel) {
|
295 |
// toc = panel;
|
296 |
// }
|
297 |
|
298 |
public Hashtable getWCSProperties(){ |
299 |
Hashtable info = new Hashtable(); |
300 |
info.put("name", getCoverageName());
|
301 |
info.put("host", getHost());
|
302 |
info.put("crs", wcs.getSRS());
|
303 |
info.put("format", wcs.getFormat());
|
304 |
String str = wcs.getTime();
|
305 |
if (str==null) |
306 |
str = "";
|
307 |
info.put("time", str);
|
308 |
str = wcs.getParameter(); |
309 |
if (str==null) |
310 |
str = "";
|
311 |
info.put("parameter", str);
|
312 |
|
313 |
return info;
|
314 |
} |
315 |
|
316 |
|
317 |
/**
|
318 |
* Returns the coverage name.
|
319 |
*
|
320 |
* Obtiene el nombre de la cobertura.
|
321 |
* @return String
|
322 |
*/
|
323 |
public String getCoverageName() { |
324 |
return wcs.getCoverageName();
|
325 |
} |
326 |
|
327 |
/**
|
328 |
* Returns the coverage format.
|
329 |
*
|
330 |
* Obtiene el formato en que la cobertura est? codificado.
|
331 |
* @return String
|
332 |
*/
|
333 |
public String getFormat() { |
334 |
return wcs.getFormat();
|
335 |
} |
336 |
|
337 |
/**
|
338 |
* Returns the WCS server URL.
|
339 |
*
|
340 |
* Obtiene la direcci?n URL del servidor WCS
|
341 |
*
|
342 |
* @return String
|
343 |
*/
|
344 |
public String getHost() { |
345 |
return wcs.getHost();
|
346 |
} |
347 |
|
348 |
/**
|
349 |
* Returns the parameter value.
|
350 |
*
|
351 |
* Obtiene el valor del par?metro.
|
352 |
* @return String
|
353 |
*/
|
354 |
public String getParameter() { |
355 |
return wcs.getParameter();
|
356 |
} |
357 |
|
358 |
/**
|
359 |
* Returns the current SRS.
|
360 |
*
|
361 |
* Obtiene el SRS actual de la cobertura.
|
362 |
* @return String
|
363 |
*/
|
364 |
public String getSRS() { |
365 |
return wcs.getSRS();
|
366 |
} |
367 |
|
368 |
/**
|
369 |
* Returns the TIME value in the WCS query.
|
370 |
*
|
371 |
* Obtiene el valor para TIME en la consulta WCS.
|
372 |
* @return String
|
373 |
*/
|
374 |
public String getTime() { |
375 |
return wcs.getTime();
|
376 |
} |
377 |
|
378 |
/**
|
379 |
* Sets the FORMAT parameter that we are requesting the WCS coverage.
|
380 |
*
|
381 |
* Establece el par?metro FORMAT en que se pide la cobertura WCS
|
382 |
* @param format
|
383 |
*/
|
384 |
public void setFormat(String format) { |
385 |
wcs.setFormat(format); |
386 |
} |
387 |
|
388 |
/**
|
389 |
* Sets the server's URL.
|
390 |
*
|
391 |
* Establece la direcci?n URL del servidor WCS
|
392 |
* @param host
|
393 |
*/
|
394 |
public void setHost(String host) { |
395 |
if (wcs == null) { |
396 |
wcs = new FMapWCSAdapter();
|
397 |
wcs.setDriver(new FMapWCSDriver());
|
398 |
} |
399 |
wcs.setHost(host); |
400 |
} |
401 |
|
402 |
/**
|
403 |
* Sets the parameter. It is defined by a name-value pair and the value is
|
404 |
* a comma-separated list of values.
|
405 |
*
|
406 |
* Establece el nombre y el valor (lista de valores separados por comas)
|
407 |
* del par?metro de la consulta WCS
|
408 |
* @param parameter
|
409 |
*/
|
410 |
public void setParameter(String parameter) { |
411 |
wcs.setParameter(parameter); |
412 |
} |
413 |
|
414 |
/**
|
415 |
* Sets the SRS parameter within the WCS query.
|
416 |
*
|
417 |
* Establece el SRS de la consulta WCS.
|
418 |
* @param srs
|
419 |
*/
|
420 |
public void setSRS(String srs) { |
421 |
wcs.setSRS(srs); |
422 |
} |
423 |
|
424 |
/**
|
425 |
* Sets the TIME parameter within the WCS query.
|
426 |
*
|
427 |
* Establece el par?metro TIME de la consulta WCS.
|
428 |
* @param time
|
429 |
*/
|
430 |
public void setTime(String time) { |
431 |
wcs.setTime(time); |
432 |
} |
433 |
|
434 |
/**
|
435 |
* Sets the COVERAGE parameter within the WCS query.
|
436 |
*
|
437 |
* Establece el par?metro COVERAGE de la consulta WCS.
|
438 |
* @param coverageName
|
439 |
*/
|
440 |
public void setCoverageName(String coverageName) { |
441 |
wcs.setCoverageName(coverageName); |
442 |
} |
443 |
|
444 |
/**
|
445 |
* Gets the max resolution allowed by the coverage. Requesting a higher resolution
|
446 |
* than this value does not cause any error, but the info responsed is just an
|
447 |
* interpolation.
|
448 |
*
|
449 |
* In exchange for obtaining a greater file and without additional information,
|
450 |
* we can easily connect it at the View.
|
451 |
*
|
452 |
*
|
453 |
* Obtiene la resoluci?n m?xima soportada por la cobertura. La petici?n
|
454 |
* de una resoluci?n superior a la soportada no provoca ning?n error, aunque
|
455 |
* la informaci?n obtenida s?lo es una mera interpolaci?n de informaci?n.
|
456 |
*
|
457 |
* A cambio de obtener un archivo mayor y sin informaci?n adicional, podemos
|
458 |
* f?cilmente acoplarlo a la vista.
|
459 |
*
|
460 |
* @return double
|
461 |
*/
|
462 |
public Point2D getMaxResolution() { |
463 |
return wcs.getMaxResolution();
|
464 |
} |
465 |
|
466 |
/**
|
467 |
* Sets the MAX resolution supported by the coverage.
|
468 |
*
|
469 |
* The max resolution is given by the server within the DescribeCoverage document
|
470 |
* in the SpationDomain section.
|
471 |
*
|
472 |
* Use this method only to load this value from there (the DescribeCoverage document)
|
473 |
* of from an already saved project because an incorrect value will bring
|
474 |
* computing errors when doing "zoom to raster resolution".
|
475 |
*
|
476 |
*
|
477 |
*
|
478 |
* Establece la resoluci?n M?XIMA que soporta la cobertura.
|
479 |
*
|
480 |
* La resoluci?n m?xima viene fijada por el servidor dentro documento
|
481 |
* DescribeCoverage en la secci?n SpatialDomain.
|
482 |
*
|
483 |
* Use este m?todo ?nicamente para cargar el valor para la resoluci?n m?xima
|
484 |
* desde all? o desde un proyecto guardado en anterioridad, puesto que un
|
485 |
* valor incorrecto reportar? (conllevar?) errores de c?lculo cuando se haga
|
486 |
* un "zoom a la resoluci?n del r?ster".
|
487 |
*
|
488 |
* @param res
|
489 |
*/
|
490 |
//public void setMaxResolution(double res){
|
491 |
public void setMaxResolution(Point2D res){ |
492 |
wcs.setMaxResolution(res); |
493 |
} |
494 |
|
495 |
/**
|
496 |
* Returns the adaptor.
|
497 |
*
|
498 |
* Obtiene el adaptor.
|
499 |
*/
|
500 |
public FMapWCSAdapter getWCSAdaptor(){
|
501 |
return wcs;
|
502 |
} |
503 |
|
504 |
/**
|
505 |
* Sets the adaptor.
|
506 |
*
|
507 |
* Establece el adaptador.
|
508 |
*
|
509 |
* @deprecated
|
510 |
* @param wcs
|
511 |
*/
|
512 |
public void setWCSAdaptor(FMapWCSAdapter wcs){ |
513 |
this.wcs = wcs;
|
514 |
} |
515 |
|
516 |
/**
|
517 |
* Returns the bounding box that is being used.
|
518 |
*
|
519 |
* Obtiene la Bounding Box sobre la que se est? operando
|
520 |
* @return Rectangle2D
|
521 |
*/
|
522 |
private Rectangle2D getBbox() { |
523 |
return wcs.getBbox();
|
524 |
} |
525 |
|
526 |
/**
|
527 |
* Returns the current resolution for the coverage at the view.
|
528 |
*
|
529 |
* Obtiene la resoluci?n actual para la cobertura de la vista.
|
530 |
* @return
|
531 |
*/
|
532 |
private Point2D getRes() { |
533 |
return wcs.getRes();
|
534 |
} |
535 |
|
536 |
/**
|
537 |
* Sets the current resolution for the coverage at the view.
|
538 |
* This value is automatically calculated by gvSIG. Thus, this method should
|
539 |
* be used only to reload this value from a previously saved project.
|
540 |
*
|
541 |
* Establece la resoluci?n actual para la cobertura de la vista.
|
542 |
* Este valor es calculado autom?ticamente por gvSIG. ?ste m?todo deber?a
|
543 |
* ser usado ?nicamente para recuperar este valor de un proyecto
|
544 |
* anteriormente guardado.
|
545 |
* @param res
|
546 |
*/
|
547 |
//private void setRes(double res) {
|
548 |
private void setRes(Point2D res) { |
549 |
wcs.setRes(res); |
550 |
} |
551 |
|
552 |
/**
|
553 |
* Sets the area of the coverage to request.
|
554 |
* This value is automatically calculated by gvSIG. Thus, this method should
|
555 |
* be used only to reload this value from a previuosly saved project.
|
556 |
*
|
557 |
* Establece el ?rea de la cobertura a pedir.
|
558 |
* Este valor es calculado autom?ticamente por gvSIG. ?ste m?todo deber?a
|
559 |
* ser usado ?nicamente para recuperar el valor de un proyecto anteriormente
|
560 |
* guardado.
|
561 |
*
|
562 |
* @param rect
|
563 |
*/
|
564 |
private void setBBox(Rectangle2D rect) { |
565 |
wcs.setBBox(rect); |
566 |
} |
567 |
|
568 |
/**
|
569 |
* Builds a coverage starting from a full GetCoverage URL.
|
570 |
* (Using this is not a regular function)
|
571 |
*
|
572 |
* Inicializa una cobertura a partir de una URL GetCoverage completa.
|
573 |
* (To use this method supposes to skip all the regular operation)
|
574 |
*
|
575 |
*/
|
576 |
public void initFromQueryString(String queryString){ |
577 |
System.out.println("Query = "+queryString); |
578 |
TreeMap map = new TreeMap(); |
579 |
String[] params = queryString.split("&"); |
580 |
for (int i = 0; i < params.length; i++) { |
581 |
String[] nameValue = params[i].split("="); |
582 |
map.put(nameValue[0].toUpperCase(), nameValue[1]); |
583 |
} |
584 |
try {
|
585 |
String coverageName = (String) map.get((String) "COVERAGE"); |
586 |
String crs = (String) map.get((String) "CRS"); |
587 |
String format = (String) map.get((String) "FORMAT"); |
588 |
String time = (String) map.get((String) "TIME"); |
589 |
String bands = (String) map.get((String) "BANDS"); |
590 |
|
591 |
setSRS(crs); |
592 |
setCoverageName(coverageName); |
593 |
if (time != null) |
594 |
setTime("TIME="+time);
|
595 |
OGCWCSService service = (OGCWCSService) wcs.getDriver(); |
596 |
service.connect(); |
597 |
|
598 |
setLabel( service.getLabel(coverageName) ); |
599 |
setName( getLabel() ); |
600 |
setFullExtent ( service.getFullExtent(coverageName, crs) ); |
601 |
setFormat( format ); |
602 |
setParameter( "BANDS="+bands );
|
603 |
setMaxResolution ( service.getMaxResolution(coverageName) ); |
604 |
|
605 |
} catch (IOException e) { |
606 |
e.printStackTrace(); |
607 |
} catch (DriverException e) {
|
608 |
e.printStackTrace(); |
609 |
} |
610 |
} |
611 |
|
612 |
/**
|
613 |
* Asignar el estado del raster
|
614 |
* @param status
|
615 |
*/
|
616 |
public void setStatus(StatusRasterInterface status){ |
617 |
this.status = status;
|
618 |
} |
619 |
|
620 |
/**
|
621 |
* Obtiene el estado del raster
|
622 |
* @return
|
623 |
*/
|
624 |
public StatusRasterInterface getStatus(){
|
625 |
return this.status; |
626 |
} |
627 |
|
628 |
/**
|
629 |
* Builds a coverage starting from a full GetCoverage URL.
|
630 |
* (Using this is not a regular function)
|
631 |
*
|
632 |
* Inicializa una cobertura a partir de una URL GetCoverage completa.
|
633 |
* (Usar este m?todo supone saltarse todo el funcionamiento normal)
|
634 |
*
|
635 |
* TODO Por completar y probar
|
636 |
* @param queryString
|
637 |
*/
|
638 |
public void initFromQueryString2(String queryString){ |
639 |
|
640 |
String host = queryString.substring(0, queryString.indexOf('?')); |
641 |
String[] params = queryString.substring(queryString.indexOf('?')+1, queryString.length()).split("="); |
642 |
setHost(host); |
643 |
for (int i = 0; i < params.length; i++) { |
644 |
String[] par_nombreValor = params[i].split("="); |
645 |
String nombre = par_nombreValor[0].toUpperCase(); |
646 |
String valor = par_nombreValor[1]; |
647 |
if (nombre.equals("COVERAGE")) setCoverageName(valor); |
648 |
else if (nombre.equals("TIME")) setTime(valor); |
649 |
else if (nombre.equals("FORMAT")) setFormat(valor); |
650 |
else if (nombre.equals("CRS")) setSRS(valor); |
651 |
else if (nombre.equals("EXCEPTIONS")) continue; |
652 |
else if (nombre.equals("RESX")) continue; |
653 |
else if (nombre.equals("RESY")) continue; |
654 |
else if (nombre.equals("RESZ")) continue; |
655 |
else if (nombre.equals("WIDTH")) continue; |
656 |
else if (nombre.equals("HEIGHT")) continue; |
657 |
else if (nombre.equals("DEPTH")) continue; |
658 |
else if (nombre.equals("BBOX")) continue; |
659 |
else if (nombre.equals("RESPONSE_CRS")) continue; |
660 |
else setParameter(nombre+"="+valor); |
661 |
} |
662 |
OGCWCSService service = (OGCWCSService) wcs.getDriver(); |
663 |
try {
|
664 |
service.connect(); |
665 |
String coverageName = getCoverageName();
|
666 |
setLabel( service.getLabel(coverageName) ); |
667 |
setName( getLabel() ); |
668 |
setFullExtent ( service.getFullExtent(coverageName, getSRS()) ); |
669 |
setMaxResolution ( service.getMaxResolution(coverageName) ); |
670 |
} catch (IOException e) { |
671 |
e.printStackTrace(); |
672 |
} catch (DriverException e) {
|
673 |
e.printStackTrace(); |
674 |
} |
675 |
|
676 |
} |
677 |
|
678 |
/**
|
679 |
* Devuelve la pila de filtros aplicada sobre la capa raster.
|
680 |
*
|
681 |
* @return RasterFilterStack.
|
682 |
*/
|
683 |
public RasterFilterStack getFilterStack() {
|
684 |
return wcs.getFilterStack();
|
685 |
} |
686 |
|
687 |
/**
|
688 |
* Asigna la pila de filtros aplicada al raster
|
689 |
* @return
|
690 |
*/
|
691 |
public void setFilterStack(RasterFilterStack stack){ |
692 |
wcs.setFilterStack(stack); |
693 |
} |
694 |
|
695 |
/* (non-Javadoc)
|
696 |
* @see com.iver.cit.gvsig.fmap.layers.FLyrDefault#setTransparency(int)
|
697 |
*/
|
698 |
public void setTransparency(int trans) { |
699 |
wcs.setTransparency(trans); |
700 |
} |
701 |
|
702 |
/* (non-Javadoc)
|
703 |
* @see com.iver.cit.gvsig.fmap.layers.RasterOperations#setBand(int, int)
|
704 |
*/
|
705 |
public void setBand(int flag, int nBand) { |
706 |
switch(flag){
|
707 |
case GeoRasterFile.RED_BAND:wcs.setBandR(nBand);break; |
708 |
case GeoRasterFile.GREEN_BAND:wcs.setBandG(nBand);break; |
709 |
case GeoRasterFile.BLUE_BAND:wcs.setBandB(nBand);break; |
710 |
} |
711 |
} |
712 |
|
713 |
/* (non-Javadoc)
|
714 |
* @see com.iver.cit.gvsig.fmap.layers.RasterOperations#getAttributes()
|
715 |
*/
|
716 |
public ArrayList getAttributes() { |
717 |
return wcs.getAttributes();
|
718 |
} |
719 |
/* (non-Javadoc)
|
720 |
* @see com.iver.cit.gvsig.fmap.layers.RasterOperations#getHeight()
|
721 |
*/
|
722 |
public double getHeight() { |
723 |
if(wcs.getGeoRasterFile() != null) |
724 |
return wcs.getGeoRasterFile().getHeight();
|
725 |
else
|
726 |
return 0; |
727 |
} |
728 |
/* (non-Javadoc)
|
729 |
* @see com.iver.cit.gvsig.fmap.layers.RasterOperations#getMaxX()
|
730 |
*/
|
731 |
public double getMaxX() { |
732 |
if(wcs.getPxRaster() != null) |
733 |
return wcs.getPxRaster().getExtent().getMax().getX();
|
734 |
else
|
735 |
return 0; |
736 |
} |
737 |
/* (non-Javadoc)
|
738 |
* @see com.iver.cit.gvsig.fmap.layers.RasterOperations#getMaxY()
|
739 |
*/
|
740 |
public double getMaxY() { |
741 |
if(wcs.getPxRaster() != null) |
742 |
return wcs.getPxRaster().getExtent().getMax().getY();
|
743 |
else
|
744 |
return 0; |
745 |
} |
746 |
/* (non-Javadoc)
|
747 |
* @see com.iver.cit.gvsig.fmap.layers.RasterOperations#getMinX()
|
748 |
*/
|
749 |
public double getMinX() { |
750 |
if(wcs.getPxRaster() != null) |
751 |
return wcs.getPxRaster().getExtent().getMin().getX();
|
752 |
else
|
753 |
return 0; |
754 |
} |
755 |
/* (non-Javadoc)
|
756 |
* @see com.iver.cit.gvsig.fmap.layers.RasterOperations#getMinY()
|
757 |
*/
|
758 |
public double getMinY() { |
759 |
if(wcs.getPxRaster() != null) |
760 |
return wcs.getPxRaster().getExtent().getMin().getY();
|
761 |
else
|
762 |
return 0; |
763 |
} |
764 |
/* (non-Javadoc)
|
765 |
* @see com.iver.cit.gvsig.fmap.layers.RasterOperations#getPixel(double, double)
|
766 |
*/
|
767 |
public int[] getPixel(double wcx, double wcy) { |
768 |
if(wcs.getPxRaster() != null) |
769 |
return wcs.getPxRaster().getPixel(wcx, wcy);
|
770 |
else
|
771 |
return null; |
772 |
} |
773 |
/* (non-Javadoc)
|
774 |
* @see com.iver.cit.gvsig.fmap.layers.RasterOperations#getSource()
|
775 |
*/
|
776 |
public RasterAdapter getSource() {
|
777 |
// TODO Auto-generated method stub
|
778 |
return null; |
779 |
} |
780 |
/* (non-Javadoc)
|
781 |
* @see com.iver.cit.gvsig.fmap.layers.RasterOperations#getWidth()
|
782 |
*/
|
783 |
public double getWidth() { |
784 |
if(wcs.getGeoRasterFile() != null) |
785 |
return wcs.getGeoRasterFile().getWidth();
|
786 |
else
|
787 |
return 0; |
788 |
} |
789 |
/* (non-Javadoc)
|
790 |
* @see com.iver.cit.gvsig.fmap.layers.RasterOperations#setPos(int, int)
|
791 |
*/
|
792 |
public void setPos(int x, int y) { |
793 |
this.posX = x;
|
794 |
this.posY = y;
|
795 |
} |
796 |
/* (non-Javadoc)
|
797 |
* @see com.iver.cit.gvsig.fmap.layers.RasterOperations#setPosWC(double, double)
|
798 |
*/
|
799 |
public void setPosWC(double x, double y) { |
800 |
this.posXWC = x;
|
801 |
this.posYWC = y;
|
802 |
} |
803 |
/* (non-Javadoc)
|
804 |
* @see com.iver.cit.gvsig.fmap.layers.RasterOperations#setRGB(int, int, int)
|
805 |
*/
|
806 |
public void setRGB(int r, int g, int b) { |
807 |
this.r = r;
|
808 |
this.g = g;
|
809 |
this.b = b;
|
810 |
} |
811 |
/* (non-Javadoc)
|
812 |
* @see com.iver.cit.gvsig.fmap.layers.RasterOperations#setSource(com.iver.cit.gvsig.fmap.layers.RasterAdapter)
|
813 |
*/
|
814 |
public void setSource(RasterAdapter ra) { |
815 |
// TODO Auto-generated method stub
|
816 |
|
817 |
} |
818 |
/* (non-Javadoc)
|
819 |
* @see com.iver.cit.gvsig.fmap.layers.layerOperations.InfoByPoint#queryByPoint(java.awt.Point)
|
820 |
*/
|
821 |
public String queryByPoint(Point p) throws DriverException { |
822 |
String data = "<file:"+getName().replaceAll("[^a-zA-Z0-9]","")+">\n"; |
823 |
ArrayList attr = this.getAttributes(); |
824 |
data += " <raster\n";
|
825 |
data += " File=\""+getName()+"\"\n"; |
826 |
for (int i=0; i<attr.size(); i++) { |
827 |
Object [] a = (Object []) attr.get(i); |
828 |
|
829 |
data += " "+a[0].toString()+"="; |
830 |
if (a[1].toString() instanceof String) |
831 |
data += "\""+a[1].toString()+"\"\n"; |
832 |
else
|
833 |
data += a[1].toString()+"\n"; |
834 |
} |
835 |
data += " Point=\""+posX+" , "+posY+"\"\n"; |
836 |
data += " Point_WC=\""+posXWC+" , "+posYWC+"\"\n"; |
837 |
data += " RGB=\""+r+", "+g+", "+b+"\"\n"; |
838 |
data += " />\n";
|
839 |
|
840 |
data += "</file:"+getName().replaceAll("[^a-zA-Z0-9]","")+">\n"; |
841 |
System.out.println(data);
|
842 |
return data;
|
843 |
} |
844 |
} |