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