Statistics
| Revision:

root / trunk / extensions / extRasterTools / src / com / iver / cit / gvsig / fmap / rasterTools / saveRaster / operations / SaveRasterThread.java @ 4441

History | View | Annotate | Download (5 KB)

1
/*
2
 * Created on 17-feb-2004
3
 *
4
 * To change the template for this generated file go to
5
 * Window>Preferences>Java>Code Generation>Code and Comments
6
 */
7
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
8
 *
9
 * Copyright (C) 2004 IVER T.I. and Generalitat Valenciana.
10
 *
11
 * This program is free software; you can redistribute it and/or
12
 * modify it under the terms of the GNU General Public License
13
 * as published by the Free Software Foundation; either version 2
14
 * of the License, or (at your option) any later version.
15
 *
16
 * This program is distributed in the hope that it will be useful,
17
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
19
 * GNU General Public License for more details.
20
 *
21
 * You should have received a copy of the GNU General Public License
22
 * along with this program; if not, write to the Free Software
23
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307,USA.
24
 *
25
 * For more information, contact:
26
 *
27
 *  Generalitat Valenciana
28
 *   Conselleria d'Infraestructures i Transport
29
 *   Av. Blasco Ib??ez, 50
30
 *   46010 VALENCIA
31
 *   SPAIN
32
 *
33
 *      +34 963862235
34
 *   gvsig@gva.es
35
 *      www.gvsig.gva.es
36
 *
37
 *    or
38
 *
39
 *   IVER T.I. S.A
40
 *   Salamanca 50
41
 *   46005 Valencia
42
 *   Spain
43
 *
44
 *   +34 963163400
45
 *   dac@iver.es
46
 */
47
package com.iver.cit.gvsig.fmap.rasterTools.saveRaster.operations;
48

    
49
import java.awt.Dimension;
50
import java.io.IOException;
51

    
52
import org.cresques.geo.ViewPortData;
53
import org.cresques.io.GeoRasterWriter;
54
import org.cresques.io.IDataWriter;
55
import org.cresques.px.Extent;
56

    
57
import com.iver.andami.PluginServices;
58
import com.iver.cit.gvsig.fmap.MapControl;
59
import com.iver.cit.gvsig.fmap.ViewPort;
60
import com.iver.cit.gvsig.fmap.layers.FLayers;
61
import com.iver.cit.gvsig.rasterTools.saveRaster.DriverProperties;
62
import com.iver.cit.gvsig.rasterTools.saveRaster.gui.ProgressSaveRasterDialog;
63

    
64
/**
65
 * Thread que se encarga de llamar a los writer para realizar la tarea
66
 * de salvado y/p compresi?n
67
 * @author Nacho Brodin <brodin_ign@gva.es>
68
 */
69
public class SaveRasterThread extends Thread{
70
                
71
        private GeoRasterWriter                                writer = null;
72
        
73
        private ProgressSaveRasterDialog         window = null;
74
        private FLayers                                         layers = null;
75
        private ViewPort                                        vp = null;
76
        private MapControl                                        mapCtrl = null;
77
        private Dimension                                         dimension = null;
78
        
79
        private String                                                 fName = "";
80
        private int                                                 sizeBlock = 64;
81
        private double[]                                        maxPercentBarList = new double[1];;
82
        private int                                                 compresion = 1;
83
        private DriverProperties                         driverProps = null;
84

    
85
                
86
        public SaveRasterThread(MapControl mapCtrl, 
87
                                                        FLayers layers, 
88
                                                        Dimension dimension, 
89
                                                        ViewPort vp, 
90
                                                        ProgressSaveRasterDialog window){
91
                this.window = window;
92
                this.layers = layers;
93
                this.mapCtrl = mapCtrl;
94
                this.dimension = dimension;
95
                this.vp = vp;
96
        }
97
                
98
        public void run(){
99
                
100
                //Creamos el servidor de datos de la vista
101
                RasterizerLayer p = new RasterizerLayer(layers, vp, sizeBlock, mapCtrl);
102
                
103
                //Asignamos la barra de progreso
104
                p.setProgressBar(window, maxPercentBarList[0]);
105
                
106
                //Creamos el driver
107
                Extent ex = new Extent(vp.getAdjustedExtent());
108
                Dimension imgSz = vp.getImageSize();
109
                ViewPortData vpData = new ViewPortData(vp.getProjection(), ex, imgSz );
110
                writer = GeoRasterWriter.getWriter((IDataWriter)p, fName, sizeBlock, 
111
                                                                                        3, vpData, compresion, dimension.width, dimension.height);
112
                
113
                //Si han sido modificadas las propiedades se asignan los valores modificados
114
                String[] prp = driverProps.getProperties(fName.toLowerCase().substring(fName.lastIndexOf(".") + 1)); 
115
                if(prp!=null)
116
                        writer.setProps(prp);
117
                
118
                //Ejecutamos el driver con los datos pasados
119
                try{
120
                        writer.dataWrite();
121
                        writer.writeClose(); 
122
                }catch(IOException ev){
123
                        ev.printStackTrace();
124
                }
125
                
126
                PluginServices.getMDIManager().closeView(this.window);
127
        }
128
        
129
        /**
130
         *Detiene la compresi?n
131
         */
132
        synchronized public void stopThread(){
133
                writer.writeCancel();
134
        }
135
        
136
        /**
137
         * Asigna el objeto que contiene las propiedades
138
         * @param driverProps
139
         */
140
        public void setProps(DriverProperties driverProps){
141
                this.driverProps = driverProps;
142
        }
143
        
144
        /**
145
         * Asigna el nombre del fichero
146
         * @param fName        Nombre del fichero
147
         */
148
        public void setFName(String fName){
149
                this.fName = fName;
150
        }
151
        
152
        /**
153
         * Asigna el GeoRasterWriter que se usar? para salvar
154
         * @param writer
155
         */
156
        public void setWriter(GeoRasterWriter writer){
157
                this.writer = writer;
158
        }
159
        
160
        /**
161
         * Asigna el tama?o de bloque que se lee de una sola vez desde el origen
162
         * Esto influye en la velocidad de escritura y depende de la memoria que 
163
         * tengamos disponible. Si disponemos de poca corremos el riesgo de que al
164
         * asignar un bloque muy grande nos de un error
165
         * @param sizeBlock Tama?o de bloque
166
         */
167
        public void setBlockSize(int sizeBlock){
168
                this.sizeBlock = sizeBlock;
169
        }
170
        
171
        /**
172
         * Asigna la compresi?n si el formato dispone de este par?metro
173
         * @param compresion Nivel de compresi?n
174
         */
175
        public void setCompresion(int compresion){
176
                this.compresion = compresion;
177
        }
178
}
179
        
180
        
181

    
182

    
183