svn-gvsig-desktop / trunk / extensions / extWCS / src / com / iver / cit / gvsig / fmap / layers / FLyrWCS.java @ 5203
History | View | Annotate | Download (26.9 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.Dimension; |
45 |
import java.awt.Graphics2D; |
46 |
import java.awt.Point; |
47 |
import java.awt.Rectangle; |
48 |
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 |
import java.awt.image.DataBuffer; |
54 |
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.Hashtable; |
62 |
import java.util.Map; |
63 |
|
64 |
import javax.swing.JOptionPane; |
65 |
|
66 |
import org.cresques.geo.ViewPortData; |
67 |
import org.cresques.io.GdalFile; |
68 |
import org.cresques.io.GeoRasterFile; |
69 |
import org.cresques.io.raster.RasterFilterStack; |
70 |
import org.cresques.io.raster.RasterFilterStackManager; |
71 |
import org.cresques.px.Extent; |
72 |
import org.cresques.px.PxRaster; |
73 |
import org.exolab.castor.xml.ValidationException; |
74 |
import org.gvsig.remoteClient.wcs.WCSStatus; |
75 |
|
76 |
import com.iver.andami.PluginServices; |
77 |
import com.iver.cit.gvsig.fmap.DriverException; |
78 |
import com.iver.cit.gvsig.fmap.ViewPort; |
79 |
import com.iver.cit.gvsig.fmap.drivers.DriverIOException; |
80 |
import com.iver.cit.gvsig.fmap.drivers.UnsupportedVersionException; |
81 |
import com.iver.cit.gvsig.fmap.drivers.WCSException; |
82 |
import com.iver.cit.gvsig.fmap.drivers.wcs.FMapWCSDriver; |
83 |
import com.iver.cit.gvsig.fmap.layers.layerOperations.InfoByPoint; |
84 |
import com.iver.cit.gvsig.fmap.layers.layerOperations.StringXMLItem; |
85 |
import com.iver.cit.gvsig.fmap.layers.layerOperations.XMLItem; |
86 |
import com.iver.cit.gvsig.fmap.operations.Cancellable; |
87 |
import com.iver.utiles.StringUtilities; |
88 |
import com.iver.utiles.XMLEntity; |
89 |
|
90 |
|
91 |
/**
|
92 |
* Class for the WCS layer.
|
93 |
*
|
94 |
* Capa para el WCS.
|
95 |
*
|
96 |
* @author jaume - jaume.dominguez@iver.es
|
97 |
*/
|
98 |
public class FLyrWCS extends FLyrDefault implements RasterOperations, InfoByPoint{ |
99 |
private FMapWCSDriver wcs = null; |
100 |
|
101 |
private URL host; |
102 |
private String coverageName; |
103 |
private Rectangle2D fullExtent; |
104 |
private String format; |
105 |
private String srs; |
106 |
private String time; |
107 |
private String parameter; |
108 |
private Point2D maxRes; |
109 |
private Hashtable onlineResources = new Hashtable(); |
110 |
|
111 |
private WCSStatus wcsStatus = new WCSStatus(); |
112 |
|
113 |
private StatusRasterInterface status = null; |
114 |
private int posX = 0, posY = 0; |
115 |
private double posXWC = 0, posYWC = 0; |
116 |
private int r = 0, g = 0, b = 0; |
117 |
private RasterFilterStackManager stackManager = null; |
118 |
private PxRaster raster = null; |
119 |
private GeoRasterFile rasterFile = null; |
120 |
private RasterFilterStack filterStack;
|
121 |
private boolean firstLoad = false; |
122 |
private int transparency = -1; |
123 |
private int rband, gband, bband; |
124 |
private VisualStatus visualStatus = new VisualStatus(); |
125 |
|
126 |
private int maxTilePrintWidth = 80000; |
127 |
private int maxTilePrintHeight = 80000; |
128 |
|
129 |
private FMapWCSDriver driver;
|
130 |
|
131 |
public FLyrWCS(){
|
132 |
super();
|
133 |
} |
134 |
|
135 |
public FLyrWCS(Map args) throws DriverIOException{ |
136 |
FMapWCSDriver drv = null;
|
137 |
String host = (String)args.get("HOST"); |
138 |
String sCoverage = (String) args.get((String) "COVERAGE"); |
139 |
|
140 |
try {
|
141 |
this.setHost(new URL(host)); |
142 |
} catch (MalformedURLException e) { |
143 |
//e.printStackTrace();
|
144 |
throw new DriverIOException("Malformed host URL, '" + host + "' (" + e.toString() + ")."); |
145 |
} |
146 |
try {
|
147 |
drv = this.getDriver();
|
148 |
} catch (Exception e) { |
149 |
// e.printStackTrace();
|
150 |
throw new DriverIOException("Can't get driver to host '" + host + "' (" + e.toString() + ")."); |
151 |
} |
152 |
|
153 |
try{
|
154 |
if (!drv.connect()){
|
155 |
throw new DriverIOException("Can't connect to host '" + host + "'."); |
156 |
} |
157 |
}catch(Exception e){ |
158 |
throw new DriverIOException("Can't connect to host '" + host + "'."); |
159 |
} |
160 |
|
161 |
WCSLayer wcsNode = drv.getLayer(sCoverage); |
162 |
|
163 |
if (wcsNode == null){ |
164 |
throw new DriverIOException("The server '" + host + "' doesn't has the coverage '" + sCoverage + "'."); |
165 |
} |
166 |
|
167 |
try{
|
168 |
this.setFullExtent(drv.getFullExtent(sCoverage,
|
169 |
(String) args.get((String) "CRS"))); |
170 |
this.setFormat((String) args.get((String) "FORMAT")); |
171 |
this.setParameter("BANDS=" + (String) args.get((String) "BANDS")); |
172 |
this.setSRS((String) args.get((String) "CRS")); |
173 |
this.setName(sCoverage);
|
174 |
this.setCoverageName(sCoverage);
|
175 |
}catch (Exception e){ |
176 |
throw new DriverIOException("The server '" + host + "' is not able to load the coverage '" + sCoverage + "'."); |
177 |
} |
178 |
|
179 |
} |
180 |
|
181 |
/**
|
182 |
* Clase que contiene los datos de visualizaci?n de WMS.
|
183 |
* @author Nacho Brodin (brodin_ign@gva.es)
|
184 |
*/
|
185 |
private class VisualStatus { |
186 |
/**
|
187 |
* Ancho y alto de la imagen o del conjunto de tiles si los tiene. Coincide con
|
188 |
* el ancho y alto del viewPort
|
189 |
*/
|
190 |
private int width = 0, height = 0; |
191 |
private double minX = 0D, minY = 0D, maxX = 0D, maxY = 0D; |
192 |
private int bandCount = 0; |
193 |
private int dataType = DataBuffer.TYPE_UNDEFINED; |
194 |
} |
195 |
|
196 |
/*
|
197 |
* (non-Javadoc)
|
198 |
* @see com.iver.cit.gvsig.fmap.layers.RasterOperations#setRGB(int, int, int)
|
199 |
*/
|
200 |
public void setRGB(int r, int g, int b) { |
201 |
this.r = r;
|
202 |
this.g = g;
|
203 |
this.b = b;
|
204 |
} |
205 |
|
206 |
/*
|
207 |
* (non-Javadoc)
|
208 |
* @see com.iver.cit.gvsig.fmap.layers.RasterOperations#getFilterStack()
|
209 |
*/
|
210 |
public RasterFilterStack getFilterStack() {
|
211 |
if(raster!=null) |
212 |
return raster.filterStack;
|
213 |
return null; |
214 |
} |
215 |
|
216 |
/*
|
217 |
* (non-Javadoc)
|
218 |
* @see com.iver.cit.gvsig.fmap.layers.RasterOperations#setFilterStack(org.cresques.io.raster.RasterFilterStack)
|
219 |
*/
|
220 |
public void setFilterStack(RasterFilterStack stack) { |
221 |
this.filterStack = stack;
|
222 |
} |
223 |
|
224 |
/*
|
225 |
* (non-Javadoc)
|
226 |
* @see com.iver.cit.gvsig.fmap.layers.RasterOperations#getSource()
|
227 |
*/
|
228 |
public RasterAdapter getSource() {
|
229 |
return null; |
230 |
} |
231 |
|
232 |
/*
|
233 |
* (non-Javadoc)
|
234 |
* @see com.iver.cit.gvsig.fmap.layers.RasterOperations#setSource(com.iver.cit.gvsig.fmap.layers.RasterAdapter)
|
235 |
*/
|
236 |
public void setSource(RasterAdapter ra) { |
237 |
} |
238 |
|
239 |
/*
|
240 |
* (non-Javadoc)
|
241 |
* @see com.iver.cit.gvsig.fmap.layers.RasterOperations#setPos(int, int)
|
242 |
*/
|
243 |
public void setPos(int x, int y) { |
244 |
this.posX = x;
|
245 |
this.posY = y;
|
246 |
} |
247 |
|
248 |
/*
|
249 |
* (non-Javadoc)
|
250 |
* @see com.iver.cit.gvsig.fmap.layers.RasterOperations#setPosWC(double, double)
|
251 |
*/
|
252 |
public void setPosWC(double x, double y) { |
253 |
this.posXWC = x;
|
254 |
this.posYWC = y;
|
255 |
} |
256 |
|
257 |
/*
|
258 |
* (non-Javadoc)
|
259 |
* @see com.iver.cit.gvsig.fmap.layers.RasterOperations#getPixel(double, double)
|
260 |
*/
|
261 |
public int[] getPixel(double wcx, double wcy) { |
262 |
if(getPxRaster() != null) |
263 |
return getPxRaster().getPixel(wcx, wcy);
|
264 |
return null; |
265 |
} |
266 |
|
267 |
/*
|
268 |
* (non-Javadoc)
|
269 |
* @see com.iver.cit.gvsig.fmap.layers.RasterOperations#setBand(int, int)
|
270 |
*/
|
271 |
public void setBand(int flag, int nBand) { |
272 |
switch(flag){
|
273 |
case GeoRasterFile.RED_BAND:setBandR(nBand);break; |
274 |
case GeoRasterFile.GREEN_BAND:setBandG(nBand);break; |
275 |
case GeoRasterFile.BLUE_BAND:setBandB(nBand);break; |
276 |
} |
277 |
} |
278 |
|
279 |
/**
|
280 |
* Sets the R-band.
|
281 |
*
|
282 |
* Asigna la banda R.
|
283 |
* @param r
|
284 |
*/
|
285 |
public void setBandR(int r){ |
286 |
this.rband = r;
|
287 |
} |
288 |
|
289 |
/**
|
290 |
* Sets the G-band.
|
291 |
*
|
292 |
* Asigna la banda G
|
293 |
* @param g
|
294 |
*/
|
295 |
public void setBandG(int g){ |
296 |
this.gband = g;
|
297 |
} |
298 |
|
299 |
/**
|
300 |
* Sets the B-band.
|
301 |
*
|
302 |
* Asigna la banda B
|
303 |
* @param b
|
304 |
*/
|
305 |
public void setBandB(int b){ |
306 |
this.bband = b;
|
307 |
} |
308 |
|
309 |
/*
|
310 |
* (non-Javadoc)
|
311 |
* @see com.iver.cit.gvsig.fmap.layers.RasterOperations#getAttributes()
|
312 |
*/
|
313 |
public ArrayList getAttributes() { |
314 |
if (rasterFile != null){ |
315 |
ArrayList attr = new ArrayList(); |
316 |
String dataType = "Byte"; |
317 |
if (rasterFile.getDataType() == DataBuffer.TYPE_BYTE) dataType = "Byte"; |
318 |
else if (visualStatus.dataType == DataBuffer.TYPE_SHORT) |
319 |
dataType = "Short";
|
320 |
else if (visualStatus.dataType == DataBuffer.TYPE_USHORT) |
321 |
dataType = "Unsigned Short";
|
322 |
else if (visualStatus.dataType == DataBuffer.TYPE_INT) |
323 |
dataType = "Integer";
|
324 |
else if (visualStatus.dataType == DataBuffer.TYPE_FLOAT) |
325 |
dataType = "Float";
|
326 |
else if (visualStatus.dataType == DataBuffer.TYPE_DOUBLE) |
327 |
dataType = "Double";
|
328 |
else
|
329 |
dataType = "Unknown";
|
330 |
|
331 |
Object [][] a = { |
332 |
{"Filename",rasterFile.getName().substring(rasterFile.getName().lastIndexOf("/")+1, rasterFile.getName().length())}, |
333 |
{"Filesize",new Long(0)}, |
334 |
{"Width",new Integer((int)this.getWidth())}, |
335 |
{"Height", new Integer((int)this.getHeight())}, |
336 |
{"Bands", new Integer(visualStatus.bandCount)}, |
337 |
{"BandDataType", dataType}
|
338 |
}; |
339 |
for (int i=0; i<a.length; i++) |
340 |
attr.add(a[i]); |
341 |
|
342 |
return attr;
|
343 |
} |
344 |
return null; |
345 |
} |
346 |
|
347 |
/*
|
348 |
* (non-Javadoc)
|
349 |
* @see com.iver.cit.gvsig.fmap.layers.RasterOperations#getMaxX()
|
350 |
*/
|
351 |
public double getMaxX() { |
352 |
return visualStatus.maxX;
|
353 |
} |
354 |
|
355 |
/*
|
356 |
* (non-Javadoc)
|
357 |
* @see com.iver.cit.gvsig.fmap.layers.RasterOperations#getMaxY()
|
358 |
*/
|
359 |
public double getMaxY() { |
360 |
return visualStatus.maxY;
|
361 |
} |
362 |
|
363 |
/*
|
364 |
* (non-Javadoc)
|
365 |
* @see com.iver.cit.gvsig.fmap.layers.RasterOperations#getMinX()
|
366 |
*/
|
367 |
public double getMinX() { |
368 |
return visualStatus.minX;
|
369 |
} |
370 |
|
371 |
/*
|
372 |
* (non-Javadoc)
|
373 |
* @see com.iver.cit.gvsig.fmap.layers.RasterOperations#getMinY()
|
374 |
*/
|
375 |
public double getMinY() { |
376 |
return visualStatus.minY;
|
377 |
} |
378 |
|
379 |
/*
|
380 |
* (non-Javadoc)
|
381 |
* @see com.iver.cit.gvsig.fmap.layers.RasterOperations#getWidth()
|
382 |
*/
|
383 |
public double getWidth() { |
384 |
return visualStatus.width;
|
385 |
} |
386 |
|
387 |
/*
|
388 |
* (non-Javadoc)
|
389 |
* @see com.iver.cit.gvsig.fmap.layers.RasterOperations#getHeight()
|
390 |
*/
|
391 |
public double getHeight() { |
392 |
return visualStatus.height;
|
393 |
} |
394 |
|
395 |
/**
|
396 |
* @deprecated
|
397 |
* @see com.iver.cit.gvsig.fmap.layers.layerOperations.InfoByPoint#getInfo
|
398 |
*/
|
399 |
public String queryByPoint(Point p) throws DriverException { |
400 |
String data = "<file:"+getName().replaceAll("[^a-zA-Z0-9]","")+">\n"; |
401 |
ArrayList attr = this.getAttributes(); |
402 |
data += " <raster\n";
|
403 |
data += " File=\""+getName()+"\"\n"; |
404 |
for (int i=0; i<attr.size(); i++) { |
405 |
Object [] a = (Object []) attr.get(i); |
406 |
|
407 |
data += " "+a[0].toString()+"="; |
408 |
if (a[1].toString() instanceof String) |
409 |
data += "\""+a[1].toString()+"\"\n"; |
410 |
else
|
411 |
data += a[1].toString()+"\n"; |
412 |
} |
413 |
data += " Point=\""+posX+" , "+posY+"\"\n"; |
414 |
data += " Point_WC=\""+posXWC+" , "+posYWC+"\"\n"; |
415 |
data += " RGB=\""+r+", "+g+", "+b+"\"\n"; |
416 |
data += " />\n";
|
417 |
|
418 |
data += "</file:"+getName().replaceAll("[^a-zA-Z0-9]","")+">\n"; |
419 |
System.out.println(data);
|
420 |
return data;
|
421 |
} |
422 |
/**
|
423 |
* @see com.iver.cit.gvsig.fmap.layers.layerOperations.InfoByPoint#getInfo
|
424 |
*/
|
425 |
public XMLItem[] getInfo(Point point, double tolerance ) throws DriverException { |
426 |
String data = "<file:"+getName().replaceAll("[^a-zA-Z0-9]","")+">\n"; |
427 |
ArrayList attr = this.getAttributes(); |
428 |
data += " <raster\n";
|
429 |
data += " File=\""+getName()+"\"\n"; |
430 |
for (int i=0; i<attr.size(); i++) { |
431 |
Object [] a = (Object []) attr.get(i); |
432 |
|
433 |
data += " "+a[0].toString()+"="; |
434 |
if (a[1].toString() instanceof String) |
435 |
data += "\""+a[1].toString()+"\"\n"; |
436 |
else
|
437 |
data += a[1].toString()+"\n"; |
438 |
} |
439 |
data += " Point=\""+posX+" , "+posY+"\"\n"; |
440 |
data += " Point_WC=\""+posXWC+" , "+posYWC+"\"\n"; |
441 |
data += " RGB=\""+r+", "+g+", "+b+"\"\n"; |
442 |
data += " />\n";
|
443 |
|
444 |
data += "</file:"+getName().replaceAll("[^a-zA-Z0-9]","")+">\n"; |
445 |
System.out.println(data);
|
446 |
|
447 |
//return data;
|
448 |
XMLItem[] item = new XMLItem[1]; |
449 |
item[0]= new StringXMLItem(data, this); |
450 |
return item;
|
451 |
} |
452 |
|
453 |
/*
|
454 |
* (non-Javadoc)
|
455 |
* @see com.iver.cit.gvsig.fmap.layers.FLayer#getFullExtent()
|
456 |
*/
|
457 |
public Rectangle2D getFullExtent() { |
458 |
return fullExtent;
|
459 |
} |
460 |
|
461 |
/*
|
462 |
* (non-Javadoc)
|
463 |
* @see com.iver.cit.gvsig.fmap.layers.FLayer#draw(java.awt.image.BufferedImage, java.awt.Graphics2D, com.iver.cit.gvsig.fmap.ViewPort, com.iver.cit.gvsig.fmap.operations.Cancellable, double)
|
464 |
*/
|
465 |
public void draw(BufferedImage image, Graphics2D g, ViewPort viewPort, Cancellable cancel, double scale) throws DriverException { |
466 |
if (isWithinScale(scale)){
|
467 |
Point2D p = viewPort.getOffset();
|
468 |
// p will be (0, 0) when drawing a view or other when painting onto
|
469 |
// the Layout.
|
470 |
visualStatus.width = viewPort.getImageWidth(); |
471 |
visualStatus.height = viewPort.getImageHeight(); |
472 |
visualStatus.minX = viewPort.getAdjustedExtent().getMinX(); |
473 |
visualStatus.minY = viewPort.getAdjustedExtent().getMinY(); |
474 |
visualStatus.maxX = viewPort.getAdjustedExtent().getMaxX(); |
475 |
visualStatus.maxY = viewPort.getAdjustedExtent().getMaxY(); |
476 |
|
477 |
Rectangle r = new Rectangle((int) p.getX(), (int) p.getY(), viewPort.getImageWidth() - 1, viewPort.getImageHeight() - 1); |
478 |
Tiling tiles = new Tiling(maxTilePrintWidth, maxTilePrintHeight, r);
|
479 |
tiles.setAffineTransform((AffineTransform) viewPort.getAffineTransform().clone());
|
480 |
for (int tileNr=0; tileNr < tiles.getNumTiles(); tileNr++) { |
481 |
// drawing part
|
482 |
try {
|
483 |
ViewPort vp = tiles.getTileViewPort(viewPort, tileNr); |
484 |
drawTile(g, vp, cancel); |
485 |
} catch (NoninvertibleTransformException e) { |
486 |
e.printStackTrace(); |
487 |
} |
488 |
} |
489 |
} |
490 |
Runtime r = Runtime.getRuntime(); |
491 |
long mem = r.totalMemory() - r.freeMemory();
|
492 |
System.err.println("Memoria total: " + (mem / 1024) +"KB"); |
493 |
} |
494 |
|
495 |
/**
|
496 |
* This is the method used to draw a tile in a WMS mosaic layer.
|
497 |
*/
|
498 |
private void drawTile(Graphics2D g, ViewPort vp, Cancellable cancel) throws DriverException { |
499 |
|
500 |
// Compute the query geometry
|
501 |
// 1. Check if it is within borders
|
502 |
Rectangle2D extent = getFullExtent();
|
503 |
if ((vp.getExtent().getMinX() > extent.getMaxX()) ||
|
504 |
(vp.getExtent().getMinY() > extent.getMaxY()) || |
505 |
(vp.getExtent().getMaxX() < extent.getMinX()) || |
506 |
(vp.getExtent().getMaxY() < extent.getMinY())) { |
507 |
return;
|
508 |
} |
509 |
|
510 |
// 2. Compute extent to be requested.
|
511 |
Rectangle2D bBox = new Rectangle2D.Double(); |
512 |
Rectangle2D.intersect(vp.getExtent(), extent, bBox);
|
513 |
|
514 |
// 3. Compute size in pixels
|
515 |
double scalex = vp.getAffineTransform().getScaleX();
|
516 |
double scaley = vp.getAffineTransform().getScaleY();
|
517 |
int wImg = (int) Math.ceil(Math.abs(bBox.getWidth() * scalex) + 1); |
518 |
int hImg = (int) Math.ceil(Math.abs(bBox.getHeight() * scaley) + 1); |
519 |
Dimension sz = new Dimension(wImg, hImg); |
520 |
|
521 |
if ((wImg <= 0) || (hImg <= 0)) { |
522 |
return;
|
523 |
} |
524 |
|
525 |
try {
|
526 |
wcsStatus.setCoveraName( coverageName ); |
527 |
wcsStatus.setExtent( bBox ); |
528 |
wcsStatus.setFormat( format ); |
529 |
wcsStatus.setHeight( hImg ); |
530 |
wcsStatus.setWidth( wImg ); |
531 |
wcsStatus.setSrs(srs); |
532 |
wcsStatus.setParameters( parameter ); |
533 |
wcsStatus.setTime( time ); |
534 |
wcsStatus.setOnlineResource((String) onlineResources.get("GetCoverage")); |
535 |
|
536 |
File f = getDriver().getCoverage(wcsStatus);
|
537 |
String nameWordFile = f.getPath() + getExtensionWorldFile();
|
538 |
com.iver.andami.Utilities.createTemp(nameWordFile, this.getDataWorldFile(bBox, sz));
|
539 |
|
540 |
if(status!=null && firstLoad){ |
541 |
status.applyStatus(this);
|
542 |
firstLoad = false;
|
543 |
} |
544 |
ViewPortData vpData = new ViewPortData(
|
545 |
vp.getProjection(), new Extent(bBox), sz );
|
546 |
vpData.setMat(vp.getAffineTransform()); |
547 |
|
548 |
rasterProcess(g, vpData, f); |
549 |
|
550 |
} catch (ValidationException e) {
|
551 |
throw new DriverException(PluginServices.getText(this, "unknown_response_format"), e); |
552 |
} catch (UnsupportedVersionException e) {
|
553 |
throw new DriverException(PluginServices.getText(this, "version_conflict"), e); |
554 |
} catch (IOException e) { |
555 |
throw new DriverException(PluginServices.getText(this, "connect_error"), e); |
556 |
} catch (WCSException e) {
|
557 |
JOptionPane.showMessageDialog((Component)PluginServices.getMainFrame(), e.getMessage()); |
558 |
this.setVisible(false); |
559 |
} |
560 |
} |
561 |
|
562 |
/**
|
563 |
* Devuelve el FMapWMSDriver.
|
564 |
*
|
565 |
* @return FMapWMSDriver
|
566 |
*
|
567 |
* @throws IllegalStateException
|
568 |
* @throws ValidationException
|
569 |
* @throws UnsupportedVersionException
|
570 |
* @throws IOException
|
571 |
*/
|
572 |
private FMapWCSDriver getDriver() throws IllegalStateException, ValidationException, UnsupportedVersionException, IOException { |
573 |
if (wcs == null) { |
574 |
wcs = new FMapWCSDriver();
|
575 |
wcs.createClient(host); |
576 |
} |
577 |
return wcs;
|
578 |
} |
579 |
|
580 |
/**
|
581 |
* Calcula el contenido del fichero de georreferenciaci?n de una imagen.
|
582 |
* @param bBox Tama?o y posici?n de la imagen (en coordenadas de usuario)
|
583 |
* @param sz Tama?o de la imagen en pixeles.
|
584 |
* @return el 'WorldFile', como String.
|
585 |
* @throws IOException
|
586 |
*/
|
587 |
public String getDataWorldFile(Rectangle2D bBox, Dimension sz) throws IOException { |
588 |
StringBuffer data = new StringBuffer(); |
589 |
data.append((bBox.getMaxX() - bBox.getMinX())/(sz.getWidth() - 1)+"\n"); |
590 |
data.append("0.0\n");
|
591 |
data.append("0.0\n");
|
592 |
data.append((bBox.getMaxY() - bBox.getMinY())/(sz.getHeight() - 1)+"\n"); |
593 |
data.append(""+bBox.getMinX()+"\n"); |
594 |
data.append(""+bBox.getMinY()+"\n"); |
595 |
return data.toString();
|
596 |
} |
597 |
|
598 |
/**
|
599 |
* Dibuja una imagen usando PxRaster
|
600 |
* @param g Graphics2D en el que hay que dibujar.
|
601 |
* @param vpData Par?metros de visualizaci?n
|
602 |
* @param file La imagen en cuesti?n.
|
603 |
*/
|
604 |
private void rasterProcess(Graphics2D g, ViewPortData vpData, File file) { |
605 |
|
606 |
//Creamos el PxRaster
|
607 |
rasterFile = new GdalFile(vpData.getProjection(), file.getAbsolutePath());
|
608 |
raster = new PxRaster(rasterFile, null, rasterFile.getExtent()); |
609 |
|
610 |
//Recuperamos la pila de filtros si ya hubiese sido cargado antes
|
611 |
if (this.filterStack!=null) |
612 |
raster.filterStack = this.filterStack;
|
613 |
|
614 |
raster.setTransparency(false);
|
615 |
|
616 |
//Asignamos transparencia y orden de bandas
|
617 |
if (this.transparency==-1 && !firstLoad); |
618 |
else
|
619 |
raster.setTransparency(this.transparency);
|
620 |
|
621 |
raster.setBand(GeoRasterFile.RED_BAND,rband); |
622 |
raster.setBand(GeoRasterFile.GREEN_BAND, gband); |
623 |
raster.setBand(GeoRasterFile.BLUE_BAND, bband); |
624 |
|
625 |
//Despues del primer pxRaster asignamos el stackManager guardado para los siguientes.
|
626 |
//Con esto conseguimos asignar los cambios que se hayan producido desde el cuadro de
|
627 |
//propiedades cuando creamos un nuevo pxRaster
|
628 |
if (this.stackManager != null) |
629 |
raster.setStackManager(this.stackManager);
|
630 |
|
631 |
if (visualStatus != null){ |
632 |
visualStatus.bandCount = raster.getBandCount(); |
633 |
visualStatus.dataType = raster.getDataType(); |
634 |
} |
635 |
|
636 |
raster.draw(g, vpData); |
637 |
|
638 |
//En el primer pxRaster de una imagen obtenemos el Stack Manager para poder modificarlo
|
639 |
//si queremos desde las propiedades
|
640 |
|
641 |
if (this.stackManager == null) |
642 |
this.stackManager = raster.getStackManager();
|
643 |
|
644 |
if (this.filterStack == null) |
645 |
this.filterStack = raster.filterStack;
|
646 |
|
647 |
rasterFile.close(); |
648 |
} |
649 |
|
650 |
public void print(Graphics2D g, ViewPort viewPort, Cancellable cancel, double scale) throws DriverException { |
651 |
draw(null, g, viewPort, cancel, scale);
|
652 |
} |
653 |
|
654 |
/**
|
655 |
* @return Returns the raster.
|
656 |
*/
|
657 |
public PxRaster getPxRaster() {
|
658 |
return raster;
|
659 |
} |
660 |
|
661 |
/**
|
662 |
* Returns the XMLEntity containing the necessary info for reproduce
|
663 |
* the layer.
|
664 |
*
|
665 |
* Devuelve el XMLEntity con la informaci?n necesaria para reproducir
|
666 |
* la capa.
|
667 |
*
|
668 |
* @return XMLEntity.
|
669 |
* @throws XMLException
|
670 |
*/
|
671 |
public XMLEntity getXMLEntity() throws XMLException { |
672 |
XMLEntity xml = super.getXMLEntity();
|
673 |
|
674 |
xml.putProperty("wcs.host", getHost());
|
675 |
xml.putProperty("wcs.fullExtent", StringUtilities.rect2String( fullExtent ));
|
676 |
xml.putProperty("wcs.layerQuery", coverageName );
|
677 |
xml.putProperty("wcs.format", format );
|
678 |
xml.putProperty("wcs.srs", srs );
|
679 |
xml.putProperty("wcs.time", time );
|
680 |
xml.putProperty("wcs.parameter", parameter );
|
681 |
xml.putProperty("wcs.coverageName", coverageName );
|
682 |
xml.putProperty("wcs.maxResX", maxRes.getX());
|
683 |
xml.putProperty("wcs.maxResY", maxRes.getY());
|
684 |
if (status!=null) |
685 |
status.getXMLEntity(xml, true, this); |
686 |
else{
|
687 |
status = new StatusLayerRaster();
|
688 |
status.getXMLEntity(xml, true, this); |
689 |
} |
690 |
return xml;
|
691 |
} |
692 |
|
693 |
/**
|
694 |
* Reproduces the layer from an XMLEntity.
|
695 |
*
|
696 |
* A partir del XMLEntity reproduce la capa.
|
697 |
*
|
698 |
* @param xml XMLEntity
|
699 |
*
|
700 |
* @throws XMLException
|
701 |
* @throws DriverException
|
702 |
* @throws DriverIOException
|
703 |
*/
|
704 |
public void setXMLEntity(XMLEntity xml) throws XMLException { |
705 |
super.setXMLEntity(xml);
|
706 |
|
707 |
// host
|
708 |
try {
|
709 |
host = new URL(xml.getStringProperty("wcs.host")); |
710 |
} catch (MalformedURLException e) { |
711 |
throw new XMLException(e); |
712 |
} |
713 |
|
714 |
// full extent
|
715 |
fullExtent = StringUtilities.string2Rect(xml.getStringProperty("wcs.fullExtent"));
|
716 |
|
717 |
// coverageQuery
|
718 |
coverageName = xml.getStringProperty("wcs.layerQuery");
|
719 |
|
720 |
// format
|
721 |
format = xml.getStringProperty("wcs.format");
|
722 |
|
723 |
// srs
|
724 |
srs = xml.getStringProperty("wcs.srs");
|
725 |
|
726 |
// time
|
727 |
time = xml.getStringProperty("wcs.time");
|
728 |
|
729 |
// parameter
|
730 |
parameter = xml.getStringProperty("wcs.parameter");
|
731 |
|
732 |
// coverage name
|
733 |
coverageName = xml.getStringProperty("wcs.coverageName");
|
734 |
|
735 |
// max resolution
|
736 |
if (xml.contains("wcs.maxRes")) |
737 |
maxRes = new Point2D.Double(xml.getDoubleProperty("wcs.maxRes"), xml.getDoubleProperty("wcs.maxRes")); |
738 |
else if (xml.contains("wcs.maxResX") && xml.contains("wcs.maxResY")) |
739 |
maxRes = new Point2D.Double(xml.getDoubleProperty("wcs.maxResX"), xml.getDoubleProperty("wcs.maxResY")); |
740 |
|
741 |
// OnlineResources
|
742 |
if (xml.contains("onlineResources")) { |
743 |
String[] operations = xml.getStringProperty("onlineResources").split("~##SEP1##~"); |
744 |
for (int i = 0; i < operations.length; i++) { |
745 |
String[] resources = operations[i].split("~##SEP2##~"); |
746 |
if (resources.length==2 && resources[1]!="") |
747 |
onlineResources.put(resources[0], resources[1]); |
748 |
} |
749 |
} |
750 |
String claseStr = null; |
751 |
if (xml.contains("raster.class")) { |
752 |
claseStr = xml.getStringProperty("raster.class");
|
753 |
} |
754 |
if (status!=null) |
755 |
status.setXMLEntity(xml, this);
|
756 |
else {
|
757 |
|
758 |
//Cuando cargamos un proyecto
|
759 |
|
760 |
if(claseStr!=null && !claseStr.equals("")){ |
761 |
try{
|
762 |
Class clase = Class.forName(claseStr); |
763 |
Constructor constr = clase.getConstructor(null); |
764 |
status = (StatusRasterInterface)constr.newInstance(null);
|
765 |
if(status!=null) |
766 |
status.setXMLEntity(xml, this);
|
767 |
} catch(ClassNotFoundException exc) { |
768 |
exc.printStackTrace(); |
769 |
} catch(InstantiationException exc) { |
770 |
exc.printStackTrace(); |
771 |
} catch(IllegalAccessException exc) { |
772 |
exc.printStackTrace(); |
773 |
} catch(NoSuchMethodException exc) { |
774 |
exc.printStackTrace(); |
775 |
} catch(InvocationTargetException exc) { |
776 |
exc.printStackTrace(); |
777 |
} |
778 |
} |
779 |
} |
780 |
firstLoad = true;
|
781 |
} |
782 |
|
783 |
public void setCoverageName(String coverageName) { |
784 |
this.coverageName = coverageName;
|
785 |
} |
786 |
|
787 |
public void setParameter(String parametersString) { |
788 |
this.parameter = parametersString;
|
789 |
} |
790 |
|
791 |
public void setTime(String time) { |
792 |
this.time = time;
|
793 |
} |
794 |
|
795 |
public void setSRS(String srs) { |
796 |
this.srs = srs;
|
797 |
} |
798 |
|
799 |
public void setFormat(String format) { |
800 |
this.format = format;
|
801 |
} |
802 |
|
803 |
|
804 |
/**
|
805 |
* Inserta el URL.
|
806 |
*
|
807 |
* @param host String.
|
808 |
* @throws MalformedURLException
|
809 |
*/
|
810 |
public void setHost(String host) { |
811 |
try {
|
812 |
setHost(new URL(host)); |
813 |
} catch (MalformedURLException e) { |
814 |
|
815 |
} |
816 |
} |
817 |
|
818 |
/**
|
819 |
* Inserta el URL.
|
820 |
*
|
821 |
* @param host URL.
|
822 |
*/
|
823 |
public void setHost(URL host) { |
824 |
this.host = host;
|
825 |
} |
826 |
|
827 |
/**
|
828 |
* Sets the layer's full extent.
|
829 |
*
|
830 |
* Establece la extensi?n m?xima de la capa.
|
831 |
*
|
832 |
* @param rect
|
833 |
*/
|
834 |
public void setFullExtent(Rectangle2D rect) { |
835 |
this.fullExtent = rect;
|
836 |
} |
837 |
|
838 |
/**
|
839 |
* Devuelve el URL.
|
840 |
*
|
841 |
* @return URL.
|
842 |
*/
|
843 |
public URL getHost() { |
844 |
return host;
|
845 |
} |
846 |
|
847 |
/**
|
848 |
* Remote source layers have a bunch of properties that are required for get them from
|
849 |
* the servers. This method supplies a hash table containing any needed field. This hash
|
850 |
* table may be used to let the client to connect to a server and restore a previously saved
|
851 |
* layer. So, the layer itself may not be saved to the disk since the actual saved
|
852 |
* info is just its properties.
|
853 |
*
|
854 |
* @return Returns a hash table containing all the required information for
|
855 |
* set up a wms layer
|
856 |
*/
|
857 |
public Hashtable getProperties(){ |
858 |
Hashtable info = new Hashtable(); |
859 |
info.put( "name", coverageName);
|
860 |
info.put( "host", getHost());
|
861 |
info.put( "crs", srs);
|
862 |
info.put( "format", format);
|
863 |
String str = time;
|
864 |
if (str==null) |
865 |
str = "";
|
866 |
info.put( "time", str);
|
867 |
str = parameter; |
868 |
if (str==null) |
869 |
str = "";
|
870 |
info.put("parameter", str);
|
871 |
|
872 |
return info;
|
873 |
} |
874 |
|
875 |
/**
|
876 |
* Obtiene la extensi?n del fichero de georreferenciaci?n
|
877 |
* @return String con la extensi?n del fichero de georreferenciaci?n dependiendo
|
878 |
* del valor del formato obtenido del servidor. Por defecto asignaremos un .wld
|
879 |
*/
|
880 |
private String getExtensionWorldFile(){ |
881 |
String extWorldFile = ".wld"; |
882 |
if (format.equals("image/tif") || format.equals("image/tiff")) |
883 |
extWorldFile = ".tfw";
|
884 |
if (format.equals("image/jpeg")) |
885 |
extWorldFile = ".jpgw";
|
886 |
return extWorldFile;
|
887 |
} |
888 |
|
889 |
public void setMaxResolution(Point2D maxResolution) { |
890 |
this.maxRes = maxResolution;
|
891 |
} |
892 |
|
893 |
/**
|
894 |
* Gets the last open GeoRasterFile against the temp file received
|
895 |
*
|
896 |
* Obtiene el ?ltimo GeoRasterFile abierto sobre el temporal recibido
|
897 |
* @return
|
898 |
*/
|
899 |
public GeoRasterFile getGeoRasterFile(){
|
900 |
return rasterFile;
|
901 |
} |
902 |
|
903 |
|
904 |
/**
|
905 |
* Asignar el estado del raster
|
906 |
* @param status
|
907 |
*/
|
908 |
public void setStatus(StatusRasterInterface status){ |
909 |
this.status = status;
|
910 |
} |
911 |
|
912 |
/**
|
913 |
* Obtiene el estado del raster
|
914 |
* @return
|
915 |
*/
|
916 |
public StatusRasterInterface getStatus(){
|
917 |
return this.status; |
918 |
} |
919 |
|
920 |
/**
|
921 |
* Gets the max resolution allowed by the coverage. Requesting a higher resolution
|
922 |
* than this value does not cause any error, but the info responsed is just an
|
923 |
* interpolation.
|
924 |
*
|
925 |
* In exchange for obtaining a greater file and without additional information,
|
926 |
* we can easily connect it at the View.
|
927 |
*
|
928 |
*
|
929 |
* Obtiene la resoluci?n m?xima soportada por la cobertura. La petici?n
|
930 |
* de una resoluci?n superior a la soportada no provoca ning?n error, aunque
|
931 |
* la informaci?n obtenida s?lo es una mera interpolaci?n de informaci?n.
|
932 |
*
|
933 |
* A cambio de obtener un archivo mayor y sin informaci?n adicional, podemos
|
934 |
* f?cilmente acoplarlo a la vista.
|
935 |
*
|
936 |
* @return double
|
937 |
*/
|
938 |
public Point2D getMaxResolution() { |
939 |
if (maxRes==null) |
940 |
maxRes = wcs.getMaxResolution(coverageName); |
941 |
return maxRes;
|
942 |
} |
943 |
|
944 |
|
945 |
public void setDriver(FMapWCSDriver driver) { |
946 |
this.driver = driver;
|
947 |
} |
948 |
} |