svn-gvsig-desktop / branches / v05 / extensions / extWMS / src / com / iver / cit / gvsig / fmap / layers / FLyrWMS.java @ 4047
History | View | Annotate | Download (28.8 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.Rectangle2D; |
51 |
import java.awt.image.BufferedImage; |
52 |
import java.io.File; |
53 |
import java.io.IOException; |
54 |
import java.lang.reflect.Constructor; |
55 |
import java.lang.reflect.InvocationTargetException; |
56 |
import java.net.MalformedURLException; |
57 |
import java.net.URL; |
58 |
import java.util.ArrayList; |
59 |
import java.util.HashMap; |
60 |
import java.util.Hashtable; |
61 |
import java.util.Iterator; |
62 |
import java.util.Vector; |
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.utils.Utilities; |
75 |
import org.gvsig.remoteClient.wms.WMSStatus; |
76 |
|
77 |
import com.iver.andami.PluginServices; |
78 |
import com.iver.cit.gvsig.fmap.DriverException; |
79 |
import com.iver.cit.gvsig.fmap.ViewPort; |
80 |
import com.iver.cit.gvsig.fmap.drivers.DriverIOException; |
81 |
import com.iver.cit.gvsig.fmap.drivers.UnsupportedVersionException; |
82 |
import com.iver.cit.gvsig.fmap.drivers.WMSException; |
83 |
import com.iver.cit.gvsig.fmap.drivers.wms.FMapWMSDriver; |
84 |
import com.iver.cit.gvsig.fmap.layers.layerOperations.InfoByPoint; |
85 |
import com.iver.cit.gvsig.fmap.operations.Cancellable; |
86 |
import com.iver.utiles.StringUtilities; |
87 |
import com.iver.utiles.XMLEntity; |
88 |
|
89 |
|
90 |
/**
|
91 |
* FMap's WMS Layer class.
|
92 |
*
|
93 |
* @author Jaume Dominguez Faus
|
94 |
* Nacho Brodin
|
95 |
*
|
96 |
*/
|
97 |
public class FLyrWMS extends FLyrDefault implements InfoByPoint, RasterOperations { |
98 |
private boolean isPrinting = false; |
99 |
private boolean mustTileDraw = false; |
100 |
private boolean mustTilePrint = true; |
101 |
private final int maxTileDrawWidth = -1; |
102 |
private final int maxTileDrawHeight = -1; |
103 |
private final int maxTilePrintWidth = 1023; |
104 |
private final int maxTilePrintHeight = 1023; |
105 |
|
106 |
public URL host; |
107 |
public String m_Format; |
108 |
|
109 |
private String m_SRS; |
110 |
private String layerQuery; |
111 |
private String infoLayerQuery; |
112 |
private FMapWMSDriver wms;
|
113 |
private WMSStatus wmsStatus;
|
114 |
private Rectangle2D fullExtent; |
115 |
private boolean wmsTransparency; |
116 |
private Vector styles; |
117 |
private Vector dimensions; |
118 |
private StatusRasterInterface status = null; |
119 |
private int posX = 0, posY = 0; |
120 |
private double posXWC = 0, posYWC = 0; |
121 |
private int r = 0, g = 0, b = 0; |
122 |
private GeoRasterFile rasterFile = null; |
123 |
private PxRaster raster = null; |
124 |
private RasterFilterStack filterStack = null; |
125 |
private boolean firstLoad = false; |
126 |
private int transparency = -1; |
127 |
private int rband = 0, gband = 1, bband = 2; |
128 |
private RasterFilterStackManager stackManager = null; |
129 |
private Hashtable onlineResources = new Hashtable(); |
130 |
|
131 |
|
132 |
|
133 |
/**
|
134 |
* Devuelve el XMLEntity con la informaci?n necesaria para reproducir la
|
135 |
* capa.
|
136 |
*
|
137 |
* @return XMLEntity.
|
138 |
* @throws XMLException
|
139 |
*/
|
140 |
public XMLEntity getXMLEntity() throws XMLException { |
141 |
XMLEntity xml = super.getXMLEntity();
|
142 |
|
143 |
xml.putProperty("fullExtent", StringUtilities.rect2String(fullExtent));
|
144 |
xml.putProperty("host", host.toExternalForm());
|
145 |
xml.putProperty("infoLayerQuery", infoLayerQuery);
|
146 |
xml.putProperty("layerQuery", layerQuery);
|
147 |
xml.putProperty("format", m_Format);
|
148 |
xml.putProperty("srs", m_SRS);
|
149 |
if (status!=null) |
150 |
status.getXMLEntity(xml, true, this); |
151 |
else{
|
152 |
status = new StatusLayerRaster();
|
153 |
status.getXMLEntity(xml, true, this); |
154 |
} |
155 |
|
156 |
xml.putProperty("wms_transparency", wmsTransparency);
|
157 |
|
158 |
if (styles!=null){ |
159 |
String stylePr = ""; |
160 |
for (int i = 0; i < styles.size(); i++) { |
161 |
stylePr += (String) styles.get(i);
|
162 |
if (i<styles.size()-1) |
163 |
stylePr += ",";
|
164 |
} |
165 |
if (stylePr.endsWith(",")) |
166 |
stylePr += " ";
|
167 |
xml.putProperty("styles", stylePr);
|
168 |
} |
169 |
if (dimensions!=null){ |
170 |
String dim = ""; |
171 |
for (int i = 0; i < dimensions.size(); i++) { |
172 |
dim += (String) dimensions.get(i);
|
173 |
if (i<dimensions.size()-1) |
174 |
dim += ",";
|
175 |
} |
176 |
if (dim.endsWith(",")) |
177 |
dim += " ";
|
178 |
xml.putProperty("dimensions", dim);
|
179 |
} |
180 |
Iterator it = onlineResources.keySet().iterator();
|
181 |
String strOnlines = ""; |
182 |
while (it.hasNext()) {
|
183 |
String key = (String) it.next(); |
184 |
String value = (String) onlineResources.get(key); |
185 |
strOnlines = key+"~##SEP2##~"+value;
|
186 |
if (it.hasNext())
|
187 |
strOnlines += "~##SEP1##~";
|
188 |
} |
189 |
xml.putProperty("onlineResources", strOnlines);
|
190 |
return xml;
|
191 |
} |
192 |
|
193 |
/**
|
194 |
* A partir del XMLEntity reproduce la capa.
|
195 |
*
|
196 |
* @param xml XMLEntity
|
197 |
*
|
198 |
* @throws XMLException
|
199 |
* @throws DriverException
|
200 |
* @throws DriverIOException
|
201 |
*/
|
202 |
public void setXMLEntity03(XMLEntity xml) |
203 |
throws XMLException {
|
204 |
super.setXMLEntity(xml);
|
205 |
fullExtent = StringUtilities.string2Rect(xml.getStringProperty( |
206 |
"fullExtent"));
|
207 |
|
208 |
try {
|
209 |
host = new URL(xml.getStringProperty("host")); |
210 |
} catch (MalformedURLException e) { |
211 |
throw new XMLException(e); |
212 |
} |
213 |
|
214 |
infoLayerQuery = xml.getStringProperty("infoLayerQuery");
|
215 |
layerQuery = xml.getStringProperty("layerQuery");
|
216 |
m_Format = xml.getStringProperty("format");
|
217 |
m_SRS = xml.getStringProperty("srs");
|
218 |
} |
219 |
|
220 |
/**
|
221 |
* A partir del XMLEntity reproduce la capa.
|
222 |
*
|
223 |
* @param xml XMLEntity
|
224 |
*
|
225 |
* @throws XMLException
|
226 |
* @throws DriverException
|
227 |
* @throws DriverIOException
|
228 |
*/
|
229 |
public void setXMLEntity(XMLEntity xml) |
230 |
throws XMLException {
|
231 |
super.setXMLEntity(xml);
|
232 |
fullExtent = StringUtilities.string2Rect(xml.getStringProperty( |
233 |
"fullExtent"));
|
234 |
|
235 |
try {
|
236 |
host = new URL(xml.getStringProperty("host")); |
237 |
} catch (MalformedURLException e) { |
238 |
throw new XMLException(e); |
239 |
} |
240 |
|
241 |
infoLayerQuery = xml.getStringProperty("infoLayerQuery");
|
242 |
layerQuery = xml.getStringProperty("layerQuery");
|
243 |
m_Format = xml.getStringProperty("format");
|
244 |
m_SRS = xml.getStringProperty("srs");
|
245 |
|
246 |
String claseStr = null; |
247 |
if (xml.contains("raster.class")) { |
248 |
claseStr = xml.getStringProperty("raster.class");
|
249 |
} |
250 |
|
251 |
if (xml.contains("wms_transparency")) |
252 |
wmsTransparency = xml.getBooleanProperty("wms_transparency");
|
253 |
|
254 |
if (xml.contains("styles")){ |
255 |
styles = new Vector(); |
256 |
String[] stl = xml.getStringProperty("styles").split(","); |
257 |
|
258 |
for (int i = 0; i < stl.length; i++) { |
259 |
if (stl[i].equals(" ")) |
260 |
stl[i]="";
|
261 |
styles.add(stl[i]); |
262 |
} |
263 |
} |
264 |
|
265 |
if (xml.contains("dimensions")){ |
266 |
dimensions = new Vector(); |
267 |
String[] dims = xml.getStringProperty("dimensions").split(","); |
268 |
for (int i = 0; i < dims.length; i++){ |
269 |
if (dims[i].equals(" ")) |
270 |
dims[i]="";
|
271 |
|
272 |
dimensions.add(dims[i]); |
273 |
} |
274 |
} |
275 |
|
276 |
if (xml.contains("onlineResources")) { |
277 |
String[] operations = xml.getStringProperty("onlineResources").split("~##SEP1##~"); |
278 |
for (int i = 0; i < operations.length; i++) { |
279 |
String[] resources = operations[i].split("~##SEP2##~"); |
280 |
if (resources.length==2 && resources[1]!="") |
281 |
onlineResources.put(resources[0], resources[1]); |
282 |
} |
283 |
} |
284 |
|
285 |
if(status!=null) |
286 |
status.setXMLEntity(xml, this);
|
287 |
else{
|
288 |
|
289 |
//Cuando cargamos un proyecto
|
290 |
|
291 |
if(claseStr!=null && !claseStr.equals("")){ |
292 |
try{
|
293 |
Class clase = Class.forName(claseStr); |
294 |
Constructor constr = clase.getConstructor(null); |
295 |
status = (StatusRasterInterface)constr.newInstance(null);
|
296 |
if(status!=null) |
297 |
status.setXMLEntity(xml, this);
|
298 |
}catch(ClassNotFoundException exc){ |
299 |
exc.printStackTrace(); |
300 |
}catch(InstantiationException exc){ |
301 |
exc.printStackTrace(); |
302 |
}catch(IllegalAccessException exc){ |
303 |
exc.printStackTrace(); |
304 |
}catch(NoSuchMethodException exc){ |
305 |
exc.printStackTrace(); |
306 |
}catch(InvocationTargetException exc){ |
307 |
exc.printStackTrace(); |
308 |
} |
309 |
} |
310 |
} |
311 |
firstLoad = true;
|
312 |
} |
313 |
|
314 |
/**
|
315 |
* @see com.iver.cit.gvsig.fmap.layers.layerOperations.InfoByPoint#queryByPoint(com.iver.cit.gvsig.fmap.operations.QueriedPoint)
|
316 |
*/
|
317 |
public String queryByPoint(Point p) throws DriverException { |
318 |
try {
|
319 |
if(wms.isQueryable())
|
320 |
{ |
321 |
//TODO
|
322 |
// check if there are layers which are not queryable
|
323 |
wmsStatus.setOnlineResource((String) onlineResources.get("GetFeatureInfo")); |
324 |
return new String(getDriver() |
325 |
.getFeatureInfo(wmsStatus,(int)p.getX(),(int)p.getY(),Integer.MAX_VALUE)); |
326 |
} |
327 |
else
|
328 |
{ |
329 |
JOptionPane.showMessageDialog((Component)PluginServices.getMainFrame() |
330 |
,PluginServices.getText(this, "wms_not_queryable")); |
331 |
return "<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?><info></info>"; |
332 |
} |
333 |
} catch (WMSException e) {
|
334 |
return "<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?><exception>" + |
335 |
e.getMessage() + "</exception>";
|
336 |
} catch (ValidationException e) {
|
337 |
throw new DriverException(PluginServices.getText(this, "unknown_response_format"), e); |
338 |
} catch (UnsupportedVersionException e) {
|
339 |
throw new DriverException(PluginServices.getText(this, "version_conflict"), e); |
340 |
} catch (IOException e) { |
341 |
throw new DriverException(PluginServices.getText(this, "connect_error"), e); |
342 |
} |
343 |
} |
344 |
|
345 |
/**
|
346 |
* @see com.iver.cit.gvsig.fmap.layers.FLayer#getFullExtent()
|
347 |
*/
|
348 |
public Rectangle2D getFullExtent() { |
349 |
return fullExtent;
|
350 |
} |
351 |
|
352 |
/**
|
353 |
*
|
354 |
* @see com.iver.cit.gvsig.fmap.layers.FLayer#draw(java.awt.image.BufferedImage,
|
355 |
* java.awt.Graphics2D, com.iver.cit.gvsig.fmap.ViewPort,
|
356 |
* com.iver.cit.gvsig.fmap.operations.Cancellable)
|
357 |
*/
|
358 |
public void draw(BufferedImage image, Graphics2D g, ViewPort viewPort, |
359 |
Cancellable cancel,double scale) throws DriverException { |
360 |
if (isWithinScale(scale)){
|
361 |
Rectangle r = new Rectangle(0, 0, viewPort.getImageWidth() - 1, viewPort.getImageHeight() - 1); |
362 |
Tiling tiles = new Tiling(maxTilePrintWidth, maxTilePrintHeight, r);
|
363 |
tiles.setAffineTransform((AffineTransform) viewPort.getAffineTransform().clone());
|
364 |
for (int tileNr=0; tileNr < tiles.getNumTiles(); tileNr++) { |
365 |
// drawing part
|
366 |
try {
|
367 |
ViewPort vp = tiles.getTileViewPort(viewPort, tileNr); |
368 |
_draw(null, g, vp, cancel,scale);
|
369 |
} catch (NoninvertibleTransformException e) { |
370 |
e.printStackTrace(); |
371 |
} |
372 |
} |
373 |
} |
374 |
} |
375 |
|
376 |
/**
|
377 |
* @see com.iver.cit.gvsig.fmap.layers.FLayer#draw(java.awt.image.BufferedImage,
|
378 |
* java.awt.Graphics2D, com.iver.cit.gvsig.fmap.ViewPort,
|
379 |
* com.iver.cit.gvsig.fmap.operations.Cancellable)
|
380 |
*/
|
381 |
public void _draw(BufferedImage image, Graphics2D g, ViewPort vp, |
382 |
Cancellable cancel,double scale) throws DriverException { |
383 |
|
384 |
// { Empieza el c?lculo de la geometr?a de la consulta.
|
385 |
// Fusilado de org.cresques.pxPxRaster, en el draw()
|
386 |
// by LWS
|
387 |
// Comprueba que tiene que dibujarse.
|
388 |
Rectangle2D extent = getFullExtent();
|
389 |
if ((vp.getExtent().getMinX() > extent.getMaxX()) ||
|
390 |
(vp.getExtent().getMinY() > extent.getMaxY()) || |
391 |
(vp.getExtent().getMaxX() < extent.getMinX()) || |
392 |
(vp.getExtent().getMaxY() < extent.getMinY())) { |
393 |
return;
|
394 |
} |
395 |
// calcula su extent.
|
396 |
Rectangle2D bBox = normalizeExtent(vp.getExtent(), extent);
|
397 |
|
398 |
// calcula el tama?o (en p?xeles)
|
399 |
double scalex = vp.getAffineTransform().getScaleX() /* g.getTransform().getScaleX()*/; |
400 |
double scaley = vp.getAffineTransform().getScaleY() /* g.getTransform().getScaleY() */; |
401 |
int wImg = (int) Math.ceil(Math.abs(bBox.getWidth() * scalex) + 1); |
402 |
int hImg = (int) Math.ceil(Math.abs(bBox.getHeight() * scaley) + 1); |
403 |
Dimension sz = new Dimension(wImg, hImg); |
404 |
|
405 |
if ((wImg <= 0) || (hImg <= 0)) { |
406 |
return;
|
407 |
} |
408 |
|
409 |
try {
|
410 |
|
411 |
if (wmsStatus == null) |
412 |
wmsStatus = new WMSStatus();
|
413 |
|
414 |
wmsStatus.setExtent( bBox ); |
415 |
wmsStatus.setFormat(m_Format); |
416 |
wmsStatus.setHeight( hImg ); |
417 |
wmsStatus.setWidth( wImg ); |
418 |
wmsStatus.setLayerNames(Utilities.createVector(layerQuery,",")); |
419 |
wmsStatus.setSrs(m_SRS); |
420 |
wmsStatus.setStyles(styles); |
421 |
wmsStatus.setDimensions(dimensions); |
422 |
wmsStatus.setTransparency(wmsTransparency); |
423 |
|
424 |
wmsStatus.setOnlineResource((String) onlineResources.get("GetMap")); |
425 |
|
426 |
|
427 |
File f = getDriver().getMap(wmsStatus);
|
428 |
String nameWordFile = f.getPath() + getExtensionWordFile();
|
429 |
com.iver.andami.Utilities.createTemp(nameWordFile, this.getDataWordFile(bBox, sz));
|
430 |
|
431 |
if(status!=null && firstLoad){ |
432 |
status.applyStatus(this);
|
433 |
firstLoad = false;
|
434 |
} |
435 |
ViewPortData vpData = new ViewPortData(
|
436 |
vp.getProjection(), new Extent(bBox), sz );
|
437 |
vpData.setMat(vp.getAffineTransform()); |
438 |
|
439 |
rasterProcess(g, vpData, f); |
440 |
|
441 |
} catch (ValidationException e) {
|
442 |
throw new DriverException(PluginServices.getText(this, "unknown_response_format"), e); |
443 |
} catch (UnsupportedVersionException e) {
|
444 |
throw new DriverException(PluginServices.getText(this, "version_conflict"), e); |
445 |
} catch (IOException e) { |
446 |
throw new DriverException(PluginServices.getText(this, "connect_error"), e); |
447 |
} catch (WMSException e) {
|
448 |
JOptionPane.showMessageDialog((Component)PluginServices.getMainFrame(), e.getMessage()); |
449 |
this.setVisible(false); |
450 |
} |
451 |
|
452 |
} |
453 |
|
454 |
/**
|
455 |
* 'Normaliza' la un Rectangle2D en funci?n de otro.
|
456 |
* Calcula la intersecci?n entre dos rectangle2D.
|
457 |
* Se utiliza para calcular que un boundingBox (o extent) no
|
458 |
* sobresalga de otro.
|
459 |
*
|
460 |
* @param sz Extent que hay que normalizar.
|
461 |
* @param extent Extent m?ximo.
|
462 |
*/
|
463 |
protected Rectangle2D normalizeExtent(Rectangle2D sz, Rectangle2D extent) { |
464 |
double vx = sz.getMinX();
|
465 |
double vy = sz.getMinY();
|
466 |
double vx2 = sz.getMaxX();
|
467 |
double vy2 = sz.getMaxY();
|
468 |
|
469 |
if (sz.getMinX() < extent.getMinX())
|
470 |
vx = extent.getMinX(); |
471 |
if (sz.getMinY() < extent.getMinY())
|
472 |
vy = extent.getMinY(); |
473 |
if (sz.getMaxX() > extent.getMaxX())
|
474 |
vx2 = extent.getMaxX(); |
475 |
if (sz.getMaxY() > extent.getMaxY())
|
476 |
vy2 = extent.getMaxY(); |
477 |
|
478 |
Rectangle2D r = new Rectangle2D.Double(vx, vy, vx2-vx, vy2-vy); |
479 |
return r;
|
480 |
} |
481 |
|
482 |
/**
|
483 |
* Obtiene la extensi?n del fichero de georreferenciaci?n
|
484 |
* @return String con la extensi?n del fichero de georreferenciaci?n dependiendo
|
485 |
* del valor del formato obtenido del servidor. Por defecto asignaremos un .wld
|
486 |
*/
|
487 |
private String getExtensionWordFile(){ |
488 |
String extWorldFile = ".wld"; |
489 |
if(m_Format.equals("image/tif") || m_Format.equals("image/tiff")) |
490 |
extWorldFile = ".tfw";
|
491 |
if(m_Format.equals("image/jpeg")) |
492 |
extWorldFile = ".jpgw";
|
493 |
return extWorldFile;
|
494 |
} |
495 |
|
496 |
/**
|
497 |
* Calcula el contenido del fichero de georreferenciaci?n de una imagen.
|
498 |
* @param bBox Tama?o y posici?n de la imagen (en coordenadas de usuario)
|
499 |
* @param sz Tama?o de la im?gen en p?xeles.
|
500 |
* @return el 'WorldFile', como String.
|
501 |
* @throws IOException
|
502 |
*/
|
503 |
public String getDataWordFile(Rectangle2D bBox, Dimension sz) throws IOException { |
504 |
StringBuffer data = new StringBuffer(); |
505 |
data.append((bBox.getMaxX() - bBox.getMinX())/(sz.getWidth() - 1)+"\n"); |
506 |
data.append("0.0\n");
|
507 |
data.append("0.0\n");
|
508 |
data.append((bBox.getMaxY() - bBox.getMinY())/(sz.getHeight() - 1)+"\n"); |
509 |
data.append(""+bBox.getMinX()+"\n"); |
510 |
data.append(""+bBox.getMinY()+"\n"); |
511 |
return data.toString();
|
512 |
} |
513 |
|
514 |
/**
|
515 |
* Dibuja una im?gen usando PxRaster
|
516 |
* @param g Graphics2D en el que hay que dibujar.
|
517 |
* @param vpData Par?metros de visualizaci?n
|
518 |
* @param file La im?gen en cuesti?n.
|
519 |
*/
|
520 |
private void rasterProcess(Graphics2D g, ViewPortData vpData, File file) { |
521 |
|
522 |
//Creamos el PxRaster
|
523 |
rasterFile = new GdalFile(vpData.getProjection(), file.getAbsolutePath());
|
524 |
raster = new PxRaster(rasterFile, null, rasterFile.getExtent()); |
525 |
|
526 |
//Recuperamos la pila de filtros si ya hubiese sido cargado antes
|
527 |
|
528 |
if(this.filterStack!=null) |
529 |
raster.filterStack = this.filterStack;
|
530 |
|
531 |
raster.setTransparency(false);
|
532 |
|
533 |
//Asignamos transparencia y orden de bandas
|
534 |
if(this.transparency==-1 && !firstLoad); |
535 |
else
|
536 |
raster.setTransparency(this.transparency);
|
537 |
|
538 |
raster.setBand(GeoRasterFile.RED_BAND,rband); |
539 |
raster.setBand(GeoRasterFile.GREEN_BAND, gband); |
540 |
raster.setBand(GeoRasterFile.BLUE_BAND, bband); |
541 |
|
542 |
//Despues del primer pxRaster asignamos el stackManager guardado para los siguientes.
|
543 |
//Con esto conseguimos asignar los cambios que se hayan producido desde el cuadro de
|
544 |
//propiedades cuando creamos un nuevo pxRaster
|
545 |
|
546 |
if(this.stackManager != null) |
547 |
raster.setStackManager(this.stackManager);
|
548 |
|
549 |
raster.draw(g, vpData); |
550 |
|
551 |
//En el primer pxRaster de una imagen obtenemos el Stack Manager para poder modificarlo
|
552 |
//si queremos desde las propiedades
|
553 |
|
554 |
if(this.stackManager == null) |
555 |
this.stackManager = raster.getStackManager();
|
556 |
|
557 |
if(this.filterStack == null) |
558 |
this.filterStack = raster.filterStack;
|
559 |
} |
560 |
|
561 |
/**
|
562 |
* @see com.iver.cit.gvsig.fmap.layers.FLayer#print(java.awt.Graphics2D,
|
563 |
* com.iver.cit.gvsig.fmap.ViewPort,
|
564 |
* com.iver.cit.gvsig.fmap.operations.Cancellable)
|
565 |
*/
|
566 |
public void print(Graphics2D g, ViewPort viewPort, Cancellable cancel,double scale) |
567 |
throws DriverException {
|
568 |
if (isVisible() && isWithinScale(scale)){
|
569 |
isPrinting = true;
|
570 |
if (!mustTilePrint) {
|
571 |
draw(null, g, viewPort, cancel,scale);
|
572 |
} else {
|
573 |
// Para no pedir imagenes demasiado grandes, vamos
|
574 |
// a hacer lo mismo que hace EcwFile: chunkear.
|
575 |
// Llamamos a drawView con cuadraditos m?s peque?os
|
576 |
// del BufferedImage ni caso, cuando se imprime viene con null
|
577 |
|
578 |
Tiling tiles = new Tiling(maxTilePrintWidth, maxTilePrintHeight, g.getClipRect());
|
579 |
tiles.setAffineTransform((AffineTransform) viewPort.getAffineTransform().clone());
|
580 |
for (int tileNr=0; tileNr < tiles.getNumTiles(); tileNr++) { |
581 |
// Parte que dibuja
|
582 |
try {
|
583 |
ViewPort vp = tiles.getTileViewPort(viewPort, tileNr); |
584 |
draw(null, g, vp, cancel,scale);
|
585 |
} catch (NoninvertibleTransformException e) { |
586 |
e.printStackTrace(); |
587 |
} |
588 |
} |
589 |
} |
590 |
isPrinting = false;
|
591 |
} |
592 |
} |
593 |
|
594 |
public void _print(Graphics2D g, ViewPort viewPort, Cancellable cancel,double scale) |
595 |
throws DriverException {
|
596 |
draw(null, g, viewPort, cancel,scale);
|
597 |
} |
598 |
|
599 |
/**
|
600 |
* Devuelve el FMapWMSDriver.
|
601 |
*
|
602 |
* @return FMapWMSDriver
|
603 |
*
|
604 |
* @throws IllegalStateException
|
605 |
* @throws ValidationException
|
606 |
* @throws UnsupportedVersionException
|
607 |
* @throws IOException
|
608 |
*/
|
609 |
private FMapWMSDriver getDriver()
|
610 |
throws IllegalStateException, ValidationException, |
611 |
UnsupportedVersionException, IOException {
|
612 |
if (wms == null) { |
613 |
//wmsClient = WMSClientFactory.getClient(host);
|
614 |
wms = new FMapWMSDriver();
|
615 |
wms.createClient(host); |
616 |
|
617 |
} |
618 |
|
619 |
return wms;
|
620 |
} |
621 |
|
622 |
/**
|
623 |
* Devuelve el FMapWMSDriver.
|
624 |
*
|
625 |
* @return FMapWMSDriver
|
626 |
*
|
627 |
* @throws IllegalStateException
|
628 |
* @throws ValidationException
|
629 |
* @throws UnsupportedVersionException
|
630 |
* @throws IOException
|
631 |
*/
|
632 |
public void setDriver(FMapWMSDriver drv) { |
633 |
wms = drv; |
634 |
} |
635 |
|
636 |
/**
|
637 |
* Devuelve el URL.
|
638 |
*
|
639 |
* @return URL.
|
640 |
*/
|
641 |
public URL getHost() { |
642 |
return host;
|
643 |
} |
644 |
|
645 |
/**
|
646 |
* Inserta el URL.
|
647 |
*
|
648 |
* @param host URL.
|
649 |
*/
|
650 |
public void setHost(URL host) { |
651 |
this.host = host;
|
652 |
} |
653 |
|
654 |
/**
|
655 |
* Devuelve la informaci?n de la consulta.
|
656 |
*
|
657 |
* @return String.
|
658 |
*/
|
659 |
public String getInfoLayerQuery() { |
660 |
return infoLayerQuery;
|
661 |
} |
662 |
|
663 |
/**
|
664 |
* Inserta la informaci?n de la consulta.
|
665 |
*
|
666 |
* @param infoLayerQuery String.
|
667 |
*/
|
668 |
public void setInfoLayerQuery(String infoLayerQuery) { |
669 |
this.infoLayerQuery = infoLayerQuery;
|
670 |
} |
671 |
|
672 |
/**
|
673 |
* Devuelve la consulta.
|
674 |
*
|
675 |
* @return String.
|
676 |
*/
|
677 |
public String getLayerQuery() { |
678 |
return layerQuery;
|
679 |
} |
680 |
|
681 |
/**
|
682 |
* Inserta la consulta.
|
683 |
*
|
684 |
* @param layerQuery consulta.
|
685 |
*/
|
686 |
public void setLayerQuery(String layerQuery) { |
687 |
this.layerQuery = layerQuery;
|
688 |
} |
689 |
|
690 |
/**
|
691 |
* Devuelve el formato.
|
692 |
*
|
693 |
* @return Formato.
|
694 |
*/
|
695 |
public String getFormat() { |
696 |
return m_Format;
|
697 |
} |
698 |
|
699 |
/**
|
700 |
* Inserta el formato.
|
701 |
*
|
702 |
* @param format Formato.
|
703 |
*/
|
704 |
public void setFormat(String format) { |
705 |
m_Format = format; |
706 |
} |
707 |
|
708 |
/**
|
709 |
* Devuelve el SRS.
|
710 |
*
|
711 |
* @return SRS.
|
712 |
*/
|
713 |
public String getSRS() { |
714 |
return m_SRS;
|
715 |
} |
716 |
|
717 |
/**
|
718 |
* Inserta el SRS.
|
719 |
*
|
720 |
* @param m_srs SRS.
|
721 |
*/
|
722 |
public void setSRS(String m_srs) { |
723 |
m_SRS = m_srs; |
724 |
} |
725 |
|
726 |
/**
|
727 |
* Inserta la extensi?n total de la capa.
|
728 |
*
|
729 |
* @param fullExtent Rect?ngulo.
|
730 |
*/
|
731 |
public void setFullExtent(Rectangle2D fullExtent) { |
732 |
this.fullExtent = fullExtent;
|
733 |
} |
734 |
|
735 |
public HashMap getProperties() { |
736 |
HashMap info = new HashMap(); |
737 |
String[] layerNames = getLayerQuery().split(","); |
738 |
Vector layers = new Vector(layerNames.length); |
739 |
try {
|
740 |
if(getDriver().connect()){
|
741 |
for (int i = 0; i < layerNames.length; i++) { |
742 |
layers.add(i, wms.getLayer(layerNames[i])); |
743 |
} |
744 |
info.put("name", getName());
|
745 |
info.put("selectedLayers", layers);
|
746 |
info.put("host", getHost());
|
747 |
info.put("srs", getSRS());
|
748 |
info.put("format", getFormat());
|
749 |
info.put("wmsTransparency", new Boolean(wmsTransparency)); |
750 |
info.put("styles", styles);
|
751 |
info.put("dimensions", dimensions);
|
752 |
return info;
|
753 |
} |
754 |
} catch (Exception e) { |
755 |
e.printStackTrace(); |
756 |
} |
757 |
return null; |
758 |
} |
759 |
|
760 |
/**
|
761 |
* Asignar el estado del raster
|
762 |
* @param status
|
763 |
*/
|
764 |
public void setStatus(StatusRasterInterface status){ |
765 |
this.status = status;
|
766 |
} |
767 |
|
768 |
/**
|
769 |
* Obtiene el estado del raster
|
770 |
* @return
|
771 |
*/
|
772 |
public StatusRasterInterface getStatus(){
|
773 |
return this.status; |
774 |
} |
775 |
|
776 |
/* (non-Javadoc)
|
777 |
* @see com.iver.cit.gvsig.fmap.layers.RasterOperations#getAttributes()
|
778 |
*/
|
779 |
public ArrayList getAttributes() { |
780 |
if(rasterFile != null){ |
781 |
ArrayList attr = new ArrayList(); |
782 |
/* String dataType = "Byte";
|
783 |
if (rasterFile.getDataType() == DataBuffer.TYPE_BYTE) dataType = "Byte";
|
784 |
else if (rasterFile.getDataType() == DataBuffer.TYPE_SHORT)
|
785 |
dataType = "Short";
|
786 |
else if (rasterFile.getDataType() == DataBuffer.TYPE_USHORT)
|
787 |
dataType = "Unsigned Short";
|
788 |
else if (rasterFile.getDataType() == DataBuffer.TYPE_INT)
|
789 |
dataType = "Integer";
|
790 |
else if (rasterFile.getDataType() == DataBuffer.TYPE_FLOAT)
|
791 |
dataType = "Float";
|
792 |
else if (rasterFile.getDataType() == DataBuffer.TYPE_DOUBLE)
|
793 |
dataType = "Double";
|
794 |
else
|
795 |
dataType = "Unknown";
|
796 |
*/
|
797 |
Object [][] a = { |
798 |
{"Filename",rasterFile.getName().substring(rasterFile.getName().lastIndexOf("/")+1, rasterFile.getName().length())}, |
799 |
{"Filesize",new Long(rasterFile.getFileSize())}, |
800 |
{"Width",new Integer(rasterFile.getWidth())}, |
801 |
{"Height", new Integer(rasterFile.getHeight())}, |
802 |
{"Bands", new Integer(rasterFile.getBandCount())} |
803 |
//{"BandDataType", dataType}
|
804 |
}; |
805 |
for (int i=0; i<a.length; i++){ |
806 |
System.out.println("===> "+a[i][0]+" "+a[i][1]); |
807 |
attr.add(a[i]); |
808 |
} |
809 |
return attr;
|
810 |
} |
811 |
return null; |
812 |
} |
813 |
/* (non-Javadoc)
|
814 |
* @see com.iver.cit.gvsig.fmap.layers.RasterOperations#getFilterStack()
|
815 |
*/
|
816 |
public RasterFilterStack getFilterStack() {
|
817 |
if(raster!=null) |
818 |
return raster.filterStack;
|
819 |
return null; |
820 |
} |
821 |
/* (non-Javadoc)
|
822 |
* @see com.iver.cit.gvsig.fmap.layers.RasterOperations#getHeight()
|
823 |
*/
|
824 |
public double getHeight() { |
825 |
if(getGeoRasterFile() != null) |
826 |
return getGeoRasterFile().getHeight();
|
827 |
return 0; |
828 |
} |
829 |
/* (non-Javadoc)
|
830 |
* @see com.iver.cit.gvsig.fmap.layers.RasterOperations#getMaxX()
|
831 |
*/
|
832 |
public double getMaxX() { |
833 |
if(getPxRaster() != null) |
834 |
return getPxRaster().getExtent().getMax().getX();
|
835 |
return 0; |
836 |
} |
837 |
/* (non-Javadoc)
|
838 |
* @see com.iver.cit.gvsig.fmap.layers.RasterOperations#getMaxY()
|
839 |
*/
|
840 |
public double getMaxY() { |
841 |
if(getPxRaster() != null) |
842 |
return getPxRaster().getExtent().getMax().getY();
|
843 |
return 0; |
844 |
} |
845 |
/* (non-Javadoc)
|
846 |
* @see com.iver.cit.gvsig.fmap.layers.RasterOperations#getMinX()
|
847 |
*/
|
848 |
public double getMinX() { |
849 |
if(getPxRaster() != null) |
850 |
return getPxRaster().getExtent().getMin().getX();
|
851 |
return 0; |
852 |
} |
853 |
/* (non-Javadoc)
|
854 |
* @see com.iver.cit.gvsig.fmap.layers.RasterOperations#getMinY()
|
855 |
*/
|
856 |
public double getMinY() { |
857 |
if(getPxRaster() != null) |
858 |
return getPxRaster().getExtent().getMin().getY();
|
859 |
return 0; |
860 |
} |
861 |
/* (non-Javadoc)
|
862 |
* @see com.iver.cit.gvsig.fmap.layers.RasterOperations#getPixel(double, double)
|
863 |
*/
|
864 |
public int[] getPixel(double wcx, double wcy) { |
865 |
if(getPxRaster() != null) |
866 |
return getPxRaster().getPixel(wcx, wcy);
|
867 |
return null; |
868 |
} |
869 |
/* (non-Javadoc)
|
870 |
* @see com.iver.cit.gvsig.fmap.layers.RasterOperations#getSource()
|
871 |
*/
|
872 |
public RasterAdapter getSource() {
|
873 |
return null; |
874 |
} |
875 |
/* (non-Javadoc)
|
876 |
* @see com.iver.cit.gvsig.fmap.layers.RasterOperations#getWidth()
|
877 |
*/
|
878 |
public double getWidth() { |
879 |
if(getGeoRasterFile() != null) |
880 |
return getGeoRasterFile().getWidth();
|
881 |
return 0; |
882 |
} |
883 |
/* (non-Javadoc)
|
884 |
* @see com.iver.cit.gvsig.fmap.layers.RasterOperations#setBand(int, int)
|
885 |
*/
|
886 |
public void setBand(int flag, int nBand) { |
887 |
switch(flag){
|
888 |
case GeoRasterFile.RED_BAND:setBandR(nBand);break; |
889 |
case GeoRasterFile.GREEN_BAND:setBandG(nBand);break; |
890 |
case GeoRasterFile.BLUE_BAND:setBandB(nBand);break; |
891 |
} |
892 |
} |
893 |
/* (non-Javadoc)
|
894 |
* @see com.iver.cit.gvsig.fmap.layers.RasterOperations#setFilterStack(org.cresques.io.raster.RasterFilterStack)
|
895 |
*/
|
896 |
public void setFilterStack(RasterFilterStack stack) { |
897 |
this.filterStack = stack;
|
898 |
} |
899 |
/* (non-Javadoc)
|
900 |
* @see com.iver.cit.gvsig.fmap.layers.RasterOperations#setPos(int, int)
|
901 |
*/
|
902 |
public void setPos(int x, int y) { |
903 |
this.posX = x;
|
904 |
this.posY = y;
|
905 |
} |
906 |
|
907 |
/* (non-Javadoc)
|
908 |
* @see com.iver.cit.gvsig.fmap.layers.RasterOperations#setPosWC(double, double)
|
909 |
*/
|
910 |
public void setPosWC(double x, double y) { |
911 |
this.posXWC = x;
|
912 |
this.posYWC = y;
|
913 |
} |
914 |
|
915 |
/* (non-Javadoc)
|
916 |
* @see com.iver.cit.gvsig.fmap.layers.RasterOperations#setRGB(int, int, int)
|
917 |
*/
|
918 |
public void setRGB(int r, int g, int b) { |
919 |
this.r = r;
|
920 |
this.g = g;
|
921 |
this.b = b;
|
922 |
} |
923 |
/* (non-Javadoc)
|
924 |
* @see com.iver.cit.gvsig.fmap.layers.RasterOperations#setSource(com.iver.cit.gvsig.fmap.layers.RasterAdapter)
|
925 |
*/
|
926 |
public void setSource(RasterAdapter ra) { |
927 |
} |
928 |
/**
|
929 |
* @return Returns the raster.
|
930 |
*/
|
931 |
public PxRaster getPxRaster() {
|
932 |
return raster;
|
933 |
} |
934 |
/**
|
935 |
* @return Returns the rasterFile.
|
936 |
*/
|
937 |
public GeoRasterFile getGeoRasterFile() {
|
938 |
return rasterFile;
|
939 |
} |
940 |
|
941 |
public void setTransparency(int trans) { |
942 |
this.transparency = trans;
|
943 |
} |
944 |
|
945 |
/**
|
946 |
* Sets the R-band.
|
947 |
*
|
948 |
* Asigna la banda R.
|
949 |
* @param r
|
950 |
*/
|
951 |
public void setBandR(int r){ |
952 |
this.rband = r;
|
953 |
} |
954 |
|
955 |
/**
|
956 |
* Sets the G-band.
|
957 |
*
|
958 |
* Asigna la banda G
|
959 |
* @param g
|
960 |
*/
|
961 |
public void setBandG(int g){ |
962 |
this.gband = g;
|
963 |
} |
964 |
|
965 |
/**
|
966 |
* Sets the B-band.
|
967 |
*
|
968 |
* Asigna la banda B
|
969 |
* @param b
|
970 |
*/
|
971 |
public void setBandB(int b){ |
972 |
this.bband = b;
|
973 |
} |
974 |
|
975 |
/**
|
976 |
* @return Returns the wmsTransparency.
|
977 |
*/
|
978 |
public boolean isWmsTransparency() { |
979 |
return wmsTransparency;
|
980 |
} |
981 |
|
982 |
/**
|
983 |
* @param wmsTransparency The wmsTransparency to set.
|
984 |
*/
|
985 |
public void setWmsTransparency(boolean wmsTransparency) { |
986 |
this.wmsTransparency = wmsTransparency;
|
987 |
} |
988 |
|
989 |
/**
|
990 |
* @param styles
|
991 |
*/
|
992 |
public void setStyles(Vector styles) { |
993 |
//laura:
|
994 |
//layer query is built with the layer in reverse order
|
995 |
// so here we build the styles upside-down.
|
996 |
if (styles != null) |
997 |
{ |
998 |
this.styles = new Vector(); |
999 |
for(int i = styles.size()-1; i>=0; i--) |
1000 |
{ |
1001 |
this.styles.add(styles.elementAt(i));
|
1002 |
} |
1003 |
} |
1004 |
} |
1005 |
|
1006 |
/**
|
1007 |
* @param dimensions
|
1008 |
*/
|
1009 |
public void setDimensions(Vector dimensions) { |
1010 |
this.dimensions = dimensions;
|
1011 |
} |
1012 |
|
1013 |
public void setOnlineResources(Hashtable onlineResources) { |
1014 |
this.onlineResources = onlineResources;
|
1015 |
} |
1016 |
|
1017 |
} |