svn-gvsig-desktop / tags / v2_0_0_Build_2020 / extensions / extWCS / src / org / gvsig / wcs / fmap / layers / FLyrWCS.java @ 33775
History | View | Annotate | Download (40.7 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 org.gvsig.wcs.fmap.layers; |
42 |
|
43 |
import java.awt.Dimension; |
44 |
import java.awt.Graphics2D; |
45 |
import java.awt.Point; |
46 |
import java.awt.Rectangle; |
47 |
import java.awt.geom.AffineTransform; |
48 |
import java.awt.geom.NoninvertibleTransformException; |
49 |
import java.awt.geom.Point2D; |
50 |
import java.awt.geom.Rectangle2D; |
51 |
import java.awt.image.BufferedImage; |
52 |
import java.awt.image.DataBuffer; |
53 |
import java.io.File; |
54 |
import java.io.IOException; |
55 |
import java.net.MalformedURLException; |
56 |
import java.net.URL; |
57 |
import java.util.ArrayList; |
58 |
import java.util.Hashtable; |
59 |
import java.util.Map; |
60 |
|
61 |
import javax.print.attribute.PrintRequestAttributeSet; |
62 |
|
63 |
import org.cresques.cts.ICoordTrans; |
64 |
import org.exolab.castor.xml.ValidationException; |
65 |
|
66 |
import org.gvsig.compat.net.ICancellable; |
67 |
import org.gvsig.fmap.crs.CRSFactory; |
68 |
import org.gvsig.fmap.dal.DataTypes; |
69 |
import org.gvsig.fmap.dal.exception.ReadException; |
70 |
import org.gvsig.fmap.geom.GeometryLocator; |
71 |
import org.gvsig.fmap.geom.GeometryManager; |
72 |
import org.gvsig.fmap.geom.Geometry.SUBTYPES; |
73 |
import org.gvsig.fmap.geom.Geometry.TYPES; |
74 |
import org.gvsig.fmap.geom.exception.CreateEnvelopeException; |
75 |
import org.gvsig.fmap.geom.exception.CreateGeometryException; |
76 |
import org.gvsig.fmap.geom.primitive.Envelope; |
77 |
import org.gvsig.fmap.mapcontext.ViewPort; |
78 |
import org.gvsig.fmap.mapcontext.exceptions.ConnectionErrorLayerException; |
79 |
import org.gvsig.fmap.mapcontext.exceptions.LoadLayerException; |
80 |
import org.gvsig.fmap.mapcontext.exceptions.UnsupportedVersionLayerException; |
81 |
import org.gvsig.fmap.mapcontext.layers.FLayer; |
82 |
import org.gvsig.fmap.mapcontext.layers.Tiling; |
83 |
import org.gvsig.fmap.raster.layers.FLyrRasterSE; |
84 |
import org.gvsig.fmap.raster.layers.IRasterLayerActions; |
85 |
import org.gvsig.fmap.raster.layers.IStatusRaster; |
86 |
import org.gvsig.fmap.raster.layers.StatusLayerRaster; |
87 |
import org.gvsig.raster.dataset.CompositeDataset; |
88 |
import org.gvsig.raster.dataset.IBuffer; |
89 |
import org.gvsig.raster.dataset.MosaicNotValidException; |
90 |
import org.gvsig.raster.dataset.MultiRasterDataset; |
91 |
import org.gvsig.raster.dataset.NotSupportedExtensionException; |
92 |
import org.gvsig.raster.dataset.RasterDriverException; |
93 |
import org.gvsig.raster.datastruct.Extent; |
94 |
import org.gvsig.raster.datastruct.ViewPortData; |
95 |
import org.gvsig.raster.grid.GridTransparency; |
96 |
import org.gvsig.raster.grid.filter.FilterTypeException; |
97 |
import org.gvsig.raster.grid.filter.RasterFilterList; |
98 |
import org.gvsig.raster.grid.filter.RasterFilterListManager; |
99 |
import org.gvsig.remoteclient.wcs.WCSStatus; |
100 |
import org.gvsig.tools.ToolsLocator; |
101 |
import org.gvsig.tools.dynobject.DynClass; |
102 |
import org.gvsig.tools.dynobject.DynStruct; |
103 |
import org.gvsig.tools.persistence.PersistenceManager; |
104 |
import org.gvsig.tools.persistence.PersistentState; |
105 |
import org.gvsig.tools.persistence.exception.PersistenceException; |
106 |
import org.gvsig.tools.task.Cancellable; |
107 |
import org.gvsig.wcs.fmap.drivers.wcs.FMapWCSDriver; |
108 |
import org.gvsig.wcs.fmap.drivers.wcs.FMapWCSDriverFactory; |
109 |
import org.gvsig.wcs.fmap.drivers.wcs.WCSDriverException; |
110 |
|
111 |
|
112 |
|
113 |
/**
|
114 |
* Class for the WCS layer.
|
115 |
*
|
116 |
* Capa para el WCS.
|
117 |
*
|
118 |
* Las capas WCS son tileadas para descargarlas del servidor. Esto quiere decir que
|
119 |
* est?n formadas por multiples ficheros raster. Por esto la fuente de datos raster (IRasterDatasource)
|
120 |
* de la capa FLyrWCS es un objeto de tipo CompositeDataset. Este objeto est? compuesto por un array
|
121 |
* bidimensional de MultiRasterDataset. Cada uno de los MultiRasterDataset corresponde con un tile
|
122 |
* salvado en disco. Estos MultiRasterDataset se crean cada vez que se repinta ya que en WCS a cada
|
123 |
* zoom varian los ficheros fuente. La secuencia de creaci?n de un CompositeDataset ser?a la siguiente:
|
124 |
* <UL>
|
125 |
* <LI>Se hace una petici?n de dibujado por parte del usuario llamando al m?todo draw de FLyrWCS</LI>
|
126 |
* <LI>Se tilea la petici?n</LI>
|
127 |
* <LI>Cada tile se dibuja abriendo una FLyrRaster para ese tile</LI>
|
128 |
* <LI>Si es el primer dibujado se guarda una referencia en la capa WMS a las propiedades de renderizado, orden de bandas,
|
129 |
* transparencia, filtros aplicados, ...</LI>
|
130 |
* <LI>Si no es el primer dibujado se asignan las propiedades de renderizado cuya referencia se guarda en la capa WMS</LI>
|
131 |
* <LI>Se guarda el MultiRasterDataset de cada tile</LI>
|
132 |
* <LI>Al acabar todos los tiles creamos un CompositeDataset con los MultiRasterDataset de todos los tiles</LI>
|
133 |
* <LI>Asignamos a la capa la referencia de las propiedades de renderizado que tenemos almacenadas. De esta forma si hay
|
134 |
* alguna modificaci?n desde el cuadro de propiedades ser? efectiva sobre los tiles que se dibujan.</LI>
|
135 |
* </UL>
|
136 |
*
|
137 |
* @author jaume - jaume.dominguez@iver.es
|
138 |
*/
|
139 |
public class FLyrWCS extends FLyrRasterSE { |
140 |
public static final String PERSISTENT_NAME = "FLyrWCS_Persistent"; |
141 |
public static final String PERSISTENT_DESCRIPTION = "FLyrWCS Persistent Definition"; |
142 |
|
143 |
private FMapWCSDriver wcs = null; |
144 |
|
145 |
private URL host; |
146 |
private String coverageName; |
147 |
private Envelope fullEnvelope;
|
148 |
private String format; |
149 |
private String srs; |
150 |
private String time; |
151 |
private String parameter; |
152 |
private Point2D maxRes; |
153 |
private Hashtable onlineResources = new Hashtable(); |
154 |
|
155 |
private WCSStatus wcsStatus = new WCSStatus(); |
156 |
|
157 |
private int posX = 0, posY = 0; |
158 |
private double posXWC = 0, posYWC = 0; |
159 |
private int r = 0, g = 0, b = 0; |
160 |
private boolean firstLoad = false; |
161 |
private VisualStatus visualStatus = new VisualStatus(); |
162 |
|
163 |
private boolean mustTileDraw = false; |
164 |
private int maxTileDrawWidth = 1023; |
165 |
private int maxTileDrawHeight = 1023; |
166 |
//private int maxTilePrintWidth = 250;
|
167 |
//private int maxTilePrintHeight = 250;
|
168 |
/**
|
169 |
* Lista de filtros aplicada en la renderizaci?n
|
170 |
*/
|
171 |
private RasterFilterList filterList = null; |
172 |
private GridTransparency transparency = null; |
173 |
private int[] renderBands = null; |
174 |
private FLyrRasterSE[] layerRaster = null; |
175 |
private ArrayList filterArguments = null; |
176 |
private int lastNColumns = 0; |
177 |
private int lastNRows = 0; |
178 |
|
179 |
private class MyCancellable implements ICancellable |
180 |
{ |
181 |
|
182 |
private Cancellable original;
|
183 |
public MyCancellable(Cancellable cancelOriginal)
|
184 |
{ |
185 |
this.original = cancelOriginal;
|
186 |
} |
187 |
public boolean isCanceled() { |
188 |
return original.isCanceled();
|
189 |
} |
190 |
public Object getID() { |
191 |
return this; |
192 |
} |
193 |
|
194 |
} |
195 |
|
196 |
public FLyrWCS(){
|
197 |
super();
|
198 |
} |
199 |
|
200 |
public FLyrWCS(Map args) throws ReadException { |
201 |
FMapWCSDriver drv = null;
|
202 |
String host = (String)args.get("HOST"); |
203 |
String sCoverage = (String) args.get("COVERAGE"); |
204 |
|
205 |
try {
|
206 |
this.setHost(new URL(host)); |
207 |
} catch (MalformedURLException e) { |
208 |
//e.printStackTrace();
|
209 |
throw new ReadException("Malformed host URL, '" + host + "' (" |
210 |
+ e.toString() + ").", e);
|
211 |
} |
212 |
try {
|
213 |
drv = this.getDriver();
|
214 |
} catch (Exception e) { |
215 |
// e.printStackTrace();
|
216 |
throw new ReadException("Can't get driver to host '" + host + "' (" |
217 |
+ e.toString() + ").", e);
|
218 |
} |
219 |
|
220 |
try{
|
221 |
if (!drv.connect(false, null)){ |
222 |
throw new ReadException( |
223 |
"Can't connect to host '" + host + "'.", null); |
224 |
} |
225 |
}catch(Exception e){ |
226 |
throw new ReadException("Can't connect to host '" + host + "'.", e); |
227 |
} |
228 |
|
229 |
WCSLayer wcsNode = drv.getLayer(sCoverage); |
230 |
|
231 |
if (wcsNode == null){ |
232 |
throw new ReadException("The server '" + host |
233 |
+ "' doesn't has the coverage '" + sCoverage + "'.", null); |
234 |
} |
235 |
|
236 |
try{
|
237 |
this.setFullExtent(drv.getFullExtent(sCoverage,
|
238 |
(String) args.get("CRS"))); |
239 |
this.setFormat((String) args.get("FORMAT")); |
240 |
this.setParameter("BANDS=" + (String) args.get("BANDS")); |
241 |
this.setSRS((String) args.get("CRS")); |
242 |
this.setName(sCoverage);
|
243 |
this.setCoverageName(sCoverage);
|
244 |
}catch (Exception e){ |
245 |
throw new ReadException("The server '" + host |
246 |
+ "' is not able to load the coverage '"
|
247 |
+ sCoverage + "'.", e);
|
248 |
} |
249 |
|
250 |
} |
251 |
|
252 |
/**
|
253 |
* Clase que contiene los datos de visualizaci?n de WCS. Tiene datos que representan al
|
254 |
* raster en la vista. Este raster puede estar compuesto por tiles por lo que valores
|
255 |
* como el ancho total o el m?nimo o m?ximo deben ser calculados a partir de todos los
|
256 |
* tiles visualizados.
|
257 |
* @author Nacho Brodin (brodin_ign@gva.es)
|
258 |
*/
|
259 |
private class VisualStatus { |
260 |
/**
|
261 |
* Ancho y alto de la imagen o del conjunto de tiles si los tiene. Coincide con
|
262 |
* el ancho y alto del viewPort
|
263 |
*/
|
264 |
private int width = 0, height = 0; |
265 |
private double minX = 0D, minY = 0D, maxX = 0D, maxY = 0D; |
266 |
private int bandCount = 0; |
267 |
private int dataType = DataBuffer.TYPE_UNDEFINED; |
268 |
|
269 |
/**
|
270 |
* Ancho y alto total del raster que ser? la suma de todos los tiles.
|
271 |
*/
|
272 |
private int rasterWidth = 0, rasterHeight = 0; |
273 |
private double rasterMinX = Double.MAX_VALUE, rasterMinY = Double.MAX_VALUE; |
274 |
private double rasterMaxX = 0, rasterMaxY = 0; |
275 |
/**
|
276 |
* Lista de nombre de fichero que componen toda la visualizaci?n.
|
277 |
*/
|
278 |
private String[] fileNames = null; |
279 |
} |
280 |
|
281 |
/**
|
282 |
* @deprecated
|
283 |
* @see com.iver.cit.gvsig.fmap.layers.layerOperations.InfoByPoint#getInfo
|
284 |
*/
|
285 |
public String queryByPoint(Point p) { |
286 |
String data = "<file:"+getName().replaceAll("[^a-zA-Z0-9]","")+">\n"; |
287 |
ArrayList attr = this.getAttributes(); |
288 |
data += " <raster\n";
|
289 |
data += " File=\""+getName()+"\"\n"; |
290 |
for (int i=0; i<attr.size(); i++) { |
291 |
Object [] a = (Object []) attr.get(i); |
292 |
|
293 |
data += " "+a[0].toString()+"="; |
294 |
if (a[1].toString() instanceof String) { |
295 |
data += "\""+a[1].toString()+"\"\n"; |
296 |
} else {
|
297 |
data += a[1].toString()+"\n"; |
298 |
} |
299 |
} |
300 |
data += " Point=\""+posX+" , "+posY+"\"\n"; |
301 |
data += " Point_WC=\""+posXWC+" , "+posYWC+"\"\n"; |
302 |
data += " RGB=\""+r+", "+g+", "+b+"\"\n"; |
303 |
data += " />\n";
|
304 |
|
305 |
data += "</file:"+getName().replaceAll("[^a-zA-Z0-9]","")+">\n"; |
306 |
System.out.println(data);
|
307 |
return data;
|
308 |
} |
309 |
|
310 |
// /**
|
311 |
// * @see com.iver.cit.gvsig.fmap.layers.layerOperations.InfoByPoint#getInfo
|
312 |
// */
|
313 |
// public XMLItem[] getInfo(Point point, double tolerance, Cancellable cancel)
|
314 |
// throws ReadException {
|
315 |
// return super.getInfo(point, tolerance, cancel);
|
316 |
// }
|
317 |
|
318 |
/**
|
319 |
* Devuelve el envelope en la proyeccion de la vista
|
320 |
*
|
321 |
*/
|
322 |
public Envelope getFullEnvelope() {
|
323 |
Envelope rAux; |
324 |
rAux = this.fullEnvelope;
|
325 |
GeometryManager geoMan = GeometryLocator.getGeometryManager(); |
326 |
|
327 |
try {
|
328 |
rAux = geoMan.createEnvelope(SUBTYPES.GEOM2D); |
329 |
|
330 |
// Esto es para cuando se crea una capa nueva con el fullExtent de
|
331 |
// ancho
|
332 |
// y alto 0.
|
333 |
if (rAux == null || rAux.getMaximum(0) - rAux.getMinimum(0) == 0 |
334 |
&& rAux.getMaximum(1) - rAux.getMinimum(1) == 0) { |
335 |
rAux = geoMan.createEnvelope(SUBTYPES.GEOM2D); |
336 |
org.gvsig.fmap.geom.primitive.Point pl = (org.gvsig.fmap.geom.primitive.Point) geoMan |
337 |
.create(TYPES.POINT, SUBTYPES.GEOM2D); |
338 |
org.gvsig.fmap.geom.primitive.Point pu = (org.gvsig.fmap.geom.primitive.Point) geoMan |
339 |
.create(TYPES.POINT, SUBTYPES.GEOM2D); |
340 |
pl.setX(0);
|
341 |
pl.setY(0);
|
342 |
pu.setX(100);
|
343 |
pu.setY(100);
|
344 |
rAux.setLowerCorner(pl); |
345 |
rAux.setUpperCorner(pu); |
346 |
} |
347 |
// Si existe reproyecci?n, reproyectar el extent
|
348 |
ICoordTrans ct = getCoordTrans(); |
349 |
if (ct != null) { |
350 |
Point2D pt1 = new Point2D.Double(rAux.getMinimum(0), rAux |
351 |
.getMinimum(1));
|
352 |
Point2D pt2 = new Point2D.Double(rAux.getMaximum(0), rAux |
353 |
.getMaximum(1));
|
354 |
pt1 = ct.convert(pt1, null);
|
355 |
pt2 = ct.convert(pt2, null);
|
356 |
org.gvsig.fmap.geom.primitive.Point pt1_geom = (org.gvsig.fmap.geom.primitive.Point) geoMan |
357 |
.create(TYPES.POINT, SUBTYPES.GEOM2D); |
358 |
pt1_geom.setX(pt1.getX()); |
359 |
pt1_geom.setY(pt1.getY()); |
360 |
org.gvsig.fmap.geom.primitive.Point pt2_geom = (org.gvsig.fmap.geom.primitive.Point) geoMan |
361 |
.create(TYPES.POINT, SUBTYPES.GEOM2D); |
362 |
pt2_geom.setX(pt2.getX()); |
363 |
pt2_geom.setY(pt2.getY()); |
364 |
|
365 |
rAux.setLowerCorner(pt1_geom); |
366 |
rAux.setUpperCorner(pt2_geom); |
367 |
} |
368 |
} catch (CreateEnvelopeException e) {
|
369 |
// TODO Auto-generated catch block
|
370 |
e.printStackTrace(); |
371 |
this.setAvailable(false); |
372 |
return null; |
373 |
} catch (CreateGeometryException e) {
|
374 |
// TODO Auto-generated catch block
|
375 |
e.printStackTrace(); |
376 |
this.setAvailable(false); |
377 |
return null; |
378 |
} |
379 |
return rAux;
|
380 |
|
381 |
} |
382 |
|
383 |
/*
|
384 |
* (non-Javadoc)
|
385 |
* @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)
|
386 |
*/
|
387 |
public void draw(BufferedImage image, Graphics2D g, ViewPort viewPort, |
388 |
Cancellable cancel, double scale) throws ReadException { |
389 |
enableStopped(); |
390 |
// callLegendChanged(null);
|
391 |
lastNColumns = lastNRows = 0;
|
392 |
|
393 |
closeAndFree(); |
394 |
|
395 |
if (isWithinScale(scale)) {
|
396 |
Point2D p = viewPort.getOffset();
|
397 |
// p will be (0, 0) when drawing a view or other when painting onto
|
398 |
// the Layout.
|
399 |
visualStatus.width = viewPort.getImageWidth(); |
400 |
visualStatus.height = viewPort.getImageHeight(); |
401 |
Envelope env = viewPort.getAdjustedExtent(); |
402 |
visualStatus.minX = env.getMinimum(0);
|
403 |
visualStatus.minY = env.getMinimum(1);
|
404 |
visualStatus.maxX = env.getMaximum(0);
|
405 |
visualStatus.maxY = env.getMaximum(1);
|
406 |
visualStatus.rasterWidth = 0;
|
407 |
visualStatus.rasterHeight = 0;
|
408 |
visualStatus.rasterMinX = Double.MAX_VALUE;
|
409 |
visualStatus.rasterMinY = Double.MAX_VALUE;
|
410 |
visualStatus.rasterMaxX = 0;
|
411 |
visualStatus.rasterMaxY = 0;
|
412 |
visualStatus.fileNames = new String[1]; |
413 |
|
414 |
try {
|
415 |
if (true) { |
416 |
if (viewPort.getImageWidth() <= maxTileDrawWidth && viewPort.getImageHeight() <= maxTileDrawHeight) {
|
417 |
layerRaster = new FLyrRasterSE[1]; |
418 |
drawTile(g, viewPort, cancel, 0, scale, 0); |
419 |
if(layerRaster != null && layerRaster[0] != null) { |
420 |
dataset = layerRaster[0].getDataSource();
|
421 |
getRender().setLastRenderBuffer(layerRaster[0].getRender().getLastRenderBuffer());
|
422 |
initializeRasterLayer(null, new IBuffer[][] { { layerRaster[0].getRender().getLastRenderBuffer() } }); |
423 |
} |
424 |
} else {
|
425 |
Rectangle r = new Rectangle((int) p.getX(), (int) p.getY(), viewPort.getImageWidth(), viewPort.getImageHeight()); |
426 |
Tiling tiles = new Tiling(maxTileDrawWidth, maxTileDrawHeight, r);
|
427 |
tiles.setAffineTransform((AffineTransform) viewPort.getAffineTransform().clone());
|
428 |
MultiRasterDataset[][] datasets = new MultiRasterDataset[tiles.getNumRows()][tiles.getNumCols()]; |
429 |
IBuffer[][] buf = new IBuffer[tiles.getNumRows()][tiles.getNumCols()]; |
430 |
visualStatus.fileNames = new String[tiles.getNumTiles()]; |
431 |
layerRaster = new FLyrRasterSE[tiles.getNumTiles()];
|
432 |
lastNColumns = tiles.getNumCols(); |
433 |
lastNRows = tiles.getNumRows(); |
434 |
for (int tileNr = 0; tileNr < tiles.getNumTiles(); tileNr++) { |
435 |
// drawing part
|
436 |
try {
|
437 |
ViewPort vp = tiles.getTileViewPort(viewPort, tileNr); |
438 |
boolean painted = drawTile(g, vp, cancel, tileNr, scale, tileNr);
|
439 |
if( layerRaster != null && |
440 |
layerRaster[tileNr] != null &&
|
441 |
painted) { |
442 |
datasets[(int) (tileNr / tiles.getNumCols())][tileNr % tiles.getNumCols()] = (MultiRasterDataset) layerRaster[tileNr].getDataSource().newDataset();
|
443 |
buf[(int) (tileNr / tiles.getNumCols())][tileNr % tiles.getNumCols()] = layerRaster[tileNr].getRender().getLastRenderBuffer();
|
444 |
} |
445 |
} catch (NoninvertibleTransformException e) { |
446 |
e.printStackTrace(); |
447 |
} |
448 |
} |
449 |
try {
|
450 |
if (datasets != null && datasets[0][0] != null) { |
451 |
dataset = new CompositeDataset(datasets);
|
452 |
initializeRasterLayer(datasets, buf); |
453 |
buf = null;
|
454 |
} |
455 |
} catch (MosaicNotValidException e) {
|
456 |
throw new ReadException( |
457 |
"No hay continuidad en el mosaico.", e);
|
458 |
} catch (LoadLayerException e) {
|
459 |
throw new ReadException( |
460 |
"Error inicializando la capa.", e);
|
461 |
} |
462 |
} |
463 |
} else {
|
464 |
layerRaster = new FLyrRasterSE[1]; |
465 |
drawTile(g, viewPort, cancel, 0, scale, 0); |
466 |
if(layerRaster != null && layerRaster[0] != null) { |
467 |
dataset = layerRaster[0].getDataSource();
|
468 |
getRender().setLastRenderBuffer(layerRaster[0].getRender().getLastRenderBuffer());
|
469 |
initializeRasterLayer(null, new IBuffer[][] { { layerRaster[0].getRender().getLastRenderBuffer() } }); |
470 |
} |
471 |
} |
472 |
} catch (ConnectionErrorLayerException e) {
|
473 |
e.printStackTrace(); |
474 |
} catch (UnsupportedVersionLayerException e) {
|
475 |
e.printStackTrace(); |
476 |
} catch (LoadLayerException e) {
|
477 |
e.printStackTrace(); |
478 |
} |
479 |
} |
480 |
disableStopped(); |
481 |
// callLegendChanged(null);
|
482 |
|
483 |
/*Runtime r = Runtime.getRuntime();
|
484 |
System.err.println("********************WCS**********************");
|
485 |
System.err.println("Memoria Total: " + (r.totalMemory() / 1024) +"KB");
|
486 |
System.err.println("Memoria Usada: " + ((r.totalMemory() - r.freeMemory()) / 1024) +"KB");
|
487 |
System.err.println("Memoria Libre: " + (r.freeMemory() / 1024) +"KB");
|
488 |
System.err.println("Memoria MaxMemory: " + (r.maxMemory() / 1024) +"KB");
|
489 |
System.err.println("*********************************************");*/
|
490 |
} |
491 |
|
492 |
/**
|
493 |
* Closes files and releases memory (pointers to null)
|
494 |
*/
|
495 |
private void closeAndFree() { |
496 |
while(readingData != null && readingData.compareTo(Thread.currentThread().toString()) != 0) |
497 |
try {
|
498 |
Thread.sleep(100); |
499 |
} catch (InterruptedException e) { |
500 |
} |
501 |
|
502 |
if(dataset != null) { |
503 |
dataset.close(); |
504 |
dataset = null;
|
505 |
} |
506 |
|
507 |
//Cerramos el dataset asociado a la capa si est? abierto.
|
508 |
if(layerRaster != null) { |
509 |
for (int i = 0; i < layerRaster.length; i++) { |
510 |
if(layerRaster[i] != null) { |
511 |
layerRaster[i].setRemoveRasterFlag(true);
|
512 |
layerRaster[i].getDataSource().close(); |
513 |
layerRaster[i].getRender().free(); |
514 |
layerRaster[i].getBufferFactory().free(); |
515 |
layerRaster[i] = null;
|
516 |
} |
517 |
} |
518 |
} |
519 |
getRender().free(); |
520 |
System.gc();
|
521 |
} |
522 |
|
523 |
/**
|
524 |
* Acciones que se realizan despu?s de asignar la fuente de datos a
|
525 |
* la capa raster.
|
526 |
*
|
527 |
* @throws LoadLayerException
|
528 |
*/
|
529 |
private void initializeRasterLayer(MultiRasterDataset[][] datasets, IBuffer[][] buf) throws LoadLayerException { |
530 |
if(this.filterList != null) |
531 |
getRender().setFilterList(filterList); |
532 |
|
533 |
if(this.renderBands != null) |
534 |
getRender().setRenderBands(renderBands); |
535 |
if(datasets != null) { |
536 |
String[][] names = new String[datasets.length][datasets[0].length]; |
537 |
for (int i = 0; i < datasets.length; i++) { |
538 |
for (int j = 0; j < datasets[i].length; j++) { |
539 |
if(datasets[i][j] != null) |
540 |
names[i][j] = datasets[i][j].getDataset(0)[0].getFName(); |
541 |
} |
542 |
} |
543 |
super.setLoadParams(names);
|
544 |
} |
545 |
super.init();
|
546 |
if(buf != null) { |
547 |
int drawablesBandCount = layerRaster[0].getDataSource().getBands().getDrawableBandsCount(); |
548 |
IBuffer buff = null;
|
549 |
if(dataset instanceof CompositeDataset) |
550 |
buff = ((CompositeDataset)dataset).generateBuffer(buf, drawablesBandCount); |
551 |
else
|
552 |
buff = buf[0][0]; |
553 |
|
554 |
if(getRender().getLastRenderBuffer() != null) |
555 |
getRender().getLastRenderBuffer().free(); |
556 |
getRender().setLastRenderBuffer(buff); |
557 |
} |
558 |
|
559 |
if (transparency == null) |
560 |
transparency = new GridTransparency(getDataSource().getTransparencyFilesStatus());
|
561 |
|
562 |
if(getRender().getLastTransparency() != null) |
563 |
getRender().getLastTransparency().free(); |
564 |
getRender().setLastTransparency(transparency); |
565 |
} |
566 |
|
567 |
/**
|
568 |
* This is the method used to draw a tile in a WCS mosaic layer.
|
569 |
*
|
570 |
* @param tile
|
571 |
* Tile number to draw
|
572 |
* @throws ReadException
|
573 |
* @return true when a tile has been painted
|
574 |
*/
|
575 |
private boolean drawTile(Graphics2D g, ViewPort vp, Cancellable cancel, |
576 |
int tile, double scale, int nLyr) throws LoadLayerException, ReadException { |
577 |
|
578 |
// Compute the query geometry
|
579 |
// 1. Check if it is within borders
|
580 |
Envelope envelope = getFullEnvelope(); |
581 |
Envelope vpEnvelope = vp.getAdjustedExtent(); |
582 |
if (!vpEnvelope.intersects(envelope)) {
|
583 |
return false; |
584 |
} |
585 |
|
586 |
// 2. Compute extent to be requested.
|
587 |
Rectangle2D bBox = new Rectangle2D.Double(); |
588 |
Rectangle2D.intersect(getRectable2DFromEnvelope(vpEnvelope),
|
589 |
getRectable2DFromEnvelope(envelope), bBox); |
590 |
|
591 |
// 3. Compute size in pixels
|
592 |
double scalex = vp.getAffineTransform().getScaleX();
|
593 |
double scaley = vp.getAffineTransform().getScaleY();
|
594 |
int wImg = (int) Math.ceil(Math.abs(bBox.getWidth() * scalex) + 1); |
595 |
int hImg = (int) Math.ceil(Math.abs(bBox.getHeight() * scaley) + 1); |
596 |
Dimension sz = new Dimension(wImg, hImg); |
597 |
|
598 |
if ((wImg <= 0) || (hImg <= 0)) { |
599 |
return false; |
600 |
} |
601 |
|
602 |
try {
|
603 |
sz = new Dimension(wImg, hImg); |
604 |
|
605 |
wcsStatus.setCoveraName( coverageName ); |
606 |
wcsStatus.setExtent( bBox ); |
607 |
wcsStatus.setFormat( format ); |
608 |
wcsStatus.setHeight( hImg ); |
609 |
wcsStatus.setWidth( wImg ); |
610 |
wcsStatus.setSrs(srs); |
611 |
wcsStatus.setParameters( parameter ); |
612 |
wcsStatus.setTime( time ); |
613 |
wcsStatus.setOnlineResource((String) onlineResources.get("GetCoverage")); |
614 |
|
615 |
File f = getDriver().getCoverage(wcsStatus, new MyCancellable(cancel)); |
616 |
if (f == null) { |
617 |
return false; |
618 |
} |
619 |
String nameWordFile = f.getPath() + getExtensionWorldFile();
|
620 |
org.gvsig.andami.Utilities.createTemp(nameWordFile, this.getDataWorldFile(bBox, sz));
|
621 |
|
622 |
IStatusRaster status = super.getStatus();
|
623 |
if(status!=null && firstLoad){ |
624 |
try {
|
625 |
status.applyStatus(this);
|
626 |
} catch (NotSupportedExtensionException e) {
|
627 |
throw new ReadException("", e); |
628 |
} catch (RasterDriverException e) {
|
629 |
throw new ReadException("", e); |
630 |
} catch (FilterTypeException e) {
|
631 |
throw new ReadException("", e); |
632 |
} |
633 |
firstLoad = false;
|
634 |
} |
635 |
ViewPortData vpData = new ViewPortData(
|
636 |
vp.getProjection(), new Extent(bBox), sz );
|
637 |
vpData.setMat(vp.getAffineTransform()); |
638 |
|
639 |
String filePath = f.getAbsolutePath();
|
640 |
visualStatus.fileNames[tile] = filePath; |
641 |
|
642 |
try {
|
643 |
rasterProcess(filePath, g, vp, scale, cancel, nLyr); |
644 |
} catch (FilterTypeException e) {
|
645 |
} |
646 |
|
647 |
// this.getRender().draw(g, vpData);
|
648 |
// rasterProcess(g, vpData, f);
|
649 |
|
650 |
// } catch (ValidationException e) {
|
651 |
// UnknownResponseFormatExceptionType type =
|
652 |
// new UnknownResponseFormatExceptionType();
|
653 |
// type.setLayerName(getName());
|
654 |
// try {
|
655 |
// type.setDriverName(getDriver().getName());
|
656 |
// } catch (Exception e1) {
|
657 |
// e1.printStackTrace();
|
658 |
// }
|
659 |
// type.setFormat(format);
|
660 |
// type.setHost(host);
|
661 |
// type.setProtocol("WCS");
|
662 |
// ReadException exception = new
|
663 |
// ReadException("unknown_response_format",type);
|
664 |
// throw exception;
|
665 |
// azabala throw new DriverException(PluginServices.getText(this, "unknown_response_format"), e);
|
666 |
// }
|
667 |
// catch (UnsupportedVersionLayerException e) {
|
668 |
// UnsuportedProtocolVersionExceptionType type =
|
669 |
// new UnsuportedProtocolVersionExceptionType();
|
670 |
// type.setLayerName(getName());
|
671 |
// try {
|
672 |
// type.setDriverName(getDriver().getName());
|
673 |
// } catch (Exception ex){
|
674 |
// }
|
675 |
// type.setUrl(host);
|
676 |
// throw new ReadException(PluginServices.getText(this,
|
677 |
// "version_conflict"), e, type);
|
678 |
|
679 |
// azabala throw new DriverException(PluginServices.getText(this, "version_conflict"), e);
|
680 |
} catch (IOException e) { |
681 |
// ConnectionErrorExceptionType type = new ConnectionErrorExceptionType();
|
682 |
// type.setLayerName(getName());
|
683 |
// try {
|
684 |
// type.setDriverName(getDriver().getName());
|
685 |
// } catch (Exception e1) {
|
686 |
// }
|
687 |
// type.setHost(host);
|
688 |
throw new ConnectionErrorLayerException(getName(),e); |
689 |
} |
690 |
// catch (WCSLayerException e) {
|
691 |
////azabala: la capturamos y la convertimos en DriverException
|
692 |
// WCSDriverExceptionType type = new WCSDriverExceptionType();
|
693 |
// type.setLayerName(getName());
|
694 |
// try {
|
695 |
// type.setDriverName(getDriver().getName());
|
696 |
// } catch (Exception e1) {
|
697 |
// }
|
698 |
// type.setWcsStatus(wcsStatus);
|
699 |
// this.setVisible(false);
|
700 |
// throw new WDriverException("Error WCS", e, type);
|
701 |
//
|
702 |
//// JOptionPane.showMessageDialog((Component)PluginServices.getMainFrame(), e.getMessage());
|
703 |
//
|
704 |
// }//
|
705 |
catch (WCSDriverException e) {
|
706 |
throw new LoadLayerException(getName(),e); |
707 |
} catch (IllegalStateException e) { |
708 |
throw new LoadLayerException(getName(),e); |
709 |
} |
710 |
return true; |
711 |
} |
712 |
|
713 |
/**
|
714 |
* Devuelve el FMapWMSDriver.
|
715 |
*
|
716 |
* @return FMapWMSDriver
|
717 |
*
|
718 |
* @throws IllegalStateException
|
719 |
* @throws ValidationException
|
720 |
* @throws UnsupportedVersionLayerException
|
721 |
* @throws IOException
|
722 |
*/
|
723 |
private FMapWCSDriver getDriver() throws IllegalStateException, IOException { |
724 |
if (wcs == null) { |
725 |
wcs = FMapWCSDriverFactory.getFMapDriverForURL(host); |
726 |
} |
727 |
return wcs;
|
728 |
} |
729 |
|
730 |
/**
|
731 |
* Calcula el contenido del fichero de georreferenciaci?n de una imagen.
|
732 |
* @param bBox Tama?o y posici?n de la imagen (en coordenadas de usuario)
|
733 |
* @param sz Tama?o de la imagen en pixeles.
|
734 |
* @return el 'WorldFile', como String.
|
735 |
* @throws IOException
|
736 |
*/
|
737 |
public String getDataWorldFile(Rectangle2D bBox, Dimension sz) throws IOException { |
738 |
StringBuffer data = new StringBuffer(); |
739 |
data.append((bBox.getMaxX() - bBox.getMinX())/(sz.getWidth() - 1)+"\n"); |
740 |
data.append("0.0\n");
|
741 |
data.append("0.0\n");
|
742 |
data.append("-"+(bBox.getMaxY() - bBox.getMinY())/(sz.getHeight() - 1)+"\n"); |
743 |
data.append(""+bBox.getMinX()+"\n"); |
744 |
data.append(""+bBox.getMaxY()+"\n"); |
745 |
return data.toString();
|
746 |
} |
747 |
|
748 |
/**
|
749 |
* Carga y dibuja el raster usando la librer?a
|
750 |
*
|
751 |
* @param filePath
|
752 |
* Ruta al fichero en disco
|
753 |
* @param g
|
754 |
* Graphics2D
|
755 |
* @param vp
|
756 |
* ViewPort
|
757 |
* @param scale
|
758 |
* Escala para el draw
|
759 |
* @param cancel
|
760 |
* Cancelaci?n para el draw
|
761 |
* @throws ReadException
|
762 |
* @throws LoadLayerException
|
763 |
*/
|
764 |
private void rasterProcess(String filePath, Graphics2D g, ViewPort vp, |
765 |
double scale, Cancellable cancel, int nLyr) throws ReadException, |
766 |
LoadLayerException, FilterTypeException { |
767 |
//Cargamos el dataset con el raster de disco.
|
768 |
layerRaster[nLyr] = FLyrRasterSE.createLayer("", filePath, vp.getProjection());
|
769 |
//layerRaster[nLyr].getRender().setBufferFactory(layerRaster[nLyr].getBufferFactory());
|
770 |
|
771 |
if(visualStatus.dataType == IBuffer.TYPE_UNDEFINED && layerRaster[nLyr].getDataType() != null) |
772 |
visualStatus.dataType = layerRaster[nLyr].getDataType()[0];
|
773 |
if(visualStatus.bandCount == 0 && layerRaster[nLyr].getBandCount() != 0) |
774 |
visualStatus.bandCount = layerRaster[nLyr].getBandCount(); |
775 |
|
776 |
if (getLegend() == null) |
777 |
lastLegend = layerRaster[nLyr].getLegend(); |
778 |
|
779 |
//En caso de cargar un proyecto con XMLEntity se crean los filtros
|
780 |
if(filterArguments != null) { |
781 |
RasterFilterList fl = new RasterFilterList();
|
782 |
fl.addEnvParam("IStatistics", layerRaster[nLyr].getDataSource().getStatistics());
|
783 |
fl.addEnvParam("MultiRasterDataset", layerRaster[nLyr].getDataSource());
|
784 |
fl.setInitDataType(layerRaster[nLyr].getDataType()[0]);
|
785 |
RasterFilterListManager filterListManager = new RasterFilterListManager(fl);
|
786 |
filterListManager.createFilterListFromStrings(filterArguments); |
787 |
StatusLayerRaster.enhancedCompV10(filterArguments, layerRaster[nLyr], filterListManager); |
788 |
filterArguments = null;
|
789 |
filterList = fl; |
790 |
} |
791 |
|
792 |
//Como el raster se carga a cada zoom el render se crea nuevamente y la lista de
|
793 |
//filtros siempre estar? vacia a cada visualizaci?n. Para evitarlo tenemos que
|
794 |
//guardar la lista de filtro aplicada en la visualizaci?n anterior.
|
795 |
if (filterList != null) |
796 |
layerRaster[nLyr].getRender().setFilterList(filterList); |
797 |
if (transparency == null) |
798 |
transparency = layerRaster[nLyr].getRender().getLastTransparency(); |
799 |
if (transparency != null) |
800 |
layerRaster[nLyr].getRender().setLastTransparency(transparency); |
801 |
if (renderBands != null) |
802 |
layerRaster[nLyr].getRender().setRenderBands(renderBands); |
803 |
|
804 |
//Dibujamos
|
805 |
layerRaster[nLyr].draw(null, g, vp, cancel, scale);
|
806 |
|
807 |
//La primera vez asignamos la lista de filtros asociada al renderizador. Guardamos una referencia
|
808 |
//en esta clase para que a cada zoom no se pierda.
|
809 |
if (filterList == null) |
810 |
filterList = layerRaster[nLyr].getRender().getFilterList(); |
811 |
if (renderBands == null) |
812 |
renderBands = layerRaster[nLyr].getRender().getRenderBands(); |
813 |
} |
814 |
|
815 |
/*
|
816 |
* (non-Javadoc)
|
817 |
* @see com.iver.cit.gvsig.fmap.layers.FLyrDefault#cloneLayer()
|
818 |
*/
|
819 |
public FLayer cloneLayer() throws Exception { |
820 |
Object par = null; |
821 |
if (dataset instanceof CompositeDataset) |
822 |
par = ((CompositeDataset) dataset).getFileNames(); |
823 |
|
824 |
FLyrRasterSE newLayer = FLyrRasterSE.createLayer(this.getName(), par, this.getProjection()); |
825 |
|
826 |
ArrayList filters = getRender().getFilterList().getStatusCloned();
|
827 |
newLayer.getRender().getFilterList().setStatus(filters); |
828 |
|
829 |
return newLayer;
|
830 |
} |
831 |
|
832 |
/*
|
833 |
* (non-Javadoc)
|
834 |
* @see org.gvsig.fmap.raster.IRasterRendering#getRenderFilterList()
|
835 |
*/
|
836 |
public RasterFilterList getRenderFilterList(){
|
837 |
return (filterList != null) ? filterList : getRender().getFilterList(); |
838 |
} |
839 |
|
840 |
/*
|
841 |
* (non-Javadoc)
|
842 |
* @see org.gvsig.raster.hierarchy.IRasterRendering#setRenderFilterList(org.gvsig.raster.grid.filter.RasterFilterList)
|
843 |
*/
|
844 |
public void setRenderFilterList(RasterFilterList filterList) { |
845 |
this.filterList = filterList;
|
846 |
super.getRender().setFilterList(filterList);
|
847 |
} |
848 |
|
849 |
/*
|
850 |
* (non-Javadoc)
|
851 |
* @see org.gvsig.fmap.raster.IRasterRendering#getRenderTransparency()
|
852 |
*/
|
853 |
public GridTransparency getRenderTransparency() {
|
854 |
return getRender().getLastTransparency();
|
855 |
// return (transparency != null) ? transparency : getRender().getLastTransparency();
|
856 |
} |
857 |
|
858 |
/*
|
859 |
* (non-Javadoc)
|
860 |
* @see org.gvsig.raster.hierarchy.IRasterRendering#getRenderBands()
|
861 |
*/
|
862 |
public int[] getRenderBands() { |
863 |
return (renderBands != null) ? renderBands : getRender().getRenderBands(); |
864 |
} |
865 |
|
866 |
/*
|
867 |
* (non-Javadoc)
|
868 |
* @see org.gvsig.raster.hierarchy.IRasterRendering#setRenderBands(int[])
|
869 |
*/
|
870 |
public void setRenderBands(int[] renderBands) { |
871 |
this.renderBands = renderBands;
|
872 |
getRender().setRenderBands(renderBands); |
873 |
} |
874 |
|
875 |
/*
|
876 |
* (non-Javadoc)
|
877 |
* @see org.gvsig.fmap.raster.layers.FLyrRasterSE#print(java.awt.Graphics2D, com.iver.cit.gvsig.fmap.ViewPort, com.iver.utiles.swing.threads.Cancellable, double, javax.print.attribute.PrintRequestAttributeSet)
|
878 |
*/
|
879 |
public void print(Graphics2D g, ViewPort viewPort, Cancellable cancel, |
880 |
double scale, PrintRequestAttributeSet properties) |
881 |
throws ReadException {
|
882 |
if (isVisible() && isWithinScale(scale)){
|
883 |
draw(null, g, viewPort, cancel, scale);
|
884 |
} |
885 |
} |
886 |
|
887 |
@Override
|
888 |
public void loadFromState(PersistentState state) |
889 |
throws PersistenceException {
|
890 |
super.loadFromState(state);
|
891 |
|
892 |
host = (URL) state.get("host"); |
893 |
|
894 |
// full extent
|
895 |
this.setFullEnvelope((Envelope) state.get("fullExtent")); |
896 |
|
897 |
// coverageQuery
|
898 |
coverageName = state.getString("layerQuery");
|
899 |
|
900 |
// format
|
901 |
format = state.getString("format");
|
902 |
|
903 |
// srs
|
904 |
srs = state.getString("srs");
|
905 |
|
906 |
// time
|
907 |
time = state.getString("time");
|
908 |
|
909 |
// parameter
|
910 |
parameter = state.getString("parameter");
|
911 |
|
912 |
// coverage name
|
913 |
coverageName = state.getString("coverageName");
|
914 |
|
915 |
// max resolution
|
916 |
if (state.hasValue("maxRes")) { |
917 |
maxRes = (Point2D) state.get("maxRes"); |
918 |
} |
919 |
|
920 |
if (state.hasValue("onlineResources")) { |
921 |
onlineResources = new Hashtable(state.getMap("onlineResources")); |
922 |
} |
923 |
|
924 |
firstLoad = true;
|
925 |
} |
926 |
|
927 |
@Override
|
928 |
public void saveToState(PersistentState state) throws PersistenceException { |
929 |
super.saveToState(state);
|
930 |
|
931 |
state.set("fullExtent", this.fullEnvelope); |
932 |
|
933 |
state.set("host", host);
|
934 |
state.set("layerQuery", coverageName);
|
935 |
state.set("format", format);
|
936 |
state.set("srs", srs );
|
937 |
state.set("time", time );
|
938 |
state.set("parameter", parameter );
|
939 |
state.set("coverageName", coverageName);
|
940 |
state.set("maxRes", maxRes);
|
941 |
state.set("onlineResources", onlineResources);
|
942 |
} |
943 |
|
944 |
public static void registerPersistent() { |
945 |
PersistenceManager manager = ToolsLocator.getPersistenceManager(); |
946 |
DynStruct definition = manager.getDefinition(PERSISTENT_NAME); |
947 |
if( definition == null ) { |
948 |
FLyrRasterSE.registerPersistent(); |
949 |
definition = manager.addDefinition( |
950 |
FLyrWCS.class, |
951 |
PERSISTENT_NAME, |
952 |
PERSISTENT_DESCRIPTION, |
953 |
null,
|
954 |
null
|
955 |
); |
956 |
|
957 |
definition.extend( |
958 |
(DynClass)ToolsLocator.getPersistenceManager() |
959 |
.getDefinition(FLyrRasterSE.class) |
960 |
); |
961 |
|
962 |
definition.addDynFieldObject("fullExtent")
|
963 |
.setType(DataTypes.ENVELOPE) |
964 |
.setMandatory(true);
|
965 |
definition.addDynFieldURL("host")
|
966 |
.setMandatory(true);
|
967 |
definition.addDynFieldString("layerQuery").setMandatory(true); |
968 |
definition.addDynFieldString("format").setMandatory(true); |
969 |
definition.addDynFieldString("srs").setMandatory(true); |
970 |
definition.addDynFieldString("time").setMandatory(true); |
971 |
definition.addDynFieldString("parameter").setMandatory(true); |
972 |
definition.addDynFieldString("coverageName").setMandatory(true); |
973 |
definition.addDynFieldObject("maxRes")
|
974 |
.setClassOfValue(Point2D.class)
|
975 |
.setMandatory(false);
|
976 |
definition.addDynFieldMap("onlineResources")
|
977 |
.setClassOfItems(String.class)
|
978 |
.setMandatory(true);
|
979 |
} |
980 |
} |
981 |
|
982 |
|
983 |
public void setCoverageName(String coverageName) { |
984 |
this.coverageName = coverageName;
|
985 |
} |
986 |
|
987 |
public void setParameter(String parametersString) { |
988 |
if (this.parameter == parametersString){ |
989 |
return;
|
990 |
} |
991 |
if (this.parameter != null && this.parameter.equals(parametersString)){ |
992 |
return;
|
993 |
} |
994 |
this.parameter = parametersString;
|
995 |
this.updateDrawVersion();
|
996 |
} |
997 |
|
998 |
public void setTime(String time) { |
999 |
if (this.time == time){ |
1000 |
return;
|
1001 |
} |
1002 |
if (this.time != null && this.time.equals(time)){ |
1003 |
return;
|
1004 |
} |
1005 |
this.time = time;
|
1006 |
this.updateDrawVersion();
|
1007 |
} |
1008 |
|
1009 |
public void setSRS(String srs) { |
1010 |
if (this.srs == srs){ |
1011 |
return;
|
1012 |
} |
1013 |
if (this.srs != null && this.srs.equals(srs)){ |
1014 |
return;
|
1015 |
} |
1016 |
this.srs = srs;
|
1017 |
this.updateDrawVersion();
|
1018 |
setProjection(CRSFactory.getCRS(srs)); |
1019 |
} |
1020 |
|
1021 |
public void setFormat(String format) { |
1022 |
if (this.format == format){ |
1023 |
return;
|
1024 |
} |
1025 |
if (this.format != null && this.format.equals(format)){ |
1026 |
return;
|
1027 |
} |
1028 |
this.format = format;
|
1029 |
this.updateDrawVersion();
|
1030 |
} |
1031 |
|
1032 |
|
1033 |
/**
|
1034 |
* Inserta el URL.
|
1035 |
*
|
1036 |
* @param host String.
|
1037 |
* @throws MalformedURLException
|
1038 |
*/
|
1039 |
public void setHost(String host) { |
1040 |
try {
|
1041 |
setHost(new URL(host)); |
1042 |
} catch (MalformedURLException e) { |
1043 |
|
1044 |
} |
1045 |
} |
1046 |
|
1047 |
/**
|
1048 |
* Inserta el URL.
|
1049 |
*
|
1050 |
* @param host URL.
|
1051 |
*/
|
1052 |
public void setHost(URL host) { |
1053 |
if (this.host == host){ |
1054 |
return;
|
1055 |
} |
1056 |
if (this.host != null && this.host.equals(host)){ |
1057 |
return;
|
1058 |
} |
1059 |
this.host = host;
|
1060 |
this.updateDrawVersion();
|
1061 |
} |
1062 |
|
1063 |
|
1064 |
/**
|
1065 |
* Devuelve el URL.
|
1066 |
*
|
1067 |
* @return URL.
|
1068 |
*/
|
1069 |
public URL getHost() { |
1070 |
return host;
|
1071 |
} |
1072 |
|
1073 |
/**
|
1074 |
* Remote source layers have a bunch of properties that are required for get them from
|
1075 |
* the servers. This method supplies a hash table containing any needed field. This hash
|
1076 |
* table may be used to let the client to connect to a server and restore a previously saved
|
1077 |
* layer. So, the layer itself may not be saved to the disk since the actual saved
|
1078 |
* info is just its properties.
|
1079 |
*
|
1080 |
* @return Returns a hash table containing all the required information for
|
1081 |
* set up a wms layer
|
1082 |
*/
|
1083 |
public Hashtable getProperties(){ |
1084 |
Hashtable info = new Hashtable(); |
1085 |
info.put( "name", coverageName);
|
1086 |
info.put( "host", getHost());
|
1087 |
info.put( "crs", srs);
|
1088 |
info.put( "format", format);
|
1089 |
String str = time;
|
1090 |
if (str==null) { |
1091 |
str = "";
|
1092 |
} |
1093 |
info.put( "time", str);
|
1094 |
str = parameter; |
1095 |
if (str==null) { |
1096 |
str = "";
|
1097 |
} |
1098 |
info.put("parameter", str);
|
1099 |
|
1100 |
return info;
|
1101 |
} |
1102 |
|
1103 |
/**
|
1104 |
* Obtiene la extensi?n del fichero de georreferenciaci?n
|
1105 |
* @return String con la extensi?n del fichero de georreferenciaci?n dependiendo
|
1106 |
* del valor del formato obtenido del servidor. Por defecto asignaremos un .wld
|
1107 |
*/
|
1108 |
private String getExtensionWorldFile(){ |
1109 |
String extWorldFile = ".wld"; |
1110 |
if (format.equals("image/tif") || format.equals("image/tiff")) { |
1111 |
extWorldFile = ".tfw";
|
1112 |
} |
1113 |
return extWorldFile;
|
1114 |
} |
1115 |
|
1116 |
public void setMaxResolution(Point2D maxResolution) { |
1117 |
if (this.maxRes == maxResolution){ |
1118 |
return;
|
1119 |
} |
1120 |
if (this.maxRes != null && this.maxRes.equals(maxResolution)){ |
1121 |
return;
|
1122 |
} |
1123 |
this.maxRes = maxResolution;
|
1124 |
this.updateDrawVersion();
|
1125 |
} |
1126 |
|
1127 |
/**
|
1128 |
* <p>
|
1129 |
* Gets the max resolution allowed by the coverage. Requesting a higher resolution
|
1130 |
* than this value does not cause any error, but the info responsed is just an
|
1131 |
* interpolation. <br>
|
1132 |
* </p>
|
1133 |
*
|
1134 |
* <p>
|
1135 |
* In exchange for obtaining a greater file and without additional information,
|
1136 |
* we can easily fit it into the View. <br>
|
1137 |
* </p>
|
1138 |
*
|
1139 |
* <p>
|
1140 |
* Obtiene la resoluci?n m?xima soportada por la cobertura. La petici?n
|
1141 |
* de una resoluci?n superior a la soportada no provoca ning?n error, aunque
|
1142 |
* la informaci?n obtenida s?lo es una mera interpolaci?n de informaci?n. <br>
|
1143 |
* </p>
|
1144 |
*
|
1145 |
* <p>
|
1146 |
* A cambio de obtener un archivo mayor y sin informaci?n adicional, podemos
|
1147 |
* f?cilmente acoplarlo a la vista. <br>
|
1148 |
* </p>
|
1149 |
*
|
1150 |
* @return double
|
1151 |
*/
|
1152 |
public Point2D getMaxResolution() { |
1153 |
if (maxRes==null) { |
1154 |
maxRes = wcs.getMaxResolution(coverageName); |
1155 |
} |
1156 |
return maxRes;
|
1157 |
} |
1158 |
|
1159 |
|
1160 |
public void setDriver(FMapWCSDriver driver) { |
1161 |
if (driver == this.wcs){ |
1162 |
return;
|
1163 |
} |
1164 |
this.wcs = driver;
|
1165 |
this.updateDrawVersion();
|
1166 |
} |
1167 |
|
1168 |
/*
|
1169 |
* (non-Javadoc)
|
1170 |
* @see com.iver.cit.gvsig.fmap.layers.RasterOperations#getTileSize()
|
1171 |
*/
|
1172 |
public int[] getTileSize() { |
1173 |
int[] size = {maxTileDrawWidth, maxTileDrawHeight}; |
1174 |
return size;
|
1175 |
} |
1176 |
|
1177 |
/*
|
1178 |
* (non-Javadoc)
|
1179 |
* @see com.iver.cit.gvsig.fmap.layers.FLyrDefault#getTocImageIcon()
|
1180 |
*/
|
1181 |
public String getTocImageIcon() { |
1182 |
return "ico-WCS-Layer"; |
1183 |
} |
1184 |
|
1185 |
/*
|
1186 |
* (non-Javadoc)
|
1187 |
* @see com.iver.cit.gvsig.fmap.layers.RasterOperations#isTiled()
|
1188 |
*/
|
1189 |
public boolean isTiled() { |
1190 |
return mustTileDraw;
|
1191 |
} |
1192 |
|
1193 |
/*
|
1194 |
* (non-Javadoc)
|
1195 |
* @see org.gvsig.fmap.raster.layers.FLyrRasterSE#isActionEnabled(int)
|
1196 |
*/
|
1197 |
public boolean isActionEnabled(int action) { |
1198 |
switch (action) {
|
1199 |
case IRasterLayerActions.ZOOM_PIXEL_RESOLUTION:
|
1200 |
case IRasterLayerActions.FLYRASTER_BAR_TOOLS:
|
1201 |
case IRasterLayerActions.BANDS_FILE_LIST:
|
1202 |
case IRasterLayerActions.GEOLOCATION:
|
1203 |
case IRasterLayerActions.PANSHARPENING:
|
1204 |
case IRasterLayerActions.SAVE_COLORINTERP:
|
1205 |
return false; |
1206 |
case IRasterLayerActions.BANDS_RGB:
|
1207 |
case IRasterLayerActions.REMOTE_ACTIONS:
|
1208 |
return true; |
1209 |
} |
1210 |
|
1211 |
return super.isActionEnabled(action); |
1212 |
} |
1213 |
|
1214 |
/*
|
1215 |
* (non-Javadoc)
|
1216 |
* @see org.gvsig.fmap.raster.layers.FLyrRasterSE#overviewsSupport()
|
1217 |
*/
|
1218 |
public boolean overviewsSupport() { |
1219 |
return false; |
1220 |
} |
1221 |
|
1222 |
/**
|
1223 |
* Inserta la extensi?n total de la capa.
|
1224 |
*
|
1225 |
* @param fullExtent
|
1226 |
* Rect?ngulo.
|
1227 |
* @deprecated
|
1228 |
*/
|
1229 |
public void setFullExtent(Rectangle2D fullExtent) { |
1230 |
this.setFullEnvelope(this.getEnvelopeFromRectable2D(fullExtent)); |
1231 |
} |
1232 |
|
1233 |
/**
|
1234 |
* Inserta la extensi?n total de la capa en la proyeccion original.
|
1235 |
*
|
1236 |
* @param fullExtent
|
1237 |
* Rect?ngulo.
|
1238 |
*/
|
1239 |
public void setFullEnvelope(Envelope envelope) { |
1240 |
Envelope cur = this.getFullEnvelope();
|
1241 |
if (cur == envelope) {
|
1242 |
return;
|
1243 |
} |
1244 |
if (cur != null && cur.equals(envelope)) { |
1245 |
return;
|
1246 |
} |
1247 |
|
1248 |
this.fullEnvelope = envelope;
|
1249 |
this.updateDrawVersion();
|
1250 |
} |
1251 |
|
1252 |
private Rectangle2D.Double getRectable2DFromEnvelope(Envelope env) { |
1253 |
return new Rectangle2D.Double(env.getMinimum(0), env.getMinimum(1), env |
1254 |
.getLength(0), env.getLength(1)); |
1255 |
} |
1256 |
|
1257 |
private Envelope getEnvelopeFromRectable2D(Rectangle2D rect) { |
1258 |
GeometryManager geoMan = GeometryLocator.getGeometryManager(); |
1259 |
Envelope rAux = null;
|
1260 |
try {
|
1261 |
rAux = geoMan.createEnvelope(rect.getMinX(), rect.getMinY(), rect |
1262 |
.getMaxX(), rect.getMaxY(), SUBTYPES.GEOM2D); |
1263 |
|
1264 |
} catch (Exception e) { |
1265 |
e.printStackTrace(); |
1266 |
return null; |
1267 |
} |
1268 |
return rAux;
|
1269 |
} |
1270 |
|
1271 |
/*
|
1272 |
* (non-Javadoc)
|
1273 |
* @see org.gvsig.fmap.raster.layers.FLyrRasterSE#getFileLayer()
|
1274 |
*/
|
1275 |
public FLayer getFileLayer() {
|
1276 |
if(layerRaster != null && layerRaster[0] != null) { |
1277 |
FLyrRasterSE ly = null;
|
1278 |
if(lastNColumns == 0 && lastNRows == 0) { //Una capa sin tilear => MultirasterDataset |
1279 |
try {
|
1280 |
ly = createLayer(layerRaster[0].getName(), layerRaster[0].getLoadParams(), layerRaster[0].getProjection()); |
1281 |
} catch (LoadLayerException e) {
|
1282 |
return null; |
1283 |
} |
1284 |
} else { //Capa tileada ==> CompositeDataset |
1285 |
String[][] s = new String[lastNRows][lastNColumns]; |
1286 |
|
1287 |
for (int i = 0; i < s.length; i++) { |
1288 |
for (int j = 0; j < s[0].length; j++) { |
1289 |
s[i][j] = ((FLyrRasterSE)layerRaster[i]).getDataSource().getNameDatasetStringList(i, j)[0];
|
1290 |
} |
1291 |
} |
1292 |
try {
|
1293 |
ly = createLayer("preview", s, getProjection());
|
1294 |
} catch (LoadLayerException e) {
|
1295 |
return null; |
1296 |
} |
1297 |
} |
1298 |
return ly;
|
1299 |
} |
1300 |
return null; |
1301 |
} |
1302 |
|
1303 |
} |