Statistics
| Revision:

svn-gvsig-desktop / trunk / extensions / extWCS / src / com / iver / cit / gvsig / fmap / layers / FLyrWCS.java @ 13773

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