root / trunk / extensions / extWCS / src / com / iver / cit / gvsig / fmap / layers / FMapWCSAdaptor.java @ 2625
History | View | Annotate | Download (21.1 KB)
1 |
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
|
---|---|
2 |
*
|
3 |
* Copyright (C) 2005 IVER T.I. and Generalitat Valenciana.
|
4 |
*
|
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 |
package com.iver.cit.gvsig.fmap.layers; |
42 |
|
43 |
import java.awt.Dimension; |
44 |
import java.awt.Graphics2D; |
45 |
import java.awt.Image; |
46 |
import java.awt.geom.Point2D; |
47 |
import java.awt.geom.Rectangle2D; |
48 |
import java.awt.image.BufferedImage; |
49 |
import java.io.File; |
50 |
import java.io.IOException; |
51 |
import java.util.ArrayList; |
52 |
|
53 |
import org.cresques.geo.ViewPortData; |
54 |
import org.cresques.io.GdalFile; |
55 |
import org.cresques.io.GeoRasterFile; |
56 |
import org.cresques.io.raster.RasterFilterStack; |
57 |
import org.cresques.io.raster.RasterFilterStackManager; |
58 |
import org.cresques.io.rasterOld.ComputeMinMaxFilter; |
59 |
import org.cresques.io.rasterOld.GreyscaleRasterToImageFilter; |
60 |
import org.cresques.io.rasterOld.LinearEnhancementFilter; |
61 |
import org.cresques.io.rasterOld.RasterBuf; |
62 |
import org.cresques.io.rasterOld.RasterStats; |
63 |
import org.cresques.io.rasterOld.RasterToImageFilter; |
64 |
import org.cresques.px.Extent; |
65 |
import org.cresques.px.PxRaster; |
66 |
|
67 |
import com.iver.cit.gvsig.fmap.DriverException; |
68 |
import com.iver.cit.gvsig.fmap.ViewPort; |
69 |
import com.iver.cit.gvsig.fmap.drivers.wcs.FMapWCSDriver; |
70 |
import com.iver.cit.gvsig.fmap.operations.Cancellable; |
71 |
|
72 |
import es.gva.cit.jgdal.Gdal; |
73 |
import es.gva.cit.jgdal.GdalBuffer; |
74 |
import es.gva.cit.jgdal.GdalException; |
75 |
import es.gva.cit.jgdal.GdalRasterBand; |
76 |
import es.gva.cit.jgdal.GeoTransform; |
77 |
import es.uji.lsi.wcs.client.ServerErrorResponseException; |
78 |
|
79 |
/**
|
80 |
* Class to interact FMapWCSDriver
|
81 |
*
|
82 |
* La clase FMapWCSAdaptor recubre la interacci?n con el FMapWCSDriver
|
83 |
* @author jaume - jaume.dominguez@iver.es
|
84 |
*
|
85 |
*/
|
86 |
public class FMapWCSAdaptor { |
87 |
private boolean driverInitialized = false; |
88 |
private FMapWCSDriver driver;
|
89 |
private Rectangle2D fullExtent, bbox; |
90 |
|
91 |
private static final double METROSXGRADO = 111120D; |
92 |
private String coverageName; |
93 |
private String SRS; |
94 |
private String format; |
95 |
private String time; |
96 |
private String parameter; |
97 |
//private double maxRes;
|
98 |
private Point2D maxRes; |
99 |
private String coverageQuery; |
100 |
private String lastCoverageQuery = ""; |
101 |
private File fCoverage = null; |
102 |
private PxRaster raster = null; |
103 |
private RasterFilterStack filterStack = null; |
104 |
private GeoRasterFile rasterFile = null; |
105 |
//private double res;
|
106 |
private Point2D res; |
107 |
private boolean zoomingToPixel; |
108 |
|
109 |
private int transparency = -1; |
110 |
private int rband = 0, gband = 1, bband = 2; |
111 |
private RasterFilterStackManager stackManager = null; |
112 |
|
113 |
/**
|
114 |
* Returns the coverage resolution
|
115 |
*
|
116 |
* obtiene la resoluci?n de la cobertura (de la capa FlyrWCS)
|
117 |
* @return
|
118 |
*/
|
119 |
//public double getRes() {
|
120 |
public Point2D getRes() { |
121 |
return res;
|
122 |
} |
123 |
|
124 |
/**
|
125 |
* Sets the coverage resolution (the layer's resolution)
|
126 |
*
|
127 |
* Establece la resoluci?n de la cobertura (de la capa FlyrWCS)
|
128 |
* @param res
|
129 |
*/
|
130 |
//public void setRes(double res) {
|
131 |
public void setRes(Point2D res) { |
132 |
this.res = res;
|
133 |
} |
134 |
|
135 |
/**
|
136 |
* Sets the driver that works with the adaptor.
|
137 |
*
|
138 |
* Establece el driver sobre el que act?a el adaptador
|
139 |
*/
|
140 |
public void setDriver(FMapWCSDriver d) { |
141 |
driver = d; |
142 |
} |
143 |
|
144 |
/**
|
145 |
* Gets a ref to the object that implements the vectorial interface in order
|
146 |
* of the Strategy can optimize the driver's function.
|
147 |
*
|
148 |
* Obtiene una referencia al objeto que implementa la interfaz vectorial con
|
149 |
* el fin de que las Strategy puedan optimizar en funci?n del driver.
|
150 |
*/
|
151 |
public FMapWCSDriver getDriver(){
|
152 |
return driver;
|
153 |
} |
154 |
|
155 |
/**
|
156 |
* Automatically called by gvSIG
|
157 |
*
|
158 |
* Llamado autom?ticamente por gvSIG.
|
159 |
* Pinta la cobertura (r?ster) en el ViewPort.
|
160 |
*
|
161 |
* @param image, g, viewPort, cancel
|
162 |
* @throws ServerErrorResponseException
|
163 |
* @throws ServerErrorResponseException
|
164 |
*/
|
165 |
public void draw(BufferedImage image, Graphics2D g, |
166 |
ViewPort viewPort, Cancellable cancel) throws DriverException, ServerErrorResponseException {
|
167 |
if (viewPort.getExtent().getMinX() > fullExtent.getMaxX())
|
168 |
return;
|
169 |
if (viewPort.getExtent().getMinY() > fullExtent.getMaxY())
|
170 |
return;
|
171 |
if (viewPort.getExtent().getMaxX() < fullExtent.getMinX())
|
172 |
return;
|
173 |
if (viewPort.getExtent().getMaxY() < fullExtent.getMinY())
|
174 |
return;
|
175 |
setBBox(viewPort.getAdjustedExtent()); |
176 |
|
177 |
double x = bbox.getMinX();
|
178 |
double y = bbox.getMinY();
|
179 |
double w = bbox.getWidth();
|
180 |
double h = bbox.getHeight();
|
181 |
|
182 |
double scalex = viewPort.getAffineTransform().getScaleX() /* g.getTransform().getScaleX()*/ , |
183 |
scaley = viewPort.getAffineTransform().getScaleY() /* g.getTransform().getScaleY() */;
|
184 |
int wImg = (int) Math.abs(w*scalex)+1, hImg = (int) Math.abs(h*scaley)+1; |
185 |
if (wImg <= 0 || hImg <= 0) return; |
186 |
|
187 |
setCoverageQuery(bbox, new Dimension(wImg, hImg)); |
188 |
|
189 |
//try {
|
190 |
if (lastCoverageQuery.compareTo(coverageQuery) != 0) { |
191 |
setWCSClientCoverageQuery(coverageQuery); |
192 |
fCoverage = driver.getCoverage(); |
193 |
} |
194 |
|
195 |
if (fCoverage != null) { |
196 |
//drawJaume(g, viewPort, fCoverage);
|
197 |
drawLWS(g, viewPort, fCoverage); |
198 |
} |
199 |
// } catch (ServerErrorResponseException e) {
|
200 |
// JOptionPane.showMessageDialog((Component)PluginServices.getMainFrame(), e.getMessage(), "Error",
|
201 |
// JOptionPane.ERROR_MESSAGE);
|
202 |
// View view=(View)PluginServices.getMDIManager().getActiveView();
|
203 |
// view.getTOC().layerRemoved(LayerCollectionEvent.createLayerRemovedEvent(this));
|
204 |
// }
|
205 |
} |
206 |
|
207 |
/**
|
208 |
* Draws using PxRaster
|
209 |
*
|
210 |
* Pinta usando PxRaster
|
211 |
*/
|
212 |
private void drawLWS(Graphics2D g, ViewPort viewPort, File fCoverage) { |
213 |
|
214 |
//Creamos el PxRaster
|
215 |
|
216 |
rasterFile = new GdalFile(viewPort.getProjection(), fCoverage.getAbsolutePath());
|
217 |
Extent e = new Extent(bbox);
|
218 |
raster = new PxRaster(rasterFile, null, rasterFile.getExtent()); |
219 |
|
220 |
//Recuperamos la pila de filtros si ya hubiese sido cargado antes
|
221 |
|
222 |
if(this.filterStack!=null) |
223 |
raster.filterStack = this.filterStack;
|
224 |
|
225 |
raster.setTransparency(false);
|
226 |
|
227 |
//Creamos el viewportdata
|
228 |
|
229 |
ViewPortData vpData = new ViewPortData(viewPort.getProjection(), e, viewPort.getImageSize() );
|
230 |
vpData.setMat(viewPort.getAffineTransform()); |
231 |
|
232 |
//Asignamos transparencia y orden de bandas
|
233 |
|
234 |
raster.setTransparency(this.transparency);
|
235 |
|
236 |
raster.setBand(GeoRasterFile.RED_BAND,rband); |
237 |
raster.setBand(GeoRasterFile.GREEN_BAND, gband); |
238 |
raster.setBand(GeoRasterFile.BLUE_BAND, bband); |
239 |
|
240 |
//Despues del primer pxRaster asignamos el stackManager guardado para los siguientes.
|
241 |
//Con esto conseguimos asignar los cambios que se hayan producido desde el cuadro de
|
242 |
//propiedades cuando creamos un nuevo pxRaster
|
243 |
|
244 |
if(this.stackManager != null) |
245 |
raster.setStackManager(this.stackManager);
|
246 |
|
247 |
raster.draw(g, vpData); |
248 |
|
249 |
//En el primer pxRaster de una imagen obtenemos el Stack Manager para poder modificarlo
|
250 |
//si queremos desde las propiedades
|
251 |
|
252 |
if(this.stackManager == null) |
253 |
this.stackManager = raster.getStackManager();
|
254 |
|
255 |
|
256 |
if(this.filterStack == null) |
257 |
this.filterStack = raster.filterStack;
|
258 |
|
259 |
|
260 |
} |
261 |
|
262 |
/**
|
263 |
* Gets the filter stack
|
264 |
*
|
265 |
* Obtiene la pila de filtros
|
266 |
* @return
|
267 |
*/
|
268 |
public RasterFilterStack getFilterStack(){
|
269 |
if(raster!=null) |
270 |
return raster.filterStack;
|
271 |
return null; |
272 |
} |
273 |
|
274 |
/**
|
275 |
* Sets the filter stack
|
276 |
*
|
277 |
* Establece la pila de filtros
|
278 |
*
|
279 |
* @param filterStack pila
|
280 |
*/
|
281 |
public void setFilterStack(RasterFilterStack filterStack){ |
282 |
this.filterStack = filterStack;
|
283 |
} |
284 |
|
285 |
/**
|
286 |
* Gets the last created PxRaster
|
287 |
*
|
288 |
* Obtiene el ?ltimo PxRaster creado
|
289 |
*
|
290 |
* @return
|
291 |
*/
|
292 |
public PxRaster getPxRaster(){
|
293 |
return raster;
|
294 |
} |
295 |
|
296 |
/**
|
297 |
* Gets the last open GeoRasterFile against the temp file received
|
298 |
*
|
299 |
* Obtiene el ?ltimo GeoRasterFile abierto sobre el temporal recibido
|
300 |
* @return
|
301 |
*/
|
302 |
public GeoRasterFile getGeoRasterFile(){
|
303 |
return rasterFile;
|
304 |
} |
305 |
|
306 |
/**
|
307 |
* Sets the Bouning Box of the query according to the zoom. If the zoom's extension
|
308 |
* is greather than the coverage's full extent or the view only covers a part of
|
309 |
* the coverage's area, it cuts the required edges to those given by the coverage's
|
310 |
* full extent.
|
311 |
*
|
312 |
* Establece la Bounding Box de la consulta seg?n el zoom. En caso de que
|
313 |
* el zoom abarque m?s de la estensi?n m?xima (fullExtent) o la vista cubra
|
314 |
* solo una parte de la cobertura, acota los l?mites necesarios a aquellos
|
315 |
* marcados por la extensi?n m?xima.
|
316 |
*
|
317 |
* @param rect
|
318 |
*/
|
319 |
public void setBBox(Rectangle2D rect) { |
320 |
double x1 = rect.getMinX();
|
321 |
double y1 = rect.getMinY();
|
322 |
double x2 = rect.getMaxX();
|
323 |
double y2 = rect.getMaxY();
|
324 |
if (x1 < fullExtent.getMinX())
|
325 |
x1 = fullExtent.getMinX(); |
326 |
if (y1 < fullExtent.getMinY())
|
327 |
y1 = fullExtent.getMinY(); |
328 |
if (x2 > fullExtent.getMaxX())
|
329 |
x2 = fullExtent.getMaxX(); |
330 |
if (y2 > fullExtent.getMaxY())
|
331 |
y2 = fullExtent.getMaxY(); |
332 |
|
333 |
if (bbox == null) |
334 |
bbox = new Rectangle2D.Double(); |
335 |
|
336 |
bbox.setRect(x1, y1, x2 - x1, y2 - y1); |
337 |
} |
338 |
|
339 |
/**
|
340 |
* Establishes the initial values that will be included in the query.
|
341 |
*
|
342 |
* Para establecer los valores iniciales que se incluiran en la consulta.
|
343 |
*
|
344 |
* @param layersRectangle
|
345 |
* @param srs
|
346 |
* @param format
|
347 |
* @param parametro
|
348 |
* @param times
|
349 |
*/
|
350 |
public void setCoverageQuery(Rectangle2D bBox, Dimension sz) { |
351 |
String coverage = "COVERAGE=" + coverageName; |
352 |
String crs = "&CRS=" + SRS; |
353 |
String boundingBox = "&BBOX=" + bBox.getMinX() |
354 |
+ "," + bBox.getMinY()
|
355 |
+ "," + bBox.getMaxX()
|
356 |
+ "," + bBox.getMaxY();
|
357 |
String time = this.time != null ? "&" + this.time : ""; |
358 |
String param = parameter != null ? "&" + parameter : ""; |
359 |
res = new Point2D.Double(bBox.getWidth() / sz.getWidth(), bBox.getHeight() / sz.getHeight()); |
360 |
|
361 |
// Calculo cutre para ver si son grados (o metros). Si da menos de 180
|
362 |
// es que son grados y lo paso a metros. (LWS)
|
363 |
if (bBox.getMaxY() < 181D) |
364 |
res.setLocation(res.getX()*METROSXGRADO, res.getY()*METROSXGRADO); |
365 |
|
366 |
String resX = "&RESX=" + res.getX(); |
367 |
String resY = "&RESY=" + res.getY(); |
368 |
String format = "&FORMAT=" + this.format; |
369 |
coverageQuery = coverage + crs + boundingBox + time + param + resX + resY + format; |
370 |
} |
371 |
|
372 |
/**
|
373 |
* Takes the coverage parameters and give them to the WCS client. After this,
|
374 |
* it is possible to launch a GetCoverage operation.
|
375 |
*
|
376 |
* Recoge los par?metros de la capa y los pasa al cliente WCS. Despu?s de
|
377 |
* esto, ya se puede lanzar una GetCoverage
|
378 |
*
|
379 |
*/
|
380 |
private void setWCSClientCoverageQuery(String query) { |
381 |
lastCoverageQuery = query; |
382 |
((FMapWCSDriver) driver).setGetCoverageParams(query); |
383 |
} |
384 |
|
385 |
/**
|
386 |
* Returns the coverage name.
|
387 |
*
|
388 |
* Devuelve el nombre de la cobertura
|
389 |
* @return
|
390 |
*/
|
391 |
public String getCoverageName() { |
392 |
return coverageName;
|
393 |
} |
394 |
|
395 |
/**
|
396 |
* Sets the coverage name.
|
397 |
*
|
398 |
* Establece el nombre de la cobertura
|
399 |
* @param coverageName
|
400 |
*/
|
401 |
public void setCoverageName(String coverageName) { |
402 |
this.coverageName = coverageName;
|
403 |
} |
404 |
|
405 |
/**
|
406 |
* Returns an string containing the query that originated the coverage.
|
407 |
*
|
408 |
* Obtiene una cadena que contiene la consulta que origin? la cobertura.
|
409 |
* @return String
|
410 |
*/
|
411 |
public String getCoverageQuery() { |
412 |
return coverageQuery;
|
413 |
} |
414 |
|
415 |
/**
|
416 |
* Sets the query string (an URL) that originates the coverage.
|
417 |
*
|
418 |
* Establece la cadena que contiene la consulta (URL) que origina la cobertura.
|
419 |
* @param coverageQuery
|
420 |
*/
|
421 |
public void setCoverageQuery(String coverageQuery) { |
422 |
this.coverageQuery = coverageQuery;
|
423 |
} |
424 |
|
425 |
/**
|
426 |
* The coverage format.
|
427 |
*
|
428 |
* El formato de la cobertura.
|
429 |
* @return String
|
430 |
*/
|
431 |
public String getFormat() { |
432 |
return format;
|
433 |
} |
434 |
|
435 |
/**
|
436 |
* Sets the coverage format to download.
|
437 |
*
|
438 |
* Establece el formato de la cobertura a descargar.
|
439 |
* @param format
|
440 |
*/
|
441 |
public void setFormat(String format) { |
442 |
this.format = format;
|
443 |
} |
444 |
|
445 |
/**
|
446 |
* Gets the max coverage extension.
|
447 |
*
|
448 |
* Obtiene la extensi?n m?xima de la cobertura
|
449 |
* @return
|
450 |
* @throws DriverException
|
451 |
* @throws IOException
|
452 |
*/
|
453 |
public Rectangle2D getFullExtent() throws IOException, DriverException { |
454 |
if (fullExtent==null) |
455 |
fullExtent = driver.getFullExtent(coverageName, SRS); |
456 |
return fullExtent;
|
457 |
} |
458 |
|
459 |
/**
|
460 |
* Sets the max extension for the coverage. This value is specified
|
461 |
* by the server. Thus, this method should be used ONLY to reload
|
462 |
* this value from a saved proyect.
|
463 |
*
|
464 |
* Establece la extensi?n m?xima de la cobertura. ?ste valor viene
|
465 |
* especificado por el servidor. No deber?a de usarse m?s que para
|
466 |
* recuperar un proyecto guardado o desde el Wizard.
|
467 |
*
|
468 |
* @param fullExtent
|
469 |
*/
|
470 |
public void setFullExtent(Rectangle2D fullExtent) { |
471 |
this.fullExtent = fullExtent;
|
472 |
} |
473 |
|
474 |
/**
|
475 |
* Gets the paramenter in name-value pair-formed string.
|
476 |
*
|
477 |
* Recupera el valor de par?metro en forma de par nombre-valor: "nombre=valor"
|
478 |
*
|
479 |
* @return String
|
480 |
*/
|
481 |
public String getParameter() { |
482 |
return parameter;
|
483 |
} |
484 |
|
485 |
/**
|
486 |
* Sets the parameter and the parameter value list of the coverage as a name-value
|
487 |
* pair form where, for the moment, value is a comma-separated values list.
|
488 |
*
|
489 |
* Establece el par?metro y la lista de valores de la cobertura en forma
|
490 |
* de par nombre-valor donde valor es, por el momento, una lista separada
|
491 |
* por comas
|
492 |
* @param parameter
|
493 |
*/
|
494 |
public void setParameter(String parameter) { |
495 |
this.parameter = parameter;
|
496 |
} |
497 |
|
498 |
/**
|
499 |
* Gets the coverage SRS
|
500 |
*
|
501 |
* Obtiene el SRS de la cobertura
|
502 |
* @return String
|
503 |
*/
|
504 |
public String getSRS() { |
505 |
return SRS;
|
506 |
} |
507 |
|
508 |
/**
|
509 |
* Sets the coverage SRS
|
510 |
*
|
511 |
* Establece el SRS
|
512 |
* @param srs
|
513 |
*/
|
514 |
public void setSRS(String srs) { |
515 |
SRS = srs; |
516 |
} |
517 |
|
518 |
/**
|
519 |
* Gets the TIME parameter.
|
520 |
*
|
521 |
* Obtiene el par?metro TIME.
|
522 |
*
|
523 |
* @return String
|
524 |
*/
|
525 |
public String getTime() { |
526 |
return time;
|
527 |
} |
528 |
|
529 |
/**
|
530 |
* Sets the TIME parameter (according with the OGC standard it may
|
531 |
* be a comma-separated value list, but probably the server will not
|
532 |
* support querys with more than one value)
|
533 |
*
|
534 |
* Establece el par?metro TIME (puede ser seg?n OGC una
|
535 |
* lista de valores separados por comas pero casi seguro que
|
536 |
* el servidor no soportar? m?s de un valor)
|
537 |
* @param time
|
538 |
*/
|
539 |
public void setTime(String time) { |
540 |
this.time = time;
|
541 |
} |
542 |
|
543 |
/**
|
544 |
* Gets the WCS server's address.
|
545 |
*
|
546 |
* Obtiene la direcci?n del servidor WCS
|
547 |
* @return String
|
548 |
*/
|
549 |
public String getHost() { |
550 |
return ((FMapWCSDriver) driver).getHost();
|
551 |
} |
552 |
|
553 |
/**
|
554 |
* Sets the WCS server address.
|
555 |
*
|
556 |
* Establece la direcci?n del servidor WCS
|
557 |
* @param host (String)
|
558 |
*/
|
559 |
public void setHost(String host) { |
560 |
((FMapWCSDriver) driver).setHost(host); |
561 |
} |
562 |
|
563 |
/**
|
564 |
* @deprecated
|
565 |
* @param g
|
566 |
* @param viewPort
|
567 |
* @param fCoverage
|
568 |
*/
|
569 |
private void drawJaume(Graphics2D g, ViewPort viewPort, File fCoverage) { |
570 |
Image coverage = renderizeRaster(getRaster(fCoverage));
|
571 |
Point2D p1 = new Point2D.Double(bbox.getMinX(), bbox.getMaxY()); |
572 |
viewPort.getAffineTransform().transform(p1, p1); |
573 |
g.drawImage(coverage, (int) p1.getX(), (int) p1.getY(), null); |
574 |
} |
575 |
|
576 |
/**
|
577 |
* Computes the geofile raster.
|
578 |
*
|
579 |
* Computa el r?ster del fichero geogr?fico.
|
580 |
*
|
581 |
* @deprecated
|
582 |
* @param coverage
|
583 |
* @return RasterBuf
|
584 |
*/
|
585 |
private RasterBuf getRaster(File coverage) { |
586 |
RasterBuf raster = null;
|
587 |
|
588 |
Gdal migdal = new Gdal();
|
589 |
GeoTransform gt = null;
|
590 |
int ancho = 0, alto = 0; |
591 |
GdalRasterBand mirasterband = null;
|
592 |
int rastercount = 0; |
593 |
|
594 |
try {
|
595 |
migdal.open(coverage.getAbsolutePath(), Gdal.GA_ReadOnly); |
596 |
} catch (Exception ge) { |
597 |
ge.printStackTrace(); |
598 |
} |
599 |
|
600 |
try {
|
601 |
gt = migdal.getGeoTransform(); |
602 |
} catch (GdalException e) {
|
603 |
System.out
|
604 |
.println("I can't obtain the array geoTransform for this image");
|
605 |
} |
606 |
|
607 |
try {
|
608 |
rastercount = migdal.getRasterCount(); |
609 |
ancho = migdal.getRasterXSize(); |
610 |
alto = migdal.getRasterYSize(); |
611 |
int ngcp = migdal.getGCPCount();
|
612 |
//System.out.println("NGCP="+ngcp);
|
613 |
} catch (GdalException ge) {
|
614 |
ge.printStackTrace(); |
615 |
//...
|
616 |
} |
617 |
|
618 |
try {
|
619 |
int dataType = migdal.getRasterBand(1).getRasterDataType(); |
620 |
GdalBuffer buf = null;
|
621 |
|
622 |
/*
|
623 |
* Evita el problema de que haya m?s de 3 bandas en el fichero esto
|
624 |
* deberia hacerse asignando a las 3 bandas del raster una banda
|
625 |
* distinta del fichero (no necesariamente 1->0, 2->1 y 3->2
|
626 |
*/
|
627 |
|
628 |
if (rastercount > 3) |
629 |
rastercount = 3;
|
630 |
if (dataType == Gdal.GDT_Byte) {
|
631 |
raster = new RasterBuf(RasterBuf.TYPE_INT, ancho, alto,
|
632 |
rastercount, null);
|
633 |
for (int iBand = 0; iBand < rastercount; iBand++) { |
634 |
mirasterband = migdal.getRasterBand(iBand + 1);
|
635 |
buf = mirasterband.readRaster(0, 0, ancho, alto, ancho, |
636 |
alto, dataType); |
637 |
for (int y = 0; y < alto; y++) |
638 |
for (int x = 0; x < ancho; x++) |
639 |
raster.setPixelInt(x, y, iBand, buf.buffByte[y |
640 |
* ancho + x] & 0xff);
|
641 |
} |
642 |
migdal.close(); |
643 |
} else if (dataType == Gdal.GDT_CInt16 |
644 |
|| dataType == Gdal.GDT_UInt16 |
645 |
|| dataType == Gdal.GDT_Int16) { |
646 |
raster = new RasterBuf(RasterBuf.TYPE_INT, ancho, alto,
|
647 |
rastercount, null);
|
648 |
for (int iBand = 0; iBand < rastercount; iBand++) { |
649 |
// System.out.println("Banda:"+iBand);
|
650 |
mirasterband = migdal.getRasterBand(iBand + 1);
|
651 |
buf = mirasterband.readRaster(0, 0, ancho, alto, ancho, |
652 |
alto, dataType); |
653 |
for (int y = 0; y < alto; y++) |
654 |
for (int x = 0; x < ancho; x++) |
655 |
raster.setPixelInt(x, y, iBand, buf.buffShort[y |
656 |
* ancho + x] & 0xffff);
|
657 |
} |
658 |
migdal.close(); |
659 |
} |
660 |
} catch (GdalException e1) {
|
661 |
e1.printStackTrace(); |
662 |
} |
663 |
return raster;
|
664 |
} |
665 |
|
666 |
/**
|
667 |
* Construye un objeto Image a partir de un RasterBuf
|
668 |
* @deprecated (usado en drawJaume)
|
669 |
* @param raster
|
670 |
* @return Image
|
671 |
*/
|
672 |
public Image renderizeRaster(RasterBuf raster) { |
673 |
RasterStats stats = new RasterStats(raster.getBandNr());
|
674 |
int alpha = 255; // transparencia |
675 |
boolean debug = false; |
676 |
ComputeMinMaxFilter filter = new ComputeMinMaxFilter(raster, stats);
|
677 |
|
678 |
LinearEnhancementFilter lEFilter = new LinearEnhancementFilter(raster,
|
679 |
stats); |
680 |
Image image = null; |
681 |
if (raster.getBandNr() == 1) |
682 |
image = new GreyscaleRasterToImageFilter(raster, alpha).getImage();
|
683 |
else
|
684 |
image = new RasterToImageFilter(raster, alpha).getImage();
|
685 |
|
686 |
if (debug)
|
687 |
stats.pinta(); |
688 |
return image;
|
689 |
} |
690 |
|
691 |
/**
|
692 |
* Returns the current bounding box.
|
693 |
*
|
694 |
* Devuelve la boundix box actual.
|
695 |
*
|
696 |
* @return Rectangle2D
|
697 |
*/
|
698 |
public Rectangle2D getBbox() { |
699 |
return bbox;
|
700 |
} |
701 |
/**
|
702 |
* Gets the max resolution of the coverage.
|
703 |
*
|
704 |
* Obtiene la resoluci?n m?xima de la cobertura
|
705 |
* @return maxRes
|
706 |
*/
|
707 |
//public double getMaxResolution() {
|
708 |
public Point2D getMaxResolution() { |
709 |
return maxRes;
|
710 |
} |
711 |
|
712 |
/**
|
713 |
* Sets the MAX resolution supported by the coverage.
|
714 |
*
|
715 |
* The max resolution is given by the server within the DescribeCoverage document
|
716 |
* in the SpationDomain section.
|
717 |
*
|
718 |
* Use this method only to load this value from there (the DescribeCoverage document)
|
719 |
* of from an already saved project because an incorrect value will bring
|
720 |
* computing errors when doing "zoom to raster resolution".
|
721 |
*
|
722 |
*
|
723 |
*
|
724 |
* Establece la resoluci?n M?XIMA que soporta la cobertura.
|
725 |
*
|
726 |
* La resoluci?n m?xima viene fijada por el servidor dentro documento
|
727 |
* DescribeCoverage en la secci?n SpatialDomain.
|
728 |
*
|
729 |
* Use este m?todo ?nicamente para cargar el valor para la resoluci?n m?xima
|
730 |
* desde all? o desde un proyecto guardado en anterioridad, puesto que un
|
731 |
* valor incorrecto reportar? (conllevar?) errores de c?lculo cuando se haga
|
732 |
* un "zoom a la resoluci?n del r?ster".
|
733 |
*
|
734 |
* @param res
|
735 |
*/
|
736 |
//public void setMaxResolution(double res) {
|
737 |
public void setMaxResolution(Point2D res) { |
738 |
maxRes = res; |
739 |
} |
740 |
/**
|
741 |
* Sets the transparency for the next PxRaster that is going to be loaded.
|
742 |
*
|
743 |
* Asigna la transparencia para el siguiente PxRaster que se cargue.
|
744 |
* @param t
|
745 |
*/
|
746 |
public void setTransparency(int t){ |
747 |
this.transparency = t;
|
748 |
} |
749 |
|
750 |
/**
|
751 |
* Sets the R-band.
|
752 |
*
|
753 |
* Asigna la banda R.
|
754 |
* @param r
|
755 |
*/
|
756 |
public void setBandR(int r){ |
757 |
this.rband = r;
|
758 |
} |
759 |
|
760 |
/**
|
761 |
* Sets the G-band.
|
762 |
*
|
763 |
* Asigna la banda G
|
764 |
* @param g
|
765 |
*/
|
766 |
public void setBandG(int g){ |
767 |
this.gband = g;
|
768 |
} |
769 |
|
770 |
/**
|
771 |
* Sets the B-band.
|
772 |
*
|
773 |
* Asigna la banda B
|
774 |
* @param b
|
775 |
*/
|
776 |
public void setBandB(int b){ |
777 |
this.bband = b;
|
778 |
} |
779 |
|
780 |
/**
|
781 |
* Gets the coverage (not the FLyrWCS) from an URL.
|
782 |
*
|
783 |
* Obtiene la cobertura (no la FLyrWCS) a partir de una URL.
|
784 |
* @param query
|
785 |
*/
|
786 |
public void getCoverageFromQuery(String query) { |
787 |
driver.setGetCoverageParams(query); |
788 |
} |
789 |
} |