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