Statistics
| Revision:

root / trunk / extensions / extWCS / src / com / iver / cit / gvsig / fmap / layers / FLyrWCS.java @ 13951

History | View | Annotate | Download (37.8 KB)

1 1877 luisw
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
2 1979 jaume
 *
3 2017 igbrotru
 * Copyright (C) 2004 IVER T.I. and Generalitat Valenciana.
4 1979 jaume
 *
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 1877 luisw
package com.iver.cit.gvsig.fmap.layers;
42
43 4356 jaume
import java.awt.Dimension;
44 1877 luisw
import java.awt.Graphics2D;
45 2623 nacho
import java.awt.Point;
46 4356 jaume
import java.awt.Rectangle;
47
import java.awt.geom.AffineTransform;
48
import java.awt.geom.NoninvertibleTransformException;
49 2330 jaume
import java.awt.geom.Point2D;
50 1877 luisw
import java.awt.geom.Rectangle2D;
51
import java.awt.image.BufferedImage;
52 4356 jaume
import java.awt.image.DataBuffer;
53
import java.io.File;
54 1986 jaume
import java.io.IOException;
55 2623 nacho
import java.lang.reflect.Constructor;
56
import java.lang.reflect.InvocationTargetException;
57 4356 jaume
import java.net.MalformedURLException;
58
import java.net.URL;
59 2623 nacho
import java.util.ArrayList;
60 2648 jaume
import java.util.Hashtable;
61 10707 jaume
import java.util.Iterator;
62 4683 jorpiell
import java.util.Map;
63 1877 luisw
64 9010 caballero
import javax.print.attribute.PrintRequestAttributeSet;
65
66 4356 jaume
import org.exolab.castor.xml.ValidationException;
67 13237 jaume
import org.gvsig.fmap.raster.layers.FLyrRasterSE;
68 13288 nacho
import org.gvsig.fmap.raster.layers.IRasterLayerActions;
69 13614 nacho
import org.gvsig.fmap.raster.layers.IStatusRaster;
70 13237 jaume
import org.gvsig.fmap.raster.layers.StatusLayerRaster;
71 13596 nacho
import org.gvsig.raster.dataset.CompositeDataset;
72 13312 nacho
import org.gvsig.raster.dataset.FileNotOpenException;
73 13596 nacho
import org.gvsig.raster.dataset.IBuffer;
74 13312 nacho
import org.gvsig.raster.dataset.InvalidSetViewException;
75 13596 nacho
import org.gvsig.raster.dataset.MosaicNotValidException;
76
import org.gvsig.raster.dataset.MultiRasterDataset;
77 13312 nacho
import org.gvsig.raster.dataset.NotSupportedExtensionException;
78
import org.gvsig.raster.dataset.RasterDataset;
79
import org.gvsig.raster.dataset.RasterDriverException;
80 13237 jaume
import org.gvsig.raster.datastruct.Extent;
81
import org.gvsig.raster.datastruct.ViewPortData;
82 13545 nacho
import org.gvsig.raster.grid.GridTransparency;
83 13260 nacho
import org.gvsig.raster.grid.filter.RasterFilterList;
84 13596 nacho
import org.gvsig.raster.grid.filter.RasterFilterListManager;
85 13823 nacho
import org.gvsig.raster.grid.filter.enhancement.LinearEnhancementFilter;
86
import org.gvsig.raster.grid.filter.statistics.TailTrimFilter;
87 4356 jaume
import org.gvsig.remoteClient.wcs.WCSStatus;
88 5409 jaume
import org.gvsig.remoteClient.wms.ICancellable;
89 2623 nacho
90 10626 caballero
import com.hardcode.gdbms.driver.exceptions.ReadDriverException;
91 10707 jaume
import com.hardcode.gdbms.engine.data.driver.DriverException;
92 10626 caballero
import com.iver.cit.gvsig.exceptions.layers.ConnectionErrorLayerException;
93
import com.iver.cit.gvsig.exceptions.layers.LoadLayerException;
94
import com.iver.cit.gvsig.exceptions.layers.UnsupportedVersionLayerException;
95 13951 jaume
import com.iver.cit.gvsig.fmap.MapContext;
96
import com.iver.cit.gvsig.fmap.MapControl;
97 1877 luisw
import com.iver.cit.gvsig.fmap.ViewPort;
98 13237 jaume
import com.iver.cit.gvsig.fmap.crs.CRSFactory;
99 1979 jaume
import com.iver.cit.gvsig.fmap.drivers.DriverIOException;
100 1961 jaume
import com.iver.cit.gvsig.fmap.drivers.wcs.FMapWCSDriver;
101 6042 jaume
import com.iver.cit.gvsig.fmap.drivers.wcs.FMapWCSDriverFactory;
102 10626 caballero
import com.iver.cit.gvsig.fmap.drivers.wcs.WCSDriverException;
103 5080 ldiaz
import com.iver.cit.gvsig.fmap.layers.layerOperations.StringXMLItem;
104 5203 ldiaz
import com.iver.cit.gvsig.fmap.layers.layerOperations.XMLItem;
105 13596 nacho
import com.iver.cit.gvsig.fmap.rendering.ILegend;
106 13951 jaume
import com.iver.cit.gvsig.fmap.rendering.LegendChangedEvent;
107 8423 nacho
import com.iver.utiles.DoubleUtilities;
108 1979 jaume
import com.iver.utiles.StringUtilities;
109
import com.iver.utiles.XMLEntity;
110 5317 fjp
import com.iver.utiles.swing.threads.Cancellable;
111 1877 luisw
112 5203 ldiaz
113 1877 luisw
/**
114 2097 jaume
 * Class for the WCS layer.
115 6042 jaume
 *
116 1961 jaume
 * Capa para el WCS.
117 13596 nacho
 *
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 6042 jaume
 *
137 1877 luisw
 * @author jaume - jaume.dominguez@iver.es
138
 */
