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