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