139 13237 jaume
public class FLyrWCS extends FLyrRasterSE {
140 4356 jaume
        private FMapWCSDriver wcs = null;
141 4934 jaume
142 4356 jaume
        private URL                                                 host;
143
        private String                                                coverageName;
144
        private Rectangle2D                                        fullExtent;
145
        private String                                                format;
146
        private String                                                srs;
147
        private String                                                time;
148
        private String                                                parameter;
149
        private Point2D                                                maxRes;
150
        private Hashtable                                         onlineResources = new Hashtable();
151 6042 jaume
152 4573 jaume
        private WCSStatus                                        wcsStatus = new WCSStatus();
153 6042 jaume
154 2651 nacho
        private int                                                 posX = 0, posY = 0;
155
        private double                                                 posXWC = 0, posYWC = 0;
156
        private int                                                 r = 0, g = 0, b = 0;
157 4356 jaume
        private boolean                                         firstLoad = false;
158
        private VisualStatus                                visualStatus = new VisualStatus();
159 4934 jaume
160 5534 nacho
        private boolean                                         mustTileDraw = false;
161 13617 nacho
        private int                                                 maxTileDrawWidth  = 1023;
162
        private int                                                        maxTileDrawHeight = 1023;
163 5534 nacho
        private int                                                 maxTilePrintWidth  = 250;
164
        private int                                                        maxTilePrintHeight = 250;
165 13260 nacho
        /**
166
         * Lista de filtros aplicada en la renderizaci?n
167
         */
168
        private RasterFilterList            filterList = null;
169 13545 nacho
        private GridTransparency                        transparency = null;
170 13596 nacho
        private int[]                       renderBands = null;
171
        private FLyrRasterSE                                layerRaster = null;
172 13651 nacho
        private ArrayList                   filterArguments = null;
173 13823 nacho
        private String[][]                                        fileNames = null;
174 13237 jaume
175 5409 jaume
        private class MyCancellable implements ICancellable
176
        {
177
178
                private Cancellable original;
179
                public MyCancellable(Cancellable cancelOriginal)
180
                {
181
                        this.original = cancelOriginal;
182
                }
183
                public boolean isCanceled() {
184
                        return original.isCanceled();
185
                }
186 6042 jaume
187 5409 jaume
        }
188 13237 jaume
189 4683 jorpiell
        public FLyrWCS(){
190
                super();
191
        }
192 6042 jaume
193 4683 jorpiell
        public FLyrWCS(Map args) throws DriverIOException{
194
                FMapWCSDriver drv = null;
195 6042 jaume
                String host = (String)args.get("HOST");
196 4683 jorpiell
                String sCoverage = (String) args.get((String) "COVERAGE");
197 6042 jaume
198 4683 jorpiell
                try {
199
                        this.setHost(new URL(host));
200
                } catch (MalformedURLException e) {
201
                        //e.printStackTrace();
202 6042 jaume
                        throw new DriverIOException("Malformed host URL, '" + host + "' (" + e.toString() + ").");
203 4683 jorpiell
                }
204
                try {
205
                        drv = this.getDriver();
206
                } catch (Exception e) {
207
                        // e.printStackTrace();
208 6042 jaume
                        throw new DriverIOException("Can't get driver to host '" + host + "' (" + e.toString() + ").");
209 4683 jorpiell
                }
210 6042 jaume
211 4683 jorpiell
                try{
212 9002 jaume
                        if (!drv.connect(false, null)){
213 4683 jorpiell
                                throw new DriverIOException("Can't connect to host '" + host + "'.");
214
                        }
215
                }catch(Exception e){
216
                        throw new DriverIOException("Can't connect to host '" + host + "'.");
217
                }
218 6042 jaume
219 4683 jorpiell
                WCSLayer wcsNode = drv.getLayer(sCoverage);
220 6042 jaume
221 4683 jorpiell
                if (wcsNode == null){
222
                        throw new DriverIOException("The server '" + host + "' doesn't has the coverage '" + sCoverage + "'.");
223 6042 jaume
                }
224
225 4683 jorpiell
                try{
226
                        this.setFullExtent(drv.getFullExtent(sCoverage,
227
                                        (String) args.get((String) "CRS")));
228
                        this.setFormat((String) args.get((String) "FORMAT"));
229
                        this.setParameter("BANDS=" + (String) args.get((String) "BANDS"));
230
                        this.setSRS((String) args.get((String) "CRS"));
231
                        this.setName(sCoverage);
232
                        this.setCoverageName(sCoverage);
233
                }catch (Exception e){
234
                        throw new DriverIOException("The server '" + host + "' is not able to load the coverage '" + sCoverage + "'.");
235
                }
236 6042 jaume
237 4683 jorpiell
        }
238 6042 jaume
239 4356 jaume
        /**
240 8423 nacho
         * Clase que contiene los datos de visualizaci?n de WCS. Tiene datos que representan al
241 8618 jaume
         * raster en la vista. Este raster puede estar compuesto por tiles por lo que valores
242 8423 nacho
         * como el ancho total o el m?nimo o m?ximo deben ser calculados a partir de todos los
243
         * tiles visualizados.
244 4356 jaume
         * @author Nacho Brodin (brodin_ign@gva.es)
245
         */
246
        private class VisualStatus {
247
                /**
248 6042 jaume
                 * Ancho y alto de la imagen o del conjunto de tiles si los tiene. Coincide con
249 4356 jaume
                 * el ancho y alto del viewPort
250
                 */
251
                private        int                                                        width = 0, height = 0;
252
                private double                                                minX = 0D, minY = 0D, maxX = 0D, maxY = 0D;
253
                private int                                                 bandCount = 0;
254
                private int                                                        dataType = DataBuffer.TYPE_UNDEFINED;
255 8618 jaume
256 8423 nacho
                /**
257
                 * Ancho y alto total del raster que ser? la suma de todos los tiles.
258
                 */
259
                private        int                                                        rasterWidth = 0, rasterHeight = 0;
260
                private        double                                                rasterMinX = Double.MAX_VALUE, rasterMinY = Double.MAX_VALUE;
261
                private        double                                                rasterMaxX = 0, rasterMaxY = 0;
262
                /**
263
                 * Lista de nombre de fichero que componen toda la visualizaci?n.
264
                 */
265
                private String[]                                        fileNames = null;
266 4356 jaume
        }
267 4934 jaume
268 4356 jaume
        /**
269 6042 jaume
         * @deprecated
270 5080 ldiaz
         * @see com.iver.cit.gvsig.fmap.layers.layerOperations.InfoByPoint#getInfo
271 4356 jaume
         */
272 13237 jaume
        public String queryByPoint(Point p) {
273 4356 jaume
                String data = "<file:"+getName().replaceAll("[^a-zA-Z0-9]","")+">\n";
274
                ArrayList attr = this.getAttributes();
275
                data += "  <raster\n";
276
                data += "    File=\""+getName()+"\"\n";
277
                for (int i=0; i<attr.size(); i++) {
278
                        Object [] a = (Object []) attr.get(i);
279 4934 jaume
280 4356 jaume
                        data += "    "+a[0].toString()+"=";
281
                        if (a[1].toString() instanceof String)
282
                                data += "\""+a[1].toString()+"\"\n";
283
                        else
284
                                data += a[1].toString()+"\n";
285
                }
286
                data += "    Point=\""+posX+" , "+posY+"\"\n";
287
                data += "    Point_WC=\""+posXWC+" , "+posYWC+"\"\n";
288
                data += "    RGB=\""+r+", "+g+", "+b+"\"\n";
289
                data += "  />\n";
290 4934 jaume
291 4356 jaume
                data += "</file:"+getName().replaceAll("[^a-zA-Z0-9]","")+">\n";
292
                System.out.println(data);
293
                return data;
294
        }
295 13312 nacho
296 5080 ldiaz
        /**
297
         * @see com.iver.cit.gvsig.fmap.layers.layerOperations.InfoByPoint#getInfo
298
         */
299 13312 nacho
        public XMLItem[] getInfo(Point point, double tolerance, Cancellable cancel ) throws ReadDriverException {
300 5080 ldiaz
                String data = "<file:"+getName().replaceAll("[^a-zA-Z0-9]","")+">\n";
301 8618 jaume
302 8423 nacho
                Point2D pReal = getMapContext().getViewPort().toMapPoint(point);
303
                Point2D px = null;
304 8618 jaume
                if(        pReal.getX() > this.getMinX() &&
305
                        pReal.getX() < this.getMaxX() &&
306
                        pReal.getY() > this.getMinY() &&
307 8423 nacho
                        pReal.getY() < this.getMaxY()){
308 8618 jaume
309 8423 nacho
                        px = new Point2D.Double();
310
                        double w = (visualStatus.rasterMaxX - visualStatus.rasterMinX);
311
                        double h = (visualStatus.rasterMaxY - visualStatus.rasterMinY);
312 8618 jaume
                        px.setLocation(((pReal.getX() - visualStatus.rasterMinX) * visualStatus.rasterWidth) / w,
313 8423 nacho
                                                        ((visualStatus.rasterMaxY - pReal.getY()) * visualStatus.rasterHeight) / h);
314
                }
315 8618 jaume
316 8423 nacho
                int[] rgb = this.getPixel(pReal.getX(), pReal.getY());
317
318 8618 jaume
                StringXMLItem[] item = new StringXMLItem[1];
319
320 5080 ldiaz
                data += "  <raster\n";
321 8423 nacho
                data += "    View_Point=\""+point.getX()+" , "+point.getY()+"\"\n";
322
                data += "    World_Point=\""+DoubleUtilities.format(pReal.getX(), 3)+" , "+ DoubleUtilities.format(pReal.getY(), 3)+"\"\n";
323 8618 jaume
                if(        px == null || px.getX() > visualStatus.rasterWidth || px.getX() < 0 ||
324 8423 nacho
                        px.getY() > visualStatus.rasterHeight || px.getY() < 0)
325
                        data += "    Pixel_Point=\"Out\"\n";
326
                else
327
                        data += "    Pixel_Point=\""+(int)px.getX()+" , "+(int)px.getY()+"\"\n";
328
                if(rgb != null)
329
                        data += "    RGB=\""+rgb[1]+"  "+rgb[2]+"  "+rgb[3]+"\"\n";
330
                data += "    Band_Value=\"";
331 5080 ldiaz
332 13312 nacho
                try {
333
                        for (int file = 0; file < visualStatus.fileNames.length; file++) {
334
                                RasterDataset rd = RasterDataset.open(getMapContext().getViewPort().getProjection(), visualStatus.fileNames[file]);
335
                                Extent ex = rd.getExtent();
336
                                if (pReal.getX() >= ex.minX() && pReal.getX() <= ex.maxX() && pReal.getY() >= ex.minY() && pReal.getY() <= ex.maxY()) {
337
                                        if (visualStatus.dataType >= 0 && visualStatus.dataType <= 3) {
338
                                                for (int i = 0; i < visualStatus.bandCount; i++) {
339
                                                        Integer value = (Integer) rd.getData((int) px.getX(), (int) px.getY(), i);
340
                                                        if (value != null)
341
                                                                data += value.intValue() + "  ";
342
                                                }
343 8423 nacho
                                        }
344 13312 nacho
                                        if (visualStatus.dataType >= 4) {
345
                                                for (int i = 0; i < visualStatus.bandCount; i++) {
346
                                                        Float value = (Float) rd.getData((int) px.getX(), (int) px.getY(), i);
347
                                                        if (value != null)
348
                                                                data += value.floatValue() + "  ";
349
                                                }
350 8423 nacho
                                        }
351 13312 nacho
                                        if (visualStatus.dataType >= 5) {
352
                                                for (int i = 0; i < visualStatus.bandCount; i++) {
353
                                                        Double value = (Double) rd.getData((int) px.getX(), (int) px.getY(), i);
354
                                                        if (value != null)
355
                                                                data += value.doubleValue() + "  ";
356
                                                }
357 8423 nacho
                                        }
358
                                }
359 13312 nacho
                                rd.close();
360 8423 nacho
                        }
361 13312 nacho
                } catch (NotSupportedExtensionException e) {
362
                        throw new ReadDriverException("Extensi?n no soportada.", e);
363
                } catch (RasterDriverException e) {
364
                        throw new ReadDriverException("Error en la apertura del fichero.", e);
365
                } catch (FileNotOpenException e) {
366
                        throw new ReadDriverException("Error en la apertura del fichero.", e);
367
                } catch (InvalidSetViewException e) {
368
                        throw new ReadDriverException("Error al asignar la vista.", e);
369
                }
370 8618 jaume
371 8423 nacho
                data += "\"\n";
372 5080 ldiaz
                data += "  />\n";
373
                data += "</file:"+getName().replaceAll("[^a-zA-Z0-9]","")+">\n";
374 8618 jaume
375
                item[0] = new StringXMLItem(data, this);
376 5080 ldiaz
                return item;
377
        }
378 8618 jaume
379 4356 jaume
        /*
380
         *  (non-Javadoc)
381
         * @see com.iver.cit.gvsig.fmap.layers.FLayer#getFullExtent()
382
         */
383
        public Rectangle2D getFullExtent() {
384
                return fullExtent;
385
        }
386 6042 jaume
387 4356 jaume
        /*
388
         *  (non-Javadoc)
389
         * @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)
390
         */
391 10626 caballero
        public void draw(BufferedImage image, Graphics2D g, ViewPort viewPort, Cancellable cancel, double scale) throws ReadDriverException {
392 13773 nacho
                enableStopped();
393 4356 jaume
                if (isWithinScale(scale)){
394
                        Point2D p = viewPort.getOffset();
395
                        // p will be (0, 0) when drawing a view or other when painting onto
396
                        // the Layout.
397
                        visualStatus.width =  viewPort.getImageWidth();
398
                        visualStatus.height =  viewPort.getImageHeight();
399
                        visualStatus.minX = viewPort.getAdjustedExtent().getMinX();
400
                        visualStatus.minY = viewPort.getAdjustedExtent().getMinY();
401
                        visualStatus.maxX = viewPort.getAdjustedExtent().getMaxX();
402
                        visualStatus.maxY = viewPort.getAdjustedExtent().getMaxY();
403 8423 nacho
                        visualStatus.rasterWidth = 0;
404
                        visualStatus.rasterHeight = 0;
405
                        visualStatus.rasterMinX = Double.MAX_VALUE;
406
                        visualStatus.rasterMinY = Double.MAX_VALUE;
407
                        visualStatus.rasterMaxX = 0;
408
                        visualStatus.rasterMaxY = 0;
409
                        visualStatus.fileNames = new String[1];
410 10626 caballero
                        try {
411 13596 nacho
                                if(true){
412
                                        if(viewPort.getImageWidth()<= maxTileDrawWidth && viewPort.getImageHeight()<=maxTileDrawHeight) {
413
                                                drawTile(g, viewPort, cancel, 0, scale);
414
                                                dataset = layerRaster.getDataSource();
415
                                                getRender().setLastRenderBuffer(layerRaster.getRender().getLastRenderBuffer());
416 13930 nacho
                                                initializeRasterLayer(null, new IBuffer[][]{{layerRaster.getRender().getLastRenderBuffer()}});
417 13596 nacho
                                        } else {
418
                                                Rectangle r = new Rectangle((int) p.getX(), (int) p.getY(), viewPort.getImageWidth(), viewPort.getImageHeight());
419
                                                Tiling tiles = new Tiling(maxTileDrawWidth, maxTileDrawHeight, r);
420
                                                tiles.setAffineTransform((AffineTransform) viewPort.getAffineTransform().clone());
421
                                                MultiRasterDataset[][] datasets = new MultiRasterDataset[tiles.getNumRows()][tiles.getNumCols()];
422
                                                IBuffer[][] buf = new IBuffer[tiles.getNumRows()][tiles.getNumCols()];
423 13823 nacho
                                                fileNames = new String[tiles.getNumRows()][tiles.getNumCols()];
424 13596 nacho
                                                visualStatus.fileNames = new String[tiles.getNumTiles()];
425
                                                for (int tileNr=0; tileNr < tiles.getNumTiles(); tileNr++) {
426
                                                        // drawing part
427
                                                        try {
428
                                                                ViewPort vp = tiles.getTileViewPort(viewPort, tileNr);
429
                                                                drawTile(g, vp, cancel, tileNr, scale);
430
                                                                if(layerRaster != null) {
431
                                                                        datasets[(int)(tileNr / tiles.getNumCols())][tileNr % tiles.getNumCols()] = (MultiRasterDataset)layerRaster.getDataSource().copy();
432
                                                                        buf[(int)(tileNr / tiles.getNumCols())][tileNr % tiles.getNumCols()] = layerRaster.getRender().getLastRenderBuffer();
433
                                                                }
434
                                                        } catch (NoninvertibleTransformException e) {
435
                                                                e.printStackTrace();
436
                                                        }
437
                                                }
438 5534 nacho
                                                try {
439 13596 nacho
                                                        if(datasets != null && datasets[0][0] != null) {
440
                                                                dataset = new CompositeDataset(datasets);
441
                                                                initializeRasterLayer(datasets, buf);
442
                                                        }
443
                                                } catch (MosaicNotValidException e) {
444
                                                        throw new ReadDriverException("No hay continuidad en el mosaico.", e);
445
                                                } catch (LoadLayerException e) {
446
                                                        throw new ReadDriverException("Error inicializando la capa.", e);
447 5534 nacho
                                                }
448 4934 jaume
                                        }
449 13596 nacho
                                } else {
450
                                        drawTile(g, viewPort, cancel, 0, scale);
451
                                        dataset = layerRaster.getDataSource();
452
                                        getRender().setLastRenderBuffer(layerRaster.getRender().getLastRenderBuffer());
453 13930 nacho
                                        initializeRasterLayer(null, new IBuffer[][]{{layerRaster.getRender().getLastRenderBuffer()}});
454 4356 jaume
                                }
455 13951 jaume
456 10626 caballero
                        }catch (ConnectionErrorLayerException e) {
457
                                e.printStackTrace();
458
                        }catch (UnsupportedVersionLayerException e) {
459
                                e.printStackTrace();
460
                        }catch (LoadLayerException e) {
461
                                e.printStackTrace();
462
                        }
463 4356 jaume
                }
464 13951 jaume
                callLegendChanged(null);
465 13773 nacho
                disableStopped();
466 4356 jaume
                Runtime r = Runtime.getRuntime();
467
                long mem = r.totalMemory() - r.freeMemory();
468
                System.err.println("Memoria total: " + (mem / 1024) +"KB");
469
        }
470 13596 nacho
471
        /**
472
         * Acciones que se realizan despu?s de asignar la fuente de datos a
473
         * la capa raster.
474
         *
475
         * @throws LoadLayerException
476
         */
477
        private void initializeRasterLayer(MultiRasterDataset[][] datasets, IBuffer[][] buf) throws LoadLayerException {
478
                if(this.filterList != null)
479
                        getRender().setFilterList(filterList);
480
                if(this.transparency != null)
481
                        getRender().setLastTransparency(transparency);
482
                if(this.renderBands != null)
483
                        getRender().setRenderBands(renderBands);
484
                if(datasets != null) {
485
                        String[][] names = new String[datasets.length][datasets[0].length];
486
                        for (int i = 0; i < datasets.length; i++)
487
                                for (int j = 0; j < datasets[i].length; j++)
488
                                        names[i][j] = datasets[i][j].getDataset(0)[0].getFName();
489
                        super.setLoadParams(names);
490
                }
491 13773 nacho
                super.init();
492 13614 nacho
                if(buf != null) {
493
                        int drawablesBandCount = layerRaster.getDataSource().getBands().getDrawableBandsCount();
494 13930 nacho
                        IBuffer buff = null;
495
                        if(dataset instanceof CompositeDataset)
496
                                buff = ((CompositeDataset)dataset).generateBuffer(buf, drawablesBandCount);
497
                        else
498
                                buff = buf[0][0];
499 13614 nacho
                        getRender().setLastRenderBuffer(buff);
500
                }
501 13596 nacho
        }
502 6042 jaume
503 4356 jaume
        /**
504 13237 jaume
         * This is the method used to draw a tile in a WCS mosaic layer.
505 8423 nacho
         * @param tile Tile number to draw
506 13237 jaume
         * @throws ReadDriverException
507 4356 jaume
         */
508 13237 jaume
        private void drawTile(Graphics2D g, ViewPort vp, Cancellable cancel, int tile, double scale) throws LoadLayerException, ReadDriverException {
509 4934 jaume
510 6042 jaume
                // Compute the query geometry
511 4356 jaume
                // 1. Check if it is within borders
512
                Rectangle2D extent = getFullExtent();
513 6426 jaume
        if ((vp.getAdjustedExtent().getMinX() > extent.getMaxX()) ||
514
                (vp.getAdjustedExtent().getMinY() > extent.getMaxY()) ||
515
                (vp.getAdjustedExtent().getMaxX() < extent.getMinX()) ||
516
                (vp.getAdjustedExtent().getMaxY() < extent.getMinY())) {
517 4934 jaume
            return;
518
        }
519 6042 jaume
520 4934 jaume
        // 2. Compute extent to be requested.
521
        Rectangle2D bBox = new Rectangle2D.Double();
522 6425 jaume
        Rectangle2D.intersect(vp.getAdjustedExtent(), extent, bBox);
523 6042 jaume
524 4934 jaume
        // 3. Compute size in pixels
525 6042 jaume
        double scalex = vp.getAffineTransform().getScaleX();
526
        double scaley = vp.getAffineTransform().getScaleY();
527 4934 jaume
        int wImg = (int) Math.ceil(Math.abs(bBox.getWidth() * scalex) + 1);
528
        int hImg = (int) Math.ceil(Math.abs(bBox.getHeight() * scaley) + 1);
529
        Dimension sz = new Dimension(wImg, hImg);
530
531
        if ((wImg <= 0) || (hImg <= 0)) {
532
            return;
533
        }
534 6042 jaume
535
                try {
536 8618 jaume
                        sz = new Dimension(wImg, hImg);
537 13237 jaume
538 4356 jaume
                        wcsStatus.setCoveraName( coverageName );
539
                        wcsStatus.setExtent( bBox );
540
                        wcsStatus.setFormat( format );
541
                        wcsStatus.setHeight( hImg );
542
                        wcsStatus.setWidth( wImg );
543
                        wcsStatus.setSrs(srs);
544
                        wcsStatus.setParameters( parameter );
545 4573 jaume
                        wcsStatus.setTime( time );
546
                        wcsStatus.setOnlineResource((String) onlineResources.get("GetCoverage"));
547 6042 jaume
548 5409 jaume
                        File f = getDriver().getCoverage(wcsStatus, new MyCancellable(cancel));
549
                        if (f == null)
550
                                return;
551 4356 jaume
                        String nameWordFile = f.getPath() + getExtensionWorldFile();
552
                        com.iver.andami.Utilities.createTemp(nameWordFile, this.getDataWorldFile(bBox, sz));
553 6042 jaume
554 13614 nacho
                        IStatusRaster status = super.getStatus();
555 4356 jaume
                        if(status!=null && firstLoad){
556
                                status.applyStatus(this);
557
                                firstLoad = false;
558
                        }
559
                        ViewPortData vpData = new ViewPortData(
560 4934 jaume
                                vp.getProjection(), new Extent(bBox), sz );
561 4356 jaume
                        vpData.setMat(vp.getAffineTransform());
562 4934 jaume
563 13237 jaume
                        String filePath = f.getAbsolutePath();
564
                        visualStatus.fileNames[tile] = filePath;
565 13260 nacho
566 13279 nacho
                        rasterProcess(filePath, g, vp, scale, cancel);
567 13260 nacho
568 13237 jaume
//                        this.getRender().draw(g, vpData);
569
//                        rasterProcess(g, vpData, f);
570 6042 jaume
571 10626 caballero
//                } catch (ValidationException e) {
572
//                        UnknownResponseFormatExceptionType type =
573
//                                new UnknownResponseFormatExceptionType();
574
//                        type.setLayerName(getName());
575
//                        try {
576
//                                type.setDriverName(getDriver().getName());
577
//                        } catch (Exception e1) {
578
//                                e1.printStackTrace();
579
//                        }
580
//                        type.setFormat(format);
581
//                        type.setHost(host);
582
//                        type.setProtocol("WCS");
583
//                        ReadDriverException exception = new ReadDriverException("unknown_response_format",type);
584
//                        throw exception;
585 7468 azabala
//        azabala                throw new DriverException(PluginServices.getText(this, "unknown_response_format"), e);
586 10626 caballero
//                }
587
//                catch (UnsupportedVersionLayerException e) {
588
//                        UnsuportedProtocolVersionExceptionType type =
589
//                                new UnsuportedProtocolVersionExceptionType();
590
//                        type.setLayerName(getName());
591
//                        try {
592
//                                type.setDriverName(getDriver().getName());
593
//                        } catch (Exception ex){
594
//                        }
595
//                        type.setUrl(host);
596
//                        throw new ReadDriverException(PluginServices.getText(this, "version_conflict"), e, type);
597 8618 jaume
598 7468 azabala
//        azabala                throw new DriverException(PluginServices.getText(this, "version_conflict"), e);
599 4356 jaume
                } catch (IOException e) {
600 10626 caballero
//                        ConnectionErrorExceptionType type = new ConnectionErrorExceptionType();
601
//                        type.setLayerName(getName());
602
//                        try {
603
//                                type.setDriverName(getDriver().getName());
604
//                        } catch (Exception e1) {
605
//                        }
606
//                        type.setHost(host);
607
                        throw new ConnectionErrorLayerException(getName(),e);
608
                }
609
//                catch (WCSLayerException e) {
610
////azabala: la capturamos y la convertimos en DriverException
611
//                        WCSDriverExceptionType type = new WCSDriverExceptionType();
612
//                        type.setLayerName(getName());
613
//                        try {
614
//                                type.setDriverName(getDriver().getName());
615
//                        } catch (Exception e1) {
616
//                        }
617
//                        type.setWcsStatus(wcsStatus);
618
//                        this.setVisible(false);
619
//                        throw new WDriverException("Error WCS", e,  type);
620
//
621
////            JOptionPane.showMessageDialog((Component)PluginServices.getMainFrame(), e.getMessage());
622
//
623
//        }//
624
                catch (WCSDriverException e) {
625
                        throw new LoadLayerException(getName(),e);
626
                } catch (IllegalStateException e) {
627
                        throw new LoadLayerException(getName(),e);
628
                }
629 4356 jaume
        }
630 6042 jaume
631 1979 jaume
        /**
632 4356 jaume
         * Devuelve el FMapWMSDriver.
633
         *
634
         * @return FMapWMSDriver
635
         *
636
         * @throws IllegalStateException
637
         * @throws ValidationException
638 10626 caballero
         * @throws UnsupportedVersionLayerException
639 4356 jaume
         * @throws IOException
640
         */
641 10626 caballero
        private FMapWCSDriver getDriver() throws IllegalStateException, IOException {
642 4356 jaume
                if (wcs == null) {
643 8218 jaume
                        wcs = FMapWCSDriverFactory.getFMapDriverForURL(host);
644 6116 jaume
                }
645 4356 jaume
                return wcs;
646
        }
647 4934 jaume
648 4356 jaume
        /**
649
         * Calcula el contenido del fichero de georreferenciaci?n de una imagen.
650
         * @param bBox Tama?o y posici?n de la imagen (en coordenadas de usuario)
651
         * @param sz Tama?o de la imagen en pixeles.
652
         * @return el 'WorldFile', como String.
653
         * @throws IOException
654
         */
655
        public String getDataWorldFile(Rectangle2D bBox, Dimension sz) throws IOException {
656
                StringBuffer data = new StringBuffer();
657 4934 jaume
            data.append((bBox.getMaxX() - bBox.getMinX())/(sz.getWidth() - 1)+"\n");
658
            data.append("0.0\n");
659
            data.append("0.0\n");
660 8281 nacho
            data.append("-"+(bBox.getMaxY() - bBox.getMinY())/(sz.getHeight() - 1)+"\n");
661 4934 jaume
            data.append(""+bBox.getMinX()+"\n");
662 8281 nacho
            data.append(""+bBox.getMaxY()+"\n");
663 4934 jaume
            return data.toString();
664 4356 jaume
        }
665 6042 jaume
666 13279 nacho
        /**
667
         * Carga y dibuja el raster usando la librer?a
668
         * @param filePath Ruta al fichero en disco
669
         * @param g Graphics2D
670
         * @param vp ViewPort
671
         * @param scale Escala para el draw
672
         * @param cancel Cancelaci?n para el draw
673
         * @throws ReadDriverException
674
         * @throws LoadLayerException
675
         */
676 13773 nacho
        private void rasterProcess(String filePath, Graphics2D g, ViewPort vp, double scale, Cancellable cancel) throws ReadDriverException, LoadLayerException {
677 13279 nacho
                //Cerramos el dataset asociado a la capa si est? abierto.
678 13596 nacho
                if(layerRaster != null) {
679
                        layerRaster.setRemoveRasterFlag(true);
680
                        layerRaster.getDataSource().close();
681 13279 nacho
                }
682
683
                //Cargamos el dataset con el raster de disco.
684 13596 nacho
                layerRaster = FLyrRasterSE.createLayer("", filePath, vp.getProjection());
685
                layerRaster.getRender().setBufferFactory(layerRaster.getBufferFactory());
686
687 13651 nacho
                //En caso de cargar un proyecto con XMLEntity se crean los filtros
688
                if(filterArguments != null) {
689
                        RasterFilterList fl = new RasterFilterList();
690
                        fl.addParam("IStatistics", layerRaster.getDataSource().getStatistics());
691
                        fl.addParam("MultiRasterDataset", layerRaster.getDataSource());
692
                        fl.setInitDataType(layerRaster.getDataType()[0]);
693
                        RasterFilterListManager filterListManager = new RasterFilterListManager(fl);
694
                        filterListManager.createFilterListFromStrings(filterArguments);
695 13823 nacho
                        if(fl.move(TailTrimFilter.class, 0))
696
                                fl.move(LinearEnhancementFilter.class, 1);
697
                        else
698
                                fl.move(LinearEnhancementFilter.class, 0);
699
                        fl.controlTypes();
700 13651 nacho
                        filterArguments = null;
701
                        filterList = fl;
702
                }
703
704 13279 nacho
                //Como el raster se carga a cada zoom el render se crea nuevamente y la lista de
705
                //filtros siempre estar? vacia a cada visualizaci?n. Para evitarlo tenemos que
706
                //guardar la lista de filtro aplicada en la visualizaci?n anterior.
707 13614 nacho
                if(this.filterList != null)
708 13596 nacho
                        layerRaster.getRender().setFilterList(filterList);
709 13545 nacho
                if(this.transparency != null)
710 13596 nacho
                        layerRaster.getRender().setLastTransparency(transparency);
711
                if(this.renderBands != null)
712
                        layerRaster.getRender().setRenderBands(renderBands);
713 13279 nacho
714
                //Dibujamos
715 13596 nacho
                layerRaster.draw(null, g, vp, cancel, scale);
716
717 13279 nacho
                //La primera vez asignamos la lista de filtros asociada al renderizador. Guardamos una referencia
718
                //en esta clase para que a cada zoom no se pierda.
719
                if (this.filterList == null)
720 13596 nacho
                        filterList = layerRaster.getRender().getFilterList();
721 13545 nacho
                if (this.transparency == null)
722 13596 nacho
                        transparency = layerRaster.getRender().getLastTransparency();
723
                if (this.renderBands == null)
724
                        renderBands = layerRaster.getRender().getRenderBands();
725
726 13279 nacho
        }
727 6042 jaume
728 13279 nacho
        /*
729
         * (non-Javadoc)
730 13823 nacho
         * @see com.iver.cit.gvsig.fmap.layers.FLyrDefault#cloneLayer()
731
         */
732
        public FLayer cloneLayer() throws Exception {
733
                Object par = null;
734
                if(dataset instanceof CompositeDataset)
735
                        par = ((CompositeDataset)dataset).getFileNames();
736
                else if(layerRaster != null)
737
                        par = layerRaster.getLoadParams();
738
739
                FLyrRasterSE newLayer = FLyrRasterSE.createLayer(this.getName(), par, this.getProjection());
740
                ArrayList filters = getRender().getFilterList().getStatusCloned();
741
                RasterFilterList filterList = new RasterFilterList();
742
                filterList.setInitDataType(newLayer.getDataType()[0]);
743
                filterList.setStatus(filters);
744
                newLayer.getRender().setFilterList(filterList);
745
                newLayer.getRender().setLastTransparency(new GridTransparency(getRenderTransparency()));
746
                return newLayer;
747
        }
748
749
        /*
750
         * (non-Javadoc)
751 13773 nacho
         * @see org.gvsig.fmap.raster.IRasterRendering#getRenderFilterList()
752
         */
753
        public RasterFilterList getRenderFilterList(){
754
                return (filterList != null) ? filterList : getRender().getFilterList();
755
        }
756
757
        /*
758
         * (non-Javadoc)
759 13823 nacho
         * @see org.gvsig.raster.hierarchy.IRasterRendering#setRenderFilterList(org.gvsig.raster.grid.filter.RasterFilterList)
760
         */
761
        public void setRenderFilterList(RasterFilterList filterList) {
762
                this.filterList = filterList;
763
                super.getRender().setFilterList(filterList);
764
        }
765
766
        /*
767
         * (non-Javadoc)
768 13773 nacho
         * @see org.gvsig.fmap.raster.IRasterRendering#getRenderTransparency()
769
         */
770
        public GridTransparency getRenderTransparency() {
771
                return (transparency != null) ? transparency : getRender().getLastTransparency();
772
        }
773
774
        /*
775
         * (non-Javadoc)
776
         * @see org.gvsig.raster.hierarchy.IRasterRendering#getRenderBands()
777
         */
778
        public int[] getRenderBands() {
779
                return (renderBands != null) ? renderBands : getRender().getRenderBands();
780
        }
781
782
        /*
783
         * (non-Javadoc)
784 13781 nacho
         * @see org.gvsig.raster.hierarchy.IRasterRendering#setRenderBands(int[])
785
         */
786
        public void setRenderBands(int[] renderBands) {
787
                this.renderBands = renderBands;
788
                getRender().setRenderBands(renderBands);
789
        }
790
791
        /*
792
         * (non-Javadoc)
793 13279 nacho
         * @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)
794
         */
795 10626 caballero
        public void print(Graphics2D g, ViewPort viewPort, Cancellable cancel, double scale, PrintRequestAttributeSet properties) throws ReadDriverException {
796 4398 jaume
                draw(null, g, viewPort, cancel, scale);
797 4356 jaume
        }
798 6042 jaume
799 4356 jaume
        /**
800 2094 jaume
         * Returns the XMLEntity containing the necessary info for reproduce
801
         * the layer.
802 6042 jaume
         *
803 2094 jaume
         * Devuelve el XMLEntity con la informaci?n necesaria para reproducir
804
         * la capa.
805 6042 jaume
         *
806 1979 jaume
         * @return XMLEntity.
807
         * @throws XMLException
808 1877 luisw
         */
809 1979 jaume
        public XMLEntity getXMLEntity() throws XMLException {
810
                XMLEntity xml = super.getXMLEntity();
811 4934 jaume
812 2003 jaume
                xml.putProperty("wcs.host", getHost());
813 4356 jaume
                xml.putProperty("wcs.fullExtent", StringUtilities.rect2String( fullExtent ));
814
                xml.putProperty("wcs.layerQuery", coverageName );
815
                xml.putProperty("wcs.format", format );
816
                xml.putProperty("wcs.srs", srs );
817
                xml.putProperty("wcs.time", time );
818
                xml.putProperty("wcs.parameter", parameter );
819
                xml.putProperty("wcs.coverageName", coverageName );
820
                xml.putProperty("wcs.maxResX", maxRes.getX());
821
                xml.putProperty("wcs.maxResY", maxRes.getY());
822 10707 jaume
823
                Iterator it = onlineResources.keySet().iterator();
824
                String strOnlines = "";
825
                while (it.hasNext()) {
826
                        String key = (String) it.next();
827
                        String value = (String) onlineResources.get(key);
828
                        strOnlines += key+"~##SEP2##~"+value;
829
                        if (it.hasNext())
830
                                strOnlines += "~##SEP1##~";
831
                }
832
                xml.putProperty("onlineResources", strOnlines);
833
834 13614 nacho
                IStatusRaster status = super.getStatus();
835 2646 jaume
                if (status!=null)
836 2623 nacho
                        status.getXMLEntity(xml, true, this);
837 2764 nacho
                else{
838
                        status = new StatusLayerRaster();
839
                        status.getXMLEntity(xml, true, this);
840
                }
841 1979 jaume
                return xml;
842
        }
843 4934 jaume
844 1979 jaume
        /**
845 2094 jaume
         * Reproduces the layer from an XMLEntity.
846 6042 jaume
         *
847 1979 jaume
         * A partir del XMLEntity reproduce la capa.
848 6042 jaume
         *
849 4934 jaume
          * @param xml XMLEntity
850 1979 jaume
         *
851
         * @throws XMLException
852
         * @throws DriverException
853
         * @throws DriverIOException
854
         */
855
        public void setXMLEntity(XMLEntity xml) throws XMLException {
856
                super.setXMLEntity(xml);
857 6042 jaume
858 4356 jaume
                // host
859
                try {
860
                        host = new URL(xml.getStringProperty("wcs.host"));
861
                } catch (MalformedURLException e) {
862
                        throw new XMLException(e);
863
                }
864 6042 jaume
865 4356 jaume
                // full extent
866
                fullExtent = StringUtilities.string2Rect(xml.getStringProperty("wcs.fullExtent"));
867 6042 jaume
868 4356 jaume
                // coverageQuery
869
                coverageName = xml.getStringProperty("wcs.layerQuery");
870 6042 jaume
871 4356 jaume
                // format
872
                format = xml.getStringProperty("wcs.format");
873 6042 jaume
874 4356 jaume
                // srs
875
                srs = xml.getStringProperty("wcs.srs");
876 6042 jaume
877 4356 jaume
                // time
878
                time = xml.getStringProperty("wcs.time");
879 6042 jaume
880 4356 jaume
                // parameter
881
                parameter = xml.getStringProperty("wcs.parameter");
882 6042 jaume
883 4356 jaume
                // coverage name
884
                coverageName = xml.getStringProperty("wcs.coverageName");
885 6042 jaume
886 4356 jaume
                // max resolution
887 2330 jaume
                if (xml.contains("wcs.maxRes"))
888 4356 jaume
                        maxRes = new Point2D.Double(xml.getDoubleProperty("wcs.maxRes"), xml.getDoubleProperty("wcs.maxRes"));
889
                else if (xml.contains("wcs.maxResX") && xml.contains("wcs.maxResY"))
890
                        maxRes = new Point2D.Double(xml.getDoubleProperty("wcs.maxResX"), xml.getDoubleProperty("wcs.maxResY"));
891 6042 jaume
892 4356 jaume
                // OnlineResources
893 4934 jaume
        if (xml.contains("onlineResources")) {
894
                String[] operations = xml.getStringProperty("onlineResources").split("~##SEP1##~");
895
                for (int i = 0; i < operations.length; i++) {
896 4356 jaume
                                String[] resources = operations[i].split("~##SEP2##~");
897
                                if (resources.length==2 && resources[1]!="")
898
                                        onlineResources.put(resources[0], resources[1]);
899
                        }
900 4934 jaume
        }
901 2623 nacho
                String claseStr = null;
902
                if (xml.contains("raster.class")) {
903
                        claseStr = xml.getStringProperty("raster.class");
904
                }
905 13237 jaume
906 13614 nacho
                IStatusRaster status = super.getStatus();
907 4356 jaume
                if (status!=null)
908 2623 nacho
                        status.setXMLEntity(xml, this);
909 4356 jaume
                else {
910 6042 jaume
                        //Cuando cargamos un proyecto
911
912 2623 nacho
                        if(claseStr!=null && !claseStr.equals("")){
913
                                try{
914 13823 nacho
                                        Class clase = LayerFactory.getLayerClassForLayerClassName(claseStr);
915 2623 nacho
                                        Constructor constr = clase.getConstructor(null);
916 13614 nacho
                                        status = (IStatusRaster)constr.newInstance(null);
917 13651 nacho
                                        if(status != null) {
918 2623 nacho
                                                status.setXMLEntity(xml, this);
919 13823 nacho
                                                ((StatusLayerRaster)status).setNameClass(claseStr);
920 13651 nacho
                                                filterArguments = status.getFilterArguments();
921
                                                transparency = status.getTransparency();
922
                                                renderBands = status.getRenderBands();
923
                                        }
924 4356 jaume
                                } catch(ClassNotFoundException exc) {
925 2623 nacho
                                        exc.printStackTrace();
926 4356 jaume
                                } catch(InstantiationException exc) {
927 2623 nacho
                                        exc.printStackTrace();
928 4356 jaume
                                } catch(IllegalAccessException exc) {
929 2623 nacho
                                        exc.printStackTrace();
930 4356 jaume
                                } catch(NoSuchMethodException exc) {
931 2623 nacho
                                        exc.printStackTrace();
932 4356 jaume
                                } catch(InvocationTargetException exc) {
933 2623 nacho
                                        exc.printStackTrace();
934 6042 jaume
                                }
935 2623 nacho
                        }
936
                }
937 4356 jaume
                firstLoad = true;
938 1979 jaume
        }
939 4934 jaume
940 4356 jaume
        public void setCoverageName(String coverageName) {
941
                this.coverageName = coverageName;
942
        }
943 4934 jaume
944 4356 jaume
        public void setParameter(String parametersString) {
945
                this.parameter = parametersString;
946
        }
947 4934 jaume
948 4356 jaume
        public void setTime(String time) {
949
                this.time = time;
950
        }
951 4934 jaume
952 4356 jaume
        public void setSRS(String srs) {
953
                this.srs = srs;
954 13237 jaume
                setProjection(CRSFactory.getCRS(srs));
955 4356 jaume
        }
956 4934 jaume
957 4356 jaume
        public void setFormat(String format) {
958
                this.format = format;
959
        }
960 4934 jaume
961
962 4356 jaume
        /**
963
         * Inserta el URL.
964
         *
965
         * @param host String.
966 6042 jaume
         * @throws MalformedURLException
967 4356 jaume
         */
968
        public void setHost(String host) {
969
                try {
970
                        setHost(new URL(host));
971
                } catch (MalformedURLException e) {
972 6042 jaume
973 4356 jaume
                }
974
        }
975 6042 jaume
976 1979 jaume
        /**
977 4356 jaume
         * Inserta el URL.
978
         *
979
         * @param host URL.
980
         */
981
        public void setHost(URL host) {
982
                this.host = host;
983
        }
984 4934 jaume
985 4356 jaume
        /**
986
         * Sets the layer's full extent.
987 6042 jaume
         *
988 4356 jaume
         * Establece la extensi?n m?xima de la capa.
989 6042 jaume
         *
990 4356 jaume
         * @param rect
991
         */
992
        public void setFullExtent(Rectangle2D rect) {
993
                this.fullExtent = rect;
994
        }
995 6042 jaume
996 4356 jaume
        /**
997
         * Devuelve el URL.
998
         *
999
         * @return URL.
1000
         */
1001
        public URL getHost() {
1002
                return host;
1003
        }
1004 4934 jaume
1005 4356 jaume
        /**
1006
         * Remote source layers have a bunch of properties that are required for get them from
1007
         * the servers. This method supplies a hash table containing any needed field. This hash
1008
         * table may be used to let the client to connect to a server and restore a previously saved
1009
         * layer. So, the layer itself may not be saved to the disk since the actual saved
1010
         * info is just its properties.
1011 6042 jaume
         *
1012 4356 jaume
         * @return Returns a hash table containing all the required information for
1013
         * set up a wms layer
1014
         */
1015
        public Hashtable getProperties(){
1016
                Hashtable info = new Hashtable();
1017
                info.put(   "name", coverageName);
1018
                info.put(   "host", getHost());
1019
                info.put(    "crs", srs);
1020
                info.put( "format", format);
1021
                String str = time;
1022 6042 jaume
                if (str==null)
1023 4356 jaume
                        str = "";
1024
                info.put(   "time", str);
1025
                str = parameter;
1026
                if (str==null)
1027
                        str = "";
1028 6042 jaume
                info.put("parameter", str);
1029
1030 4356 jaume
                return info;
1031
        }
1032 4934 jaume
1033 4356 jaume
        /**
1034
         * Obtiene la extensi?n del fichero de georreferenciaci?n
1035
         * @return String con la extensi?n del fichero de georreferenciaci?n dependiendo
1036 6042 jaume
         * del valor del formato obtenido del servidor. Por defecto asignaremos un .wld
1037 4356 jaume
         */
1038
        private String getExtensionWorldFile(){
1039
                String extWorldFile = ".wld";
1040 4934 jaume
            if (format.equals("image/tif") || format.equals("image/tiff"))
1041
                    extWorldFile = ".tfw";
1042
            if (format.equals("image/jpeg"))
1043
                    extWorldFile = ".jpgw";
1044
            return extWorldFile;
1045 4356 jaume
        }
1046 6042 jaume
1047 4356 jaume
        public void setMaxResolution(Point2D maxResolution) {
1048
                this.maxRes = maxResolution;
1049
        }
1050 4934 jaume
1051 4356 jaume
        /**
1052 13237 jaume
         * <p>
1053 4356 jaume
         * Gets the max resolution allowed by the coverage. Requesting a higher resolution
1054
         * than this value does not cause any error, but the info responsed is just an
1055 13237 jaume
         * interpolation. <br>
1056
         * </p>
1057
         *
1058
         * <p>
1059 4356 jaume
         * In exchange for obtaining a greater file and without additional information,
1060 13237 jaume
         * we can easily fit it into the View. <br>
1061
         * </p>
1062 6042 jaume
         *
1063 13237 jaume
         * <p>
1064 4356 jaume
         * Obtiene la resoluci?n m?xima soportada por la cobertura. La petici?n
1065
         * de una resoluci?n superior a la soportada no provoca ning?n error, aunque
1066 13237 jaume
         * la informaci?n obtenida s?lo es una mera interpolaci?n de informaci?n. <br>
1067
         * </p>
1068
         *
1069
         * <p>
1070 4356 jaume
         * A cambio de obtener un archivo mayor y sin informaci?n adicional, podemos
1071 13237 jaume
         * f?cilmente acoplarlo a la vista. <br>
1072
         * </p>
1073
         *
1074 4356 jaume
         * @return double
1075
         */
1076
        public Point2D getMaxResolution() {
1077
                if (maxRes==null)
1078
                        maxRes = wcs.getMaxResolution(coverageName);
1079
                return maxRes;
1080
        }
1081 4934 jaume
1082 6042 jaume
1083 4356 jaume
        public void setDriver(FMapWCSDriver driver) {
1084 8577 jaume
                this.wcs = driver;
1085 4356 jaume
        }
1086 6042 jaume
1087 6005 nacho
        /*
1088
         *  (non-Javadoc)
1089
         * @see com.iver.cit.gvsig.fmap.layers.RasterOperations#getTileSize()
1090
         */
1091
        public int[] getTileSize() {
1092 6042 jaume
                int[] size = {maxTileDrawWidth, maxTileDrawHeight};
1093 6005 nacho
                return size;
1094
        }
1095
1096
        /*
1097
         *  (non-Javadoc)
1098
         * @see com.iver.cit.gvsig.fmap.layers.RasterOperations#isTiled()
1099
         */
1100
        public boolean isTiled() {
1101
                return mustTileDraw;
1102
        }
1103 13288 nacho
1104
        /*
1105
         * (non-Javadoc)
1106
         * @see org.gvsig.fmap.raster.layers.FLyrRasterSE#isActionEnabled(int)
1107
         */
1108
        public boolean isActionEnabled(int action) {
1109 13600 bsanchez
                switch (action) {
1110
                        case IRasterLayerActions.ZOOM_PIXEL_RESOLUTION:
1111
                        case IRasterLayerActions.FLYRASTER_BAR_TOOLS:
1112 13607 bsanchez
                        case IRasterLayerActions.BANDS_FILE_LIST:
1113 13823 nacho
                        case IRasterLayerActions.PANSHARPENING:
1114 13600 bsanchez
                                return false;
1115 13614 nacho
                        case IRasterLayerActions.BANDS_RGB:
1116
                                return true;
1117 13600 bsanchez
                }
1118
1119 13288 nacho
                return super.isActionEnabled(action);
1120
        }
1121 13596 nacho
1122 13279 nacho
}