root / tags / v1_0_2_Build_916 / extensions / extRasterTools / src / org / gvsig / rasterTools / saveRaster / operations / SaveRasterThread.java @ 12327
History | View | Annotate | Download (6 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 org.gvsig.rasterTools.saveRaster.operations; |
48 |
|
49 |
import java.awt.Dimension; |
50 |
import java.io.File; |
51 |
import java.io.IOException; |
52 |
|
53 |
import org.cresques.geo.ViewPortData; |
54 |
import org.cresques.io.GeoRasterWriter; |
55 |
import org.cresques.io.IDataWriter; |
56 |
import org.cresques.io.data.RasterBuf; |
57 |
import org.cresques.px.Extent; |
58 |
import org.gvsig.rasterTools.saveRaster.ui.info.EndInfoDialog; |
59 |
import org.gvsig.rasterTools.saveRaster.ui.properties.ProgressSaveRasterDialog; |
60 |
import org.gvsig.rasterTools.saveRaster.util.DriverProperties; |
61 |
|
62 |
import com.iver.andami.PluginServices; |
63 |
import com.iver.cit.gvsig.fmap.MapControl; |
64 |
import com.iver.cit.gvsig.fmap.ViewPort; |
65 |
import com.iver.cit.gvsig.fmap.layers.FLayers; |
66 |
|
67 |
/**
|
68 |
* Thread que se encarga de llamar a los writer para realizar la tarea
|
69 |
* de salvado y/p compresi?n
|
70 |
* @author Nacho Brodin <brodin_ign@gva.es>
|
71 |
*/
|
72 |
public class SaveRasterThread extends Thread{ |
73 |
|
74 |
private GeoRasterWriter writer = null; |
75 |
|
76 |
private ProgressSaveRasterDialog window = null; |
77 |
private FLayers layers = null; |
78 |
private ViewPort vp = null; |
79 |
private MapControl mapCtrl = null; |
80 |
private Dimension dimension = null; |
81 |
|
82 |
private String fName = ""; |
83 |
private int sizeBlock = GeoRasterWriter.blockSizeDefault; |
84 |
private double[] maxPercentBarList = new double[1];; |
85 |
private int compresion = 10; |
86 |
private DriverProperties driverProps = null; |
87 |
|
88 |
|
89 |
public SaveRasterThread(MapControl mapCtrl,
|
90 |
FLayers layers, |
91 |
Dimension dimension,
|
92 |
ViewPort vp, |
93 |
ProgressSaveRasterDialog window){ |
94 |
this.window = window;
|
95 |
this.layers = layers;
|
96 |
this.mapCtrl = mapCtrl;
|
97 |
this.dimension = dimension;
|
98 |
this.vp = vp;
|
99 |
} |
100 |
|
101 |
public void run(){ |
102 |
long t2;
|
103 |
long t1 = new java.util.Date().getTime(); |
104 |
|
105 |
//Creamos el servidor de datos de la vista
|
106 |
RasterizerLayer p = new RasterizerLayer(layers, vp, sizeBlock, mapCtrl, this); |
107 |
|
108 |
//Asignamos la barra de progreso
|
109 |
p.setProgressBar(window, maxPercentBarList[0]);
|
110 |
|
111 |
//Creamos el driver
|
112 |
Extent ex = new Extent(vp.getAdjustedExtent());
|
113 |
Dimension imgSz = vp.getImageSize();
|
114 |
ViewPortData vpData = new ViewPortData(vp.getProjection(), ex, imgSz );
|
115 |
writer = GeoRasterWriter.getWriter((IDataWriter)p, fName, sizeBlock, |
116 |
3, vpData, compresion, dimension.width,
|
117 |
dimension.height, RasterBuf.TYPE_IMAGE); |
118 |
|
119 |
//Si han sido modificadas las propiedades se asignan los valores modificados
|
120 |
String[] prp = driverProps.getProperties(fName.toLowerCase().substring(fName.lastIndexOf(".") + 1)); |
121 |
if(prp != null) |
122 |
writer.setProps(prp); |
123 |
|
124 |
//Ejecutamos el driver con los datos pasados
|
125 |
try{
|
126 |
writer.dataWrite(); |
127 |
writer.writeClose(); |
128 |
}catch(IOException ev){ |
129 |
return;
|
130 |
} |
131 |
|
132 |
t2 = new java.util.Date().getTime();
|
133 |
|
134 |
try{
|
135 |
this.setEndInfo(fName, (t2 - t1));
|
136 |
PluginServices.getMDIManager().closeWindow(this.window);
|
137 |
}catch(ArrayIndexOutOfBoundsException exc){ |
138 |
//Si la ventana se ha cerrado ya es porque ha sido cancelada por lo que
|
139 |
//producir? esta excepci?n. En este caso no se lanza la ventana de informaci?n
|
140 |
//de finalizaci?n.
|
141 |
} |
142 |
} |
143 |
|
144 |
private void setEndInfo(String fName, long milis){ |
145 |
EndInfoDialog info = new EndInfoDialog();
|
146 |
info.setFileName(" "+fName);
|
147 |
File f = new File(fName); |
148 |
info.setSize(f.length()); |
149 |
info.setTime(milis); |
150 |
if( fName.endsWith("ecw") || |
151 |
fName.endsWith("jp2") ||
|
152 |
fName.endsWith("jpg") ||
|
153 |
fName.endsWith("jpeg"))
|
154 |
info.setCompression(true);
|
155 |
else
|
156 |
info.setCompression(false);
|
157 |
PluginServices.getMDIManager().addWindow(info); |
158 |
} |
159 |
|
160 |
/**
|
161 |
*Detiene la compresi?n
|
162 |
*/
|
163 |
synchronized public void stopThread(){ |
164 |
if(writer != null) |
165 |
writer.writeCancel(); |
166 |
} |
167 |
|
168 |
/**
|
169 |
* Asigna el objeto que contiene las propiedades
|
170 |
* @param driverProps
|
171 |
*/
|
172 |
public void setProps(DriverProperties driverProps){ |
173 |
this.driverProps = driverProps;
|
174 |
} |
175 |
|
176 |
/**
|
177 |
* Asigna el nombre del fichero
|
178 |
* @param fName Nombre del fichero
|
179 |
*/
|
180 |
public void setFName(String fName){ |
181 |
this.fName = fName;
|
182 |
} |
183 |
|
184 |
/**
|
185 |
* Asigna el GeoRasterWriter que se usar? para salvar
|
186 |
* @param writer
|
187 |
*/
|
188 |
public void setWriter(GeoRasterWriter writer){ |
189 |
this.writer = writer;
|
190 |
} |
191 |
|
192 |
/**
|
193 |
* Asigna el tama?o de bloque que se lee de una sola vez desde el origen
|
194 |
* Esto influye en la velocidad de escritura y depende de la memoria que
|
195 |
* tengamos disponible. Si disponemos de poca corremos el riesgo de que al
|
196 |
* asignar un bloque muy grande nos de un error
|
197 |
* @param sizeBlock Tama?o de bloque
|
198 |
*/
|
199 |
public void setBlockSize(int sizeBlock){ |
200 |
this.sizeBlock = sizeBlock;
|
201 |
} |
202 |
|
203 |
/**
|
204 |
* Asigna la compresi?n si el formato dispone de este par?metro
|
205 |
* @param compresion Nivel de compresi?n
|
206 |
*/
|
207 |
public void setCompresion(int compresion){ |
208 |
this.compresion = compresion;
|
209 |
} |
210 |
} |
211 |
|
212 |
|
213 |
|
214 |
|
215 |
|