gvsig-raster / org.gvsig.raster.wcs / trunk / org.gvsig.raster.wcs / org.gvsig.raster.wcs.app / org.gvsig.raster.wcs.app.wcsclient / src / main / java / org / gvsig / raster / wcs / app / wcsclient / layer / FLyrWCS.java @ 1426
History | View | Annotate | Download (36.2 KB)
1 |
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
|
---|---|
2 |
*
|
3 |
* Copyright (C) 2004 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 org.gvsig.raster.wcs.app.wcsclient.layer; |
42 |
|
43 |
import java.awt.Dimension; |
44 |
import java.awt.Graphics2D; |
45 |
import java.awt.Point; |
46 |
import java.awt.Rectangle; |
47 |
import java.awt.geom.AffineTransform; |
48 |
import java.awt.geom.NoninvertibleTransformException; |
49 |
import java.awt.geom.Point2D; |
50 |
import java.awt.geom.Rectangle2D; |
51 |
import java.awt.image.BufferedImage; |
52 |
import java.io.IOException; |
53 |
import java.util.HashMap; |
54 |
import java.util.List; |
55 |
|
56 |
import javax.print.attribute.PrintRequestAttributeSet; |
57 |
import javax.swing.JOptionPane; |
58 |
|
59 |
import org.cresques.cts.IProjection; |
60 |
import org.gvsig.compat.net.ICancellable; |
61 |
import org.gvsig.fmap.dal.DALLocator; |
62 |
import org.gvsig.fmap.dal.DataManager; |
63 |
import org.gvsig.fmap.dal.DataParameters; |
64 |
import org.gvsig.fmap.dal.DataStore; |
65 |
import org.gvsig.fmap.dal.DataStoreParameters; |
66 |
import org.gvsig.fmap.dal.coverage.RasterLocator; |
67 |
import org.gvsig.fmap.dal.coverage.RasterManager; |
68 |
import org.gvsig.fmap.dal.coverage.datastruct.Extent; |
69 |
import org.gvsig.fmap.dal.coverage.datastruct.ViewPortData; |
70 |
import org.gvsig.fmap.dal.coverage.exception.FilePaletteException; |
71 |
import org.gvsig.fmap.dal.coverage.exception.InfoByPointException; |
72 |
import org.gvsig.fmap.dal.coverage.exception.InvalidSetViewException; |
73 |
import org.gvsig.fmap.dal.coverage.exception.ProcessInterruptedException; |
74 |
import org.gvsig.fmap.dal.coverage.exception.RasterDriverException; |
75 |
import org.gvsig.fmap.dal.coverage.exception.RemoteServiceException; |
76 |
import org.gvsig.fmap.dal.coverage.grid.RasterFilter; |
77 |
import org.gvsig.fmap.dal.coverage.store.RasterDataStore; |
78 |
import org.gvsig.fmap.dal.coverage.store.parameter.RasterDataParameters; |
79 |
import org.gvsig.fmap.dal.coverage.store.parameter.TileDataParameters; |
80 |
import org.gvsig.fmap.dal.coverage.store.props.Transparency; |
81 |
import org.gvsig.fmap.dal.exception.DataException; |
82 |
import org.gvsig.fmap.dal.exception.InitializeException; |
83 |
import org.gvsig.fmap.dal.exception.ProviderNotRegisteredException; |
84 |
import org.gvsig.fmap.dal.exception.ReadException; |
85 |
import org.gvsig.fmap.dal.exception.ValidateDataParametersException; |
86 |
import org.gvsig.fmap.dal.spi.DataManagerProviderServices; |
87 |
import org.gvsig.fmap.geom.GeometryLocator; |
88 |
import org.gvsig.fmap.geom.GeometryManager; |
89 |
import org.gvsig.fmap.geom.Geometry.SUBTYPES; |
90 |
import org.gvsig.fmap.geom.exception.CreateEnvelopeException; |
91 |
import org.gvsig.fmap.geom.primitive.Envelope; |
92 |
import org.gvsig.fmap.mapcontext.ViewPort; |
93 |
import org.gvsig.fmap.mapcontext.exceptions.LoadLayerException; |
94 |
import org.gvsig.fmap.mapcontext.layers.FLayer; |
95 |
import org.gvsig.fmap.mapcontext.layers.FLyrDefault; |
96 |
import org.gvsig.fmap.mapcontext.layers.Tiling; |
97 |
import org.gvsig.gui.beans.Messages; |
98 |
import org.gvsig.raster.fmap.layers.DefaultFLyrRaster; |
99 |
import org.gvsig.raster.fmap.layers.IRasterLayerActions; |
100 |
import org.gvsig.raster.fmap.layers.NotAvailableStateException; |
101 |
import org.gvsig.raster.util.CancelTaskImpl; |
102 |
import org.gvsig.raster.wcs.io.WCSDataParameters; |
103 |
import org.gvsig.raster.wcs.io.WCSServerExplorer; |
104 |
import org.gvsig.raster.wcs.io.WCSServerExplorerParameters; |
105 |
import org.gvsig.tools.ToolsLocator; |
106 |
import org.gvsig.tools.dynobject.DynObjectSet; |
107 |
import org.gvsig.tools.dynobject.DynStruct; |
108 |
import org.gvsig.tools.persistence.PersistenceManager; |
109 |
import org.gvsig.tools.persistence.PersistentState; |
110 |
import org.gvsig.tools.persistence.exception.PersistenceException; |
111 |
import org.gvsig.tools.task.Cancellable; |
112 |
import org.gvsig.tools.task.SimpleTaskStatus; |
113 |
import org.gvsig.tools.task.TaskStatusManager; |
114 |
import org.slf4j.Logger; |
115 |
import org.slf4j.LoggerFactory; |
116 |
|
117 |
|
118 |
/**
|
119 |
* Class for the WCS layer.
|
120 |
*
|
121 |
* Capa para el WCS.
|
122 |
*
|
123 |
* Las capas WCS son tileadas para descargarlas del servidor. Esto quiere decir que
|
124 |
* est?n formadas por multiples ficheros raster. Por esto la fuente de datos raster (IRasterDatasource)
|
125 |
* de la capa FLyrWCS es un objeto de tipo CompositeDataset. Este objeto est? compuesto por un array
|
126 |
* bidimensional de MultiRasterDataset. Cada uno de los MultiRasterDataset corresponde con un tile
|
127 |
* salvado en disco. Estos MultiRasterDataset se crean cada vez que se repinta ya que en WCS a cada
|
128 |
* zoom varian los ficheros fuente. La secuencia de creaci?n de un CompositeDataset ser?a la siguiente:
|
129 |
* <UL>
|
130 |
* <LI>Se hace una petici?n de dibujado por parte del usuario llamando al m?todo draw de FLyrWCS</LI>
|
131 |
* <LI>Se tilea la petici?n</LI>
|
132 |
* <LI>Cada tile se dibuja abriendo una FLyrRaster para ese tile</LI>
|
133 |
* <LI>Si es el primer dibujado se guarda una referencia en la capa WCS a las propiedades de renderizado, orden de bandas,
|
134 |
* transparencia, filtros aplicados, ...</LI>
|
135 |
* <LI>Si no es el primer dibujado se asignan las propiedades de renderizado cuya referencia se guarda en la capa WCS</LI>
|
136 |
* <LI>Se guarda el MultiRasterDataset de cada tile</LI>
|
137 |
* <LI>Al acabar todos los tiles creamos un CompositeDataset con los MultiRasterDataset de todos los tiles</LI>
|
138 |
* <LI>Asignamos a la capa la referencia de las propiedades de renderizado que tenemos almacenadas. De esta forma si hay
|
139 |
* alguna modificaci?n desde el cuadro de propiedades ser? efectiva sobre los tiles que se dibujan.</LI>
|
140 |
* </UL>
|
141 |
*
|
142 |
* @author jaume - jaume.dominguez@iver.es
|
143 |
*/
|
144 |
public class FLyrWCS extends DefaultFLyrRaster { |
145 |
public static final String PERSISTENT_NAME = "FLyrWCS_Persistent"; |
146 |
public static final String PERSISTENT_DESCRIPTION = "FLyrWCS Persistent Definition"; |
147 |
private static final int MAX_RETRY_TIMES = 5; |
148 |
|
149 |
private static final GeometryManager geomManager = GeometryLocator.getGeometryManager(); |
150 |
private static final Logger logger = LoggerFactory.getLogger(FLyrWCS.class); |
151 |
private boolean isPrinting = false; |
152 |
|
153 |
private boolean mustTileDraw = false; |
154 |
private int maxTileDrawWidth = 1023; |
155 |
private int maxTileDrawHeight = 1023; |
156 |
private final int maxTilePrintWidth = 1023; |
157 |
private final int maxTilePrintHeight = 1023; |
158 |
|
159 |
private boolean firstLoad = false; |
160 |
private Envelope fullEnvelope = null; |
161 |
private int callCount; |
162 |
private RasterManager rManager = RasterLocator.getManager();
|
163 |
private DataStoreParameters params = null; |
164 |
private WCSServerExplorer explorer = null; |
165 |
private boolean deleteCache = false; |
166 |
|
167 |
@SuppressWarnings("unused") |
168 |
private class MyCancellable implements ICancellable { |
169 |
private Cancellable original;
|
170 |
|
171 |
public MyCancellable(Cancellable cancelOriginal) {
|
172 |
this.original = cancelOriginal;
|
173 |
} |
174 |
|
175 |
public boolean isCanceled() { |
176 |
return original.isCanceled();
|
177 |
} |
178 |
|
179 |
public Object getID() { |
180 |
return this; |
181 |
} |
182 |
} |
183 |
|
184 |
public FLyrWCS() {
|
185 |
super();
|
186 |
this.updateDrawVersion();
|
187 |
try {
|
188 |
enableAwake(); |
189 |
} catch (NotAvailableStateException e) {
|
190 |
logger.error("Fallo el estado de open. Closed=" + isClosed() + " Awake=" + isAwake(), this, e); |
191 |
} |
192 |
} |
193 |
|
194 |
public FLyrWCS(DataStoreParameters dataStoreParameters) throws Exception { |
195 |
this();
|
196 |
//Create the explorer and connect
|
197 |
DataManager dataManager = DALLocator.getDataManager(); |
198 |
WCSServerExplorerParameters explorerParams = (WCSServerExplorerParameters) |
199 |
dataManager.createServerExplorerParameters(WCSServerExplorer.NAME); |
200 |
explorerParams.setHost((String)dataStoreParameters.getDynValue("uri")); |
201 |
WCSServerExplorer wmsServerExplorer = |
202 |
(WCSServerExplorer) dataManager.openServerExplorer(WCSServerExplorer.NAME, explorerParams); |
203 |
wmsServerExplorer.connect(null);
|
204 |
wmsServerExplorer.getCoverageList(); |
205 |
|
206 |
//Set the parameters
|
207 |
setParameters((WCSDataParameters)dataStoreParameters); |
208 |
setExplorer(wmsServerExplorer); |
209 |
} |
210 |
|
211 |
public static DataStore createDataStore(String host, IProjection srs) throws InitializeException { |
212 |
DataManagerProviderServices dataman = (DataManagerProviderServices) DALLocator.getDataManager(); |
213 |
RasterDataParameters params = null;
|
214 |
try {
|
215 |
params = (RasterDataParameters)dataman.createServerExplorerParameters(WCSServerExplorer.NAME); |
216 |
} catch (InitializeException e) {
|
217 |
return null; |
218 |
} catch (ProviderNotRegisteredException e) {
|
219 |
return null; |
220 |
} |
221 |
params.setURI(host); |
222 |
params.setSRS(srs); |
223 |
|
224 |
try {
|
225 |
return dataman.openStore(params.getDataStoreName(), params);
|
226 |
} catch (ValidateDataParametersException e) {
|
227 |
throw new InitializeException(e); |
228 |
} catch (ProviderNotRegisteredException e) {
|
229 |
throw new InitializeException(e); |
230 |
} |
231 |
} |
232 |
|
233 |
/*
|
234 |
* (non-Javadoc)
|
235 |
* @see org.gvsig.raster.fmap.layers.DefaultFLyrRaster#setDataStore(org.gvsig.fmap.dal.DataStore)
|
236 |
*/
|
237 |
public void setDataStore(DataStore dataStore) throws LoadLayerException { |
238 |
this.dataStore = (RasterDataStore) dataStore;
|
239 |
try {
|
240 |
if(this.dataStore.isOpen()) |
241 |
enableOpen(); |
242 |
} catch (NotAvailableStateException e) {
|
243 |
logger.error("Fallo el estado de open. Closed=" + isClosed() + " Awake=" + isAwake(), this, e); |
244 |
} |
245 |
setProjection(this.dataStore.getProjection());
|
246 |
} |
247 |
|
248 |
/*
|
249 |
* (non-Javadoc)
|
250 |
* @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)
|
251 |
*/
|
252 |
public void draw(BufferedImage image, Graphics2D g, ViewPort viewPort, Cancellable cancel, double scale) throws ReadException { |
253 |
TaskStatusManager manager = ToolsLocator.getTaskStatusManager(); |
254 |
SimpleTaskStatus taskStatus = new RasterTaskStatus("Drawing " + getName() + "...", cancel); |
255 |
manager.add(taskStatus); |
256 |
taskStatus.setAutoremove(true);
|
257 |
|
258 |
if(!firstLoad) {
|
259 |
try {
|
260 |
initFilters(); |
261 |
} catch (FilePaletteException e) {
|
262 |
logger.error(e.getMessage(), this, e);
|
263 |
} |
264 |
firstLoad = true;
|
265 |
} |
266 |
|
267 |
callCount = 0;
|
268 |
|
269 |
enableStopped(); |
270 |
|
271 |
if(recalcLevel) {
|
272 |
double pixelSize = viewPort.getEnvelope().getLength(0) / (double)viewPort.getImageWidth(); |
273 |
zoomLevel = dataStore.getNearestLevel(pixelSize); |
274 |
} |
275 |
recalcLevel = true;
|
276 |
|
277 |
if (isWithinScale(scale)) {
|
278 |
|
279 |
if(mustTileDraw) {
|
280 |
Point2D p = viewPort.getOffset();
|
281 |
Rectangle r = new Rectangle((int) p.getX(), (int) p.getY(), viewPort.getImageWidth(), viewPort.getImageHeight()); |
282 |
Tiling tiles = new Tiling(maxTileDrawWidth, maxTileDrawHeight, r);
|
283 |
tiles.setAffineTransform((AffineTransform) viewPort.getAffineTransform().clone());
|
284 |
|
285 |
for (int tileNr = 0; tileNr < tiles.getNumTiles(); tileNr++) { |
286 |
// drawing part
|
287 |
try {
|
288 |
ViewPort vp = tiles.getTileViewPort(viewPort, tileNr); |
289 |
drawTile(g, vp, taskStatus, scale); |
290 |
} catch (LoadLayerException e) {
|
291 |
throw new ReadException(e.getMessage(), e); |
292 |
} catch (NoninvertibleTransformException e) { |
293 |
throw new ReadException(e.getMessage(), e); |
294 |
} |
295 |
} |
296 |
} else {
|
297 |
try {
|
298 |
drawTile(g, viewPort, taskStatus, scale); |
299 |
} catch (LoadLayerException e) {
|
300 |
throw new ReadException(e.getMessage(), e); |
301 |
} |
302 |
} |
303 |
} |
304 |
disableStopped(); |
305 |
|
306 |
/*Runtime r = Runtime.getRuntime();
|
307 |
System.err.println("********************WCS**********************");
|
308 |
System.err.println("Memoria Total: " + (r.totalMemory() / 1024) +"KB");
|
309 |
System.err.println("Memoria Usada: " + ((r.totalMemory() - r.freeMemory()) / 1024) +"KB");
|
310 |
System.err.println("Memoria Libre: " + (r.freeMemory() / 1024) +"KB");
|
311 |
System.err.println("Memoria MaxMemory: " + (r.maxMemory() / 1024) +"KB");
|
312 |
System.err.println("*********************************************");*/
|
313 |
} |
314 |
|
315 |
/**
|
316 |
* This is the method used to draw a tile in a WCS mosaic layer.
|
317 |
* @throws LoadLayerException
|
318 |
* @throws ReadDriverException
|
319 |
* @return true when a tile has been painted
|
320 |
*/
|
321 |
@SuppressWarnings("deprecation") |
322 |
private void drawTile(Graphics2D g, ViewPort vp, SimpleTaskStatus taskStatus, double scale) throws LoadLayerException, ReadException { |
323 |
callCount++; |
324 |
|
325 |
// Compute the query geometry
|
326 |
// 1. Check if it is within borders
|
327 |
Envelope envelope = getFullEnvelope(); |
328 |
Envelope vpEnv = vp.getAdjustedExtent(); |
329 |
if (!vpEnv.intersects(envelope)) {
|
330 |
return;
|
331 |
} |
332 |
|
333 |
// 2. Compute extent to be requested.
|
334 |
Rectangle2D bBox = new Rectangle2D.Double(); |
335 |
Rectangle2D.intersect(getRectable2DFromEnvelope(vpEnv),
|
336 |
getRectable2DFromEnvelope(envelope), bBox); |
337 |
|
338 |
// 3. Compute size in pixels
|
339 |
double scalex = vp.getAffineTransform().getScaleX();
|
340 |
double scaley = vp.getAffineTransform().getScaleY();
|
341 |
int wImg = (int) Math.ceil(Math.abs(bBox.getWidth() * scalex) + 1); |
342 |
int hImg = (int) Math.ceil(Math.abs(bBox.getHeight() * scaley) + 1); |
343 |
|
344 |
Dimension sz = new Dimension(wImg, hImg); |
345 |
|
346 |
if ((wImg <= 0) || (hImg <= 0)) { |
347 |
return;
|
348 |
} |
349 |
|
350 |
try {
|
351 |
//Rectangle2D extent = new Rectangle2D.Double();
|
352 |
//Rectangle2D.Double vpExtent = this.getRectable2DFromEnvelope(vpEnv);
|
353 |
//Rectangle2D.intersect(vpExtent, bBox, extent);
|
354 |
|
355 |
Extent ex = rManager.getDataStructFactory().createExtent( |
356 |
vp.getAdjustedEnvelope().getMinimum(0),
|
357 |
vp.getAdjustedEnvelope().getMaximum(1),
|
358 |
vp.getAdjustedEnvelope().getMaximum(0),
|
359 |
vp.getAdjustedEnvelope().getMinimum(1));
|
360 |
ViewPortData vpData = rManager.createViewPortData(vp.getProjection(), ex, sz ); |
361 |
vpData.setMat(vp.getAffineTransform()); |
362 |
|
363 |
try {
|
364 |
getParameters().setExtent(bBox); |
365 |
getParameters().setWidth(wImg); |
366 |
getParameters().setHeight(hImg); |
367 |
if(params instanceof WCSDataParameters) { |
368 |
getRender().draw(g, vpData, taskStatus); |
369 |
} else {
|
370 |
Envelope adjustedExtent = vp.getAdjustedExtent(); |
371 |
Extent e = rManager.getDataStructFactory().createExtent(adjustedExtent.getLowerCorner().getX(), |
372 |
adjustedExtent.getUpperCorner().getY(), adjustedExtent.getUpperCorner().getX(), |
373 |
adjustedExtent.getLowerCorner().getY()); |
374 |
ViewPortData vp2 = rManager.createViewPortData(vp.getProjection(), e, vp.getImageSize() ); |
375 |
vp2.setMat(vp.getAffineTransform()); |
376 |
getParameters().setExtent(ex.toRectangle2D()); |
377 |
getRender().drawTiledService(g, vp2, vp.getImageSize(), taskStatus); |
378 |
} |
379 |
} catch (RasterDriverException e) {
|
380 |
setAvailable(false);
|
381 |
JOptionPane.showMessageDialog(null, "Problems drawing this layer:" + e.getMessage(), Messages.getText("Error"), JOptionPane.ERROR_MESSAGE); |
382 |
logger.info("Problems drawing this layer:" + e.getMessage(), e);
|
383 |
} catch (InvalidSetViewException e) {
|
384 |
throw new RemoteServiceException("Problems drawing this layer: " + e.getMessage(), e); |
385 |
} catch (ProcessInterruptedException e) {
|
386 |
} finally {
|
387 |
taskStatus.terminate(); |
388 |
} |
389 |
|
390 |
} catch (RemoteServiceException e) {
|
391 |
if (!taskStatus.isCancellationRequested()) {
|
392 |
if (callCount < MAX_RETRY_TIMES) {
|
393 |
logger.warn("\n[ FLyrWCS.drawFixedSize() ] Failed in trying " + callCount + "/" + MAX_RETRY_TIMES + ")\n"); // mess code |
394 |
drawTile(g, vp, taskStatus, scale); |
395 |
} else {
|
396 |
if (!isPrinting) {
|
397 |
this.setVisible(false); |
398 |
} |
399 |
throw new LoadLayerException(getName(), e); |
400 |
} |
401 |
} |
402 |
} |
403 |
callCount--; |
404 |
return;
|
405 |
} |
406 |
|
407 |
/**
|
408 |
* Gets the explorer
|
409 |
* @return
|
410 |
*/
|
411 |
public WCSServerExplorer getExplorer() {
|
412 |
return this.explorer; |
413 |
} |
414 |
|
415 |
/**
|
416 |
* <p>
|
417 |
* Gets the max resolution allowed by the coverage. Requesting a higher resolution
|
418 |
* than this value does not cause any error, but the info responsed is just an
|
419 |
* interpolation. <br>
|
420 |
* </p>
|
421 |
*
|
422 |
* <p>
|
423 |
* In exchange for obtaining a greater file and without additional information,
|
424 |
* we can easily fit it into the View. <br>
|
425 |
* </p>
|
426 |
*
|
427 |
* <p>
|
428 |
* Obtiene la resoluci?n m?xima soportada por la cobertura. La petici?n
|
429 |
* de una resoluci?n superior a la soportada no provoca ning?n error, aunque
|
430 |
* la informaci?n obtenida s?lo es una mera interpolaci?n de informaci?n. <br>
|
431 |
* </p>
|
432 |
*
|
433 |
* <p>
|
434 |
* A cambio de obtener un archivo mayor y sin informaci?n adicional, podemos
|
435 |
* f?cilmente acoplarlo a la vista. <br>
|
436 |
* </p>
|
437 |
*
|
438 |
* @return double
|
439 |
*/
|
440 |
public Point2D getMaxResolution() { |
441 |
return explorer.getMaxResolution(getName());
|
442 |
} |
443 |
|
444 |
private Rectangle2D.Double getRectable2DFromEnvelope(Envelope env) { |
445 |
return new Rectangle2D.Double(env.getMinimum(0), env.getMinimum(1), env |
446 |
.getLength(0), env.getLength(1)); |
447 |
} |
448 |
|
449 |
/**
|
450 |
* Calcula el contenido del fichero de georreferenciaci?n de una imagen.
|
451 |
* @param bBox Tama?o y posici?n de la imagen (en coordenadas de usuario)
|
452 |
* @param sz Tama?o de la imagen en pixeles.
|
453 |
* @return el 'WorldFile', como String.
|
454 |
* @throws IOException
|
455 |
*/
|
456 |
public String getDataWorldFile(Rectangle2D bBox, Dimension sz) throws IOException { |
457 |
StringBuffer data = new StringBuffer(); |
458 |
data.append((bBox.getMaxX() - bBox.getMinX()) / (sz.getWidth() - 1) + "\n"); |
459 |
data.append("0.0\n");
|
460 |
data.append("0.0\n");
|
461 |
data.append("-" + (bBox.getMaxY() - bBox.getMinY()) / (sz.getHeight() - 1) + "\n"); |
462 |
data.append("" + bBox.getMinX() + "\n"); |
463 |
data.append("" + bBox.getMaxY() + "\n"); |
464 |
return data.toString();
|
465 |
} |
466 |
|
467 |
/*
|
468 |
* (non-Javadoc)
|
469 |
* @see com.iver.cit.gvsig.fmap.layers.FLyrDefault#cloneLayer()
|
470 |
*/
|
471 |
public FLayer cloneLayer() throws Exception { |
472 |
RasterDataStore ds = dataStore.cloneDataStore(); |
473 |
FLyrWCS layer = new FLyrWCS();
|
474 |
layer.setName(getParameters().getCoverageName()); |
475 |
layer.setOpenRasterStore(ds); |
476 |
layer.fullEnvelope = fullEnvelope; |
477 |
layer.params = params; |
478 |
layer.explorer = explorer; |
479 |
|
480 |
List<RasterFilter> filters = getRender().getFilterList().getStatusCloned();
|
481 |
|
482 |
//Hacemos una copia de las bandas a renderizar
|
483 |
if(getRender().getRenderBands() != null) { |
484 |
int[] rb = new int[getRender().getRenderBands().length]; |
485 |
for (int i = 0; i < rb.length; i++) |
486 |
rb[i] = getRender().getRenderBands()[i]; |
487 |
layer.getRender().setRenderBands(rb); |
488 |
} |
489 |
|
490 |
//Asignamos el entorno
|
491 |
if(layer.getRender().getFilterList() == null) |
492 |
layer.getRender().setFilterList(RasterLocator.getManager().createEmptyFilterList(getRender().getFilterList().getInitDataType())); |
493 |
layer.getRender().getFilterList().setEnv(getRender().getFilterList().getEnv()); |
494 |
layer.getRender().getFilterList().setStatus(filters); |
495 |
|
496 |
// Asignamos los valores noData del original
|
497 |
layer.setNoDataValue(getNoDataValue()); |
498 |
if(dataStore.getNoDataValue().isDefined())
|
499 |
layer.setNoDataTransparent(true);
|
500 |
layer.enableOpen(); |
501 |
|
502 |
return layer;
|
503 |
} |
504 |
|
505 |
public Transparency getRenderTransparency() { |
506 |
return getRender().getLastTransparency();
|
507 |
} |
508 |
|
509 |
/*
|
510 |
* (non-Javadoc)
|
511 |
* @see org.gvsig.fmap.raster.layers.FLyrRasterSE#print(java.awt.Graphics2D, com.iver.cit.gvsig.fmap.ViewPort, com.iver.utiles.swing.threads.Cancellable, double, javax.print.attribute.PrintRequestAttributeSet)
|
512 |
*/
|
513 |
public void print(Graphics2D g, ViewPort viewPort, Cancellable cancel, double scale, PrintRequestAttributeSet properties) throws ReadException { |
514 |
if (isVisible() && isWithinScale(scale)){
|
515 |
draw(null, g, viewPort, cancel, scale);
|
516 |
} |
517 |
} |
518 |
|
519 |
/**
|
520 |
* Inserta la extensi?n total de la capa en la proyeccion original.
|
521 |
*
|
522 |
* @param fullExtent
|
523 |
* Rect?ngulo.
|
524 |
*/
|
525 |
public void setFullEnvelope(Envelope envelope) { |
526 |
Envelope cur = this.getFullEnvelope();
|
527 |
if (cur == envelope) {
|
528 |
return;
|
529 |
} |
530 |
if (cur != null && cur.equals(envelope)) { |
531 |
return;
|
532 |
} |
533 |
|
534 |
this.fullEnvelope = envelope;
|
535 |
this.updateDrawVersion();
|
536 |
} |
537 |
|
538 |
/**
|
539 |
* Sets the layer's full extent.
|
540 |
*
|
541 |
* Establece la extensi?n m?xima de la capa.
|
542 |
*
|
543 |
* @param rect
|
544 |
*/
|
545 |
public void setFullExtent(Rectangle2D fullExtent) { |
546 |
this.setFullEnvelope(this.getEnvelopeFromRectable2D(fullExtent)); |
547 |
} |
548 |
|
549 |
private Envelope getEnvelopeFromRectable2D(Rectangle2D rect) { |
550 |
try {
|
551 |
return geomManager.createEnvelope(rect.getMinX(), rect.getMinY(),
|
552 |
rect.getMaxX(), rect.getMaxY(), |
553 |
SUBTYPES.GEOM2D); |
554 |
} catch (CreateEnvelopeException e) {
|
555 |
logger.error("Error creating the envelope", e);
|
556 |
} |
557 |
return null; |
558 |
} |
559 |
|
560 |
|
561 |
public HashMap<String, Object> getProperties() { |
562 |
HashMap<String, Object> info = new HashMap<String, Object>(); |
563 |
try {
|
564 |
info.put("name", getName());
|
565 |
info.put("selectedLayers", getParameters().getCoverageName());
|
566 |
info.put("host", getParameters().getURI());
|
567 |
info.put("crs", getParameters().getSRSCode());
|
568 |
info.put("format", getParameters().getFormat());
|
569 |
info.put("time", getParameters().getTime());
|
570 |
return info;
|
571 |
} catch (Exception e) { |
572 |
e.printStackTrace(); |
573 |
} |
574 |
return null; |
575 |
} |
576 |
|
577 |
/*
|
578 |
* (non-Javadoc)
|
579 |
* @see com.iver.cit.gvsig.fmap.layers.RasterOperations#getTileSize()
|
580 |
*/
|
581 |
public int[] getTileSize() { |
582 |
int[] size = {maxTileDrawWidth, maxTileDrawHeight}; |
583 |
return size;
|
584 |
} |
585 |
|
586 |
/*
|
587 |
* (non-Javadoc)
|
588 |
* @see org.gvsig.raster.fmap.layers.DefaultFLyrRaster#getTocImageIcon()
|
589 |
*/
|
590 |
public String getTocImageIcon() { |
591 |
return "ico-WCS-Layer"; |
592 |
} |
593 |
|
594 |
/*
|
595 |
* (non-Javadoc)
|
596 |
* @see com.iver.cit.gvsig.fmap.layers.RasterOperations#isTiled()
|
597 |
*/
|
598 |
public boolean isTiled() { |
599 |
return mustTileDraw;
|
600 |
} |
601 |
|
602 |
@SuppressWarnings("deprecation") |
603 |
@Override
|
604 |
public DynObjectSet getInfo(Point p, double tolerance, Cancellable cancel, |
605 |
boolean fast) throws LoadLayerException, DataException { |
606 |
|
607 |
//try {
|
608 |
ViewPort viewPort = getMapContext().getViewPort(); |
609 |
|
610 |
Point tiledPoint = new Point((int) p.getX() % maxTilePrintWidth, (int) p.getY() % maxTilePrintHeight); |
611 |
Rectangle rect = new Rectangle(0, 0, viewPort.getImageWidth() - 1, viewPort.getImageHeight() - 1); |
612 |
Tiling tiles = new Tiling(maxTilePrintWidth, maxTilePrintHeight, rect);
|
613 |
tiles.setAffineTransform((AffineTransform) viewPort.getAffineTransform().clone());
|
614 |
int nCols = tiles.getNumCols();
|
615 |
|
616 |
int col = (int) p.getX() / maxTilePrintWidth; |
617 |
int row = (int) p.getY() / maxTilePrintHeight; |
618 |
int tileIndex = (row * nCols) + col;
|
619 |
|
620 |
ViewPort vp = null;
|
621 |
try {
|
622 |
vp = tiles.getTileViewPort(viewPort, tileIndex); |
623 |
} catch (NoninvertibleTransformException e1) { |
624 |
throw new LoadLayerException("", e1); |
625 |
} |
626 |
|
627 |
getParameters().setExtent(this.getRectable2DFromEnvelope(vp.getAdjustedExtent()));
|
628 |
getParameters().setWidth(vp.getImageWidth()); |
629 |
getParameters().setHeight(vp.getImageHeight()); |
630 |
|
631 |
CancelTaskImpl cancellable = new CancelTaskImpl(cancel);
|
632 |
getParameters().setCancellable(cancellable); |
633 |
|
634 |
String fInfo;
|
635 |
try {
|
636 |
fInfo = getDataStore().getInfoByPoint(tiledPoint.getX(), tiledPoint.getY(), cancellable); |
637 |
} catch (InfoByPointException e) {
|
638 |
throw new LoadLayerException("Error in getInfoByPoint", e); |
639 |
} |
640 |
return new DynObjectSetWCSInfo(fInfo, DynObjectSetWCSInfo.TYPE_TEXT); |
641 |
} |
642 |
|
643 |
/*
|
644 |
* (non-Javadoc)
|
645 |
* @see org.gvsig.raster.fmap.layers.FLyrRaster#getFileFormat()
|
646 |
*/
|
647 |
@Override
|
648 |
public String getFileFormat() { |
649 |
return "WCS"; |
650 |
} |
651 |
|
652 |
/*
|
653 |
* (non-Javadoc)
|
654 |
* @see org.gvsig.fmap.raster.layers.FLyrRasterSE#isActionEnabled(int)
|
655 |
*/
|
656 |
public boolean isActionEnabled(int action) { |
657 |
switch (action) {
|
658 |
case IRasterLayerActions.ZOOM_PIXEL_RESOLUTION:
|
659 |
case IRasterLayerActions.FLYRASTER_BAR_TOOLS:
|
660 |
case IRasterLayerActions.BANDS_FILE_LIST:
|
661 |
case IRasterLayerActions.GEOLOCATION:
|
662 |
case IRasterLayerActions.PANSHARPENING:
|
663 |
case IRasterLayerActions.SAVE_COLORINTERP:
|
664 |
return false; |
665 |
case IRasterLayerActions.BANDS_RGB:
|
666 |
case IRasterLayerActions.REMOTE_ACTIONS:
|
667 |
case IRasterLayerActions.COLOR_TABLE:
|
668 |
return true; |
669 |
} |
670 |
|
671 |
return super.isActionEnabled(action); |
672 |
} |
673 |
|
674 |
/*
|
675 |
* (non-Javadoc)
|
676 |
* @see org.gvsig.fmap.raster.layers.FLyrRasterSE#overviewsSupport()
|
677 |
*/
|
678 |
public boolean overviewsSupport() { |
679 |
return false; |
680 |
} |
681 |
|
682 |
/*
|
683 |
* (non-Javadoc)
|
684 |
* @see org.gvsig.raster.fmap.layers.FLyrRaster#getFullRasterExtent()
|
685 |
*/
|
686 |
public org.gvsig.fmap.dal.coverage.datastruct.Extent getFullRasterExtent() {
|
687 |
Envelope env = getFullEnvelope(); |
688 |
double minx = env.getMinimum(0); |
689 |
double miny = env.getMinimum(1); |
690 |
double maxx = env.getMaximum(0); |
691 |
double maxy = env.getMaximum(1); |
692 |
Point2D ul = new Point2D.Double(minx, maxy); |
693 |
Point2D ur = new Point2D.Double(maxx, maxy); |
694 |
Point2D ll = new Point2D.Double(minx, miny); |
695 |
Point2D lr = new Point2D.Double(maxx, miny); |
696 |
return rManager.getDataStructFactory().createExtent(ul, lr, ur, ll);
|
697 |
} |
698 |
|
699 |
@SuppressWarnings("deprecation") |
700 |
public WCSDataParameters getParameters() {
|
701 |
if(params == null) { |
702 |
DataManager datamanager = DALLocator.getDataManager(); |
703 |
WCSServerExplorerParameters explorerParams = null;
|
704 |
try {
|
705 |
explorerParams = (WCSServerExplorerParameters) datamanager.createServerExplorerParameters(WCSServerExplorer.NAME); |
706 |
explorerParams.setHost("");
|
707 |
explorer = (WCSServerExplorer) datamanager.createServerExplorer(explorerParams); |
708 |
DataStoreParameters parameters = explorer.getStoreParameters(); |
709 |
if(parameters instanceof WCSDataParameters) { |
710 |
params = (WCSDataParameters) parameters; |
711 |
} |
712 |
} catch (InitializeException e) {
|
713 |
} catch (ProviderNotRegisteredException e) {
|
714 |
} catch (ValidateDataParametersException e) {
|
715 |
} |
716 |
} |
717 |
return getWCSParameters(params);
|
718 |
} |
719 |
|
720 |
/**
|
721 |
* Gets <code>WCSDataParameters</code>
|
722 |
* @param parameters
|
723 |
* @return
|
724 |
*/
|
725 |
private WCSDataParameters getWCSParameters(DataStoreParameters parameters) {
|
726 |
WCSDataParameters params = null;
|
727 |
if(parameters instanceof WCSDataParameters) { |
728 |
params = (WCSDataParameters) parameters; |
729 |
} |
730 |
|
731 |
if(parameters instanceof TileDataParameters) { |
732 |
DataParameters p = ((TileDataParameters) parameters).getDataParameters(); |
733 |
if(p instanceof WCSDataParameters) { |
734 |
params = (WCSDataParameters) p; |
735 |
} |
736 |
} |
737 |
return params;
|
738 |
} |
739 |
|
740 |
/**
|
741 |
* Sets the explorer
|
742 |
* @param explorer
|
743 |
*/
|
744 |
public void setExplorer(WCSServerExplorer explorer) { |
745 |
this.explorer = explorer;
|
746 |
} |
747 |
|
748 |
/**
|
749 |
* Assigns the flag to delete this layer from the cache
|
750 |
* @param selected
|
751 |
*/
|
752 |
public void deleteCache(boolean deleteCache) { |
753 |
this.deleteCache = deleteCache;
|
754 |
} |
755 |
|
756 |
/**
|
757 |
* Sets the data store parameters
|
758 |
* @param params
|
759 |
* @throws InitializeException
|
760 |
*/
|
761 |
public void setParameters(DataStoreParameters params) throws InitializeException { |
762 |
this.params = params;
|
763 |
|
764 |
if(params instanceof TileDataParameters) { |
765 |
((TileDataParameters)params).deleteCache(deleteCache); |
766 |
} |
767 |
|
768 |
DataManagerProviderServices dataman = (DataManagerProviderServices) DALLocator.getDataManager(); |
769 |
try {
|
770 |
DataStore dStore = dataman.openStore(params.getDataStoreName(), params); |
771 |
this.setDataStore(dStore);
|
772 |
|
773 |
if(params instanceof WCSDataParameters) { |
774 |
this.setName((String)((WCSDataParameters)params).getURI()); |
775 |
} |
776 |
|
777 |
if(params instanceof TileDataParameters) { |
778 |
DataParameters p = ((TileDataParameters) params).getDataParameters(); |
779 |
if(p instanceof WCSDataParameters) { |
780 |
this.setName((String)((WCSDataParameters) p).getURI()); |
781 |
} |
782 |
} |
783 |
} catch (ValidateDataParametersException e) {
|
784 |
throw new InitializeException(e); |
785 |
} catch (ProviderNotRegisteredException e) {
|
786 |
throw new InitializeException(e); |
787 |
} catch (LoadLayerException e) {
|
788 |
throw new InitializeException(e); |
789 |
} |
790 |
} |
791 |
|
792 |
/*
|
793 |
* (non-Javadoc)
|
794 |
* @see org.gvsig.raster.fmap.layers.DefaultFLyrRaster#loadFromState(org.gvsig.tools.persistence.PersistentState)
|
795 |
*/
|
796 |
@Override
|
797 |
public void loadFromState(PersistentState state) |
798 |
throws PersistenceException {
|
799 |
String host = state.getString("host"); |
800 |
try {
|
801 |
getParameters(); |
802 |
WCSServerExplorerParameters params = (WCSServerExplorerParameters)explorer.getParameters(); |
803 |
params.setHost(host); |
804 |
explorer.connect(new CancelTaskImpl());
|
805 |
explorer.getCoverageList(); |
806 |
} catch (Exception e) { |
807 |
throw new PersistenceException("Server comunication error", e); |
808 |
} |
809 |
|
810 |
super.loadFromState(state);
|
811 |
params = getDataStore().getParameters(); |
812 |
this.fullEnvelope = (Envelope) state.get("fullEnvelope"); |
813 |
try {
|
814 |
if(this.dataStore.isOpen()) |
815 |
enableOpen(); |
816 |
} catch (NotAvailableStateException e) {
|
817 |
logger.error("Fallo el estado de open. Closed=" + isClosed() + " Awake=" + isAwake(), this, e); |
818 |
} |
819 |
//getParameters().setCoverageName((String)state.get("name"));
|
820 |
} |
821 |
|
822 |
/*
|
823 |
* (non-Javadoc)
|
824 |
* @see org.gvsig.raster.fmap.layers.DefaultFLyrRaster#saveToState(org.gvsig.tools.persistence.PersistentState)
|
825 |
*/
|
826 |
@Override
|
827 |
public void saveToState(PersistentState state) throws PersistenceException { |
828 |
super.saveToState(state);
|
829 |
state.set("fullEnvelope", this.fullEnvelope); |
830 |
state.set("host", getParameters().getURI());
|
831 |
state.set("name", getName());
|
832 |
} |
833 |
|
834 |
public static void registerPersistent() { |
835 |
PersistenceManager manager = ToolsLocator.getPersistenceManager(); |
836 |
DynStruct definition = manager.getDefinition(PERSISTENT_NAME); |
837 |
if( definition == null ) { |
838 |
if (manager.getDefinition(FLyrDefault.class) == null) { |
839 |
FLyrDefault.registerPersistent(); |
840 |
} |
841 |
|
842 |
definition = manager.addDefinition( |
843 |
FLyrWCS.class, |
844 |
PERSISTENT_NAME, |
845 |
PERSISTENT_DESCRIPTION, |
846 |
null,
|
847 |
null
|
848 |
); |
849 |
|
850 |
definition.extend(PersistenceManager.PERSISTENCE_NAMESPACE, "FLyrDefault");
|
851 |
} |
852 |
|
853 |
DefaultFLyrRaster.registerPersistence(definition); |
854 |
definition.addDynFieldObject("fullEnvelope").setClassOfValue(Envelope.class).setMandatory(false); |
855 |
definition.addDynFieldString("host").setMandatory(false); |
856 |
definition.addDynFieldString("name").setMandatory(false); |
857 |
} |
858 |
|
859 |
/* public static void registerPersistent() {
|
860 |
PersistenceManager manager = ToolsLocator.getPersistenceManager();
|
861 |
DynStruct definition = manager.getDefinition(PERSISTENT_NAME);
|
862 |
if( definition == null ) {
|
863 |
if (manager.getDefinition(DefaultFLyrRaster.class) == null) {
|
864 |
DefaultFLyrRaster.registerPersistence();
|
865 |
}
|
866 |
|
867 |
definition = manager.addDefinition(
|
868 |
FLyrWCS.class,
|
869 |
PERSISTENT_NAME,
|
870 |
PERSISTENT_DESCRIPTION,
|
871 |
null,
|
872 |
null
|
873 |
);
|
874 |
|
875 |
definition.extend(PersistenceManager.PERSISTENCE_NAMESPACE, DefaultFLyrRaster.PERSISTENT_NAME);
|
876 |
}
|
877 |
|
878 |
definition.addDynFieldObject("fullEnvelope").setClassOfValue(Envelope.class).setMandatory(true);
|
879 |
definition.addDynFieldString("host").setMandatory(true);
|
880 |
definition.addDynFieldBoolean("deleteCache").setMandatory(false);
|
881 |
definition.addDynFieldString("time").setMandatory(false);
|
882 |
definition.addDynFieldObject("maxres").setClassOfValue(Point2D.class).setMandatory(false);
|
883 |
definition.addDynFieldString("parameter").setMandatory(false);
|
884 |
definition.addDynFieldString("srsstr").setMandatory(false);
|
885 |
definition.addDynFieldString("format").setMandatory(false);
|
886 |
definition.addDynFieldString("name").setMandatory(false);
|
887 |
definition.addDynFieldObject("extent").setClassOfValue(Rectangle2D.class).setMandatory(false);
|
888 |
definition.addDynFieldInt("width").setMandatory(true);
|
889 |
definition.addDynFieldInt("height").setMandatory(true);
|
890 |
definition.addDynFieldBoolean("override").setMandatory(false);
|
891 |
definition.addDynFieldMap("onlineResources").setClassOfItems(String.class).setMandatory(false);
|
892 |
definition.addDynFieldString("depth").setMandatory(false);
|
893 |
}*/
|
894 |
|
895 |
/*
|
896 |
* (non-Javadoc)
|
897 |
* @see org.gvsig.raster.fmap.layers.DefaultFLyrRaster#saveToState(org.gvsig.tools.persistence.PersistentState)
|
898 |
*/
|
899 |
/*public void saveToState(PersistentState state) throws PersistenceException {
|
900 |
super.saveToState(state);
|
901 |
state.set("fullEnvelope", this.fullEnvelope);
|
902 |
state.set("host", getParameters().getURI());
|
903 |
state.set("time", getParameters().getTime());
|
904 |
state.set("deleteCache", getParameters().isDeletingCache());
|
905 |
state.set("maxres", getParameters().getMaxResolution());
|
906 |
state.set("parameter", getParameters().getParameter());
|
907 |
state.set("srsstr", getParameters().getSRSCode());
|
908 |
state.set("format", getParameters().getFormat());
|
909 |
state.set("name", getParameters().getCoverageName());
|
910 |
state.set("extent", getParameters().getExtent());
|
911 |
state.set("width", getParameters().getWidth());
|
912 |
state.set("height", getParameters().getHeight());
|
913 |
state.set("override", getParameters().isOverridingHost());
|
914 |
state.set("onlineResources", getParameters().getOnlineResource());
|
915 |
state.set("depth", getParameters().getDepth());
|
916 |
}*/
|
917 |
|
918 |
/*
|
919 |
* (non-Javadoc)
|
920 |
* @see org.gvsig.raster.fmap.layers.DefaultFLyrRaster#loadFromState(org.gvsig.tools.persistence.PersistentState)
|
921 |
*/
|
922 |
/* public void loadFromState(PersistentState state)
|
923 |
throws PersistenceException {
|
924 |
super.loadFromState(state);
|
925 |
|
926 |
this.fullEnvelope = (Envelope) state.get("fullExtent");
|
927 |
getParameters().setURI(state.getString("host"));
|
928 |
getParameters().setTime(state.getString("time"));
|
929 |
getParameters().setFormat(state.getString("format"));
|
930 |
getParameters().deleteCache(state.getBoolean("deleteCache"));
|
931 |
getParameters().setMaxResolution((Point2D)state.get("maxres"));
|
932 |
getParameters().setParameter(state.getString("parameter"));
|
933 |
getParameters().setSRS(state.getString("srsstr"));
|
934 |
getParameters().setFormat(state.getString("format"));
|
935 |
getParameters().setCoverageName(state.getString("name"));
|
936 |
getParameters().setExtent((Rectangle2D)state.get("extent"));
|
937 |
getParameters().setWidth(state.getInt("width"));
|
938 |
getParameters().setHeight(state.getInt("height"));
|
939 |
getParameters().setOverrideHost(state.getBoolean("override"));
|
940 |
getParameters().setOnlineResources(new Hashtable(state.getMap("onlineResources")));
|
941 |
getParameters().setDepth(state.getString("depth"));
|
942 |
}*/
|
943 |
} |