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