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