Statistics
| Revision:

root / trunk / extensions / extRemoteSensing / src / org / gvsig / remotesensing / mosaic / process / MosaicProcess.java @ 26076

History | View | Annotate | Download (20 KB)

1
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
2
 *
3
 * Copyright (C) 2006 Instituto de Desarrollo Regional 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
 * For more information, contact:
20
 *
21
 *  Generalitat Valenciana
22
 *   Conselleria d'Infraestructures i Transport
23
 *   Av. Blasco Iba?ez, 50
24
 *   46010 VALENCIA
25
 *   SPAIN
26
 *
27
 *      +34 963862235
28
 *   gvsig@gva.es
29
 *      www.gvsig.gva.es
30
 *
31
 *    or
32
 *
33
 *   Instituto de Desarrollo Regional (Universidad de Castilla La-Mancha)
34
 *   Campus Universitario s/n
35
 *   02071 Alabacete
36
 *   Spain
37
 *
38
 *   +34 967 599 200
39
 */
40

    
41
package org.gvsig.remotesensing.mosaic.process;
42

    
43
import java.awt.geom.AffineTransform;
44
import java.awt.image.DataBuffer;
45
import java.io.File;
46
import java.io.IOException;
47

    
48
import org.gvsig.fmap.raster.layers.FLyrRasterSE;
49
import org.gvsig.raster.RasterProcess;
50
import org.gvsig.raster.buffer.BufferFactory;
51
import org.gvsig.raster.buffer.BufferInterpolation;
52
import org.gvsig.raster.buffer.RasterBuffer;
53
import org.gvsig.raster.buffer.RasterBufferInvalidException;
54
import org.gvsig.raster.buffer.WriterBufferServer;
55
import org.gvsig.raster.dataset.FileNotOpenException;
56
import org.gvsig.raster.dataset.GeoRasterWriter;
57
import org.gvsig.raster.dataset.IBuffer;
58
import org.gvsig.raster.dataset.IRasterDataSource;
59
import org.gvsig.raster.dataset.InvalidSetViewException;
60
import org.gvsig.raster.dataset.NotSupportedExtensionException;
61
import org.gvsig.raster.dataset.io.RasterDriverException;
62
import org.gvsig.raster.grid.Grid;
63
import org.gvsig.raster.grid.GridExtent;
64
import org.gvsig.raster.grid.OutOfGridException;
65
import org.gvsig.raster.grid.filter.RasterFilter;
66
import org.gvsig.raster.grid.filter.enhancement.EnhancementStretchListManager;
67
import org.gvsig.raster.grid.filter.enhancement.LinearStretchParams;
68
import org.gvsig.raster.util.RasterToolsUtil;
69
import org.gvsig.remotesensing.RemoteSensingUtils;
70

    
71
import com.iver.andami.PluginServices;
72
import com.iver.cit.gvsig.exceptions.layers.LoadLayerException;
73

    
74
/** 
75
* Clase que implementa el proceso de construccion de un mosaico mediante los m?todos b?sicos.
76
* 
77
* @params
78
* <LI>FLyrRasterSE[] "inputRasterLayers": Capas raster de entrada</LI>
79
* <LI>int "methodCode": M?todo de construcci?n (0:Valor m?ximo, 1:Valor m?nimo, 2: Valor Medio,
80
* 3: Valor del pixel de la capa superior, 4:Valor del pixel de la capa inferior)</LI>
81
* <LI>String "outputPath": Ruta completa al fichero de salida del proceso</LI>
82
* 
83
* @result
84
* <LI>outputRassterLayers[]: Capas raster resultantes</LI>
85
*
86
* 
87
* @author aMu?oz (alejandro.mu?oz@uclm.es)
88
* @version 30/4/2008
89
* */
90

    
91
public class MosaicProcess extends RasterProcess {
92
        
93
        public static final int MAX                 = 0;
94
        public static final int MIN                 = 1;
95
        public static final int AVERAGE         = 2;
96
        public static final int FRONT                 = 3;
97
        public static final int BACK                 = 4;
98

    
99
        // Layers que intervienen en el proceso
100
        private FLyrRasterSE inputRasterLayers[] = null;
101
        
102
        //Layer de salida
103
        private FLyrRasterSE outputRasterLayer = null;
104

    
105
        // Extend completo del mosaico
106
        private GridExtent fullExtend= null;
107
        
108
        // Grid resultante
109
        Grid mosaicGrid = null;
110
        
111
        // Buffers con las imagenes
112
        IBuffer buffers[]= null;
113
        
114
        // Codigo operacion mayor, menor,media valor de la situada encima.
115
        int codOp= 0; 
116
        
117
        // indicador de proceso
118
        int percent=0, proceso=0;
119
         
120
        // writer para escritura en fichero 
121
        private WriterBufferServer writerBufferServer =null;
122
        
123
        //  Numero de bandas 3 o 1 dependiendo de si es RGB o Nivel de gris
124
        int resultbandCount=0;
125
         
126
        // Fichero de salida
127
        private String fileName=null; 
128
        
129
        
130
        
131
        /** Inicializaci?n de los par?metros
132
         *  layers -  FLayers con los layers seleccionados para el mosaico.
133
         * 
134
         *         En la inicializacion se calcula el grid resultante.
135
         * */
136
        public void init() {
137
                
138
                inputRasterLayers= (FLyrRasterSE[])getParam("inputRasterLayers");
139
                codOp= getIntParam("methodCode");
140
                resultbandCount= getIntParam("numbands");
141
                fileName = getStringParam("outputPath");
142
                
143
//                 Calculo del extend resultante
144
                fullExtend= calculateExtend(inputRasterLayers);
145
                
146
                try {
147
                                mosaicGrid= new Grid(fullExtend,fullExtend,IBuffer.TYPE_BYTE,new int[] { 0, 1, 2 });
148
                                resultbandCount = mosaicGrid.getBandCount();
149
                } catch (RasterBufferInvalidException e) {
150
                        RasterToolsUtil.messageBoxError("buffer_incorrecto", this, e);
151
                }
152
        }
153

    
154
        
155
        /**
156
         *  Proceso
157
         * */
158
        public void process() throws InterruptedException {
159
                
160
                // Parte de carga de los datos
161
                buffers= new RasterBuffer[inputRasterLayers.length];
162
                IRasterDataSource dsetCopy = null; 
163
                try {
164
                
165
                        double minX= fullExtend.getMin().getX();
166
                        double minY= fullExtend.getMin().getY();
167
                        double maxX=  fullExtend.getMax().getX();
168
                        double maxY=  fullExtend.getMax().getY();
169
                        // Se cargan todos los raster en los grid correspondientes
170
                        percent=1;
171
                        for(int i=0; i< inputRasterLayers.length;i++)
172
                        {        
173
                                dsetCopy = ((FLyrRasterSE)inputRasterLayers[i]).getDataSource().newDataset();
174
                                BufferFactory bufferFactory = new BufferFactory(dsetCopy);
175
                                bufferFactory.setAdjustToExtent(false);
176
                                if (!RasterBuffer.loadInMemory(dsetCopy))
177
                                        bufferFactory.setReadOnly(true);
178
                                // Si pongo solo las renderizadas en algunos casos da problemas
179
                                bufferFactory.setDrawableBands(inputRasterLayers[i].getRenderBands());
180
                                
181
                                GridExtent gridExtent = new GridExtent(fullExtend.getMin().getX(),
182
                                                fullExtend.getMin().getY(),
183
                                                fullExtend.getMax().getX(),
184
                                                fullExtend.getMax().getY(),
185
                                                 inputRasterLayers[i].getAffineTransform().getScaleX(),
186
                                                 inputRasterLayers[i].getAffineTransform().getScaleY());
187
                                
188
                                bufferFactory.setAreaOfInterest(minX,minY,maxX,maxY,gridExtent.getNX(),gridExtent.getNY());
189
                                buffers[i]= (RasterBuffer) bufferFactory.getRasterBuf();
190
                                buffers[i] = ((RasterBuffer)buffers[i]).getAdjustedWindow(fullExtend.getNX(), fullExtend.getNY(), BufferInterpolation.INTERPOLATION_Bilinear);
191
                                percent=(int)((i+1)*100/inputRasterLayers.length);
192

    
193
                                //Aplicar filtro de realce si es necesario:
194
                                
195
                                if(buffers[i].getDataType()!=DataBuffer.TYPE_BYTE){
196
                                        LinearStretchParams leParams = null;
197
                                        leParams = LinearStretchParams.createStandardParam(inputRasterLayers[i].getRenderBands(), 0.0, bufferFactory.getDataSource().getStatistics(), false);
198
                                
199
                                        RasterFilter linearStretchEnhancementFilter = EnhancementStretchListManager.createEnhancedFilter(leParams, bufferFactory.getDataSource().getStatistics(),
200
                                                        inputRasterLayers[i].getRenderBands(), false);
201
                                        linearStretchEnhancementFilter.addParam("raster", buffers[i]);
202
                                        linearStretchEnhancementFilter.execute();
203
                                        
204
                                        buffers[i] = (IBuffer)linearStretchEnhancementFilter.getResult("raster");
205
                                }
206
                        
207
                        }
208
                }catch (RasterDriverException e) {
209
                        RasterToolsUtil.messageBoxError(PluginServices.getText(this, "error_writer"), this, e);        
210
                } catch (InvalidSetViewException e) {
211
                        RasterToolsUtil.messageBoxError(PluginServices.getText(this, "error_extension"), this, e);        
212
                } catch (InterruptedException e) {
213
                        Thread.currentThread().interrupt();
214
                } catch (FileNotOpenException e) {
215
                        RasterToolsUtil.messageBoxError(PluginServices.getText(this, "error_writer"), this, e);        
216
                } 
217
                
218
                proceso=1;
219
            
220
//                 Construccion del mosaico: Operaci?n M?ximo
221
                if(codOp==0){
222
                        int progress = 0;
223
                        for(int band=0; band<resultbandCount; band++){
224
                                mosaicGrid.setBandToOperate(band);
225
                                for(int row=0; row<mosaicGrid.getLayerNY(); row++){
226
                                        progress++;
227
                                        for(int col=0; col<mosaicGrid.getLayerNX();col++){
228
                                                setValueMax(col,row,band);
229
                                        }
230
                                        percent=(int)( progress*100/(mosaicGrid.getLayerNY()*resultbandCount));
231
                                }
232
                        }
233
                }
234
                
235
//                Construccion del mosaico: Operaci?n M?nimo
236
                if(codOp==1){
237
                        int progress = 0;
238
                        for(int band=0; band<resultbandCount; band++){
239
                                mosaicGrid.setBandToOperate(band);
240
                                for(int row=0; row<mosaicGrid.getLayerNY(); row++){
241
                                        progress++;
242
                                        for(int col=0; col<mosaicGrid.getLayerNX();col++){
243
                                                setValueMin(col,row,band);
244
                                        }
245
                                        percent=(int)( progress*100/(mosaicGrid.getLayerNY()*resultbandCount));
246
                                }
247
                        }
248
                }
249
                
250
//                 Construccion del mosaico: Operaci?n Media
251
                if(codOp==2){
252
                        int progress = 0;
253
                        for(int band=0; band<resultbandCount; band++){
254
                                mosaicGrid.setBandToOperate(band);
255
                                for(int col=0; col<mosaicGrid.getLayerNY(); col++){
256
                                        progress++;
257
                                        for(int row=0; row<mosaicGrid.getLayerNX();row++){
258
                                                setValueMean(row,col,band);
259
                                        }
260
                                        percent=(int)( progress*100/(mosaicGrid.getLayerNY()*resultbandCount));
261
                                }
262
                        }
263
                }
264
                
265
//                Construccion del mosaico: Operacion valor de capa de delantera
266
                if(codOp==3){
267
                        int progress = 0;
268
                        for(int band=0; band<resultbandCount; band++){
269
                                mosaicGrid.setBandToOperate(band);
270
                                for(int row=0; row<mosaicGrid.getLayerNY(); row++){
271
                                        progress++;
272
                                        for(int col=0; col<mosaicGrid.getLayerNX();col++){
273
                                                setValueFront(col,row,band);
274
                                        }
275
                                        percent=(int)( progress*100/(mosaicGrid.getLayerNY()*resultbandCount));
276
                                }
277
                        }
278
                }
279
                
280
                
281
//                Construccion del mosaico: Operaci?n Valor de capa de trasera
282
                if(codOp==4){
283
                        
284
                        // Cambio de orden del los elementos del buffer las capas inferiores pasan al principio del array
285
                        IBuffer buffersCopy[]= new RasterBuffer[buffers.length];
286
                        for(int i=0; i<buffers.length;i++)
287
                                buffersCopy[i]=buffers[i];
288
                        int k=buffers.length-1;
289
                        for(int i=0; i<buffers.length;i++){
290
                                buffers[i]=buffersCopy[k];
291
                                k--;
292
                        }
293
                        int progress = 0;
294
                        for(int band=0; band<resultbandCount; band++){
295
                                mosaicGrid.setBandToOperate(band);
296
                                for(int row=0; row<mosaicGrid.getLayerNY(); row++){
297
                                        progress++;
298
                                        for(int col=0; col<mosaicGrid.getLayerNX();col++){
299
                                                setValueBack(col,row,band);
300
                                        }
301
                                        percent=(int)( progress*100/(mosaicGrid.getLayerNY()*resultbandCount));
302
                                }
303
                        }
304
                }
305
                
306
                // Se liberan los buffers
307
                for(int i=0; i<inputRasterLayers.length;i++)
308
                        buffers[i].free();
309
                
310
                // Escritura en fichero
311
                proceso=2;
312
                createLayer();
313
                if (externalActions != null)
314
                        externalActions.end(outputRasterLayer);
315
        }
316

    
317
        
318
        /**
319
         *  M?todo que establece para la coordenada x,y el valor m?ximo 
320
         *  de todos los valores para ese p?xel en cualquiera de las imagenes.
321
         *  Si el valor en cualquiera de las imagenes es noData no es tenido en cuenta 
322
         *  @param cordenada x 
323
         *  @param coordenada y  
324
         * */
325
        public void setValueMax(int x, int y, int band){
326
                byte result=-128;
327
                for(int buf=0;buf<buffers.length;buf++){
328
                        //byte data = (byte)(buffers[buf].getElemByte(y,x,band)&0xff);
329
                        byte data = (byte)RemoteSensingUtils.getCellValueInLayerCoords(buffers[buf], x, y, band);
330
//                                 TODO: TENER EN CUENTA NODATA REAL DEL BUFER
331
                        if(data==(byte)mosaicGrid.getNoDataValue())
332
                                data=-128;
333
                        result=(byte) Math.max((byte)result,(byte)data);                
334
                }
335
                try {
336
                                mosaicGrid.setCellValue(x,y,(byte)result);
337
                } catch (OutOfGridException e) {
338
                                e.printStackTrace();
339
                }
340
        }
341
        
342
        /**
343
         *  M?todo que establece para la coordenada x,y el valor m?ximo 
344
         *  de todos los valores para ese p?xel en cualquiera de las imagenes.
345
         *  Si el valor en cualquiera de las imagenes es noData no es tenido en cuenta 
346
         *  @param cordenada x 
347
         *  @param coordenada y  
348
         * */
349
        public void setValueMin(int x, int y,int band){
350
                byte result=127;
351
                        for(int buf=0;buf<buffers.length;buf++){
352
                                byte data = (byte)RemoteSensingUtils.getCellValueInLayerCoords(buffers[buf], x, y, band);
353
                                // TO DO: TENER EN CUENTA NO DATA
354
                                if(data==(byte)mosaicGrid.getNoDataValue())
355
                                        data=127;
356
                                result=(byte) Math.min((byte)result,(byte)data);                
357
                        }
358
                        try {
359
                                mosaicGrid.setCellValue(x,y,(byte)result);
360
                        } catch (OutOfGridException e) {
361
                                // TODO Auto-generated catch block
362
                                e.printStackTrace();
363
                        }
364
        }
365
        
366
        
367
        /**
368
         *  M?todo que establece para la coordenada x,y el valor medio  
369
         *  de todos los valores para ese p?xel en cualquiera de las imagenes.
370
         *  Si el valor en cualquiera de las imagenes es noData no es tenido en cuenta 
371
         *  @param cordenada x 
372
         *  @param coordenada y  
373
         * */
374
        public void setValueMean(int x, int y, int band){
375
                int result=0;
376
                int buffTotales= buffers.length;
377
                for(int buf=0;buf<buffers.length;buf++){
378
                        int data = (int)RemoteSensingUtils.getCellValueInLayerCoords(buffers[buf], x, y, band);
379
                        //TODO: TENER EN CUENTA NODATA REAL DEL BUFER
380
                        if(data==(byte)mosaicGrid.getNoDataValue()){
381
                                buffTotales--;
382
                                data =0;
383
                        }
384
                        result+=data;                
385
                }
386
                if(buffTotales==0)
387
                        buffTotales=1;
388
                result=(byte)((result/buffTotales));
389
                try {
390
                                mosaicGrid.setCellValue(x,y,(byte)(result));
391
                } catch (OutOfGridException e) {
392
                                e.printStackTrace();
393
                }
394
        }
395
        
396
        
397
        /**
398
         *  M?todo que establece para la coordenada x,y el valor de la capa superior 
399
         *  en caso de solape. Se parte de un array de buffer ordenados, de tal manera que
400
         *  el primer elemento corresponde a la capa situada mas al frente. El ?ltimo por 
401
         *  contra es el situado al fondo.
402
         
403
         *  @param cordenada x 
404
         *  @param coordenada y  
405
         * */
406
        public void setValueFront(int x, int y, int band){
407
                byte result=0;
408
                for(int buf=0;buf<buffers.length;buf++){
409
                        result = (byte)RemoteSensingUtils.getCellValueInLayerCoords(buffers[buf], x, y, band);
410
                        // TO DO : Valor no data del buffer
411
                        if(result!=(byte)mosaicGrid.getNoDataValue())
412
                                        break;
413
                }
414
                
415
                try {
416
                                mosaicGrid.setCellValue(x,y,(byte)result);
417
                } catch (OutOfGridException e) {
418
                                e.printStackTrace();
419
                }
420
        }
421
        
422
        
423
        /**
424
         *  M?todo que establece para la coordenada x,y el valor de la capa inferior
425
         *  en caso de solape. Se parte de un array de buffer ordenados, de tal manera que
426
         *  el primer elemento corresponde a la capa situada mas al frente. El ?ltimo por 
427
         *  contra es el situado al fondo.
428
         
429
         *  @param cordenada x 
430
         *  @param coordenada y  
431
         * */
432
        public void setValueBack(int x, int y, int band){
433
                byte result=0;
434
                for(int buf=0;buf<buffers.length;buf++){
435
                        result = (byte)RemoteSensingUtils.getCellValueInLayerCoords(buffers[buf], x, y, band);
436
                        // TO DO : Valor no data del buffer
437
                        if(result!=(byte)mosaicGrid.getNoDataValue())
438
                                        break;
439
                }
440
                
441
                try {
442
                                mosaicGrid.setCellValue(x,y,(byte)result);
443
                } catch (OutOfGridException e) {
444
                                e.printStackTrace();
445
                }
446
        }
447
        
448
        
449
        /**
450
         * M?todo que calcula el extend resultante para la operaci?n de mosaico
451
         * 
452
         * @param layers que intervienen en la operacion.
453
         * @return GridExtend del mosaico
454
         * */
455
        
456
        private GridExtent calculateExtend (FLyrRasterSE layers[]){
457
                
458
                GridExtent result= null;
459
                IRasterDataSource dsetCopy = null; 
460
                double cellSize=Double.MAX_VALUE;
461
                double minX=0,maxX=0,minY=0,maxY=0;
462
                // Se obtiene el menor tama?o de celda mayor
463
                for(int i=0; i< layers.length;i++)
464
                {        
465
                        dsetCopy = ((FLyrRasterSE)layers[i]).getDataSource().newDataset();
466
                        BufferFactory bufferFactory = new BufferFactory(dsetCopy);
467
                        bufferFactory.setAdjustToExtent(false);
468
                        cellSize= Math.min(cellSize,bufferFactory.getDataSource().getCellSize());
469
                }
470
                
471
                minX = layers[0].getFullExtent().getMinX();
472
                minY = layers[0].getFullExtent().getMinY();
473
                maxX = layers[0].getFullExtent().getMaxX();
474
                maxY = layers[0].getFullExtent().getMaxY();
475
                
476
                for(int i=1; i<layers.length;i++){
477
                        
478
                        minX= Math.min(minX,layers[i].getFullExtent().getMinX());
479
                        minY= Math.min(minY,layers[i].getFullExtent().getMinY());
480
                        maxX= Math.max(maxX,layers[i].getFullExtent().getMaxX());
481
                        maxY= Math.max(maxY,layers[i].getFullExtent().getMaxY());
482
                }
483
                
484
                result = new GridExtent(minX,minY,maxX,maxY,cellSize);
485
                return result;
486
        }
487
        
488
        /**
489
         * Escritura del resultado en disco y carga en la vista 
490
         */
491
        public void createLayer(){
492
                try{
493
                        // Escritura de los datos a fichero temporal
494
                        int endIndex = fileName.lastIndexOf(".");
495
                        if (endIndex < 0)
496
                                 endIndex = fileName.length();
497
                        GeoRasterWriter grw = null;
498
                        writerBufferServer = new WriterBufferServer(mosaicGrid.getRasterBuf());
499
                        AffineTransform aTransform = new AffineTransform(fullExtend.getCellSize(),0.0,0.0,-fullExtend.getCellSize(),fullExtend.getMin().getX(),fullExtend.getMax().getY());
500
                        grw = GeoRasterWriter.getWriter(writerBufferServer, fileName, mosaicGrid.getBandCount(),aTransform, mosaicGrid.getRasterBuf().getWidth(), mosaicGrid.getRasterBuf().getHeight(), mosaicGrid.getRasterBuf().getDataType(), GeoRasterWriter.getWriter(fileName).getParams(), inputRasterLayers[0].getProjection());
501
                        grw.dataWrite();
502
                        grw.setWkt((String)((FLyrRasterSE)inputRasterLayers[0]).getWktProjection());
503
                        grw.writeClose();
504
                        mosaicGrid.getRasterBuf().free();
505
                        outputRasterLayer = FLyrRasterSE.createLayer(fileName.substring(fileName.lastIndexOf(File.separator) + 1, endIndex),
506
                                        fileName, null);
507
        
508
                } catch (NotSupportedExtensionException e) {
509
                        RasterToolsUtil.messageBoxError(PluginServices.getText(this, "error_writer_notsupportedextension"), this, e);
510
                } catch (IOException e) {
511
                        RasterToolsUtil.messageBoxError(PluginServices.getText(this, "error_writer"), this, e);
512
                } catch (InterruptedException e) {
513
                                Thread.currentThread().interrupt();
514
                } catch (RasterDriverException e) {
515
                        RasterToolsUtil.messageBoxError(PluginServices.getText(this, "raster_buffer_invalid_extension"), this, e);
516
                } catch (LoadLayerException e) {
517
                        RasterToolsUtil.messageBoxError("error_cargar_capa", this, e);
518
                }
519

    
520
        }
521
        
522
        public Object getResult() {
523
                return outputRasterLayer;
524
        }
525

    
526

    
527
        /**
528
         * @return descripcion
529
         * */
530
        public String getTitle() {
531
                return PluginServices.getText(this,"mosaic_process");
532
        }
533

    
534
        
535
        /**
536
         *  @return String con el log en cada parte del proceso
537
         * */
538
        public String getLog()
539
        {
540
                if(proceso==0)
541
                        return PluginServices.getText(this,"load_buffer_data");
542
                else if (proceso==1)
543
                        return PluginServices.getText(this,"generate_mosaic");
544
                else
545
                        return PluginServices.getText(this,"write_to_file");
546
        }
547
        
548
        /**
549
         * @return  indicador de progreso
550
         * */
551
        public int getPercent() {
552
                if(writerBufferServer==null)
553
                        return percent;
554
                else 
555
                        return writerBufferServer.getPercent();
556
        }
557

    
558

    
559
        /*
560
        // Identificaci?n de zonas de solapamiento
561
        public boolean getSolapes(FLyrRasterSE raster1, FLyrRasterSE raster2){
562
                
563
                Grid grid1=null, grid2=null, aux=null;;
564
                IRasterDataSource dsetCopy = null; 
565
                dsetCopy =raster1.getDataSource().newDataset();
566
                BufferFactory bufferFactory = new BufferFactory(dsetCopy);
567
                
568
                IRasterDataSource dsetCopy2 = null; 
569
                dsetCopy2 =raster2.getDataSource().newDataset();
570
                BufferFactory bufferFactory2 = new BufferFactory(dsetCopy2);
571
                
572
                
573
                if (!RasterBuffer.loadInMemory(dsetCopy))
574
                        bufferFactory.setReadOnly(true);        
575
                
576
                try {
577
                        grid1 = new Grid(bufferFactory,raster1.getRenderBands());
578
                        grid2= new Grid(bufferFactory2,raster2.getRenderBands());
579
                } catch (RasterBufferInvalidException e) {
580
                        e.printStackTrace();
581
                }        
582
                
583
                // En grid1 la imagen con la cordenada x menor.
584
                if(grid2.getGridExtent().getMin().getX()< grid1.getGridExtent().getMin().getX())
585
                        {
586
                                try {
587
                                        grid1 = new Grid(bufferFactory2,raster2.getRenderBands());
588
                                        grid2= new Grid(bufferFactory,raster1.getRenderBands());
589
                                } catch (RasterBufferInvalidException e) {
590
                                        e.printStackTrace();
591
                                }        
592
                                
593
                        }
594
                
595
                double xmin= grid1.getGridExtent().getMin().getX();
596
                double xmax= grid1.getGridExtent().getMax().getX();
597
                double ymin= grid1.getGridExtent().getMin().getY();
598
                double ymax= grid1.getGridExtent().getMax().getY();
599
                
600
                double xmin2= grid2.getGridExtent().getMin().getX();
601
                double ymin2= grid2.getGridExtent().getMin().getY();
602
                
603
                if(!(xmin2>xmin && xmin2<xmax)){
604
                        System.out.print("Las imagenes no se solapan en las X");
605
                        return false;
606
                }
607
        
608
                if(!(ymin2>ymin && ymin2<ymax)){
609
                        System.out.print("Las imagenes no se solapan en las Y");
610
                        return false;
611
                }
612
                
613
                // Detectado el solapamiento
614
                System.out.print("Rango x["+ xmin2 + ","+ Math.min(xmax,grid2.getGridExtent().getMax().getX())+"].");
615
                System.out.print("Rango y["+ ymin2 + ","+ Math.min(ymax,grid2.getGridExtent().getMax().getY())+"].");
616
                
617
                return true;
618
        }*/
619

    
620

    
621
}