svn-gvsig-desktop / tags / v1_0_2_Build_896 / extensions / extWCS / src / com / iver / cit / gvsig / fmap / layers / FLyrWCS.java @ 10391
History | View | Annotate | Download (33.6 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 | 4683 | jorpiell | import java.util.Map; |
62 | 1877 | luisw | |
63 | 9013 | caballero | import javax.print.attribute.PrintRequestAttributeSet; |
64 | |||
65 | 5980 | nacho | import org.cresques.filter.RasterFilterStack; |
66 | import org.cresques.filter.RasterFilterStackManager; |
||
67 | 4356 | jaume | import org.cresques.geo.ViewPortData; |
68 | 5991 | nacho | import org.cresques.io.GdalFile; |
69 | 2623 | nacho | import org.cresques.io.GeoRasterFile; |
70 | 9058 | nacho | import org.cresques.io.data.Grid; |
71 | import org.cresques.io.exceptions.NotSupportedExtensionException; |
||
72 | 4356 | jaume | import org.cresques.px.Extent; |
73 | import org.cresques.px.PxRaster; |
||
74 | import org.exolab.castor.xml.ValidationException; |
||
75 | import org.gvsig.remoteClient.wcs.WCSStatus; |
||
76 | 5409 | jaume | import org.gvsig.remoteClient.wms.ICancellable; |
77 | 2623 | nacho | |
78 | 2420 | jaume | import com.iver.andami.PluginServices; |
79 | 8765 | jjdelcerro | import com.iver.cit.gvsig.fmap.ConnectionErrorExceptionType; |
80 | 1877 | luisw | import com.iver.cit.gvsig.fmap.DriverException; |
81 | 8765 | jjdelcerro | import com.iver.cit.gvsig.fmap.UnknownResponseFormatExceptionType; |
82 | import com.iver.cit.gvsig.fmap.UnsuportedProtocolVersionExceptionType; |
||
83 | 1877 | luisw | import com.iver.cit.gvsig.fmap.ViewPort; |
84 | 8765 | jjdelcerro | import com.iver.cit.gvsig.fmap.WCSDriverExceptionType; |
85 | 1979 | jaume | import com.iver.cit.gvsig.fmap.drivers.DriverIOException; |
86 | 4356 | jaume | import com.iver.cit.gvsig.fmap.drivers.UnsupportedVersionException; |
87 | 1961 | jaume | import com.iver.cit.gvsig.fmap.drivers.wcs.FMapWCSDriver; |
88 | 6042 | jaume | import com.iver.cit.gvsig.fmap.drivers.wcs.FMapWCSDriverFactory; |
89 | 5409 | jaume | import com.iver.cit.gvsig.fmap.drivers.wcs.WCSException; |
90 | 4356 | jaume | import com.iver.cit.gvsig.fmap.layers.layerOperations.InfoByPoint; |
91 | 5080 | ldiaz | import com.iver.cit.gvsig.fmap.layers.layerOperations.StringXMLItem; |
92 | 5203 | ldiaz | import com.iver.cit.gvsig.fmap.layers.layerOperations.XMLItem; |
93 | 8765 | jjdelcerro | import com.iver.utiles.DoubleUtilities; |
94 | 1979 | jaume | import com.iver.utiles.StringUtilities; |
95 | import com.iver.utiles.XMLEntity; |
||
96 | 5317 | fjp | import com.iver.utiles.swing.threads.Cancellable; |
97 | 1877 | luisw | |
98 | 5203 | ldiaz | |
99 | 1877 | luisw | /**
|
100 | 2097 | jaume | * Class for the WCS layer.
|
101 | 6042 | jaume | *
|
102 | 1961 | jaume | * Capa para el WCS.
|
103 | 6042 | jaume | *
|
104 | 1877 | luisw | * @author jaume - jaume.dominguez@iver.es
|
105 | */
|
||
106 | 4356 | jaume | public class FLyrWCS extends FLyrDefault implements RasterOperations, InfoByPoint{ |
107 | private FMapWCSDriver wcs = null; |
||
108 | 4934 | jaume | |
109 | 4356 | jaume | private URL host; |
110 | private String coverageName; |
||
111 | private Rectangle2D fullExtent; |
||
112 | private String format; |
||
113 | private String srs; |
||
114 | private String time; |
||
115 | private String parameter; |
||
116 | private Point2D maxRes; |
||
117 | private Hashtable onlineResources = new Hashtable(); |
||
118 | 6042 | jaume | |
119 | 4573 | jaume | private WCSStatus wcsStatus = new WCSStatus(); |
120 | 6042 | jaume | |
121 | 2623 | nacho | private StatusRasterInterface status = null; |
122 | 2651 | nacho | private int posX = 0, posY = 0; |
123 | private double posXWC = 0, posYWC = 0; |
||
124 | private int r = 0, g = 0, b = 0; |
||
125 | 4356 | jaume | private RasterFilterStackManager stackManager = null; |
126 | private PxRaster raster = null; |
||
127 | private GeoRasterFile rasterFile = null; |
||
128 | private RasterFilterStack filterStack;
|
||
129 | private boolean firstLoad = false; |
||
130 | 5534 | nacho | private int rband = 0, gband = 1, bband = 2; |
131 | 4356 | jaume | private VisualStatus visualStatus = new VisualStatus(); |
132 | 4934 | jaume | |
133 | 5534 | nacho | private boolean mustTileDraw = false; |
134 | private int maxTileDrawWidth = 1023; |
||
135 | private int maxTileDrawHeight = 1023; |
||
136 | private int maxTilePrintWidth = 250; |
||
137 | private int maxTilePrintHeight = 250; |
||
138 | 9058 | nacho | |
139 | private Grid grid = null; |
||
140 | 4934 | jaume | |
141 | 5409 | jaume | private class MyCancellable implements ICancellable |
142 | { |
||
143 | |||
144 | private Cancellable original;
|
||
145 | public MyCancellable(Cancellable cancelOriginal)
|
||
146 | { |
||
147 | this.original = cancelOriginal;
|
||
148 | } |
||
149 | public boolean isCanceled() { |
||
150 | return original.isCanceled();
|
||
151 | } |
||
152 | 6042 | jaume | |
153 | 5409 | jaume | } |
154 | 4683 | jorpiell | public FLyrWCS(){
|
155 | super();
|
||
156 | } |
||
157 | 6042 | jaume | |
158 | 4683 | jorpiell | public FLyrWCS(Map args) throws DriverIOException{ |
159 | 8765 | jjdelcerro | FMapWCSDriver drv = null;
|
160 | 6042 | jaume | String host = (String)args.get("HOST"); |
161 | 4683 | jorpiell | String sCoverage = (String) args.get((String) "COVERAGE"); |
162 | 6042 | jaume | |
163 | 4683 | jorpiell | try {
|
164 | this.setHost(new URL(host)); |
||
165 | } catch (MalformedURLException e) { |
||
166 | //e.printStackTrace();
|
||
167 | 6042 | jaume | throw new DriverIOException("Malformed host URL, '" + host + "' (" + e.toString() + ")."); |
168 | 4683 | jorpiell | } |
169 | 8765 | jjdelcerro | try {
|
170 | drv = this.getDriver();
|
||
171 | } catch (Exception e) { |
||
172 | // e.printStackTrace();
|
||
173 | throw new DriverIOException("Can't get driver to host '" + host + "' (" + e.toString() + ")."); |
||
174 | } |
||
175 | |||
176 | 4683 | jorpiell | try{
|
177 | 9048 | jaume | if (!drv.connect(false, null)){ |
178 | 4683 | jorpiell | throw new DriverIOException("Can't connect to host '" + host + "'."); |
179 | } |
||
180 | }catch(Exception e){ |
||
181 | throw new DriverIOException("Can't connect to host '" + host + "'."); |
||
182 | } |
||
183 | 6042 | jaume | |
184 | 8765 | jjdelcerro | WCSLayer wcsNode = drv.getLayer(sCoverage); |
185 | |||
186 | 4683 | jorpiell | if (wcsNode == null){ |
187 | throw new DriverIOException("The server '" + host + "' doesn't has the coverage '" + sCoverage + "'."); |
||
188 | 6042 | jaume | } |
189 | |||
190 | 4683 | jorpiell | try{
|
191 | 8765 | jjdelcerro | this.setFullExtent(drv.getFullExtent(sCoverage,
|
192 | 4683 | jorpiell | (String) args.get((String) "CRS"))); |
193 | this.setFormat((String) args.get((String) "FORMAT")); |
||
194 | this.setParameter("BANDS=" + (String) args.get((String) "BANDS")); |
||
195 | this.setSRS((String) args.get((String) "CRS")); |
||
196 | this.setName(sCoverage);
|
||
197 | this.setCoverageName(sCoverage);
|
||
198 | }catch (Exception e){ |
||
199 | throw new DriverIOException("The server '" + host + "' is not able to load the coverage '" + sCoverage + "'."); |
||
200 | } |
||
201 | 6042 | jaume | |
202 | 4683 | jorpiell | } |
203 | 6042 | jaume | |
204 | 4356 | jaume | /**
|
205 | 8765 | jjdelcerro | * Clase que contiene los datos de visualizaci?n de WCS. Tiene datos que representan al
|
206 | * raster en la vista. Este raster puede estar compuesto por tiles por lo que valores
|
||
207 | * como el ancho total o el m?nimo o m?ximo deben ser calculados a partir de todos los
|
||
208 | * tiles visualizados.
|
||
209 | 4356 | jaume | * @author Nacho Brodin (brodin_ign@gva.es)
|
210 | */
|
||
211 | private class VisualStatus { |
||
212 | /**
|
||
213 | 6042 | jaume | * Ancho y alto de la imagen o del conjunto de tiles si los tiene. Coincide con
|
214 | 4356 | jaume | * el ancho y alto del viewPort
|
215 | */
|
||
216 | private int width = 0, height = 0; |
||
217 | private double minX = 0D, minY = 0D, maxX = 0D, maxY = 0D; |
||
218 | private int bandCount = 0; |
||
219 | private int dataType = DataBuffer.TYPE_UNDEFINED; |
||
220 | 8765 | jjdelcerro | |
221 | /**
|
||
222 | * Ancho y alto total del raster que ser? la suma de todos los tiles.
|
||
223 | */
|
||
224 | private int rasterWidth = 0, rasterHeight = 0; |
||
225 | private double rasterMinX = Double.MAX_VALUE, rasterMinY = Double.MAX_VALUE; |
||
226 | private double rasterMaxX = 0, rasterMaxY = 0; |
||
227 | /**
|
||
228 | * Lista de nombre de fichero que componen toda la visualizaci?n.
|
||
229 | */
|
||
230 | private String[] fileNames = null; |
||
231 | 4356 | jaume | } |
232 | 4934 | jaume | |
233 | 4356 | jaume | /*
|
234 | * (non-Javadoc)
|
||
235 | * @see com.iver.cit.gvsig.fmap.layers.RasterOperations#setRGB(int, int, int)
|
||
236 | */
|
||
237 | public void setRGB(int r, int g, int b) { |
||
238 | this.r = r;
|
||
239 | this.g = g;
|
||
240 | this.b = b;
|
||
241 | } |
||
242 | 6042 | jaume | |
243 | 4356 | jaume | /*
|
244 | * (non-Javadoc)
|
||
245 | * @see com.iver.cit.gvsig.fmap.layers.RasterOperations#getFilterStack()
|
||
246 | */
|
||
247 | public RasterFilterStack getFilterStack() {
|
||
248 | if(raster!=null) |
||
249 | return raster.filterStack;
|
||
250 | return null; |
||
251 | } |
||
252 | 6042 | jaume | |
253 | 4356 | jaume | /*
|
254 | * (non-Javadoc)
|
||
255 | * @see com.iver.cit.gvsig.fmap.layers.RasterOperations#setFilterStack(org.cresques.io.raster.RasterFilterStack)
|
||
256 | */
|
||
257 | public void setFilterStack(RasterFilterStack stack) { |
||
258 | this.filterStack = stack;
|
||
259 | } |
||
260 | 6042 | jaume | |
261 | 4356 | jaume | /*
|
262 | * (non-Javadoc)
|
||
263 | * @see com.iver.cit.gvsig.fmap.layers.RasterOperations#getSource()
|
||
264 | */
|
||
265 | public RasterAdapter getSource() {
|
||
266 | return null; |
||
267 | } |
||
268 | 6042 | jaume | |
269 | 4356 | jaume | /*
|
270 | * (non-Javadoc)
|
||
271 | * @see com.iver.cit.gvsig.fmap.layers.RasterOperations#setSource(com.iver.cit.gvsig.fmap.layers.RasterAdapter)
|
||
272 | */
|
||
273 | public void setSource(RasterAdapter ra) { |
||
274 | } |
||
275 | 6042 | jaume | |
276 | 4356 | jaume | /*
|
277 | * (non-Javadoc)
|
||
278 | * @see com.iver.cit.gvsig.fmap.layers.RasterOperations#setPos(int, int)
|
||
279 | */
|
||
280 | public void setPos(int x, int y) { |
||
281 | this.posX = x;
|
||
282 | this.posY = y;
|
||
283 | } |
||
284 | 6042 | jaume | |
285 | 4356 | jaume | /*
|
286 | * (non-Javadoc)
|
||
287 | * @see com.iver.cit.gvsig.fmap.layers.RasterOperations#setPosWC(double, double)
|
||
288 | */
|
||
289 | public void setPosWC(double x, double y) { |
||
290 | this.posXWC = x;
|
||
291 | this.posYWC = y;
|
||
292 | } |
||
293 | 6042 | jaume | |
294 | 4356 | jaume | /*
|
295 | * (non-Javadoc)
|
||
296 | * @see com.iver.cit.gvsig.fmap.layers.RasterOperations#getPixel(double, double)
|
||
297 | */
|
||
298 | public int[] getPixel(double wcx, double wcy) { |
||
299 | if(getPxRaster() != null) |
||
300 | return getPxRaster().getPixel(wcx, wcy);
|
||
301 | 4934 | jaume | return null; |
302 | 4356 | jaume | } |
303 | 6042 | jaume | |
304 | 4356 | jaume | /*
|
305 | * (non-Javadoc)
|
||
306 | * @see com.iver.cit.gvsig.fmap.layers.RasterOperations#setBand(int, int)
|
||
307 | */
|
||
308 | public void setBand(int flag, int nBand) { |
||
309 | switch(flag){
|
||
310 | case GeoRasterFile.RED_BAND:setBandR(nBand);break; |
||
311 | case GeoRasterFile.GREEN_BAND:setBandG(nBand);break; |
||
312 | case GeoRasterFile.BLUE_BAND:setBandB(nBand);break; |
||
313 | } |
||
314 | } |
||
315 | 6042 | jaume | |
316 | 4356 | jaume | /**
|
317 | * Sets the R-band.
|
||
318 | 6042 | jaume | *
|
319 | 4356 | jaume | * Asigna la banda R.
|
320 | * @param r
|
||
321 | */
|
||
322 | public void setBandR(int r){ |
||
323 | this.rband = r;
|
||
324 | } |
||
325 | 6042 | jaume | |
326 | 4356 | jaume | /**
|
327 | * Sets the G-band.
|
||
328 | 6042 | jaume | *
|
329 | 4356 | jaume | * Asigna la banda G
|
330 | * @param g
|
||
331 | */
|
||
332 | public void setBandG(int g){ |
||
333 | this.gband = g;
|
||
334 | } |
||
335 | 6042 | jaume | |
336 | 4356 | jaume | /**
|
337 | * Sets the B-band.
|
||
338 | 6042 | jaume | *
|
339 | 4356 | jaume | * Asigna la banda B
|
340 | * @param b
|
||
341 | */
|
||
342 | public void setBandB(int b){ |
||
343 | this.bband = b;
|
||
344 | } |
||
345 | 6042 | jaume | |
346 | 4356 | jaume | /*
|
347 | * (non-Javadoc)
|
||
348 | * @see com.iver.cit.gvsig.fmap.layers.RasterOperations#getAttributes()
|
||
349 | */
|
||
350 | public ArrayList getAttributes() { |
||
351 | if (rasterFile != null){ |
||
352 | ArrayList attr = new ArrayList(); |
||
353 | String dataType = "Byte"; |
||
354 | if (rasterFile.getDataType() == DataBuffer.TYPE_BYTE) dataType = "Byte"; |
||
355 | else if (visualStatus.dataType == DataBuffer.TYPE_SHORT) |
||
356 | dataType = "Short";
|
||
357 | else if (visualStatus.dataType == DataBuffer.TYPE_USHORT) |
||
358 | dataType = "Unsigned Short";
|
||
359 | else if (visualStatus.dataType == DataBuffer.TYPE_INT) |
||
360 | dataType = "Integer";
|
||
361 | else if (visualStatus.dataType == DataBuffer.TYPE_FLOAT) |
||
362 | dataType = "Float";
|
||
363 | else if (visualStatus.dataType == DataBuffer.TYPE_DOUBLE) |
||
364 | dataType = "Double";
|
||
365 | else
|
||
366 | dataType = "Unknown";
|
||
367 | 4934 | jaume | |
368 | 4356 | jaume | Object [][] a = { |
369 | 4934 | jaume | {"Filename",rasterFile.getName().substring(rasterFile.getName().lastIndexOf("/")+1, rasterFile.getName().length())}, |
370 | {"Filesize",new Long(0)}, |
||
371 | {"Width",new Integer((int)this.getWidth())}, |
||
372 | {"Height", new Integer((int)this.getHeight())}, |
||
373 | {"Bands", new Integer(visualStatus.bandCount)}, |
||
374 | {"BandDataType", dataType}
|
||
375 | 4356 | jaume | }; |
376 | for (int i=0; i<a.length; i++) |
||
377 | attr.add(a[i]); |
||
378 | 4934 | jaume | |
379 | 4356 | jaume | return attr;
|
380 | } |
||
381 | return null; |
||
382 | } |
||
383 | 6042 | jaume | |
384 | 4356 | jaume | /*
|
385 | * (non-Javadoc)
|
||
386 | * @see com.iver.cit.gvsig.fmap.layers.RasterOperations#getMaxX()
|
||
387 | */
|
||
388 | public double getMaxX() { |
||
389 | return visualStatus.maxX;
|
||
390 | } |
||
391 | 6042 | jaume | |
392 | 4356 | jaume | /*
|
393 | * (non-Javadoc)
|
||
394 | * @see com.iver.cit.gvsig.fmap.layers.RasterOperations#getMaxY()
|
||
395 | */
|
||
396 | public double getMaxY() { |
||
397 | return visualStatus.maxY;
|
||
398 | } |
||
399 | 6042 | jaume | |
400 | 4356 | jaume | /*
|
401 | * (non-Javadoc)
|
||
402 | * @see com.iver.cit.gvsig.fmap.layers.RasterOperations#getMinX()
|
||
403 | */
|
||
404 | public double getMinX() { |
||
405 | return visualStatus.minX;
|
||
406 | } |
||
407 | 6042 | jaume | |
408 | 4356 | jaume | /*
|
409 | * (non-Javadoc)
|
||
410 | * @see com.iver.cit.gvsig.fmap.layers.RasterOperations#getMinY()
|
||
411 | */
|
||
412 | public double getMinY() { |
||
413 | return visualStatus.minY;
|
||
414 | } |
||
415 | 6042 | jaume | |
416 | 4356 | jaume | /*
|
417 | * (non-Javadoc)
|
||
418 | * @see com.iver.cit.gvsig.fmap.layers.RasterOperations#getWidth()
|
||
419 | */
|
||
420 | public double getWidth() { |
||
421 | return visualStatus.width;
|
||
422 | } |
||
423 | 6042 | jaume | |
424 | 4356 | jaume | /*
|
425 | * (non-Javadoc)
|
||
426 | * @see com.iver.cit.gvsig.fmap.layers.RasterOperations#getHeight()
|
||
427 | */
|
||
428 | public double getHeight() { |
||
429 | return visualStatus.height;
|
||
430 | } |
||
431 | 6042 | jaume | |
432 | 5080 | ldiaz | /**
|
433 | 6042 | jaume | * @deprecated
|
434 | 5080 | ldiaz | * @see com.iver.cit.gvsig.fmap.layers.layerOperations.InfoByPoint#getInfo
|
435 | 4356 | jaume | */
|
436 | public String queryByPoint(Point p) throws DriverException { |
||
437 | String data = "<file:"+getName().replaceAll("[^a-zA-Z0-9]","")+">\n"; |
||
438 | ArrayList attr = this.getAttributes(); |
||
439 | data += " <raster\n";
|
||
440 | data += " File=\""+getName()+"\"\n"; |
||
441 | for (int i=0; i<attr.size(); i++) { |
||
442 | Object [] a = (Object []) attr.get(i); |
||
443 | 4934 | jaume | |
444 | 4356 | jaume | data += " "+a[0].toString()+"="; |
445 | if (a[1].toString() instanceof String) |
||
446 | data += "\""+a[1].toString()+"\"\n"; |
||
447 | else
|
||
448 | data += a[1].toString()+"\n"; |
||
449 | } |
||
450 | data += " Point=\""+posX+" , "+posY+"\"\n"; |
||
451 | data += " Point_WC=\""+posXWC+" , "+posYWC+"\"\n"; |
||
452 | data += " RGB=\""+r+", "+g+", "+b+"\"\n"; |
||
453 | data += " />\n";
|
||
454 | 4934 | jaume | |
455 | 4356 | jaume | data += "</file:"+getName().replaceAll("[^a-zA-Z0-9]","")+">\n"; |
456 | System.out.println(data);
|
||
457 | return data;
|
||
458 | } |
||
459 | 5080 | ldiaz | /**
|
460 | * @see com.iver.cit.gvsig.fmap.layers.layerOperations.InfoByPoint#getInfo
|
||
461 | */
|
||
462 | 8765 | jjdelcerro | public XMLItem[] getInfo(Point point, double tolerance, Cancellable cancel ) throws DriverException { |
463 | 5080 | ldiaz | String data = "<file:"+getName().replaceAll("[^a-zA-Z0-9]","")+">\n"; |
464 | 8765 | jjdelcerro | |
465 | Point2D pReal = getMapContext().getViewPort().toMapPoint(point);
|
||
466 | Point2D px = null; |
||
467 | if( pReal.getX() > this.getMinX() && |
||
468 | pReal.getX() < this.getMaxX() &&
|
||
469 | pReal.getY() > this.getMinY() &&
|
||
470 | pReal.getY() < this.getMaxY()){
|
||
471 | |||
472 | px = new Point2D.Double(); |
||
473 | double w = (visualStatus.rasterMaxX - visualStatus.rasterMinX);
|
||
474 | double h = (visualStatus.rasterMaxY - visualStatus.rasterMinY);
|
||
475 | px.setLocation(((pReal.getX() - visualStatus.rasterMinX) * visualStatus.rasterWidth) / w, |
||
476 | ((visualStatus.rasterMaxY - pReal.getY()) * visualStatus.rasterHeight) / h); |
||
477 | } |
||
478 | |||
479 | int[] rgb = this.getPixel(pReal.getX(), pReal.getY()); |
||
480 | |||
481 | StringXMLItem[] item = new StringXMLItem[1]; |
||
482 | |||
483 | 5080 | ldiaz | data += " <raster\n";
|
484 | 8765 | jjdelcerro | data += " View_Point=\""+point.getX()+" , "+point.getY()+"\"\n"; |
485 | data += " World_Point=\""+DoubleUtilities.format(pReal.getX(), 3)+" , "+ DoubleUtilities.format(pReal.getY(), 3)+"\"\n"; |
||
486 | if( px == null || px.getX() > visualStatus.rasterWidth || px.getX() < 0 || |
||
487 | 9058 | nacho | px.getY() > visualStatus.rasterHeight || px.getY() < 0)
|
488 | data += " Pixel_Point=\"Out\"\n";
|
||
489 | else{
|
||
490 | data += " Pixel_Point=\""+(int)px.getX()+" , "+(int)px.getY()+"\"\n"; |
||
491 | data += " Band_Value=\"";
|
||
492 | for(int file = 0; file < visualStatus.fileNames.length; file++ ){ |
||
493 | GdalFile rf; |
||
494 | try {
|
||
495 | rf = new GdalFile(getMapContext().getViewPort().getProjection(), visualStatus.fileNames[file]);
|
||
496 | } catch (NotSupportedExtensionException e) {
|
||
497 | throw new DriverException("Open File Error."); |
||
498 | 8765 | jjdelcerro | } |
499 | 9058 | nacho | Extent ex = rf.getExtent(); |
500 | |||
501 | if(pReal.getX() >= ex.minX() && pReal.getX() <= ex.maxX() && pReal.getY() >= ex.minY() && pReal.getY() <= ex.maxY()){
|
||
502 | for(int i = 0; i < visualStatus.bandCount; i++){ |
||
503 | Object pxData = rf.getData((int)px.getX(), (int)px.getY(), i); |
||
504 | if(pxData != null){ |
||
505 | if(visualStatus.dataType >= 0 && visualStatus.dataType <= 3) |
||
506 | data += ((Integer)pxData).intValue()+" "; |
||
507 | |||
508 | if(visualStatus.dataType >= 4) |
||
509 | data += ((Float)pxData).floatValue()+" "; |
||
510 | |||
511 | if(visualStatus.dataType >= 5) |
||
512 | data += ((Double)pxData).doubleValue()+" "; |
||
513 | } |
||
514 | } |
||
515 | 8765 | jjdelcerro | } |
516 | 9058 | nacho | rf.close(); |
517 | 8765 | jjdelcerro | } |
518 | 9058 | nacho | data += "\"\n";
|
519 | 8765 | jjdelcerro | } |
520 | 9058 | nacho | |
521 | if(rgb != null) |
||
522 | data += " RGB=\""+rgb[1]+" "+rgb[2]+" "+rgb[3]+"\"\n"; |
||
523 | |||
524 | data += " />\n";
|
||
525 | data += "</file:"+getName().replaceAll("[^a-zA-Z0-9]","")+">\n"; |
||
526 | 8765 | jjdelcerro | |
527 | 9058 | nacho | item[0] = new StringXMLItem(data, this); |
528 | return item;
|
||
529 | 5080 | ldiaz | } |
530 | 6042 | jaume | |
531 | 4356 | jaume | /*
|
532 | * (non-Javadoc)
|
||
533 | * @see com.iver.cit.gvsig.fmap.layers.FLayer#getFullExtent()
|
||
534 | */
|
||
535 | public Rectangle2D getFullExtent() { |
||
536 | return fullExtent;
|
||
537 | } |
||
538 | 6042 | jaume | |
539 | 4356 | jaume | /*
|
540 | * (non-Javadoc)
|
||
541 | * @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)
|
||
542 | */
|
||
543 | public void draw(BufferedImage image, Graphics2D g, ViewPort viewPort, Cancellable cancel, double scale) throws DriverException { |
||
544 | 6402 | jaume | |
545 | 4356 | jaume | if (isWithinScale(scale)){
|
546 | Point2D p = viewPort.getOffset();
|
||
547 | // p will be (0, 0) when drawing a view or other when painting onto
|
||
548 | // the Layout.
|
||
549 | visualStatus.width = viewPort.getImageWidth(); |
||
550 | visualStatus.height = viewPort.getImageHeight(); |
||
551 | visualStatus.minX = viewPort.getAdjustedExtent().getMinX(); |
||
552 | visualStatus.minY = viewPort.getAdjustedExtent().getMinY(); |
||
553 | visualStatus.maxX = viewPort.getAdjustedExtent().getMaxX(); |
||
554 | visualStatus.maxY = viewPort.getAdjustedExtent().getMaxY(); |
||
555 | 8765 | jjdelcerro | visualStatus.rasterWidth = 0;
|
556 | visualStatus.rasterHeight = 0;
|
||
557 | visualStatus.rasterMinX = Double.MAX_VALUE;
|
||
558 | visualStatus.rasterMinY = Double.MAX_VALUE;
|
||
559 | visualStatus.rasterMaxX = 0;
|
||
560 | visualStatus.rasterMaxY = 0;
|
||
561 | visualStatus.fileNames = new String[1]; |
||
562 | 6042 | jaume | |
563 | 5534 | nacho | if(mustTileDraw){
|
564 | if(viewPort.getImageWidth()<= maxTileDrawWidth && viewPort.getImageHeight()<=maxTileDrawHeight)
|
||
565 | 8765 | jjdelcerro | drawTile(g, viewPort, cancel, 0);
|
566 | 5534 | nacho | else{
|
567 | Rectangle r = new Rectangle((int) p.getX(), (int) p.getY(), viewPort.getImageWidth(), viewPort.getImageHeight()); |
||
568 | Tiling tiles = new Tiling(maxTileDrawWidth, maxTileDrawHeight, r);
|
||
569 | tiles.setAffineTransform((AffineTransform) viewPort.getAffineTransform().clone());
|
||
570 | 8765 | jjdelcerro | visualStatus.fileNames = new String[tiles.getNumTiles()]; |
571 | 5534 | nacho | for (int tileNr=0; tileNr < tiles.getNumTiles(); tileNr++) { |
572 | // drawing part
|
||
573 | try {
|
||
574 | ViewPort vp = tiles.getTileViewPort(viewPort, tileNr); |
||
575 | 8765 | jjdelcerro | drawTile(g, vp, cancel, tileNr); |
576 | 5534 | nacho | } catch (NoninvertibleTransformException e) { |
577 | e.printStackTrace(); |
||
578 | } |
||
579 | 4934 | jaume | } |
580 | 4356 | jaume | } |
581 | 5534 | nacho | }else
|
582 | 8765 | jjdelcerro | drawTile(g, viewPort, cancel, 0);
|
583 | 4356 | jaume | } |
584 | Runtime r = Runtime.getRuntime(); |
||
585 | long mem = r.totalMemory() - r.freeMemory();
|
||
586 | System.err.println("Memoria total: " + (mem / 1024) +"KB"); |
||
587 | } |
||
588 | 6042 | jaume | |
589 | 4356 | jaume | /**
|
590 | * This is the method used to draw a tile in a WMS mosaic layer.
|
||
591 | 8765 | jjdelcerro | * @param tile Tile number to draw
|
592 | 4356 | jaume | */
|
593 | 8765 | jjdelcerro | private void drawTile(Graphics2D g, ViewPort vp, Cancellable cancel, int tile) throws DriverException { |
594 | 4934 | jaume | |
595 | 6042 | jaume | // Compute the query geometry
|
596 | 4356 | jaume | // 1. Check if it is within borders
|
597 | Rectangle2D extent = getFullExtent();
|
||
598 | 6426 | jaume | if ((vp.getAdjustedExtent().getMinX() > extent.getMaxX()) ||
|
599 | (vp.getAdjustedExtent().getMinY() > extent.getMaxY()) || |
||
600 | (vp.getAdjustedExtent().getMaxX() < extent.getMinX()) || |
||
601 | (vp.getAdjustedExtent().getMaxY() < extent.getMinY())) { |
||
602 | 4934 | jaume | return;
|
603 | } |
||
604 | 6042 | jaume | |
605 | 4934 | jaume | // 2. Compute extent to be requested.
|
606 | Rectangle2D bBox = new Rectangle2D.Double(); |
||
607 | 6425 | jaume | Rectangle2D.intersect(vp.getAdjustedExtent(), extent, bBox);
|
608 | 6042 | jaume | |
609 | 4934 | jaume | // 3. Compute size in pixels
|
610 | 6042 | jaume | double scalex = vp.getAffineTransform().getScaleX();
|
611 | double scaley = vp.getAffineTransform().getScaleY();
|
||
612 | 4934 | jaume | int wImg = (int) Math.ceil(Math.abs(bBox.getWidth() * scalex) + 1); |
613 | int hImg = (int) Math.ceil(Math.abs(bBox.getHeight() * scaley) + 1); |
||
614 | Dimension sz = new Dimension(wImg, hImg); |
||
615 | |||
616 | if ((wImg <= 0) || (hImg <= 0)) { |
||
617 | return;
|
||
618 | } |
||
619 | 6042 | jaume | |
620 | try {
|
||
621 | 8765 | jjdelcerro | sz = new Dimension(wImg, hImg); |
622 | Rectangle2D.intersect(vp.getAdjustedExtent(), extent, bBox);
|
||
623 | |||
624 | 4356 | jaume | wcsStatus.setCoveraName( coverageName ); |
625 | wcsStatus.setExtent( bBox ); |
||
626 | wcsStatus.setFormat( format ); |
||
627 | wcsStatus.setHeight( hImg ); |
||
628 | wcsStatus.setWidth( wImg ); |
||
629 | wcsStatus.setSrs(srs); |
||
630 | wcsStatus.setParameters( parameter ); |
||
631 | 4573 | jaume | wcsStatus.setTime( time ); |
632 | wcsStatus.setOnlineResource((String) onlineResources.get("GetCoverage")); |
||
633 | 6042 | jaume | |
634 | 5409 | jaume | File f = getDriver().getCoverage(wcsStatus, new MyCancellable(cancel)); |
635 | if (f == null) |
||
636 | return;
|
||
637 | 4356 | jaume | String nameWordFile = f.getPath() + getExtensionWorldFile();
|
638 | com.iver.andami.Utilities.createTemp(nameWordFile, this.getDataWorldFile(bBox, sz));
|
||
639 | 6042 | jaume | |
640 | 9058 | nacho | /*if(status!=null && firstLoad){
|
641 | 4356 | jaume | status.applyStatus(this);
|
642 | firstLoad = false;
|
||
643 | 9058 | nacho | }*/
|
644 | 4356 | jaume | ViewPortData vpData = new ViewPortData(
|
645 | 4934 | jaume | vp.getProjection(), new Extent(bBox), sz );
|
646 | 4356 | jaume | vpData.setMat(vp.getAffineTransform()); |
647 | 4934 | jaume | |
648 | 8765 | jjdelcerro | visualStatus.fileNames[tile] = f.getAbsolutePath(); |
649 | 4356 | jaume | rasterProcess(g, vpData, f); |
650 | 6042 | jaume | |
651 | 4356 | jaume | } catch (ValidationException e) {
|
652 | 8765 | jjdelcerro | UnknownResponseFormatExceptionType type = |
653 | new UnknownResponseFormatExceptionType();
|
||
654 | type.setLayerName(getName()); |
||
655 | try {
|
||
656 | type.setDriverName(getDriver().getName()); |
||
657 | } catch (Exception e1) { |
||
658 | e1.printStackTrace(); |
||
659 | } |
||
660 | type.setFormat(format); |
||
661 | type.setHost(host); |
||
662 | type.setProtocol("WCS");
|
||
663 | DriverException exception = new DriverException("unknown_response_format", type); |
||
664 | throw exception;
|
||
665 | // azabala throw new DriverException(PluginServices.getText(this, "unknown_response_format"), e);
|
||
666 | } |
||
667 | catch (UnsupportedVersionException e) {
|
||
668 | UnsuportedProtocolVersionExceptionType type = |
||
669 | new UnsuportedProtocolVersionExceptionType();
|
||
670 | type.setLayerName(getName()); |
||
671 | try {
|
||
672 | type.setDriverName(getDriver().getName()); |
||
673 | } catch (Exception ex){ |
||
674 | } |
||
675 | type.setUrl(host); |
||
676 | throw new DriverException(PluginServices.getText(this, "version_conflict"), e, type); |
||
677 | |||
678 | // azabala throw new DriverException(PluginServices.getText(this, "version_conflict"), e);
|
||
679 | 4356 | jaume | } catch (IOException e) { |
680 | 8765 | jjdelcerro | ConnectionErrorExceptionType type = new ConnectionErrorExceptionType();
|
681 | type.setLayerName(getName()); |
||
682 | try {
|
||
683 | type.setDriverName(getDriver().getName()); |
||
684 | } catch (Exception e1) { |
||
685 | } |
||
686 | type.setHost(host); |
||
687 | throw new DriverException(PluginServices. |
||
688 | getText(this, "connect_error"), e, type); |
||
689 | 4356 | jaume | } catch (WCSException e) {
|
690 | 8765 | jjdelcerro | //azabala: la capturamos y la convertimos en DriverException
|
691 | WCSDriverExceptionType type = new WCSDriverExceptionType();
|
||
692 | type.setLayerName(getName()); |
||
693 | try {
|
||
694 | type.setDriverName(getDriver().getName()); |
||
695 | } catch (Exception e1) { |
||
696 | } |
||
697 | type.setWcsStatus(wcsStatus); |
||
698 | this.setVisible(false); |
||
699 | throw new DriverException("Error WCS", e, type); |
||
700 | |||
701 | // JOptionPane.showMessageDialog((Component)PluginServices.getMainFrame(), e.getMessage());
|
||
702 | |||
703 | }//catch
|
||
704 | 4356 | jaume | } |
705 | 6042 | jaume | |
706 | 1979 | jaume | /**
|
707 | 4356 | jaume | * Devuelve el FMapWMSDriver.
|
708 | *
|
||
709 | * @return FMapWMSDriver
|
||
710 | *
|
||
711 | * @throws IllegalStateException
|
||
712 | * @throws ValidationException
|
||
713 | * @throws UnsupportedVersionException
|
||
714 | * @throws IOException
|
||
715 | */
|
||
716 | private FMapWCSDriver getDriver() throws IllegalStateException, ValidationException, UnsupportedVersionException, IOException { |
||
717 | if (wcs == null) { |
||
718 | 8765 | jjdelcerro | wcs = FMapWCSDriverFactory.getFMapDriverForURL(host); |
719 | 6116 | jaume | } |
720 | 4356 | jaume | return wcs;
|
721 | } |
||
722 | 4934 | jaume | |
723 | 4356 | jaume | /**
|
724 | * Calcula el contenido del fichero de georreferenciaci?n de una imagen.
|
||
725 | * @param bBox Tama?o y posici?n de la imagen (en coordenadas de usuario)
|
||
726 | * @param sz Tama?o de la imagen en pixeles.
|
||
727 | * @return el 'WorldFile', como String.
|
||
728 | * @throws IOException
|
||
729 | */
|
||
730 | public String getDataWorldFile(Rectangle2D bBox, Dimension sz) throws IOException { |
||
731 | StringBuffer data = new StringBuffer(); |
||
732 | 4934 | jaume | data.append((bBox.getMaxX() - bBox.getMinX())/(sz.getWidth() - 1)+"\n"); |
733 | data.append("0.0\n");
|
||
734 | data.append("0.0\n");
|
||
735 | 8765 | jjdelcerro | data.append("-"+(bBox.getMaxY() - bBox.getMinY())/(sz.getHeight() - 1)+"\n"); |
736 | 4934 | jaume | data.append(""+bBox.getMinX()+"\n"); |
737 | 8765 | jjdelcerro | data.append(""+bBox.getMaxY()+"\n"); |
738 | 4934 | jaume | return data.toString();
|
739 | 4356 | jaume | } |
740 | 6042 | jaume | |
741 | 4356 | jaume | /**
|
742 | * Dibuja una imagen usando PxRaster
|
||
743 | * @param g Graphics2D en el que hay que dibujar.
|
||
744 | * @param vpData Par?metros de visualizaci?n
|
||
745 | * @param file La imagen en cuesti?n.
|
||
746 | */
|
||
747 | 9058 | nacho | private void rasterProcess(Graphics2D g, ViewPortData vpData, File file)throws DriverException { |
748 | 6042 | jaume | |
749 | //Creamos el PxRaster
|
||
750 | 9058 | nacho | try{
|
751 | rasterFile = new GdalFile(vpData.getProjection(), file.getAbsolutePath());
|
||
752 | } catch (NotSupportedExtensionException e) {
|
||
753 | throw new DriverException("Open File Error"); |
||
754 | } |
||
755 | 4356 | jaume | raster = new PxRaster(rasterFile, null, rasterFile.getExtent()); |
756 | 6042 | jaume | |
757 | 9058 | nacho | if(status!=null && firstLoad){ |
758 | status.applyStatus(this);
|
||
759 | firstLoad = false;
|
||
760 | } |
||
761 | |||
762 | grid = new Grid(rasterFile);
|
||
763 | grid.addRenderizer(raster); |
||
764 | |||
765 | 8765 | jjdelcerro | visualStatus.rasterWidth += rasterFile.getWidth(); |
766 | visualStatus.rasterHeight += rasterFile.getHeight(); |
||
767 | if(raster.getExtent().getMin().getX() < visualStatus.rasterMinX)
|
||
768 | visualStatus.rasterMinX = raster.getExtent().getMin().getX(); |
||
769 | if(raster.getExtent().getMin().getY() < visualStatus.rasterMinY)
|
||
770 | visualStatus.rasterMinY = raster.getExtent().getMin().getY(); |
||
771 | if(raster.getExtent().getMax().getX() > visualStatus.rasterMaxX)
|
||
772 | visualStatus.rasterMaxX = raster.getExtent().getMax().getX(); |
||
773 | if(raster.getExtent().getMax().getY() > visualStatus.rasterMaxY)
|
||
774 | visualStatus.rasterMaxY = raster.getExtent().getMax().getY(); |
||
775 | 9058 | nacho | |
776 | 4356 | jaume | //Recuperamos la pila de filtros si ya hubiese sido cargado antes
|
777 | if (this.filterStack!=null) |
||
778 | raster.filterStack = this.filterStack;
|
||
779 | 6042 | jaume | |
780 | 4356 | jaume | raster.setTransparency(false);
|
781 | 6042 | jaume | |
782 | 4356 | jaume | //Asignamos transparencia y orden de bandas
|
783 | 8569 | nacho | if (getTransparency() == -1 && !firstLoad); |
784 | 4356 | jaume | else
|
785 | 8569 | nacho | raster.setTransparency(getTransparency()); |
786 | 6042 | jaume | |
787 | 4356 | jaume | raster.setBand(GeoRasterFile.RED_BAND,rband); |
788 | raster.setBand(GeoRasterFile.GREEN_BAND, gband); |
||
789 | raster.setBand(GeoRasterFile.BLUE_BAND, bband); |
||
790 | 6042 | jaume | |
791 | 4356 | jaume | //Despues del primer pxRaster asignamos el stackManager guardado para los siguientes.
|
792 | 6042 | jaume | //Con esto conseguimos asignar los cambios que se hayan producido desde el cuadro de
|
793 | 4356 | jaume | //propiedades cuando creamos un nuevo pxRaster
|
794 | if (this.stackManager != null) |
||
795 | 6042 | jaume | raster.setStackManager(this.stackManager);
|
796 | 4934 | jaume | |
797 | 4356 | jaume | if (visualStatus != null){ |
798 | visualStatus.bandCount = raster.getBandCount(); |
||
799 | visualStatus.dataType = raster.getDataType(); |
||
800 | } |
||
801 | 6042 | jaume | |
802 | 4356 | jaume | raster.draw(g, vpData); |
803 | 6042 | jaume | |
804 | 4356 | jaume | //En el primer pxRaster de una imagen obtenemos el Stack Manager para poder modificarlo
|
805 | //si queremos desde las propiedades
|
||
806 | 6042 | jaume | |
807 | 4356 | jaume | if (this.stackManager == null) |
808 | 6042 | jaume | this.stackManager = raster.getStackManager();
|
809 | |||
810 | 4356 | jaume | if (this.filterStack == null) |
811 | this.filterStack = raster.filterStack;
|
||
812 | 6042 | jaume | |
813 | 4356 | jaume | rasterFile.close(); |
814 | } |
||
815 | 6042 | jaume | |
816 | 9013 | caballero | public void print(Graphics2D g, ViewPort viewPort, Cancellable cancel, double scale, PrintRequestAttributeSet properties) throws DriverException { |
817 | 4398 | jaume | draw(null, g, viewPort, cancel, scale);
|
818 | 4356 | jaume | } |
819 | 6042 | jaume | |
820 | 4356 | jaume | /**
|
821 | * @return Returns the raster.
|
||
822 | */
|
||
823 | public PxRaster getPxRaster() {
|
||
824 | return raster;
|
||
825 | } |
||
826 | 4934 | jaume | |
827 | 4356 | jaume | /**
|
828 | 2094 | jaume | * Returns the XMLEntity containing the necessary info for reproduce
|
829 | * the layer.
|
||
830 | 6042 | jaume | *
|
831 | 2094 | jaume | * Devuelve el XMLEntity con la informaci?n necesaria para reproducir
|
832 | * la capa.
|
||
833 | 6042 | jaume | *
|
834 | 1979 | jaume | * @return XMLEntity.
|
835 | * @throws XMLException
|
||
836 | 1877 | luisw | */
|
837 | 1979 | jaume | public XMLEntity getXMLEntity() throws XMLException { |
838 | XMLEntity xml = super.getXMLEntity();
|
||
839 | 4934 | jaume | |
840 | 2003 | jaume | xml.putProperty("wcs.host", getHost());
|
841 | 4356 | jaume | xml.putProperty("wcs.fullExtent", StringUtilities.rect2String( fullExtent ));
|
842 | xml.putProperty("wcs.layerQuery", coverageName );
|
||
843 | xml.putProperty("wcs.format", format );
|
||
844 | xml.putProperty("wcs.srs", srs );
|
||
845 | xml.putProperty("wcs.time", time );
|
||
846 | xml.putProperty("wcs.parameter", parameter );
|
||
847 | xml.putProperty("wcs.coverageName", coverageName );
|
||
848 | xml.putProperty("wcs.maxResX", maxRes.getX());
|
||
849 | xml.putProperty("wcs.maxResY", maxRes.getY());
|
||
850 | 2646 | jaume | if (status!=null) |
851 | 2623 | nacho | status.getXMLEntity(xml, true, this); |
852 | 2764 | nacho | else{
|
853 | status = new StatusLayerRaster();
|
||
854 | status.getXMLEntity(xml, true, this); |
||
855 | } |
||
856 | 1979 | jaume | return xml;
|
857 | } |
||
858 | 4934 | jaume | |
859 | 1979 | jaume | /**
|
860 | 2094 | jaume | * Reproduces the layer from an XMLEntity.
|
861 | 6042 | jaume | *
|
862 | 1979 | jaume | * A partir del XMLEntity reproduce la capa.
|
863 | 6042 | jaume | *
|
864 | 4934 | jaume | * @param xml XMLEntity
|
865 | 1979 | jaume | *
|
866 | * @throws XMLException
|
||
867 | * @throws DriverException
|
||
868 | * @throws DriverIOException
|
||
869 | */
|
||
870 | public void setXMLEntity(XMLEntity xml) throws XMLException { |
||
871 | super.setXMLEntity(xml);
|
||
872 | 6042 | jaume | |
873 | 4356 | jaume | // host
|
874 | try {
|
||
875 | host = new URL(xml.getStringProperty("wcs.host")); |
||
876 | } catch (MalformedURLException e) { |
||
877 | throw new XMLException(e); |
||
878 | } |
||
879 | 6042 | jaume | |
880 | 4356 | jaume | // full extent
|
881 | fullExtent = StringUtilities.string2Rect(xml.getStringProperty("wcs.fullExtent"));
|
||
882 | 6042 | jaume | |
883 | 4356 | jaume | // coverageQuery
|
884 | coverageName = xml.getStringProperty("wcs.layerQuery");
|
||
885 | 6042 | jaume | |
886 | 4356 | jaume | // format
|
887 | format = xml.getStringProperty("wcs.format");
|
||
888 | 6042 | jaume | |
889 | 4356 | jaume | // srs
|
890 | srs = xml.getStringProperty("wcs.srs");
|
||
891 | 6042 | jaume | |
892 | 4356 | jaume | // time
|
893 | time = xml.getStringProperty("wcs.time");
|
||
894 | 6042 | jaume | |
895 | 4356 | jaume | // parameter
|
896 | parameter = xml.getStringProperty("wcs.parameter");
|
||
897 | 6042 | jaume | |
898 | 4356 | jaume | // coverage name
|
899 | coverageName = xml.getStringProperty("wcs.coverageName");
|
||
900 | 6042 | jaume | |
901 | 4356 | jaume | // max resolution
|
902 | 2330 | jaume | if (xml.contains("wcs.maxRes")) |
903 | 4356 | jaume | maxRes = new Point2D.Double(xml.getDoubleProperty("wcs.maxRes"), xml.getDoubleProperty("wcs.maxRes")); |
904 | else if (xml.contains("wcs.maxResX") && xml.contains("wcs.maxResY")) |
||
905 | maxRes = new Point2D.Double(xml.getDoubleProperty("wcs.maxResX"), xml.getDoubleProperty("wcs.maxResY")); |
||
906 | 6042 | jaume | |
907 | 4356 | jaume | // OnlineResources
|
908 | 4934 | jaume | if (xml.contains("onlineResources")) { |
909 | String[] operations = xml.getStringProperty("onlineResources").split("~##SEP1##~"); |
||
910 | for (int i = 0; i < operations.length; i++) { |
||
911 | 4356 | jaume | String[] resources = operations[i].split("~##SEP2##~"); |
912 | if (resources.length==2 && resources[1]!="") |
||
913 | onlineResources.put(resources[0], resources[1]); |
||
914 | } |
||
915 | 4934 | jaume | } |
916 | 2623 | nacho | String claseStr = null; |
917 | if (xml.contains("raster.class")) { |
||
918 | claseStr = xml.getStringProperty("raster.class");
|
||
919 | } |
||
920 | 4356 | jaume | if (status!=null) |
921 | 2623 | nacho | status.setXMLEntity(xml, this);
|
922 | 4356 | jaume | else {
|
923 | 6042 | jaume | //Cuando cargamos un proyecto
|
924 | |||
925 | 2623 | nacho | if(claseStr!=null && !claseStr.equals("")){ |
926 | try{
|
||
927 | Class clase = Class.forName(claseStr); |
||
928 | Constructor constr = clase.getConstructor(null); |
||
929 | status = (StatusRasterInterface)constr.newInstance(null);
|
||
930 | if(status!=null) |
||
931 | status.setXMLEntity(xml, this);
|
||
932 | 4356 | jaume | } catch(ClassNotFoundException exc) { |
933 | 2623 | nacho | exc.printStackTrace(); |
934 | 4356 | jaume | } catch(InstantiationException exc) { |
935 | 2623 | nacho | exc.printStackTrace(); |
936 | 4356 | jaume | } catch(IllegalAccessException exc) { |
937 | 2623 | nacho | exc.printStackTrace(); |
938 | 4356 | jaume | } catch(NoSuchMethodException exc) { |
939 | 2623 | nacho | exc.printStackTrace(); |
940 | 4356 | jaume | } catch(InvocationTargetException exc) { |
941 | 2623 | nacho | exc.printStackTrace(); |
942 | 6042 | jaume | } |
943 | 2623 | nacho | } |
944 | } |
||
945 | 4356 | jaume | firstLoad = true;
|
946 | 1979 | jaume | } |
947 | 4934 | jaume | |
948 | 4356 | jaume | public void setCoverageName(String coverageName) { |
949 | this.coverageName = coverageName;
|
||
950 | } |
||
951 | 4934 | jaume | |
952 | 4356 | jaume | public void setParameter(String parametersString) { |
953 | this.parameter = parametersString;
|
||
954 | } |
||
955 | 4934 | jaume | |
956 | 4356 | jaume | public void setTime(String time) { |
957 | this.time = time;
|
||
958 | } |
||
959 | 4934 | jaume | |
960 | 4356 | jaume | public void setSRS(String srs) { |
961 | this.srs = srs;
|
||
962 | } |
||
963 | 4934 | jaume | |
964 | 4356 | jaume | public void setFormat(String format) { |
965 | this.format = format;
|
||
966 | } |
||
967 | 4934 | jaume | |
968 | |||
969 | 4356 | jaume | /**
|
970 | * Inserta el URL.
|
||
971 | *
|
||
972 | * @param host String.
|
||
973 | 6042 | jaume | * @throws MalformedURLException
|
974 | 4356 | jaume | */
|
975 | public void setHost(String host) { |
||
976 | try {
|
||
977 | setHost(new URL(host)); |
||
978 | } catch (MalformedURLException e) { |
||
979 | 6042 | jaume | |
980 | 4356 | jaume | } |
981 | } |
||
982 | 6042 | jaume | |
983 | 1979 | jaume | /**
|
984 | 4356 | jaume | * Inserta el URL.
|
985 | *
|
||
986 | * @param host URL.
|
||
987 | */
|
||
988 | public void setHost(URL host) { |
||
989 | this.host = host;
|
||
990 | } |
||
991 | 4934 | jaume | |
992 | 4356 | jaume | /**
|
993 | * Sets the layer's full extent.
|
||
994 | 6042 | jaume | *
|
995 | 4356 | jaume | * Establece la extensi?n m?xima de la capa.
|
996 | 6042 | jaume | *
|
997 | 4356 | jaume | * @param rect
|
998 | */
|
||
999 | public void setFullExtent(Rectangle2D rect) { |
||
1000 | this.fullExtent = rect;
|
||
1001 | } |
||
1002 | 6042 | jaume | |
1003 | 4356 | jaume | /**
|
1004 | * Devuelve el URL.
|
||
1005 | *
|
||
1006 | * @return URL.
|
||
1007 | */
|
||
1008 | public URL getHost() { |
||
1009 | return host;
|
||
1010 | } |
||
1011 | 4934 | jaume | |
1012 | 4356 | jaume | /**
|
1013 | * Remote source layers have a bunch of properties that are required for get them from
|
||
1014 | * the servers. This method supplies a hash table containing any needed field. This hash
|
||
1015 | * table may be used to let the client to connect to a server and restore a previously saved
|
||
1016 | * layer. So, the layer itself may not be saved to the disk since the actual saved
|
||
1017 | * info is just its properties.
|
||
1018 | 6042 | jaume | *
|
1019 | 4356 | jaume | * @return Returns a hash table containing all the required information for
|
1020 | * set up a wms layer
|
||
1021 | */
|
||
1022 | public Hashtable getProperties(){ |
||
1023 | Hashtable info = new Hashtable(); |
||
1024 | info.put( "name", coverageName);
|
||
1025 | info.put( "host", getHost());
|
||
1026 | info.put( "crs", srs);
|
||
1027 | info.put( "format", format);
|
||
1028 | String str = time;
|
||
1029 | 6042 | jaume | if (str==null) |
1030 | 4356 | jaume | str = "";
|
1031 | info.put( "time", str);
|
||
1032 | str = parameter; |
||
1033 | if (str==null) |
||
1034 | str = "";
|
||
1035 | 6042 | jaume | info.put("parameter", str);
|
1036 | |||
1037 | 4356 | jaume | return info;
|
1038 | } |
||
1039 | 4934 | jaume | |
1040 | 4356 | jaume | /**
|
1041 | * Obtiene la extensi?n del fichero de georreferenciaci?n
|
||
1042 | * @return String con la extensi?n del fichero de georreferenciaci?n dependiendo
|
||
1043 | 6042 | jaume | * del valor del formato obtenido del servidor. Por defecto asignaremos un .wld
|
1044 | 4356 | jaume | */
|
1045 | private String getExtensionWorldFile(){ |
||
1046 | String extWorldFile = ".wld"; |
||
1047 | 4934 | jaume | if (format.equals("image/tif") || format.equals("image/tiff")) |
1048 | extWorldFile = ".tfw";
|
||
1049 | if (format.equals("image/jpeg")) |
||
1050 | extWorldFile = ".jpgw";
|
||
1051 | return extWorldFile;
|
||
1052 | 4356 | jaume | } |
1053 | 6042 | jaume | |
1054 | 4356 | jaume | public void setMaxResolution(Point2D maxResolution) { |
1055 | this.maxRes = maxResolution;
|
||
1056 | } |
||
1057 | 4934 | jaume | |
1058 | 4356 | jaume | /**
|
1059 | * Gets the last open GeoRasterFile against the temp file received
|
||
1060 | 6042 | jaume | *
|
1061 | 4356 | jaume | * Obtiene el ?ltimo GeoRasterFile abierto sobre el temporal recibido
|
1062 | * @return
|
||
1063 | */
|
||
1064 | public GeoRasterFile getGeoRasterFile(){
|
||
1065 | return rasterFile;
|
||
1066 | } |
||
1067 | 6042 | jaume | |
1068 | |||
1069 | 4356 | jaume | /**
|
1070 | * Asignar el estado del raster
|
||
1071 | * @param status
|
||
1072 | */
|
||
1073 | public void setStatus(StatusRasterInterface status){ |
||
1074 | this.status = status;
|
||
1075 | } |
||
1076 | 6042 | jaume | |
1077 | 4356 | jaume | /**
|
1078 | * Obtiene el estado del raster
|
||
1079 | * @return
|
||
1080 | */
|
||
1081 | public StatusRasterInterface getStatus(){
|
||
1082 | return this.status; |
||
1083 | } |
||
1084 | 6042 | jaume | |
1085 | 4356 | jaume | /**
|
1086 | * Gets the max resolution allowed by the coverage. Requesting a higher resolution
|
||
1087 | * than this value does not cause any error, but the info responsed is just an
|
||
1088 | * interpolation.
|
||
1089 | 6042 | jaume | *
|
1090 | 4356 | jaume | * In exchange for obtaining a greater file and without additional information,
|
1091 | * we can easily connect it at the View.
|
||
1092 | 6042 | jaume | *
|
1093 | *
|
||
1094 | 4356 | jaume | * Obtiene la resoluci?n m?xima soportada por la cobertura. La petici?n
|
1095 | * de una resoluci?n superior a la soportada no provoca ning?n error, aunque
|
||
1096 | 6042 | jaume | * la informaci?n obtenida s?lo es una mera interpolaci?n de informaci?n.
|
1097 | *
|
||
1098 | 4356 | jaume | * A cambio de obtener un archivo mayor y sin informaci?n adicional, podemos
|
1099 | * f?cilmente acoplarlo a la vista.
|
||
1100 | 6042 | jaume | *
|
1101 | 4356 | jaume | * @return double
|
1102 | */
|
||
1103 | public Point2D getMaxResolution() { |
||
1104 | if (maxRes==null) |
||
1105 | maxRes = wcs.getMaxResolution(coverageName); |
||
1106 | return maxRes;
|
||
1107 | } |
||
1108 | 4934 | jaume | |
1109 | 6042 | jaume | |
1110 | 4356 | jaume | public void setDriver(FMapWCSDriver driver) { |
1111 | 8765 | jjdelcerro | this.wcs = driver;
|
1112 | 4356 | jaume | } |
1113 | 6042 | jaume | |
1114 | 6005 | nacho | /*
|
1115 | * (non-Javadoc)
|
||
1116 | * @see com.iver.cit.gvsig.fmap.layers.RasterOperations#getTileSize()
|
||
1117 | */
|
||
1118 | public int[] getTileSize() { |
||
1119 | 6042 | jaume | int[] size = {maxTileDrawWidth, maxTileDrawHeight}; |
1120 | 6005 | nacho | return size;
|
1121 | } |
||
1122 | |||
1123 | /*
|
||
1124 | * (non-Javadoc)
|
||
1125 | * @see com.iver.cit.gvsig.fmap.layers.RasterOperations#isTiled()
|
||
1126 | */
|
||
1127 | public boolean isTiled() { |
||
1128 | return mustTileDraw;
|
||
1129 | } |
||
1130 | 9058 | nacho | |
1131 | /**
|
||
1132 | * Obtiene el tipo de dato de la capa raster
|
||
1133 | * @return Entero que representa el tipo de dato de la capa raster.
|
||
1134 | */
|
||
1135 | public int getDataType() { |
||
1136 | return rasterFile.getDataType();
|
||
1137 | } |
||
1138 | |||
1139 | /**
|
||
1140 | * Obtiene el grid asociado al raster que hay cargado en ese momento
|
||
1141 | * @return grid
|
||
1142 | */
|
||
1143 | public Grid getGrid(){
|
||
1144 | return grid;
|
||
1145 | } |
||
1146 | 4356 | jaume | } |