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