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