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