gvsig-raster / org.gvsig.raster / trunk / org.gvsig.raster / org.gvsig.raster.fmap / src / main / java / org / gvsig / raster / fmap / layers / DefaultFLyrRaster.java @ 1868
History | View | Annotate | Download (70.6 KB)
1 |
/* gvSIG. Geographic Information System of the Valencian Government
|
---|---|
2 |
*
|
3 |
* Copyright (C) 2007-2008 Infrastructures and Transports Department
|
4 |
* of the Valencian Government (CIT)
|
5 |
*
|
6 |
* This program is free software; you can redistribute it and/or
|
7 |
* modify it under the terms of the GNU General Public License
|
8 |
* as published by the Free Software Foundation; either version 2
|
9 |
* of the License, or (at your option) any later version.
|
10 |
*
|
11 |
* This program is distributed in the hope that it will be useful,
|
12 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
13 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
14 |
* GNU General Public License for more details.
|
15 |
*
|
16 |
* You should have received a copy of the GNU General Public License
|
17 |
* along with this program; if not, write to the Free Software
|
18 |
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
19 |
* MA 02110-1301, USA.
|
20 |
*
|
21 |
*/
|
22 |
package org.gvsig.raster.fmap.layers; |
23 |
|
24 |
import java.awt.Dimension; |
25 |
import java.awt.Graphics2D; |
26 |
import java.awt.Point; |
27 |
import java.awt.Rectangle; |
28 |
import java.awt.geom.AffineTransform; |
29 |
import java.awt.geom.NoninvertibleTransformException; |
30 |
import java.awt.geom.Point2D; |
31 |
import java.awt.geom.Rectangle2D; |
32 |
import java.awt.image.BufferedImage; |
33 |
import java.io.File; |
34 |
import java.io.IOException; |
35 |
import java.util.ArrayList; |
36 |
import java.util.HashMap; |
37 |
import java.util.List; |
38 |
import java.util.Set; |
39 |
|
40 |
import org.cresques.cts.IProjection; |
41 |
import org.gvsig.compat.print.PrintAttributes; |
42 |
import org.gvsig.fmap.crs.CRSFactory; |
43 |
import org.gvsig.fmap.dal.DataStore; |
44 |
import org.gvsig.fmap.dal.DataStoreParameters; |
45 |
import org.gvsig.fmap.dal.coverage.RasterLibrary; |
46 |
import org.gvsig.fmap.dal.coverage.RasterLocator; |
47 |
import org.gvsig.fmap.dal.coverage.RasterManager; |
48 |
import org.gvsig.fmap.dal.coverage.dataset.Buffer; |
49 |
import org.gvsig.fmap.dal.coverage.datastruct.ColorItem; |
50 |
import org.gvsig.fmap.dal.coverage.datastruct.ColorTableLibrary; |
51 |
import org.gvsig.fmap.dal.coverage.datastruct.Extent; |
52 |
import org.gvsig.fmap.dal.coverage.datastruct.NoData; |
53 |
import org.gvsig.fmap.dal.coverage.datastruct.Params; |
54 |
import org.gvsig.fmap.dal.coverage.datastruct.ViewPortData; |
55 |
import org.gvsig.fmap.dal.coverage.exception.FileNotOpenException; |
56 |
import org.gvsig.fmap.dal.coverage.exception.FilePaletteException; |
57 |
import org.gvsig.fmap.dal.coverage.exception.FilterManagerException; |
58 |
import org.gvsig.fmap.dal.coverage.exception.FilterTypeException; |
59 |
import org.gvsig.fmap.dal.coverage.exception.GridException; |
60 |
import org.gvsig.fmap.dal.coverage.exception.InvalidSetViewException; |
61 |
import org.gvsig.fmap.dal.coverage.exception.InvalidSourceException; |
62 |
import org.gvsig.fmap.dal.coverage.exception.NotSupportedExtensionException; |
63 |
import org.gvsig.fmap.dal.coverage.exception.ProcessInterruptedException; |
64 |
import org.gvsig.fmap.dal.coverage.exception.ROIException; |
65 |
import org.gvsig.fmap.dal.coverage.exception.RasterDriverException; |
66 |
import org.gvsig.fmap.dal.coverage.exception.RmfSerializerException; |
67 |
import org.gvsig.fmap.dal.coverage.grid.Grid; |
68 |
import org.gvsig.fmap.dal.coverage.grid.ROI; |
69 |
import org.gvsig.fmap.dal.coverage.grid.RasterFilter; |
70 |
import org.gvsig.fmap.dal.coverage.grid.RasterFilterList; |
71 |
import org.gvsig.fmap.dal.coverage.grid.RasterFilterListManager; |
72 |
import org.gvsig.fmap.dal.coverage.grid.render.Render; |
73 |
import org.gvsig.fmap.dal.coverage.grid.render.VisualPropertyEvent; |
74 |
import org.gvsig.fmap.dal.coverage.grid.render.VisualPropertyListener; |
75 |
import org.gvsig.fmap.dal.coverage.process.TaskEventManager; |
76 |
import org.gvsig.fmap.dal.coverage.store.RasterDataStore; |
77 |
import org.gvsig.fmap.dal.coverage.store.RasterQuery; |
78 |
import org.gvsig.fmap.dal.coverage.store.parameter.RasterDataParameters; |
79 |
import org.gvsig.fmap.dal.coverage.store.parameter.RasterFileStoreParameters; |
80 |
import org.gvsig.fmap.dal.coverage.store.parameter.TileDataParameters; |
81 |
import org.gvsig.fmap.dal.coverage.store.props.ColorInterpretation; |
82 |
import org.gvsig.fmap.dal.coverage.store.props.ColorTable; |
83 |
import org.gvsig.fmap.dal.coverage.store.props.Statistics; |
84 |
import org.gvsig.fmap.dal.coverage.util.CRSUtils; |
85 |
import org.gvsig.fmap.dal.coverage.util.ColorConversion; |
86 |
import org.gvsig.fmap.dal.coverage.util.FileUtils; |
87 |
import org.gvsig.fmap.dal.coverage.util.Historical; |
88 |
import org.gvsig.fmap.dal.coverage.util.MathUtils; |
89 |
import org.gvsig.fmap.dal.coverage.util.ProviderServices; |
90 |
import org.gvsig.fmap.dal.coverage.util.RasterUtils; |
91 |
import org.gvsig.fmap.dal.exception.CloseException; |
92 |
import org.gvsig.fmap.dal.exception.DataException; |
93 |
import org.gvsig.fmap.dal.exception.InitializeException; |
94 |
import org.gvsig.fmap.dal.exception.ReadException; |
95 |
import org.gvsig.fmap.dal.raster.spi.CoverageStoreProviderServices; |
96 |
import org.gvsig.fmap.geom.GeometryLocator; |
97 |
import org.gvsig.fmap.geom.GeometryManager; |
98 |
import org.gvsig.fmap.geom.Geometry.SUBTYPES; |
99 |
import org.gvsig.fmap.geom.Geometry.TYPES; |
100 |
import org.gvsig.fmap.geom.exception.CreateEnvelopeException; |
101 |
import org.gvsig.fmap.geom.primitive.Envelope; |
102 |
import org.gvsig.fmap.geom.type.GeometryType; |
103 |
import org.gvsig.fmap.geom.type.GeometryTypeNotSupportedException; |
104 |
import org.gvsig.fmap.geom.type.GeometryTypeNotValidException; |
105 |
import org.gvsig.fmap.mapcontext.MapContextLocator; |
106 |
import org.gvsig.fmap.mapcontext.MapContextManager; |
107 |
import org.gvsig.fmap.mapcontext.ViewPort; |
108 |
import org.gvsig.fmap.mapcontext.exceptions.LoadLayerException; |
109 |
import org.gvsig.fmap.mapcontext.exceptions.ReloadLayerException; |
110 |
import org.gvsig.fmap.mapcontext.layers.FLayer; |
111 |
import org.gvsig.fmap.mapcontext.layers.FLyrDefault; |
112 |
import org.gvsig.fmap.mapcontext.layers.LayerChangeSupport; |
113 |
import org.gvsig.fmap.mapcontext.layers.LayerListener; |
114 |
import org.gvsig.fmap.mapcontext.layers.Tiling; |
115 |
import org.gvsig.fmap.mapcontext.layers.operations.Classifiable; |
116 |
import org.gvsig.fmap.mapcontext.layers.operations.InfoByPoint; |
117 |
import org.gvsig.fmap.mapcontext.layers.operations.SingleLayer; |
118 |
import org.gvsig.fmap.mapcontext.rendering.legend.ILegend; |
119 |
import org.gvsig.fmap.mapcontext.rendering.legend.events.listeners.LegendListener; |
120 |
import org.gvsig.raster.fmap.legend.ColorTableLegend; |
121 |
import org.gvsig.raster.fmap.roi.VectorialROIsReader; |
122 |
import org.gvsig.raster.util.RasterNotLoadException; |
123 |
import org.gvsig.tools.ToolsLocator; |
124 |
import org.gvsig.tools.dynobject.DynClass; |
125 |
import org.gvsig.tools.dynobject.DynObjectManager; |
126 |
import org.gvsig.tools.dynobject.DynObjectSet; |
127 |
import org.gvsig.tools.dynobject.DynStruct; |
128 |
import org.gvsig.tools.exception.BaseException; |
129 |
import org.gvsig.tools.persistence.PersistenceManager; |
130 |
import org.gvsig.tools.persistence.PersistentState; |
131 |
import org.gvsig.tools.persistence.exception.PersistenceException; |
132 |
import org.gvsig.tools.task.Cancellable; |
133 |
import org.gvsig.tools.task.SimpleTaskStatus; |
134 |
import org.gvsig.tools.task.TaskStatusManager; |
135 |
import org.gvsig.tools.task.impl.BaseTaskStatus; |
136 |
import org.slf4j.Logger; |
137 |
import org.slf4j.LoggerFactory; |
138 |
|
139 |
/**
|
140 |
* Raster layer
|
141 |
*
|
142 |
* @author Nacho Brodin (nachobrodin@gmail.com)
|
143 |
*/
|
144 |
@SuppressWarnings("deprecation") |
145 |
public class DefaultFLyrRaster extends FLyrDefault implements FLyrRaster, Multiresolution, InfoByPoint, Classifiable, |
146 |
IRasterLayerActions, ILayerState, VisualPropertyListener, SingleLayer { |
147 |
public static final String PERSISTENT_NAME = "FLyrRasterSE_Persistent"; |
148 |
public static final String PERSISTENT_DESCRIPTION = "FLyrRasterSE Persistent"; |
149 |
private RasterManager rManager = RasterLocator.getManager();
|
150 |
private boolean mustTileDraw = false; |
151 |
private boolean mustTilePrint = true; |
152 |
private int maxTileDrawWidth = 200; |
153 |
private int maxTileDrawHeight = 200; |
154 |
private int maxTilePrintWidth = 1500; |
155 |
private int maxTilePrintHeight = 1500; |
156 |
private boolean firstLoad = false; |
157 |
private boolean removeRasterFlag = true; |
158 |
protected RasterDataStore dataStore = null; |
159 |
protected Render render = null; |
160 |
private int posX = 0; |
161 |
private int posY = 0; |
162 |
private double posXWC = 0; |
163 |
private int posYWC = 0; |
164 |
private int r = 0; |
165 |
private int g = 0; |
166 |
private int b = 0; |
167 |
private LayerChangeSupport layerChangeSupport = new LayerChangeSupport(); |
168 |
private FLyrState state = new FLyrState(); |
169 |
protected ILegend lastLegend = null; |
170 |
protected ColorTable colorTableLoadedFromProject = null; |
171 |
protected boolean loadedFromProject = false; |
172 |
private RasterDrawStrategy strategy = null; |
173 |
static private IConfiguration configuration = new DefaultLayerConfiguration(); |
174 |
protected int zoomLevel = 1; |
175 |
public boolean recalcLevel = true; |
176 |
private String uri = null; |
177 |
|
178 |
private static GeometryManager geomManager = GeometryLocator.getGeometryManager(); |
179 |
private static final Logger logger = LoggerFactory.getLogger(DefaultFLyrRaster.class); |
180 |
protected FileUtils fileUtil = RasterLocator.getManager().getFileUtils();
|
181 |
protected RasterUtils rasterUtil = RasterLocator.getManager().getRasterUtils();
|
182 |
protected CRSUtils crsUtil = RasterLocator.getManager().getCRSUtils();
|
183 |
protected MathUtils mathUtil = RasterLocator.getManager().getMathUtils();
|
184 |
|
185 |
/*
|
186 |
* TODO: Refactoring de ROIS (Eliminar List<ROI> a nivel de capa)
|
187 |
* Una capa r?ster deber?a poder tener ROIs de tipo r?ster y de tipo vectorial asociados. Adem?s
|
188 |
* debe poder tener una lista de estos por lo que ser?a necesario un interfaz en la que se pueda
|
189 |
* seleccionar la capa de ROIs a utilizar.
|
190 |
*
|
191 |
* Por otro lado, las ROIs deben ser del proveedor de datos. Este con tendr? una lista de estos.
|
192 |
* Las ROIs deber?an modelarse como proveedores de datos de tipo r?ster o de tipo vectorial, ya que
|
193 |
* tener una lista de geometr?as en memoria como hasta ahora puede ser muy poco eficiente en caso
|
194 |
* de que la lista de ROIs sea muy grande. Adem?s deber?a optimizarse el acceso isInside para que las
|
195 |
* operaciones con ROIs asociados sean lo m?s r?pidas posible.
|
196 |
*/
|
197 |
private List<ROI> rois = null; |
198 |
|
199 |
public class RasterTaskStatus extends BaseTaskStatus { |
200 |
Cancellable c = null;
|
201 |
|
202 |
public RasterTaskStatus(String tittle, Cancellable c) { |
203 |
super(tittle);
|
204 |
this.c = c;
|
205 |
} |
206 |
|
207 |
public boolean isCancellationRequested() { |
208 |
if(c != null) |
209 |
return this.c.isCanceled(); |
210 |
return false; |
211 |
} |
212 |
|
213 |
public void cancelRequest() { |
214 |
if(c != null) |
215 |
this.c.setCanceled(true); |
216 |
} |
217 |
} |
218 |
|
219 |
/**
|
220 |
* Lista de transformaciones afines que son aplicadas. Esta lista es
|
221 |
* simplemente un historico que no se utiliza. Es posible utilizarlo para
|
222 |
* recuperar transformaciones anteriores.
|
223 |
*/
|
224 |
private Historical affineTransformList = null; |
225 |
protected String readingData = null; |
226 |
//It is set to true if the method init has been called at least once
|
227 |
protected boolean layerInitialize = false; |
228 |
|
229 |
public DefaultFLyrRaster() {
|
230 |
affineTransformList = rManager.createHistoricalService(); |
231 |
} |
232 |
|
233 |
public static void registerDynClass() { |
234 |
DynObjectManager manager = ToolsLocator.getDynObjectManager(); |
235 |
DynClass dynClass = manager.add("RasterInfo", "Raster layer Info by point"); |
236 |
dynClass.setNamespace("InfoByPoint");
|
237 |
dynClass.addDynFieldString("File");
|
238 |
dynClass.addDynFieldString("View Point");
|
239 |
dynClass.addDynFieldString("Pixel Point");
|
240 |
dynClass.addDynFieldString("RGB");
|
241 |
dynClass.addDynFieldString("CMYK");
|
242 |
dynClass.addDynFieldString("HSL");
|
243 |
dynClass.addDynFieldString("Band Value");
|
244 |
dynClass.addDynFieldString("World Point");
|
245 |
} |
246 |
|
247 |
/**
|
248 |
* Builds a new raster layer
|
249 |
* @param fileName
|
250 |
* @return
|
251 |
* @throws RasterNotLoadException
|
252 |
* @throws LoadLayerException
|
253 |
*/
|
254 |
public static DefaultFLyrRaster createLayer(String layerName, File file) throws LoadLayerException { |
255 |
ProviderServices provServ = RasterLocator.getManager().getProviderServices(); |
256 |
RasterDataParameters storeParameters = provServ.createParameters(file.getName()); |
257 |
storeParameters.setURI(file.getPath()); |
258 |
|
259 |
MapContextManager mcm = MapContextLocator.getMapContextManager(); |
260 |
DefaultFLyrRaster lyr = (DefaultFLyrRaster) mcm.createLayer(layerName, storeParameters); |
261 |
|
262 |
return lyr;
|
263 |
} |
264 |
|
265 |
/*
|
266 |
* (non-Javadoc)
|
267 |
* @see com.iver.cit.gvsig.fmap.layers.FLyrDefault#setName(java.lang.String)
|
268 |
*/
|
269 |
public void setName(String name) { |
270 |
super.setName(name);
|
271 |
|
272 |
//Si la capa tiene nombre acivamos el estado awake
|
273 |
if(name != null) |
274 |
try {
|
275 |
if(isClosed())
|
276 |
enableAwake(); |
277 |
} catch (NotAvailableStateException e) {
|
278 |
logger.error("Fallo el estado de open. Closed=" + isClosed() + " Active=" + isOpen(), this, e); |
279 |
} |
280 |
} |
281 |
|
282 |
/*
|
283 |
* (non-Javadoc)
|
284 |
* @see com.iver.cit.gvsig.fmap.layers.FLyrDefault#wakeUp()
|
285 |
*/
|
286 |
public void wakeUp(){ |
287 |
try {
|
288 |
reload(); |
289 |
} catch (ReloadLayerException e) {
|
290 |
// No se ha podido recuperar la capa con exito
|
291 |
} |
292 |
} |
293 |
|
294 |
/*
|
295 |
* @see com.iver.cit.gvsig.fmap.layers.FLayer#load()
|
296 |
*/
|
297 |
public void load() throws LoadLayerException { |
298 |
if (isStopped() || getDataStore() == null) |
299 |
return;
|
300 |
|
301 |
enableStopped(); // Paramos la capa mientras se hace un load
|
302 |
|
303 |
int test = -1; |
304 |
DataStoreParameters params = getDataStore().getParameters(); |
305 |
DataStoreParameters p = params; |
306 |
if (params != null) { |
307 |
if(params instanceof TileDataParameters) { |
308 |
uri = ((RasterDataParameters)params).getURI(); |
309 |
if(uri == null) |
310 |
p = (DataStoreParameters)((TileDataParameters)params).getDataParameters(); |
311 |
} |
312 |
if(uri == null) { |
313 |
if(params instanceof RasterDataParameters) |
314 |
uri = ((RasterDataParameters)p).getURI(); |
315 |
} |
316 |
test = uri.indexOf("ecwp:");
|
317 |
} |
318 |
|
319 |
if (test != -1) { |
320 |
String urlECW = uri.substring(test + 6); |
321 |
uri = "ecwp://" + urlECW;
|
322 |
System.err.println(test + " " + uri); |
323 |
} |
324 |
|
325 |
try {
|
326 |
if(!getDataStore().isOpen())
|
327 |
dataStore = rManager.getProviderServices().open(params); |
328 |
} catch (NotSupportedExtensionException e) {
|
329 |
throw new LoadLayerException(this.getName()); |
330 |
} catch (RasterDriverException e) {
|
331 |
throw new LoadLayerException(this.getName()); |
332 |
} |
333 |
} |
334 |
|
335 |
/**
|
336 |
* Acciones de inicializaci?n despu?s de que la fuente de datos
|
337 |
* de la capa est? asignada. El tipo de fuente de datos es variable
|
338 |
* puede ser MultiRasterDataset, CompositeDataset u otras que existan e
|
339 |
* implementen IRasterDatasource.
|
340 |
* @throws FilePaletteException
|
341 |
*/
|
342 |
public void init() throws LoadLayerException, FilePaletteException { |
343 |
layerInitialize = true;
|
344 |
|
345 |
if (getDataStore() == null) |
346 |
throw new LoadLayerException("Formato no valido", new IOException()); |
347 |
|
348 |
render = getDataStore().getRender(); |
349 |
render.addVisualPropertyListener(this);
|
350 |
initFilters(); |
351 |
|
352 |
//Inicializaci?n del historico de transformaciones
|
353 |
affineTransformList.clear(); |
354 |
affineTransformList.add(this.getAffineTransform());
|
355 |
|
356 |
try {
|
357 |
if(!isOpen())
|
358 |
enableOpen(); |
359 |
} catch (NotAvailableStateException e) {
|
360 |
throw new LoadLayerException("Fallo el estado de open. Closed=" + isClosed() + " Awake=" + isAwake(), e); |
361 |
} |
362 |
} |
363 |
|
364 |
/*
|
365 |
* (non-Javadoc)
|
366 |
* @see org.gvsig.raster.fmap.layers.FLyrRaster#readProjection()
|
367 |
*/
|
368 |
public IProjection readProjection() throws RasterDriverException { |
369 |
try {
|
370 |
crsUtil.setCRSFactory(CRSFactory.cp); |
371 |
if( getDataStore() == null ) |
372 |
return null; |
373 |
return crsUtil.convertWktToIProjection(getDataStore().getWktProjection());
|
374 |
} catch (Exception e) { |
375 |
throw new RasterDriverException("Problems converting from WKT to IProjection", e); |
376 |
} catch (Error e) { |
377 |
e.printStackTrace(); |
378 |
return null; |
379 |
} |
380 |
} |
381 |
|
382 |
/**
|
383 |
* Crea el objeto renderizador de raster
|
384 |
* @return Rendering
|
385 |
*/
|
386 |
public Render getRender() {
|
387 |
if (render == null) { |
388 |
if(getDataStore() != null) { |
389 |
render = getDataStore().getRender(); |
390 |
render.addVisualPropertyListener(this);
|
391 |
} |
392 |
} |
393 |
return render;
|
394 |
} |
395 |
|
396 |
/*
|
397 |
* (non-Javadoc)
|
398 |
* @see org.gvsig.raster.fmap.layers.FLyrRaster#getURI()
|
399 |
*/
|
400 |
public String getURI() { |
401 |
return uri;
|
402 |
} |
403 |
|
404 |
/*
|
405 |
* (non-Javadoc)
|
406 |
* @see org.gvsig.raster.fmap.layers.FLyrRaster#setNoDataTransparent(boolean)
|
407 |
*/
|
408 |
public void setNoDataTransparent(boolean t) { |
409 |
getNoDataValue().setNoDataTransparent(t); |
410 |
if(getRender().getLastTransparency() != null) { |
411 |
getRender().getLastTransparency().setNoData(getDataStore().getNoDataValue()); |
412 |
getRender().getLastTransparency().activeTransparency(); |
413 |
} |
414 |
} |
415 |
|
416 |
/**
|
417 |
* Initializes the filter list to render this raster layer
|
418 |
* @throws FilePaletteException
|
419 |
*/
|
420 |
protected void initFilters() throws FilePaletteException { |
421 |
if(getDataType() == null) |
422 |
return;
|
423 |
|
424 |
RasterFilterList filterList = rManager.createEmptyFilterList(getDataType()[0]);
|
425 |
if(loadedFromProject) {
|
426 |
filterList = getDataStore().getRender().getFilterList(); |
427 |
} |
428 |
filterList.addEnvParam("IStatistics", getDataStore().getStatistics());
|
429 |
filterList.addEnvParam("MultiRasterDataset", getDataStore());
|
430 |
|
431 |
if(getDataStore() == null) |
432 |
return;
|
433 |
|
434 |
if(getDataStore().getNoDataValue() != null) { |
435 |
getDataStore().getNoDataValue().load(); |
436 |
if(getDataStore().getNoDataValue().isDefined())
|
437 |
setNoDataTransparent(true);
|
438 |
} |
439 |
|
440 |
filterList.setInitDataType(getDataType()[0]);
|
441 |
|
442 |
// Quitamos la leyenda
|
443 |
lastLegend = null;
|
444 |
|
445 |
try {
|
446 |
//Si en la carga del proyecto se carg? una tabla de color asignamos esta
|
447 |
if(colorTableLoadedFromProject != null) { |
448 |
setLastLegend(colorTableLoadedFromProject); |
449 |
RasterFilterListManager colorTableManager = filterList.getManagerByID("ColorTable");
|
450 |
Params params = filterList.createEmptyFilterParams(); |
451 |
params.setParam("colorTable", colorTableLoadedFromProject);
|
452 |
colorTableManager.addFilter(params); |
453 |
} else
|
454 |
//sino ponemos la tabla asociada al raster
|
455 |
if (getDataStore().getColorTable() != null) { |
456 |
ColorTable table = getDataStore().getColorTable(); |
457 |
setLastLegend(table); |
458 |
RasterFilterListManager colorTableManager = filterList.getManagerByID("ColorTable");
|
459 |
Params params = filterList.createEmptyFilterParams(); |
460 |
params.setParam("colorTable", table);
|
461 |
colorTableManager.addFilter(params); |
462 |
} else //sino hace lo que dice en las preferencias |
463 |
if(getDataStore().needEnhanced() ||
|
464 |
(loadedFromProject && filterList.get("enhanced_stretch") != null)) |
465 |
loadEnhancedOrColorTable(filterList); |
466 |
colorTableLoadedFromProject = null;
|
467 |
|
468 |
getRender().setFilterList(filterList); |
469 |
// Inicializo la transparencia para el render
|
470 |
if(!loadedFromProject) {
|
471 |
getRender().setLastTransparency(getDataStore().getTransparency().cloneTransparency()); |
472 |
} |
473 |
loadedFromProject = false;
|
474 |
} catch (FilterTypeException e) {
|
475 |
//Ha habido un error en la asignaci?n de filtros por los que no se a?ade ninguno.
|
476 |
logger.error("Error a?adiendo filtros en la inicializaci?n de capa " + this.getName() + " Datatype=" + this.getDataType(), null, e); |
477 |
} catch (FilterManagerException e) {
|
478 |
//Ha habido un error en la asignaci?n de filtros por los que no se a?ade ninguno.
|
479 |
logger.error("Error a?adiendo filtros en la inicializaci?n de capa " + this.getName() + " Datatype=" + this.getDataType(), null, e); |
480 |
} |
481 |
} |
482 |
|
483 |
/**
|
484 |
* Mira la configuracion para saber si debe cargar un realce o una tabla
|
485 |
* de color por defecto
|
486 |
* @param filterManager
|
487 |
* @throws FilterTypeException
|
488 |
* @throws FilePaletteException
|
489 |
*/
|
490 |
private void loadEnhancedOrColorTable(RasterFilterList filterList) throws FilterTypeException, FilterManagerException, FilePaletteException { |
491 |
String colorTableName = null; |
492 |
if(configuration != null) |
493 |
colorTableName = configuration.getValueString("loadlayer_usecolortable", (String) null); |
494 |
|
495 |
String palettesPath = System.getProperty("user.home") + |
496 |
File.separator +
|
497 |
"gvSIG" + // PluginServices.getArguments()[0] + |
498 |
File.separator + "colortable"; |
499 |
|
500 |
Statistics stats = getDataStore().getStatistics(); |
501 |
ColorTableLibrary colorTableLibrary = rManager.getDataStructFactory().getColorTableLibrary(); |
502 |
|
503 |
if (colorTableName != null) |
504 |
try {
|
505 |
stats.calculate(RasterLibrary.statisticsScale); |
506 |
if (getDataStore().getBandCount() == 1) { |
507 |
ArrayList<String> fileList = colorTableLibrary.getPaletteFileList(palettesPath); |
508 |
for (int i = 0; i < fileList.size(); i++) { |
509 |
ArrayList<ColorItem> paletteItems = new ArrayList<ColorItem>(); |
510 |
String paletteName = colorTableLibrary.loadPalette(palettesPath, (String) fileList.get(i), paletteItems); |
511 |
if (paletteName.equals(colorTableName)) {
|
512 |
if (paletteItems.size() <= 0) |
513 |
continue;
|
514 |
|
515 |
ColorTable colorTable = colorTableLibrary.createColorTable(); |
516 |
colorTable.setName(paletteName); |
517 |
colorTable.createPaletteFromColorItems(paletteItems, true);
|
518 |
colorTable.setInterpolated(true);
|
519 |
|
520 |
colorTable.createColorTableInRange(stats.getMinimun(), stats.getMaximun(), true);
|
521 |
|
522 |
setLastLegend(colorTable); |
523 |
|
524 |
RasterFilterListManager colorTableManager = filterList.getManagerByID("ColorTable");
|
525 |
Params params = filterList.createEmptyFilterParams(); |
526 |
params.setParam("colorTable", colorTable);
|
527 |
colorTableManager.addFilter(params); |
528 |
return;
|
529 |
} |
530 |
} |
531 |
} |
532 |
} catch (FileNotOpenException e) {
|
533 |
// No podemos aplicar el filtro
|
534 |
} catch (RasterDriverException e) {
|
535 |
// No podemos aplicar el filtro
|
536 |
} catch (ProcessInterruptedException e) {
|
537 |
// El usuario ha cancelado el proceso
|
538 |
} |
539 |
|
540 |
RasterFilterListManager enhancementManager = filterList.getManagerByID("EnhancementStretch");
|
541 |
RasterFilter f = filterList.getByName("enhanced_stretch");
|
542 |
if(f == null) { |
543 |
Params params = filterList.createEmptyFilterParams(); |
544 |
params.setParam("stats", stats);
|
545 |
params.setParam("remove", new Boolean(false)); |
546 |
params.setParam("renderBands", getRender().getRenderBands());
|
547 |
params.setParam("stretchs", null);//coge el LinearStretchParams por defecto |
548 |
params.setParam("rgb", new Boolean(true)); |
549 |
enhancementManager.addFilter(params); |
550 |
} |
551 |
} |
552 |
|
553 |
/*
|
554 |
* (non-Javadoc)
|
555 |
* @see org.gvsig.raster.fmap.layers.FLyrRaster#isReproyectable()
|
556 |
*/
|
557 |
public boolean isReproyectable() { |
558 |
if (getDataStore() == null) |
559 |
return false; |
560 |
return getDataStore().isReproyectable();
|
561 |
} |
562 |
|
563 |
/**
|
564 |
* @throws ReadException
|
565 |
* @throws ReadDriverException
|
566 |
* @see com.iver.cit.gvsig.fmap.layers.LayerOperations#draw(java.awt.image.BufferedImage,
|
567 |
* java.awt.Graphics2D, com.iver.cit.gvsig.fmap.ViewPort,
|
568 |
* com.iver.utiles.swing.threads.Cancellable)
|
569 |
*/
|
570 |
public void draw(BufferedImage image, Graphics2D g, ViewPort vp, Cancellable cancel, double scale) throws ReadException { |
571 |
TaskEventManager task = rManager.getRasterTask(); |
572 |
task.setEvent(null);
|
573 |
|
574 |
if(!layerInitialize) {
|
575 |
if (getDataStore() != null) |
576 |
try {
|
577 |
this.init();
|
578 |
} catch (FilePaletteException e) {
|
579 |
throw new ReadException("Error in raster legend", e); |
580 |
} catch (LoadLayerException e) {
|
581 |
throw new ReadException("Error initializing the layer", e); |
582 |
} |
583 |
} |
584 |
|
585 |
try {
|
586 |
if (!isOpen())
|
587 |
return;
|
588 |
|
589 |
enableStopped(); |
590 |
// callLegendChanged(null);
|
591 |
|
592 |
//Solo el zoom normal recalcula el nivel dependiendo de la escala. El zoom por niveles asigna
|
593 |
//?l el nivel de zoom por lo que no habr? que recalcularlo.
|
594 |
if(recalcLevel) {
|
595 |
double pixelSize = vp.getEnvelope().getLength(0) / (double)vp.getImageWidth(); |
596 |
zoomLevel = getDataStore().getNearestLevel(pixelSize); |
597 |
} |
598 |
recalcLevel = true;
|
599 |
|
600 |
strategy = new RasterDrawStrategy(getMapContext(), this); |
601 |
strategy.stackStrategy(); |
602 |
HashMap<DefaultFLyrRaster, Boolean> tStr = strategy.getStrategy(); |
603 |
if (tStr != null && |
604 |
tStr.get(this) != null && |
605 |
((Boolean) (tStr.get(this))).booleanValue() == false) { |
606 |
disableStopped(); |
607 |
return;
|
608 |
} |
609 |
|
610 |
if (isWithinScale(scale)) {
|
611 |
|
612 |
if (mustTileDraw) {
|
613 |
Point2D p = vp.getOffset();
|
614 |
Rectangle r = new Rectangle((int) p.getX(), (int) p.getY(), vp.getImageWidth(), vp.getImageHeight()); |
615 |
Tiling tiles = new Tiling(maxTileDrawWidth, maxTileDrawHeight, r);
|
616 |
tiles.setAffineTransform((AffineTransform) vp.getAffineTransform().clone());
|
617 |
for (int tileNr = 0; tileNr < tiles.getNumTiles(); tileNr++) |
618 |
// drawing part
|
619 |
try {
|
620 |
ViewPort vport = tiles.getTileViewPort(vp, tileNr); |
621 |
draw(image, g, vport, cancel); |
622 |
} catch (InterruptedException e) { |
623 |
System.out.println("Se ha cancelado el pintado"); |
624 |
} catch (InvalidSetViewException e) {
|
625 |
throw new ReadException("Error reading file.", e); |
626 |
} catch (RasterDriverException e) {
|
627 |
throw new ReadException("Error reading file.", e); |
628 |
} catch (NoninvertibleTransformException e) { |
629 |
throw new ReadException("Error in the transformation.", e); |
630 |
} |
631 |
} else
|
632 |
try {
|
633 |
draw(image, g, vp, cancel); |
634 |
} catch (InterruptedException e) { |
635 |
System.out.println("Se ha cancelado el pintado"); |
636 |
} catch (InvalidSetViewException e) {
|
637 |
throw new ReadException("Error reading file.", e); |
638 |
} catch (RasterDriverException e) {
|
639 |
throw new ReadException("Error reading file.", e); |
640 |
} |
641 |
|
642 |
} |
643 |
|
644 |
//callLegendChanged(null);
|
645 |
} finally {
|
646 |
disableStopped(); |
647 |
task.setEvent(null);
|
648 |
} |
649 |
} |
650 |
|
651 |
protected void draw(BufferedImage image, Graphics2D g, ViewPort vp, Cancellable cancel) throws RasterDriverException, InvalidSetViewException, InterruptedException { |
652 |
Envelope adjustedExtent = vp.getAdjustedExtent(); |
653 |
if (adjustedExtent == null) |
654 |
return;
|
655 |
Extent e = rManager.getDataStructFactory().createExtent(adjustedExtent.getLowerCorner().getX(), |
656 |
adjustedExtent.getUpperCorner().getY(), adjustedExtent |
657 |
.getUpperCorner().getX(), |
658 |
adjustedExtent |
659 |
.getLowerCorner().getY()); |
660 |
Dimension imgSz = vp.getImageSize();
|
661 |
ViewPortData vp2 = rManager.getDataStructFactory().createViewPortData(vp.getProjection(), e, imgSz ); |
662 |
vp2.setMat(vp.getAffineTransform()); |
663 |
//vp2.setTime(vp.getTime());
|
664 |
|
665 |
TaskStatusManager manager = ToolsLocator.getTaskStatusManager(); |
666 |
SimpleTaskStatus taskStatus = new RasterTaskStatus("Drawing " + getName() + "...", cancel); |
667 |
manager.add(taskStatus); |
668 |
taskStatus.setAutoremove(true);
|
669 |
|
670 |
//Crea la reproyecci?n al vuelo la primera vez
|
671 |
RasterDataParameters params = (RasterDataParameters)getDataStore().getParameters(); |
672 |
if(!getRender().isReprojectingOnTheFly() &&
|
673 |
getDataStore().getProjection() != null &&
|
674 |
params.getReprojectionOption() == RasterDataParameters.ON_THE_FLY) { |
675 |
getRender().createReprojectionOnTheFly(getDataStore(), getCoordTrans(), taskStatus); |
676 |
} |
677 |
|
678 |
try {
|
679 |
if(getDataStore().isTiled()) {
|
680 |
getRender().drawTiledService(g, vp2, vp.getImageSize(), taskStatus); |
681 |
} else {
|
682 |
getRender().draw(g, vp2, taskStatus); |
683 |
} |
684 |
} catch (ProcessInterruptedException e1) {
|
685 |
} finally {
|
686 |
taskStatus.terminate(); |
687 |
} |
688 |
} |
689 |
|
690 |
/**
|
691 |
* Inserta la proyecci?n.
|
692 |
*
|
693 |
* @param proj Proyecci?n.
|
694 |
*/
|
695 |
public void setProjection(IProjection proj) { |
696 |
try {
|
697 |
getDataStore().setProjection(proj, true);
|
698 |
super.setProjection(proj);
|
699 |
} catch (RmfSerializerException e) {
|
700 |
logger.error("Error saving the projection", e);
|
701 |
} |
702 |
} |
703 |
|
704 |
public void setProjection(IProjection proj, boolean persist) { |
705 |
try {
|
706 |
getDataStore().setProjection(proj, persist); |
707 |
super.setProjection(proj);
|
708 |
} catch (RmfSerializerException e) {
|
709 |
logger.error("Error saving the projection", e);
|
710 |
} |
711 |
} |
712 |
|
713 |
/*
|
714 |
* (non-Javadoc)
|
715 |
* @see org.gvsig.fmap.mapcontext.layers.FLayer#getFullEnvelope()
|
716 |
*/
|
717 |
public Envelope getFullEnvelope() {
|
718 |
//TODO:DEPURACION Comentamos !isOpen porque getFullExtent de FLayers da una excepci?n ya que siempre espera
|
719 |
//un extent aunque la capa no est? abierta
|
720 |
if(/*!isOpen() || */getDataStore() == null || getDataStore().getExtent() == null) |
721 |
return null; |
722 |
|
723 |
Rectangle2D e = getDataStore().getExtent().toRectangle2D();
|
724 |
try {
|
725 |
return geomManager.createEnvelope(e.getX(), e.getY(), e.getMaxX(), e
|
726 |
.getMaxY(), SUBTYPES.GEOM2D); |
727 |
|
728 |
/*
|
729 |
No es necesario
|
730 |
ICoordTrans ct = getCoordTrans();
|
731 |
RasterDataParameters params = (RasterDataParameters)getDataStore().getParameters();
|
732 |
if (ct != null && params.getReprojectionOption() == RasterDataParameters.ON_THE_FLY) {
|
733 |
env = env.convert(ct);
|
734 |
}
|
735 |
return env;*/
|
736 |
|
737 |
} catch (CreateEnvelopeException e1) {
|
738 |
logger.error("Error creating the envelope", e);
|
739 |
return null; |
740 |
} |
741 |
} |
742 |
|
743 |
/**
|
744 |
* Obtiene el valor del pixel del Image en la posici?n x,y
|
745 |
* @param x Posici?n x
|
746 |
* @param y Posici?n y
|
747 |
* @return valor de pixel
|
748 |
*/
|
749 |
// public int[] getPixel(int pxx, int pxy) {
|
750 |
// int[] argb = { -1, -1, -1, -1 };
|
751 |
// if (!isOpen() || (image == null))
|
752 |
// return argb;
|
753 |
// if (pxx >= 0 && pxx < image.getWidth() && pxy >= 0 && pxy < image.getHeight()) {
|
754 |
// int value = image.getRGB(pxx, pxy);
|
755 |
// argb[0] = ((value & 0xff000000) >> 24);
|
756 |
// argb[1] = ((value & 0x00ff0000) >> 16);
|
757 |
// argb[2] = ((value & 0x0000ff00) >> 8);
|
758 |
// argb[3] = (value & 0x000000ff);
|
759 |
// }
|
760 |
// return argb;
|
761 |
// }
|
762 |
|
763 |
/*
|
764 |
* (non-Javadoc)
|
765 |
* @see org.gvsig.raster.shared.IRasterGeoOperations#getMaxX()
|
766 |
*/
|
767 |
public double getMaxX() { |
768 |
if(getFullEnvelope() != null) |
769 |
return getFullEnvelope().getMaximum(0); |
770 |
return -1; |
771 |
} |
772 |
|
773 |
/*
|
774 |
* (non-Javadoc)
|
775 |
* @see org.gvsig.raster.shared.IRasterGeoOperations#getMaxY()
|
776 |
*/
|
777 |
public double getMaxY() { |
778 |
if(getFullEnvelope() != null) |
779 |
return this.getFullEnvelope().getMaximum(1); |
780 |
return -1; |
781 |
} |
782 |
|
783 |
/*
|
784 |
* (non-Javadoc)
|
785 |
* @see org.gvsig.raster.shared.IRasterGeoOperations#getMinX()
|
786 |
*/
|
787 |
public double getMinX() { |
788 |
if(getFullEnvelope() != null) |
789 |
return getFullEnvelope().getMinimum(0); |
790 |
return -1; |
791 |
} |
792 |
|
793 |
/*
|
794 |
* (non-Javadoc)
|
795 |
* @see org.gvsig.raster.shared.IRasterGeoOperations#getMinY()
|
796 |
*/
|
797 |
public double getMinY() { |
798 |
if(getFullEnvelope() != null) |
799 |
return getFullEnvelope().getMinimum(1); |
800 |
return -1; |
801 |
} |
802 |
|
803 |
/* (non-Javadoc)
|
804 |
* @deprecated. See String getInfo(Point p) throws DriverException
|
805 |
* @see com.iver.cit.gvsig.fmap.layers.layerOperations.InfoByPoint#queryByPoint(java.awt.Point)
|
806 |
*/
|
807 |
public String queryByPoint(Point p) { |
808 |
if (!isOpen())
|
809 |
return null; |
810 |
ColorConversion conv = rManager.getColorConversion(); |
811 |
|
812 |
String data = "<file:" + normalizeAsXMLTag(getName()) + ">\n"; |
813 |
|
814 |
ArrayList<Object> attr = getAttributes(); |
815 |
data += " <raster\n";
|
816 |
data += " File=\"" + getFile() + "\"\n"; |
817 |
for (int i = 0; i < attr.size(); i++) { |
818 |
Object[] a = (Object[]) attr.get(i); |
819 |
|
820 |
data += " " + a[0].toString() + "="; |
821 |
if (a[1].toString() instanceof String) |
822 |
data += "\"" + a[1].toString() + "\"\n"; |
823 |
else
|
824 |
data += a[1].toString() + "\n"; |
825 |
} |
826 |
data += " Point=\"" + posX + " , " + posY + "\"\n"; |
827 |
data += " Point_WC=\"" + mathUtil.format(posXWC, 3) + " , " + mathUtil.format(posYWC, 3) + "\"\n"; |
828 |
data += " RGB=\"" + r + ", " + g + ", " + b + "\"\n"; |
829 |
double[] cmyk = conv.RGBtoCMYK(r & 0xff, g & 0xff, b & 0xff, 1D); |
830 |
data += " CMYK=\"" + mathUtil.format(cmyk[0], 4) + ", " + mathUtil.format(cmyk[1], 4) + ", " + mathUtil.format(cmyk[2], 4) + "," + mathUtil.format(cmyk[3], 4) + "\"\n"; |
831 |
double[] hsl = conv.RGBtoHSL(r & 0xff, g & 0xff, b & 0xff); |
832 |
hsl[0] = (int)(255.0 * hsl[0] / 360.0 + 0.5); |
833 |
hsl[2] = (int) (hsl[2] * 255. + 0.5); |
834 |
hsl[1] = (int) (hsl[1] * 255. + 0.5); |
835 |
data += " HSL=\"" + mathUtil.format(hsl[0], 4) + ", " + mathUtil.format(hsl[1], 4) + ", " + mathUtil.format(hsl[2], 4) + "\"\n"; |
836 |
data += " />\n";
|
837 |
|
838 |
data += "</file:" + normalizeAsXMLTag(getName()) + ">\n"; |
839 |
return data;
|
840 |
} |
841 |
|
842 |
/**
|
843 |
* Filters a string for being suitable as XML Tag, erasing
|
844 |
* all not alphabetic or numeric characters.
|
845 |
* @param s
|
846 |
* @return string normalized
|
847 |
*/
|
848 |
private String normalizeAsXMLTag(String s) { |
849 |
return s.replaceAll("[^a-zA-Z0-9]", ""); |
850 |
} |
851 |
|
852 |
/*
|
853 |
* (non-Javadoc)
|
854 |
* @see org.gvsig.raster.fmap.layers.FLyrRaster#getAttributes()
|
855 |
*/
|
856 |
public ArrayList<Object> getAttributes() { |
857 |
ArrayList<Object> attr = new ArrayList<Object>(); |
858 |
if(!isOpen())
|
859 |
return attr;
|
860 |
Object [][] a = { |
861 |
{"Filename", getDataStore().getName()},
|
862 |
{"Filesize", new Long(getDataStore().getFileSize())}, |
863 |
{"Width", new Integer((int)getDataStore().getWidth())}, |
864 |
{"Height", new Integer((int)getDataStore().getHeight())}, |
865 |
{"Bands", new Integer(getDataStore().getBandCount())} |
866 |
}; |
867 |
for (int i = 0; i < a.length; i++) |
868 |
attr.add(a[i]); |
869 |
return attr;
|
870 |
} |
871 |
|
872 |
|
873 |
/* (non-Javadoc)
|
874 |
* @see com.iver.cit.gvsig.fmap.layers.FLayer#print(java.awt.Graphics2D, com.iver.cit.gvsig.fmap.ViewPort, com.iver.cit.gvsig.fmap.operations.Cancellable)
|
875 |
*/
|
876 |
public void print(Graphics2D g, ViewPort viewPort, Cancellable cancel, |
877 |
double scale, PrintAttributes propeties) throws ReadException { |
878 |
|
879 |
if (/*!isOpen() ||*/ !isVisible() || !isWithinScale(scale)) |
880 |
return;
|
881 |
|
882 |
TaskStatusManager manager = ToolsLocator.getTaskStatusManager(); |
883 |
SimpleTaskStatus taskStatus = new RasterTaskStatus("Printing raster " + getName() + "...", cancel); |
884 |
manager.add(taskStatus); |
885 |
taskStatus.setAutoremove(true);
|
886 |
|
887 |
if (!mustTilePrint)
|
888 |
draw(null, g, viewPort, cancel,scale);
|
889 |
else {
|
890 |
Tiling tiles = new Tiling(maxTilePrintWidth, maxTilePrintHeight, g.getClipBounds());
|
891 |
tiles.setAffineTransform((AffineTransform) viewPort.getAffineTransform().clone());
|
892 |
taskStatus.setRangeOfValues(0, tiles.getNumTiles());
|
893 |
for (int tileNr = 0; tileNr < tiles.getNumTiles(); tileNr++) { |
894 |
// Parte que dibuja
|
895 |
try {
|
896 |
ViewPort vp = tiles.getTileViewPort(viewPort, tileNr); |
897 |
draw(null, g, vp, cancel, scale);
|
898 |
taskStatus.setCurValue(tileNr); |
899 |
} catch (NoninvertibleTransformException e) { |
900 |
throw new ReadException("Error en la transformaci?n.", e); |
901 |
} finally {
|
902 |
taskStatus.terminate(); |
903 |
} |
904 |
} |
905 |
} |
906 |
|
907 |
taskStatus.terminate(); |
908 |
} |
909 |
|
910 |
/*public void _print(Graphics2D g, ViewPort viewPort, Cancellable cancel,
|
911 |
double scale) throws ReadException {
|
912 |
if(!isOpen())
|
913 |
return;
|
914 |
|
915 |
// Para no pedir imagenes demasiado grandes, vamos
|
916 |
// a hacer lo mismo que hace EcwFile: chunkear.
|
917 |
// Llamamos a drawView con cuadraditos m?s peque?os
|
918 |
// del BufferedImage ni caso, cuando se imprime viene con null
|
919 |
|
920 |
int numW, numH;
|
921 |
int stepX, stepY;
|
922 |
int xProv, yProv;
|
923 |
int A = 1500;
|
924 |
int H = 1500;
|
925 |
int altoAux, anchoAux;
|
926 |
|
927 |
AffineTransform mat = (AffineTransform) viewPort.getAffineTransform().clone();
|
928 |
|
929 |
// Vamos a hacerlo en trozos de AxH
|
930 |
Rectangle r = g.getClipBounds();
|
931 |
numW = (r.width) / A;
|
932 |
numH = (r.height) / H;
|
933 |
|
934 |
double[] srcPts = new double[8];
|
935 |
double[] dstPts = new double[8];
|
936 |
|
937 |
yProv = r.y;
|
938 |
for (stepY = 0; stepY < numH + 1; stepY++) {
|
939 |
if ((yProv + H) > r.getMaxY())
|
940 |
altoAux = (int) r.getMaxY() - yProv;
|
941 |
else
|
942 |
altoAux = H;
|
943 |
|
944 |
xProv = r.x;
|
945 |
for (stepX = 0; stepX < numW + 1; stepX++) {
|
946 |
if ((xProv + A) > r.getMaxX())
|
947 |
anchoAux = (int) r.getMaxX() - xProv;
|
948 |
else
|
949 |
anchoAux = A;
|
950 |
|
951 |
//Rectangle newRect = new Rectangle(xProv, yProv, anchoAux, altoAux);
|
952 |
|
953 |
// Parte que dibuja
|
954 |
srcPts[0] = xProv;
|
955 |
srcPts[1] = yProv;
|
956 |
srcPts[2] = xProv + anchoAux + 1;
|
957 |
srcPts[3] = yProv;
|
958 |
srcPts[4] = xProv + anchoAux + 1;
|
959 |
srcPts[5] = yProv + altoAux + 1;
|
960 |
srcPts[6] = xProv;
|
961 |
srcPts[7] = yProv + altoAux + 1;
|
962 |
|
963 |
try {
|
964 |
mat.inverseTransform(srcPts, 0, dstPts, 0, 4);
|
965 |
Rectangle2D.Double rectCuadricula = new Rectangle2D.Double(dstPts[0], dstPts[1], dstPts[2] - dstPts[0], dstPts[5] - dstPts[3]);
|
966 |
// Extent extent = new Extent(rectCuadricula);
|
967 |
|
968 |
Dimension tam = new Dimension(anchoAux + 1, altoAux + 1);
|
969 |
ViewPort vp = (ViewPort)viewPort.clone();
|
970 |
vp.setImageSize(tam);
|
971 |
Envelope env = geomManager.createEnvelope(rectCuadricula
|
972 |
.getMinX(), rectCuadricula.getMinY(),
|
973 |
rectCuadricula.getMaxX(), rectCuadricula.getMaxY(),
|
974 |
SUBTYPES.GEOM2D);
|
975 |
vp.setEnvelope(env);
|
976 |
vp.setAffineTransform(mat);
|
977 |
draw(null, g, vp, cancel, scale);
|
978 |
|
979 |
} catch (NoninvertibleTransformException e) {
|
980 |
//throw new ReadDriverException("Error en la transformaci?n.", e);
|
981 |
} catch (ReadException e) {
|
982 |
//throw new ReadDriverException("Error en la transformaci?n.", e);
|
983 |
} catch (CreateEnvelopeException e) {
|
984 |
logger.error("Error creating the envelope", e);
|
985 |
} catch (CloneNotSupportedException e) {
|
986 |
logger.error("Error cloning the viewport", e);
|
987 |
}
|
988 |
// Fin parte que dibuja
|
989 |
xProv = xProv + A;
|
990 |
}
|
991 |
yProv = yProv + H;
|
992 |
}
|
993 |
}*/
|
994 |
|
995 |
/**
|
996 |
* Borra de la lista de listeners el que se pasa como par?metro.
|
997 |
*
|
998 |
* @param o LayerListener a borrar.
|
999 |
*
|
1000 |
* @return True si ha sido correcto el borrado del Listener.
|
1001 |
*/
|
1002 |
public boolean removeLayerListener(LayerListener o) { |
1003 |
if (this.isRemoveRasterFlag()) { |
1004 |
try {
|
1005 |
enableClosed(); |
1006 |
} catch (NotAvailableStateException e1) {
|
1007 |
// No se ha podido cambiar el estado de la capa a cerrado
|
1008 |
} |
1009 |
} |
1010 |
|
1011 |
// Salva a RMF
|
1012 |
if (getDataStore() != null) |
1013 |
// Guardamos la GeoReferenciacion de cada dataset
|
1014 |
try {
|
1015 |
getDataStore().saveGeoreferencingToRmf(); |
1016 |
} catch (Exception e) { |
1017 |
logger.info("error_salvando_rmf", e);
|
1018 |
} |
1019 |
|
1020 |
if (this.isRemoveRasterFlag()) { |
1021 |
if (getDataStore() != null) { |
1022 |
String[] files = getFileName().clone(); |
1023 |
|
1024 |
try {
|
1025 |
getDataStore().close(); |
1026 |
} catch (CloseException e) {
|
1027 |
} |
1028 |
|
1029 |
dataStore = null;
|
1030 |
if(render != null) |
1031 |
render.dispose(); |
1032 |
render = null;
|
1033 |
// System.gc();
|
1034 |
this.setRemoveRasterFlag(true); |
1035 |
|
1036 |
for (int i = 0; i < files.length; i++) { |
1037 |
File file = new File(files[i]); |
1038 |
File dirTemp = fileUtil.getTemporalFile();
|
1039 |
if(!file.exists())
|
1040 |
continue;
|
1041 |
if (dirTemp.compareTo(file.getParentFile()) == 0) { |
1042 |
file.delete(); |
1043 |
|
1044 |
// Borramos todos los ficheros que puedan tener relacion con el fichero actual
|
1045 |
String basefile = file.getName();
|
1046 |
File basepath = file.getParentFile();
|
1047 |
int last = basefile.lastIndexOf("."); |
1048 |
if (last != -1) |
1049 |
basefile = basefile.substring(0, last + 1); |
1050 |
File[] list = basepath.listFiles(); |
1051 |
for (int j = 0; j < list.length; j++) |
1052 |
if (list[j].getName().startsWith(basefile))
|
1053 |
list[j].delete(); |
1054 |
} |
1055 |
} |
1056 |
} |
1057 |
} |
1058 |
updateDrawVersion(); |
1059 |
return super.layerListeners.remove(o); |
1060 |
} |
1061 |
|
1062 |
/*
|
1063 |
* (non-Javadoc)
|
1064 |
* @see org.gvsig.raster.fmap.layers.FLyrRaster#isRemoveRasterFlag()
|
1065 |
*/
|
1066 |
public boolean isRemoveRasterFlag() { |
1067 |
return removeRasterFlag;
|
1068 |
} |
1069 |
|
1070 |
/*
|
1071 |
* (non-Javadoc)
|
1072 |
* @see org.gvsig.raster.fmap.layers.FLyrRaster#setRemoveRasterFlag(boolean)
|
1073 |
*/
|
1074 |
public void setRemoveRasterFlag(boolean removeRasterFlag) { |
1075 |
this.removeRasterFlag = removeRasterFlag;
|
1076 |
} |
1077 |
|
1078 |
/*
|
1079 |
* (non-Javadoc)
|
1080 |
* @see com.iver.cit.gvsig.fmap.layers.FLyrDefault#getTocImageIcon()
|
1081 |
*/
|
1082 |
public String getTocImageIcon() { |
1083 |
return "map-ok-ico"; |
1084 |
} |
1085 |
|
1086 |
/*
|
1087 |
* (non-Javadoc)
|
1088 |
* @see org.gvsig.raster.fmap.layers.FLyrRaster#getTileSize()
|
1089 |
*/
|
1090 |
public int[] getTileSize() { |
1091 |
int[] size = {maxTileDrawWidth, maxTileDrawHeight}; |
1092 |
return size;
|
1093 |
} |
1094 |
|
1095 |
/*
|
1096 |
* (non-Javadoc)
|
1097 |
* @see org.gvsig.raster.fmap.layers.FLyrRaster#isTiled()
|
1098 |
*/
|
1099 |
public boolean isTiled() { |
1100 |
return mustTileDraw;
|
1101 |
} |
1102 |
|
1103 |
/*
|
1104 |
* (non-Javadoc)
|
1105 |
* @see org.gvsig.raster.fmap.layers.FLyrRaster#isGeoreferenced()
|
1106 |
*/
|
1107 |
public boolean isGeoreferenced() { |
1108 |
return getDataStore().isGeoreferenced();
|
1109 |
} |
1110 |
|
1111 |
/*
|
1112 |
* (non-Javadoc)
|
1113 |
* @see org.gvsig.raster.fmap.layers.FLyrRaster#getNoDataValue()
|
1114 |
*/
|
1115 |
public NoData getNoDataValue() {
|
1116 |
return getDataStore().getNoDataValue();
|
1117 |
} |
1118 |
|
1119 |
/**
|
1120 |
* Sets the nodata value for this layer
|
1121 |
* @param nd
|
1122 |
*/
|
1123 |
public void setNoDataValue(NoData nd) { |
1124 |
if (getDataStore() != null) |
1125 |
getDataStore().setNoDataValue(nd); |
1126 |
} |
1127 |
|
1128 |
/**
|
1129 |
* Gets the height in world coordinates of this raster layer
|
1130 |
*/
|
1131 |
public double getWCHeight() { |
1132 |
return getFullEnvelope().getMaximum(1); |
1133 |
} |
1134 |
|
1135 |
/**
|
1136 |
* Gets the width in world coordinates of this raster layer
|
1137 |
*/
|
1138 |
public double getWCWidth() { |
1139 |
return getFullEnvelope().getMaximum(0); |
1140 |
} |
1141 |
|
1142 |
/**
|
1143 |
* Gets the size of all files of this raster layer
|
1144 |
*/
|
1145 |
public long[] getFileSize() { |
1146 |
if (getDataStore() == null) |
1147 |
return null; |
1148 |
|
1149 |
return getDataStore().getFileSizeByProvider();
|
1150 |
} |
1151 |
|
1152 |
/**
|
1153 |
* Gets the list of file names
|
1154 |
*/
|
1155 |
public String[] getFileName() { |
1156 |
if (getDataStore() == null) |
1157 |
return null; |
1158 |
|
1159 |
return getDataStore().getURIByProvider();
|
1160 |
} |
1161 |
|
1162 |
/**
|
1163 |
* Returns the number of files in this raster layer
|
1164 |
*/
|
1165 |
public int getFileCount() { |
1166 |
return getDataStore().getProviderCount();
|
1167 |
} |
1168 |
|
1169 |
/*
|
1170 |
* (non-Javadoc)
|
1171 |
* @see org.gvsig.raster.fmap.layers.FLyrRaster#getFileFormat()
|
1172 |
*/
|
1173 |
public String getFileFormat() { |
1174 |
if(getDataStore().getSourceType() == RasterDataStore.FILE) {
|
1175 |
String fName = getDataStore().getName();
|
1176 |
int index = fName.lastIndexOf(".") + 1; |
1177 |
String ext = null; |
1178 |
if (index > 0) |
1179 |
ext = fName.substring(fName.lastIndexOf(".") + 1, fName.length()); |
1180 |
return ext;
|
1181 |
} |
1182 |
if(getDataStore().getSourceType() == RasterDataStore.POSTGIS) {
|
1183 |
return "POSTGIS"; |
1184 |
} |
1185 |
return null; |
1186 |
} |
1187 |
|
1188 |
/*
|
1189 |
* (non-Javadoc)
|
1190 |
* @see org.gvsig.fmap.raster.IRasterOperations#getDatatype()
|
1191 |
*/
|
1192 |
public int[] getDataType() { |
1193 |
return getDataStore().getDataType();
|
1194 |
} |
1195 |
|
1196 |
/**
|
1197 |
* Sets the filter list
|
1198 |
*/
|
1199 |
public void setRenderFilterList(RasterFilterList filterList) { |
1200 |
getRender().setFilterList(filterList); |
1201 |
} |
1202 |
|
1203 |
/*
|
1204 |
* (non-Javadoc)
|
1205 |
* @see org.gvsig.fmap.mapcontext.layers.operations.InfoByPoint#getInfo(java.awt.Point, double, org.gvsig.tools.task.Cancellable, boolean)
|
1206 |
*/
|
1207 |
public DynObjectSet getInfo(org.gvsig.fmap.geom.primitive.Point p, double tolerance) throws LoadLayerException, DataException { |
1208 |
DynObjectSetRasterInfo info = new DynObjectSetRasterInfo();
|
1209 |
|
1210 |
if (!isOpen()) {
|
1211 |
info.addField("Layer not open", normalizeAsXMLTag(getName()), 0); |
1212 |
return info;
|
1213 |
} |
1214 |
|
1215 |
Point2D pReal = new Point2D.Double(p.getX(), p.getY()); |
1216 |
Point2D px = new Point2D.Double(); |
1217 |
if( pReal.getX() > this.getMinX() && |
1218 |
pReal.getX() < this.getMaxX() &&
|
1219 |
pReal.getY() > this.getMinY() &&
|
1220 |
pReal.getY() < this.getMaxY()) {
|
1221 |
px = transformPoint(pReal); |
1222 |
} |
1223 |
//int[] rgb = getPixel((int) p.getX(), (int) p.getY());
|
1224 |
//ColorConversion conv = rManager.getColorConversion();
|
1225 |
|
1226 |
info.addField("File", normalizeAsXMLTag(getName()), 0); |
1227 |
info.addField("View Point", "[" + p.getX() + " , " + p.getY() + "]", 1); |
1228 |
info.addField("World Point", "[" + mathUtil.format(pReal.getX(), 3) + " , " + mathUtil.format(pReal.getY(), 3) + "]", 2); |
1229 |
if (px == null) |
1230 |
info.addField("Pixel Point", "Out", 3); |
1231 |
else
|
1232 |
info.addField("Pixel Point", "[" + (int) px.getX() + ", " + (int) px.getY() + "]", 3); |
1233 |
|
1234 |
//La informaci?n RGB no puede obtener de la capa
|
1235 |
|
1236 |
/*info.addField("RGB", "[" + rgb[1] + ", " + rgb[2] + ", " + rgb[3] + "]", 4);
|
1237 |
double[] cmyk = conv.RGBtoCMYK(rgb[1] & 0xff, rgb[2] & 0xff, rgb[3] & 0xff, 1D);
|
1238 |
info.addField("CMYK", "[" + mathUtil.format(cmyk[0], 4) + ", " + mathUtil.format(cmyk[1], 4) + ", " + mathUtil.format(cmyk[2], 4) + ", " + mathUtil.format(cmyk[3], 4) + "]", 5);
|
1239 |
double[] hsl = conv.RGBtoHSL(rgb[1] & 0xff, rgb[2] & 0xff, rgb[3] & 0xff);
|
1240 |
hsl[0] = (int)(255.0 * hsl[0] / 360.0 + 0.5);
|
1241 |
hsl[2] = (int) (hsl[2] * 255. + 0.5);
|
1242 |
hsl[1] = (int) (hsl[1] * 255. + 0.5);
|
1243 |
info.addField("HSL", "[" + mathUtil.format(hsl[0], 4) + ", " + mathUtil.format(hsl[1], 4) + ", " + mathUtil.format(hsl[2], 4) + "]", 6);*/
|
1244 |
|
1245 |
String data = "["; |
1246 |
try {
|
1247 |
if (px != null) { |
1248 |
if(getDataType()[0] >= 0 && getDataType()[0] <= 3) { |
1249 |
for(int i = 0; i < getDataStore().getBandCount(); i++) { |
1250 |
if(getDataStore().isInside(pReal)) {
|
1251 |
Point2D pxAux = transformPoint(pReal);
|
1252 |
int val = ((Integer)getDataStore().getData((int)pxAux.getX(), |
1253 |
(int)pxAux.getY(), i)).intValue();
|
1254 |
if(getDataType()[0] == Buffer.TYPE_BYTE) |
1255 |
data += (val & 0x000000ff) + ", "; |
1256 |
else
|
1257 |
data += val + ", ";
|
1258 |
} |
1259 |
} |
1260 |
} |
1261 |
if(getDataType()[0] == 4) { |
1262 |
for(int i = 0; i < getDataStore().getBandCount(); i++) { |
1263 |
if(getDataStore().isInside(pReal)) {
|
1264 |
Point2D pxAux = transformPoint(pReal);
|
1265 |
data += ((Float)getDataStore().getData((int)pxAux.getX(), |
1266 |
(int)pxAux.getY(), i)).floatValue() + ", "; |
1267 |
} |
1268 |
} |
1269 |
} |
1270 |
if(getDataType()[0] == 5) { |
1271 |
for(int i = 0; i < getDataStore().getBandCount(); i++) { |
1272 |
if(getDataStore().isInside(pReal)) {
|
1273 |
Point2D pxAux = transformPoint(pReal);
|
1274 |
data += ((Double)getDataStore().getData((int)pxAux.getX(), |
1275 |
(int)pxAux.getY(), i)).doubleValue() + ", "; |
1276 |
} |
1277 |
} |
1278 |
} |
1279 |
} |
1280 |
data += "]";
|
1281 |
info.addField("Band Value", data, 7); |
1282 |
} catch (RasterDriverException ex) {
|
1283 |
throw new LoadLayerException("Error en el acceso al dataset", ex); |
1284 |
} catch (InvalidSetViewException ex) {
|
1285 |
throw new LoadLayerException("Error en la asignaci?n de la vista en getData", ex); |
1286 |
} catch (FileNotOpenException ex) {
|
1287 |
throw new LoadLayerException("Fichero no abierto en el dataset", ex); |
1288 |
} |
1289 |
return info;
|
1290 |
} |
1291 |
|
1292 |
/**
|
1293 |
* Transforma un punto real a coordenadas pixel
|
1294 |
*
|
1295 |
* @param numberBand
|
1296 |
* @param pReal
|
1297 |
* @return
|
1298 |
* @throws LoadLayerException
|
1299 |
* @throws ReadDriverException
|
1300 |
*/
|
1301 |
private Point2D transformPoint(Point2D pReal) throws LoadLayerException { |
1302 |
AffineTransform at = getDataStore().getAffineTransform();
|
1303 |
Point2D px = new Point2D.Double(); |
1304 |
//px = new Point2D.Double(pReal.getX(), pReal.getY());
|
1305 |
try {
|
1306 |
at.inverseTransform(pReal, px); |
1307 |
return px;
|
1308 |
} catch (NoninvertibleTransformException e) { |
1309 |
throw new LoadLayerException("Error en la transformaci?n del punto", e); |
1310 |
} |
1311 |
} |
1312 |
|
1313 |
/*
|
1314 |
* (non-Javadoc)
|
1315 |
* @see org.gvsig.fmap.raster.IRasterDataset#getInfo(java.lang.String)
|
1316 |
*/
|
1317 |
public Object getInfo(String key) { |
1318 |
if (key.equals("DriverName")) |
1319 |
return "gvSIG Raster Driver"; |
1320 |
return null; |
1321 |
} |
1322 |
|
1323 |
/*
|
1324 |
* (non-Javadoc)
|
1325 |
* @see org.gvsig.raster.fmap.layers.FLyrRaster#getBandCountFromDataset()
|
1326 |
*/
|
1327 |
public int[] getBandCountFromDataset() { |
1328 |
return getDataStore().getBandCountByProvider();
|
1329 |
} |
1330 |
|
1331 |
/*
|
1332 |
* (non-Javadoc)
|
1333 |
* @see org.gvsig.raster.shared.IRasterOperations#getColourInterpretation(int, int)
|
1334 |
*/
|
1335 |
public String getColorInterpretation(int band, int dataset) { |
1336 |
if (this.getDataStore().getColorInterpretation().get(band) == null) |
1337 |
return "Undefined"; |
1338 |
return this.getDataStore().getColorInterpretation().get(band); |
1339 |
} |
1340 |
|
1341 |
/*
|
1342 |
* (non-Javadoc)
|
1343 |
* @see org.gvsig.raster.fmap.layers.FLyrRaster#getWktProjection()
|
1344 |
*/
|
1345 |
public String getWktProjection() throws RasterDriverException { |
1346 |
return getDataStore().getWktProjection();
|
1347 |
} |
1348 |
|
1349 |
/*
|
1350 |
* (non-Javadoc)
|
1351 |
* @see org.gvsig.raster.fmap.layers.FLyrRaster#isRGB()
|
1352 |
*/
|
1353 |
public boolean isRGB() { |
1354 |
if ((getDataStore() == null) || (render == null)) |
1355 |
return false; |
1356 |
|
1357 |
if (getDataStore().getDataType()[0] != Buffer.TYPE_BYTE) |
1358 |
return false; |
1359 |
|
1360 |
boolean R = false; |
1361 |
boolean G = false; |
1362 |
boolean B = false; |
1363 |
|
1364 |
int[] renderBands = render.getRenderBands(); |
1365 |
for (int i = 0; i < renderBands.length; i++) |
1366 |
if (renderBands[i] >= 0) |
1367 |
switch (i) {
|
1368 |
case 0: |
1369 |
R = true;
|
1370 |
break;
|
1371 |
case 1: |
1372 |
G = true;
|
1373 |
break;
|
1374 |
case 2: |
1375 |
B = true;
|
1376 |
break;
|
1377 |
} |
1378 |
|
1379 |
if (R && G && B)
|
1380 |
return true; |
1381 |
|
1382 |
return false; |
1383 |
} |
1384 |
|
1385 |
/**
|
1386 |
* Obtiene el grid de la capa completa. Hay que tener cuidado porque cuando se hace esta
|
1387 |
* petici?n se carga un buffer con todos los datos de la capa. Este buffer puede ser
|
1388 |
* cacheado o no dependiendo del tama?o de esta.
|
1389 |
* @param interpolated true si se solicita un grid interpolado y false si se solicita sin interpolar.
|
1390 |
* @return Grid.
|
1391 |
* @throws InterruptedException
|
1392 |
* @deprecated Don't use a <code>Grid</code> object. This will be removed soon
|
1393 |
*/
|
1394 |
public Grid getFullGrid(boolean interpolated) throws GridException, InterruptedException { |
1395 |
RasterQuery query = rManager.createQuery(); |
1396 |
query.setAllDrawableBands(); |
1397 |
Buffer bf = null; |
1398 |
try {
|
1399 |
query.setAreaOfInterest(); |
1400 |
bf = getDataStore().query(query); |
1401 |
} catch (RasterDriverException e) {
|
1402 |
throw new GridException("Error reading buffer"); |
1403 |
} catch (ProcessInterruptedException e) {
|
1404 |
throw new InterruptedException("Carga interrumpida"); |
1405 |
} catch (InvalidSetViewException e) {
|
1406 |
throw new GridException("Error reading buffer"); |
1407 |
} |
1408 |
return rManager.createGrid(bf, getDataStore(), interpolated);
|
1409 |
} |
1410 |
|
1411 |
/**
|
1412 |
* @deprecated Don't use a <code>Grid</code> object. This will be removed soon
|
1413 |
*/
|
1414 |
public Grid getReadOnlyFullGrid(boolean interpolated) throws GridException, InterruptedException { |
1415 |
RasterQuery query = rManager.createQuery(); |
1416 |
query.setReadOnly(true);
|
1417 |
query.setAllDrawableBands(); |
1418 |
Buffer bf = null; |
1419 |
try {
|
1420 |
query.setAreaOfInterest(); |
1421 |
bf = getDataStore().query(query); |
1422 |
} catch (RasterDriverException e) {
|
1423 |
throw new GridException("Error reading buffer"); |
1424 |
} catch (ProcessInterruptedException e) {
|
1425 |
throw new InterruptedException("Carga interrumpida"); |
1426 |
} catch (InvalidSetViewException e) {
|
1427 |
throw new GridException("Error reading buffer"); |
1428 |
} |
1429 |
return rManager.createGrid(bf, getDataStore(), interpolated);
|
1430 |
} |
1431 |
|
1432 |
/**
|
1433 |
* Obtiene el tama?o de celda de la fuente de datos
|
1434 |
* @return double con el tama?o de celda
|
1435 |
*/
|
1436 |
public double getCellSize() { |
1437 |
return (getDataStore() != null) ? getDataStore().getCellSize() : 1; |
1438 |
} |
1439 |
|
1440 |
/*
|
1441 |
* (non-Javadoc)
|
1442 |
* @see org.gvsig.raster.fmap.layers.FLyrRaster#getFullRasterExtent()
|
1443 |
*/
|
1444 |
public Extent getFullRasterExtent() {
|
1445 |
return this.getDataStore().getExtent(); |
1446 |
} |
1447 |
|
1448 |
|
1449 |
/**
|
1450 |
* Devuelve el fichero asociado a la capa o null si no tiene.
|
1451 |
* @return Fichero.
|
1452 |
*/
|
1453 |
public File getFile() { |
1454 |
if(getDataStore().getParameters() instanceof RasterFileStoreParameters) |
1455 |
return ((RasterFileStoreParameters)getDataStore().getParameters()).getFile();
|
1456 |
return new File(""); |
1457 |
} |
1458 |
|
1459 |
/**
|
1460 |
* Consulta si un fichero es aceptado o no para este tipo de capa.
|
1461 |
* @param file Fichero a consultar
|
1462 |
* @return true si es aceptado y false si no lo es.
|
1463 |
*/
|
1464 |
public boolean isFileAccepted(File file) { |
1465 |
return getDataStore().isFileSupported(file.getName());
|
1466 |
} |
1467 |
|
1468 |
/**
|
1469 |
* Consulta si un fichero es aceptado o no para este tipo de capa.
|
1470 |
* @param file Fichero a consultar
|
1471 |
* @return true si es aceptado y false si no lo es.
|
1472 |
*/
|
1473 |
public static boolean isFileSupported(File file) { |
1474 |
return RasterLocator.getManager().getProviderServices().isExtensionSupported(file.getName());
|
1475 |
} |
1476 |
|
1477 |
/*
|
1478 |
* (non-Javadoc)
|
1479 |
* @see org.gvsig.raster.fmap.layers.FLyrRaster#existColorTable()
|
1480 |
*/
|
1481 |
public boolean existColorTable() { |
1482 |
return getRender().existColorTable();
|
1483 |
} |
1484 |
|
1485 |
/**
|
1486 |
* Returns true if the data store has an alpha band
|
1487 |
*/
|
1488 |
public boolean existsAlphaBand() { |
1489 |
if(getDataStore().getColorInterpretation() != null) |
1490 |
return getDataStore().getColorInterpretation().hasAlphaBand();
|
1491 |
else
|
1492 |
return false; |
1493 |
} |
1494 |
|
1495 |
/*
|
1496 |
* (non-Javadoc)
|
1497 |
* @see org.gvsig.raster.fmap.layers.FLyrRaster#getAlphaBandNumber()
|
1498 |
*/
|
1499 |
public int getAlphaBandNumber() { |
1500 |
if(getDataStore().getColorInterpretation() != null) |
1501 |
return getDataStore().getColorInterpretation().getBand(ColorInterpretation.ALPHA_BAND);
|
1502 |
return -1; |
1503 |
} |
1504 |
|
1505 |
/**
|
1506 |
* Define la ultima leyenda valida de la capa o se pone a null para que la
|
1507 |
* capa busque una leyenda valida.
|
1508 |
* @param ct
|
1509 |
*/
|
1510 |
public void setLastLegend(ColorTable ct) { |
1511 |
lastLegend = ColorTableLegend.createLegend(ct); |
1512 |
} |
1513 |
|
1514 |
/**
|
1515 |
* Devuelve la Leyenda de la capa.
|
1516 |
* @return Leyenda.
|
1517 |
*/
|
1518 |
public ILegend getLegend() {
|
1519 |
if (lastLegend != null) |
1520 |
return lastLegend;
|
1521 |
|
1522 |
return null; |
1523 |
} |
1524 |
|
1525 |
/*
|
1526 |
* (non-Javadoc)
|
1527 |
* @see com.iver.cit.gvsig.fmap.layers.layerOperations.Classifiable#addLegendListener(com.iver.cit.gvsig.fmap.layers.LegendListener)
|
1528 |
*/
|
1529 |
public void addLegendListener(LegendListener listener) { |
1530 |
layerChangeSupport.addLayerListener(listener); |
1531 |
} |
1532 |
|
1533 |
/*
|
1534 |
* (non-Javadoc)
|
1535 |
* @see com.iver.cit.gvsig.fmap.layers.layerOperations.Classifiable#getShapeType()
|
1536 |
*/
|
1537 |
public int getShapeType() { |
1538 |
return TYPES.SURFACE;
|
1539 |
} |
1540 |
|
1541 |
/*
|
1542 |
* (non-Javadoc)
|
1543 |
* @see com.iver.cit.gvsig.fmap.layers.layerOperations.Classifiable#removeLegendListener(com.iver.cit.gvsig.fmap.layers.LegendListener)
|
1544 |
*/
|
1545 |
public void removeLegendListener(LegendListener listener) { |
1546 |
if(layerChangeSupport != null) |
1547 |
layerChangeSupport.removeLayerListener(listener); |
1548 |
} |
1549 |
|
1550 |
/*
|
1551 |
* (non-Javadoc)
|
1552 |
* @see org.gvsig.raster.fmap.layers.FLyrRaster#isInside(java.awt.geom.Point2D)
|
1553 |
*/
|
1554 |
public boolean isInside(Point2D p) { |
1555 |
return getDataStore().isInside(p);
|
1556 |
} |
1557 |
|
1558 |
/*
|
1559 |
* (non-Javadoc)
|
1560 |
* @see org.gvsig.raster.fmap.layers.FLyrRaster#getAffineTransform()
|
1561 |
*/
|
1562 |
public AffineTransform getAffineTransform() { |
1563 |
return getDataStore().getAffineTransform();
|
1564 |
} |
1565 |
|
1566 |
/*
|
1567 |
* (non-Javadoc)
|
1568 |
* @see org.gvsig.raster.fmap.layers.FLyrRaster#setAffineTransform(java.awt.geom.AffineTransform)
|
1569 |
*/
|
1570 |
public void setAffineTransform(AffineTransform transf) { |
1571 |
if(transf == null) |
1572 |
return;
|
1573 |
affineTransformList.add(transf); |
1574 |
getDataStore().setAffineTransform(transf); |
1575 |
updateDrawVersion(); |
1576 |
} |
1577 |
|
1578 |
/*
|
1579 |
* (non-Javadoc)
|
1580 |
* @see org.gvsig.raster.fmap.layers.FLyrRaster#setAffineTransformWithoutHistorical(java.awt.geom.AffineTransform)
|
1581 |
*/
|
1582 |
public void setAffineTransformWithoutHistorical(AffineTransform transf) { |
1583 |
getDataStore().setAffineTransform(transf); |
1584 |
updateDrawVersion(); |
1585 |
} |
1586 |
|
1587 |
/*
|
1588 |
* (non-Javadoc)
|
1589 |
* @see org.gvsig.raster.fmap.layers.FLyrRaster#getAffineTransformHistorical()
|
1590 |
*/
|
1591 |
public Historical getAffineTransformHistorical() {
|
1592 |
return this.affineTransformList; |
1593 |
} |
1594 |
|
1595 |
/*
|
1596 |
* (non-Javadoc)
|
1597 |
* @see org.gvsig.raster.fmap.layers.FLyrRaster#saveGeoToRmf()
|
1598 |
*/
|
1599 |
public void saveGeoToRmf() throws RmfSerializerException { |
1600 |
if (!isOpen())
|
1601 |
return;
|
1602 |
|
1603 |
getDataStore().saveGeoreferencingToRmf(); |
1604 |
|
1605 |
affineTransformList.clear(); |
1606 |
affineTransformList.add(this.getAffineTransform());
|
1607 |
} |
1608 |
|
1609 |
/*
|
1610 |
* (non-Javadoc)
|
1611 |
* @see org.gvsig.fmap.raster.layers.IRasterLayerActions#isActionEnabled(int)
|
1612 |
*/
|
1613 |
public boolean isActionEnabled(int action) { |
1614 |
switch (action) {
|
1615 |
case IRasterLayerActions.BANDS_FILE_LIST:
|
1616 |
if (existColorTable() || getDataStore().isMosaic())
|
1617 |
return false; |
1618 |
break;
|
1619 |
case IRasterLayerActions.BANDS_RGB:
|
1620 |
if (existColorTable())
|
1621 |
return false; |
1622 |
break;
|
1623 |
case IRasterLayerActions.REPROJECT:
|
1624 |
if (!isReproyectable())
|
1625 |
return false; |
1626 |
break;
|
1627 |
case IRasterLayerActions.CREATEOVERVIEWS:
|
1628 |
return overviewsSupport();
|
1629 |
case IRasterLayerActions.OPACITY:
|
1630 |
case IRasterLayerActions.TRANSPARENCY:
|
1631 |
case IRasterLayerActions.BRIGHTNESSCONTRAST:
|
1632 |
case IRasterLayerActions.ENHANCED:
|
1633 |
case IRasterLayerActions.PANSHARPENING:
|
1634 |
case IRasterLayerActions.SELECT_LAYER:
|
1635 |
case IRasterLayerActions.SAVE_COLORINTERP:
|
1636 |
return true; |
1637 |
case IRasterLayerActions.REMOTE_ACTIONS:
|
1638 |
return false; |
1639 |
case IRasterLayerActions.TAILTRIM:
|
1640 |
case IRasterLayerActions.GEOLOCATION:
|
1641 |
return !(getDataStore().isTiled());
|
1642 |
} |
1643 |
return true; |
1644 |
} |
1645 |
|
1646 |
/*
|
1647 |
* (non-Javadoc)
|
1648 |
* @see com.iver.cit.gvsig.fmap.layers.FLyrDefault#setVisible(boolean)
|
1649 |
*/
|
1650 |
public void setVisible(boolean visibility) { |
1651 |
if(visibility)
|
1652 |
state.disableStopped(); |
1653 |
else
|
1654 |
enableStopped(); |
1655 |
|
1656 |
if(isAwake() || isClosed())
|
1657 |
try {
|
1658 |
this.load();
|
1659 |
} catch (LoadLayerException e) {
|
1660 |
e.printStackTrace(); |
1661 |
} |
1662 |
|
1663 |
/*
|
1664 |
* Cuando se modifica la visibilidad de una capa raster se hace un updateDrawVersion de todas las
|
1665 |
* capas raster de ese MapContext. Esto es porque la estrategia utilizada por RasterDrawStrategy hace
|
1666 |
* que se cacheen en blanco las capas raster que est?n ocultas debajo de otras. Al hacer invisibles las
|
1667 |
* de arriba la cache que estaba en blanco hace que no se pinte nada. Para evitar esto las marcamos todas
|
1668 |
* como que han sido modificadas para que se vuelvan a leer.
|
1669 |
*/
|
1670 |
if(getMapContext() != null) { |
1671 |
ArrayList<FLayer> listLayers = new ArrayList<FLayer>(); |
1672 |
listLayers = RasterDrawStrategy.getLayerList(getMapContext().getLayers(), listLayers); |
1673 |
for (int i = 0; i < listLayers.size(); i++) |
1674 |
if(listLayers.get(i) instanceof DefaultFLyrRaster) |
1675 |
((DefaultFLyrRaster)listLayers.get(i)).updateDrawVersion(); |
1676 |
} |
1677 |
|
1678 |
super.setVisible(visibility);
|
1679 |
} |
1680 |
|
1681 |
/**
|
1682 |
* Consulta la transparencia asignada en la ?ltima renderizaci?n de la capa
|
1683 |
* @return valor de transparencia
|
1684 |
*/
|
1685 |
public int getTransparency() { |
1686 |
try {
|
1687 |
return getRender().getLastTransparency().getOpacity();
|
1688 |
} catch (NullPointerException e) { |
1689 |
return super.getTransparency(); |
1690 |
} |
1691 |
} |
1692 |
|
1693 |
/**
|
1694 |
* Consulta si tiene aplicada alguna transparencia en la ?ltima renderizaci?n
|
1695 |
* o no.
|
1696 |
* @return true si se aplic? alguna transparencia en la ?ltima renderizaci?n.
|
1697 |
*/
|
1698 |
public boolean isTransparent() { |
1699 |
return getRender().getLastTransparency().isTransparencyActive();
|
1700 |
} |
1701 |
|
1702 |
/**
|
1703 |
* Asigna la transparencia de la siguiente renderizaci?n
|
1704 |
* @param valor de transparencia
|
1705 |
*/
|
1706 |
public void setTransparency(int trans) { |
1707 |
super.setTransparency(trans);
|
1708 |
try {
|
1709 |
getRender().getLastTransparency().setOpacity(trans); |
1710 |
} catch (NullPointerException e) { |
1711 |
//Solo asigna la transparencia a la clase padre y no a la renderizaci?n
|
1712 |
} |
1713 |
} |
1714 |
|
1715 |
public List<ROI> getRois() throws ROIException { |
1716 |
if(rois == null) { |
1717 |
try {
|
1718 |
List<File> fileList = getDataStore().getROIFileListFromRmf(); |
1719 |
if(fileList != null & fileList.size() > 0 && fileList.get(0) != null) { |
1720 |
File f = fileList.get(0); |
1721 |
IProjection proj = getProjection(); |
1722 |
if(proj == null) { |
1723 |
proj = getMapContext().getProjection(); |
1724 |
} |
1725 |
VectorialROIsReader reader = new VectorialROIsReader(
|
1726 |
f.getPath(), |
1727 |
getReadOnlyFullGrid(false), //TODO: Eliminar el Grid de VectorialROIsReader |
1728 |
proj, |
1729 |
getFullEnvelope()); |
1730 |
rois = new ArrayList<ROI>(); |
1731 |
rois = reader.read(rois); |
1732 |
} |
1733 |
} catch (Exception e) { |
1734 |
throw new ROIException("error_getting_ROIS", e); |
1735 |
} |
1736 |
} |
1737 |
return rois;
|
1738 |
} |
1739 |
|
1740 |
public void setRois(List<ROI> rois) { |
1741 |
this.rois = rois;
|
1742 |
} |
1743 |
|
1744 |
public void setROIsFiles(List<File> file) throws RmfSerializerException { |
1745 |
getDataStore().saveROIFileListToRmf(file); |
1746 |
} |
1747 |
|
1748 |
public List<File> getROIsFiles() throws RmfSerializerException { |
1749 |
return getDataStore().getROIFileListFromRmf();
|
1750 |
} |
1751 |
|
1752 |
/**
|
1753 |
* Si ya tiene una estrategia de dibujado de raster calculada la devuelve, sino
|
1754 |
* devolver? null.
|
1755 |
* @return TreeMap con la lista de capas a dibujar
|
1756 |
*/
|
1757 |
public HashMap<DefaultFLyrRaster, Boolean> getRasterStrategy() { |
1758 |
if(strategy != null) |
1759 |
return strategy.getStrategy();
|
1760 |
return null; |
1761 |
} |
1762 |
|
1763 |
/**
|
1764 |
* @return the configuration
|
1765 |
*/
|
1766 |
static public IConfiguration getConfiguration() { |
1767 |
return configuration;
|
1768 |
} |
1769 |
|
1770 |
/**
|
1771 |
* @param configuration the configuration to set
|
1772 |
*/
|
1773 |
static public void setConfiguration(IConfiguration configuration) { |
1774 |
DefaultFLyrRaster.configuration = configuration; |
1775 |
} |
1776 |
|
1777 |
/*
|
1778 |
* (non-Javadoc)
|
1779 |
* @see com.iver.cit.gvsig.fmap.layers.FLyrDefault#reload()
|
1780 |
*/
|
1781 |
public void reload() throws ReloadLayerException { |
1782 |
try {
|
1783 |
super.reload();
|
1784 |
if (getMapContext() == null) |
1785 |
return;
|
1786 |
if (isStopped())
|
1787 |
disableStopped(); |
1788 |
load(); |
1789 |
getMapContext().invalidate(); |
1790 |
} catch (LoadLayerException e) {
|
1791 |
setAvailable(false);
|
1792 |
throw new ReloadLayerException(getName(), e); |
1793 |
} |
1794 |
} |
1795 |
|
1796 |
/**
|
1797 |
* Devuelve si la capa tiene soporte para poder generar overviews
|
1798 |
* @return
|
1799 |
*/
|
1800 |
public boolean overviewsSupport() { |
1801 |
if ((getDataStore() != null) && (getDataStore().overviewsSupport())) |
1802 |
return true; |
1803 |
|
1804 |
return false; |
1805 |
} |
1806 |
|
1807 |
/**
|
1808 |
* Devuelve si la asignacion de las bandas a renderizar representa una capa
|
1809 |
* en escala de grises
|
1810 |
* @return
|
1811 |
*/
|
1812 |
public boolean isRenderingAsGray() { |
1813 |
int[] renderBands = getRender().getRenderBands(); |
1814 |
if ((renderBands != null) && (renderBands.length == 3) && (renderBands[0] >= 0) && |
1815 |
(renderBands[0] == renderBands[1]) && (renderBands[1] == renderBands[2])) |
1816 |
return true; |
1817 |
return false; |
1818 |
} |
1819 |
|
1820 |
/*
|
1821 |
* (non-Javadoc)
|
1822 |
* @see org.gvsig.raster.grid.render.VisualPropertyListener#actionValueChanged(org.gvsig.raster.grid.render.VisualPropertyEvent)
|
1823 |
*/
|
1824 |
public void visualPropertyValueChanged(VisualPropertyEvent e) { |
1825 |
updateDrawVersion(); |
1826 |
} |
1827 |
|
1828 |
/*
|
1829 |
* (non-Javadoc)
|
1830 |
* @see org.gvsig.raster.fmap.layers.FLyrRaster#adjustWorldRequest(java.awt.geom.Point2D)
|
1831 |
*/
|
1832 |
public Point2D adjustWorldRequest(Point2D req) { |
1833 |
Envelope ext = null;
|
1834 |
|
1835 |
ext = getFullEnvelope(); |
1836 |
req.setLocation(Math.max(ext.getMinimum(0), req.getX()), Math.max(ext.getMinimum(1), req.getY())); |
1837 |
req.setLocation(Math.min(ext.getMaximum(0), req.getX()), Math.min(ext.getMaximum(1), req.getY())); |
1838 |
return req;
|
1839 |
} |
1840 |
|
1841 |
/*
|
1842 |
* (non-Javadoc)
|
1843 |
* @see org.gvsig.fmap.mapcontext.layers.FLyrDefault#cloneLayer()
|
1844 |
*/
|
1845 |
public FLayer cloneLayer() throws Exception { |
1846 |
RasterDataStore ds = getDataStore().cloneDataStore(); |
1847 |
DefaultFLyrRaster newLayer = new DefaultFLyrRaster();
|
1848 |
newLayer.setName(getName()); |
1849 |
newLayer.setOpenRasterStore(ds); |
1850 |
newLayer.firstLoad = firstLoad; |
1851 |
|
1852 |
List<RasterFilter> filters = getRender().getFilterList().getStatusCloned();
|
1853 |
|
1854 |
//Hacemos una copia de las bandas a renderizar
|
1855 |
if(getRender().getRenderBands() != null) { |
1856 |
int[] rb = new int[getRender().getRenderBands().length]; |
1857 |
for (int i = 0; i < rb.length; i++) |
1858 |
rb[i] = getRender().getRenderBands()[i]; |
1859 |
newLayer.getRender().setRenderBands(rb); |
1860 |
} |
1861 |
|
1862 |
//Asignamos el entorno
|
1863 |
if(newLayer.getRender().getFilterList() == null) |
1864 |
newLayer.getRender().setFilterList(RasterLocator.getManager().createEmptyFilterList(getRender().getFilterList().getInitDataType())); |
1865 |
newLayer.getRender().getFilterList().setEnv(getRender().getFilterList().getEnv()); |
1866 |
newLayer.getRender().getFilterList().setStatus(filters); |
1867 |
|
1868 |
// Asignamos los valores noData del original
|
1869 |
newLayer.setNoDataValue(getNoDataValue()); |
1870 |
if(getDataStore().getNoDataValue().isDefined())
|
1871 |
newLayer.setNoDataTransparent(true);
|
1872 |
newLayer.enableOpen(); |
1873 |
|
1874 |
return newLayer;
|
1875 |
} |
1876 |
|
1877 |
/*
|
1878 |
* (non-Javadoc)
|
1879 |
* @see org.gvsig.raster.fmap.layers.FLyrRaster#getFileLayer()
|
1880 |
*/
|
1881 |
public FLayer getFileLayer() throws RasterDriverException { |
1882 |
try {
|
1883 |
return cloneLayer();
|
1884 |
} catch (Exception e) { |
1885 |
} |
1886 |
return null; |
1887 |
} |
1888 |
|
1889 |
/*
|
1890 |
* (non-Javadoc)
|
1891 |
* @see org.gvsig.raster.fmap.layers.FLyrRaster#addFile(java.lang.String)
|
1892 |
*/
|
1893 |
public void addFile(String file) throws InvalidSourceException { |
1894 |
getDataStore().addFile(file); |
1895 |
} |
1896 |
|
1897 |
/*
|
1898 |
* (non-Javadoc)
|
1899 |
* @see org.gvsig.raster.fmap.layers.FLyrRaster#removeFile(java.lang.String)
|
1900 |
*/
|
1901 |
public void removeFile(String file) { |
1902 |
getDataStore().removeFile(file); |
1903 |
} |
1904 |
|
1905 |
/*****************************************************/
|
1906 |
|
1907 |
public void disableStopped() { |
1908 |
if(state != null) |
1909 |
state.disableStopped(); |
1910 |
} |
1911 |
|
1912 |
public void enableAwake() throws NotAvailableStateException {state.enableAwake();} |
1913 |
|
1914 |
public void enableClosed() throws NotAvailableStateException { |
1915 |
if(state != null) |
1916 |
state.enableClosed(); |
1917 |
} |
1918 |
|
1919 |
public void enableOpen() throws NotAvailableStateException {state.enableOpen();} |
1920 |
|
1921 |
public void enableStopped() {state.enableStopped();} |
1922 |
|
1923 |
public boolean isAwake() {return state.isAwake();} |
1924 |
|
1925 |
public boolean isClosed() {return state.isClosed();} |
1926 |
|
1927 |
public boolean isOpen() {return state.isOpen();} |
1928 |
|
1929 |
public boolean isStopped() {return state.isStopped();} |
1930 |
|
1931 |
|
1932 |
@SuppressWarnings("unchecked") |
1933 |
public Set getMetadataChildren() { |
1934 |
return null; |
1935 |
} |
1936 |
|
1937 |
public Object getMetadataID() { |
1938 |
return getName();
|
1939 |
} |
1940 |
|
1941 |
public String getMetadataName() { |
1942 |
return null; |
1943 |
} |
1944 |
|
1945 |
/*
|
1946 |
* (non-Javadoc)
|
1947 |
* @see org.gvsig.raster.fmap.layers.FLyrRaster#getDataStore()
|
1948 |
*/
|
1949 |
public RasterDataStore getDataStore() {
|
1950 |
if(dataStore != null) { |
1951 |
RasterDataParameters params = (RasterDataParameters)dataStore.getParameters(); |
1952 |
if (getCoordTrans() != null && params.getReprojectionOption() == RasterDataParameters.ON_THE_FLY) { |
1953 |
this.dataStore.setCoordTrans(getCoordTrans());
|
1954 |
} |
1955 |
} |
1956 |
return this.dataStore; |
1957 |
} |
1958 |
|
1959 |
/*
|
1960 |
* (non-Javadoc)
|
1961 |
* @see org.cresques.geo.Projected#getProjection()
|
1962 |
*/
|
1963 |
public IProjection getProjection() {
|
1964 |
RasterDataParameters p = (RasterDataParameters)getDataStore().getParameters(); |
1965 |
if(p.getReprojectionOption() == RasterDataParameters.DONT_CHANGE_PROJECTION)
|
1966 |
return null; |
1967 |
return getDataStore().getProjection();
|
1968 |
} |
1969 |
|
1970 |
public void setOpenRasterStore(DataStore dataStore) throws LoadLayerException { |
1971 |
if(dataStore instanceof CoverageStoreProviderServices) { |
1972 |
try {
|
1973 |
this.dataStore = rManager.getProviderServices().open(
|
1974 |
((CoverageStoreProviderServices) dataStore).getProvider(), |
1975 |
dataStore.getParameters()); |
1976 |
} catch (NotSupportedExtensionException e) {
|
1977 |
throw new LoadLayerException("Extension not supported", e); |
1978 |
} catch (RasterDriverException e) {
|
1979 |
throw new LoadLayerException("Error opening the DataStore", e); |
1980 |
} |
1981 |
} else
|
1982 |
this.dataStore = (RasterDataStore) dataStore;
|
1983 |
try {
|
1984 |
enableAwake(); |
1985 |
} catch (NotAvailableStateException e) {
|
1986 |
throw new LoadLayerException("Fallo el estado de open. Closed=" + isClosed() + " Active=" + isOpen(), e); |
1987 |
} |
1988 |
if(getDataStore().getProjection() != null) { |
1989 |
try {
|
1990 |
getDataStore().setProjection(getDataStore().getProjection(), false);
|
1991 |
super.setProjection(getDataStore().getProjection());
|
1992 |
} catch (RmfSerializerException e) {
|
1993 |
//persist is false
|
1994 |
} |
1995 |
} |
1996 |
} |
1997 |
|
1998 |
/*
|
1999 |
* (non-Javadoc)
|
2000 |
* @see org.gvsig.fmap.mapcontext.layers.operations.SingleLayer#setDataStore(org.gvsig.fmap.dal.DataStore)
|
2001 |
*/
|
2002 |
public void setDataStore(DataStore dataStore) throws LoadLayerException { |
2003 |
setOpenRasterStore(dataStore); |
2004 |
load(); |
2005 |
} |
2006 |
|
2007 |
/*
|
2008 |
* (non-Javadoc)
|
2009 |
* @see org.gvsig.raster.fmap.layers.FLyrRaster#isRemote()
|
2010 |
*/
|
2011 |
public boolean isRemote() { |
2012 |
return false; |
2013 |
} |
2014 |
|
2015 |
/**
|
2016 |
* Returns true if exists a process reading data from this layer
|
2017 |
* @return
|
2018 |
*/
|
2019 |
public boolean isReadingData() { |
2020 |
return readingData != null; |
2021 |
} |
2022 |
|
2023 |
/**
|
2024 |
* When a process is using information of this layer this variable will contain
|
2025 |
* the thread ID.
|
2026 |
* @param readingData
|
2027 |
*/
|
2028 |
public synchronized void setReadingData(String readingData) { |
2029 |
this.readingData = readingData;
|
2030 |
} |
2031 |
|
2032 |
public DynObjectSet getInfo(Point p, double tolerance, Cancellable cancel, |
2033 |
boolean fast)
|
2034 |
throws LoadLayerException, DataException {
|
2035 |
return null; |
2036 |
} |
2037 |
|
2038 |
public DynObjectSet getInfo(Point p, double tolerance, Cancellable cancel) |
2039 |
throws LoadLayerException, DataException {
|
2040 |
return null; |
2041 |
} |
2042 |
|
2043 |
@Override
|
2044 |
protected void doDispose() throws BaseException { |
2045 |
if(render != null) |
2046 |
render.dispose(); |
2047 |
if(getDataStore() != null) |
2048 |
getDataStore().dispose(); |
2049 |
finalize(); |
2050 |
} |
2051 |
|
2052 |
/*
|
2053 |
* (non-Javadoc)
|
2054 |
* @see org.gvsig.fmap.mapcontext.layers.Multiresolution#getZoomLevel()
|
2055 |
*/
|
2056 |
public int getZoomLevel() { |
2057 |
return zoomLevel;
|
2058 |
} |
2059 |
|
2060 |
/*
|
2061 |
* (non-Javadoc)
|
2062 |
* @see org.gvsig.fmap.mapcontext.layers.Multiresolution#setZoomLevel(int)
|
2063 |
*/
|
2064 |
public void setZoomLevel(int zoomLevel) { |
2065 |
this.zoomLevel = zoomLevel;
|
2066 |
} |
2067 |
|
2068 |
/*
|
2069 |
* (non-Javadoc)
|
2070 |
* @see org.gvsig.fmap.mapcontext.layers.Multiresolution#increaseZoomLevel()
|
2071 |
*/
|
2072 |
public boolean increaseZoomLevel() { |
2073 |
if(zoomLevel < (this.getDataStore().getZoomLevels() - 1)) { |
2074 |
zoomLevel ++; |
2075 |
recalcLevel = false;
|
2076 |
return true; |
2077 |
} |
2078 |
return false; |
2079 |
} |
2080 |
|
2081 |
/*
|
2082 |
* (non-Javadoc)
|
2083 |
* @see org.gvsig.fmap.mapcontext.layers.Multiresolution#decreaseZoomLevel()
|
2084 |
*/
|
2085 |
public boolean decreaseZoomLevel() { |
2086 |
if(zoomLevel > 0) { |
2087 |
zoomLevel --; |
2088 |
recalcLevel = false;
|
2089 |
return true; |
2090 |
} |
2091 |
return false; |
2092 |
} |
2093 |
|
2094 |
/*
|
2095 |
* (non-Javadoc)
|
2096 |
* @see org.gvsig.fmap.mapcontext.layers.Multiresolution#getCoordsInLevel(java.awt.geom.Point2D, int, int, int)
|
2097 |
*/
|
2098 |
public Envelope getCoordsInLevel(Point2D center, int level, int w, int h) throws CreateEnvelopeException { |
2099 |
Extent ex = getDataStore().getCoordsInLevel(center, level, w, h); |
2100 |
return geomManager.createEnvelope(ex.getULX(), ex.getULY(), ex.getLRX(), ex.getLRY(), SUBTYPES.GEOM2D);
|
2101 |
} |
2102 |
|
2103 |
/*
|
2104 |
* (non-Javadoc)
|
2105 |
* @see org.gvsig.fmap.mapcontext.layers.Multiresolution#isEnabledMultiresolution()
|
2106 |
*/
|
2107 |
public boolean isEnabledMultiresolution() { |
2108 |
return getDataStore().isTiled();
|
2109 |
} |
2110 |
|
2111 |
/*
|
2112 |
* (non-Javadoc)
|
2113 |
* @see org.gvsig.raster.fmap.layers.Multiresolution#setTileServer(java.lang.Class)
|
2114 |
*/
|
2115 |
public void setTileServer(Class<?> tileServer) throws InitializeException { |
2116 |
getDataStore().setTileServer(tileServer); |
2117 |
} |
2118 |
|
2119 |
@SuppressWarnings("unchecked") |
2120 |
@Override
|
2121 |
public void loadFromState(PersistentState state) |
2122 |
throws PersistenceException {
|
2123 |
super.loadFromState(state);
|
2124 |
|
2125 |
//this.status = (IStatusRaster)state.get("status");
|
2126 |
List<ROI> rois = state.getList("rois"); |
2127 |
if(rois != null) { |
2128 |
this.rois = new ArrayList<ROI>(); |
2129 |
this.rois.addAll(rois);
|
2130 |
} |
2131 |
this.zoomLevel = state.getInt("zoomLevel"); |
2132 |
this.recalcLevel = state.getBoolean("recalcLevel"); |
2133 |
if(getDataStore() == null) |
2134 |
this.dataStore = (RasterDataStore)state.get("rasterdatastore"); |
2135 |
this.lastLegend = (ILegend)state.get("legend"); |
2136 |
this.colorTableLoadedFromProject = (ColorTable)state.get("colortable"); |
2137 |
this.zoomLevel = state.getInt("zoomLevel"); |
2138 |
this.recalcLevel = state.getBoolean("recalcLevel"); |
2139 |
loadedFromProject = true;
|
2140 |
} |
2141 |
|
2142 |
@Override
|
2143 |
public void saveToState(PersistentState state) throws PersistenceException { |
2144 |
super.saveToState(state);
|
2145 |
|
2146 |
//state.set("status", status);
|
2147 |
state.set("rasterdatastore", getDataStore());
|
2148 |
state.set("legend", lastLegend);
|
2149 |
state.set("rois", rois);
|
2150 |
state.set("colortable", getRender().getColorTable());
|
2151 |
state.set("zoomLevel", zoomLevel);
|
2152 |
state.set("recalcLevel", recalcLevel);
|
2153 |
} |
2154 |
|
2155 |
public static void registerPersistence() { |
2156 |
PersistenceManager manager = ToolsLocator.getPersistenceManager(); |
2157 |
DynStruct definition = manager.getDefinition(PERSISTENT_NAME); |
2158 |
if( definition == null ) { |
2159 |
if (manager.getDefinition(FLyrDefault.class) == null) { |
2160 |
FLyrDefault.registerPersistent(); |
2161 |
} |
2162 |
definition = manager.addDefinition( |
2163 |
DefaultFLyrRaster.class, |
2164 |
PERSISTENT_NAME, |
2165 |
PERSISTENT_DESCRIPTION, |
2166 |
null,
|
2167 |
null
|
2168 |
); |
2169 |
definition.extend(PersistenceManager.PERSISTENCE_NAMESPACE, "FLyrDefault");
|
2170 |
|
2171 |
registerPersistence(definition); |
2172 |
} |
2173 |
} |
2174 |
|
2175 |
public static void registerPersistence(DynStruct definition) { |
2176 |
//definition.addDynFieldObject("status").setClassOfValue(StatusLayerRaster.class).setMandatory(false);
|
2177 |
definition.addDynFieldObject("rasterdatastore").setClassOfValue(RasterDataStore.class).setMandatory(true); |
2178 |
definition.addDynFieldObject("legend").setClassOfValue(ILegend.class).setMandatory(false); |
2179 |
definition.addDynFieldList("rois").setClassOfItems(ROI.class).setMandatory(false); |
2180 |
definition.addDynFieldObject("colortable").setClassOfValue(ColorTable.class).setMandatory(false); |
2181 |
definition.addDynFieldInt("zoomlevel").setMandatory(false); |
2182 |
definition.addDynFieldBoolean("recalcLevel").setMandatory(false); |
2183 |
} |
2184 |
|
2185 |
/*
|
2186 |
* (non-Javadoc)
|
2187 |
* @see org.gvsig.fmap.mapcontext.layers.operations.Classifiable#getGeometryType()
|
2188 |
*/
|
2189 |
public GeometryType getGeometryType() throws ReadException { |
2190 |
try {
|
2191 |
return GeometryLocator.getGeometryManager().getGeometryType(TYPES.SURFACE, SUBTYPES.GEOM2D);
|
2192 |
} catch (GeometryTypeNotSupportedException e) {
|
2193 |
throw new ReadException(getDataStore().getName(), e); |
2194 |
} catch (GeometryTypeNotValidException e) {
|
2195 |
throw new ReadException(getDataStore().getName(), e); |
2196 |
} |
2197 |
} |
2198 |
|
2199 |
public void setDataStore(DataStore dataStore, String domain) throws LoadLayerException { |
2200 |
setDataStore(dataStore); |
2201 |
} |
2202 |
|
2203 |
/*
|
2204 |
* (non-Javadoc)
|
2205 |
* @see java.lang.Object#finalize()
|
2206 |
*/
|
2207 |
protected void finalize() { |
2208 |
layerChangeSupport = null;
|
2209 |
state = null;
|
2210 |
lastLegend = null;
|
2211 |
colorTableLoadedFromProject = null;
|
2212 |
if(rois != null) { |
2213 |
rois.clear(); |
2214 |
rois = null;
|
2215 |
} |
2216 |
strategy = null;
|
2217 |
configuration = null;
|
2218 |
fileUtil = null;
|
2219 |
rasterUtil = null;
|
2220 |
crsUtil = null;
|
2221 |
mathUtil = null;
|
2222 |
uri = null;
|
2223 |
affineTransformList = null;
|
2224 |
readingData = null;
|
2225 |
dataStore = null;
|
2226 |
render = null;
|
2227 |
} |
2228 |
|
2229 |
} |