Revision 7256
org.gvsig.raster.tools/tags/org.gvsig.raster.tools-2.2.50/org.gvsig.raster.tools.app.basic/buildNumber.properties | ||
---|---|---|
1 |
#Thu Jun 15 08:09:26 CEST 2017 |
|
2 |
buildNumber=101 |
|
0 | 3 |
org.gvsig.raster.tools/tags/org.gvsig.raster.tools-2.2.50/org.gvsig.raster.tools.app.basic/src/main/assembly/gvsig-plugin-package.xml | ||
---|---|---|
1 |
<assembly> |
|
2 |
<id>gvsig-plugin-package</id> |
|
3 |
<formats> |
|
4 |
<format>zip</format> |
|
5 |
</formats> |
|
6 |
<baseDirectory>${project.artifactId}</baseDirectory> |
|
7 |
<includeBaseDirectory>true</includeBaseDirectory> |
|
8 |
<files> |
|
9 |
<file> |
|
10 |
<source>target/${project.artifactId}-${project.version}.jar</source> |
|
11 |
<outputDirectory>lib</outputDirectory> |
|
12 |
</file> |
|
13 |
<file> |
|
14 |
<source>target/package.info</source> |
|
15 |
</file> |
|
16 |
</files> |
|
17 |
|
|
18 |
<fileSets> |
|
19 |
<fileSet> |
|
20 |
<directory>src/main/resources-plugin</directory> |
|
21 |
<outputDirectory>.</outputDirectory> |
|
22 |
</fileSet> |
|
23 |
</fileSets> |
|
24 |
|
|
25 |
|
|
26 |
<dependencySets> |
|
27 |
<dependencySet> |
|
28 |
<useProjectArtifact>false</useProjectArtifact> |
|
29 |
<useTransitiveDependencies>false</useTransitiveDependencies> |
|
30 |
<outputDirectory>lib</outputDirectory> |
|
31 |
<includes> |
|
32 |
<include>org.gvsig:org.gvsig.raster.tools.app.basic:jar</include> |
|
33 |
<include>org.gvsig:org.gvsig.raster.tools.algorithm.layerdatatype:jar</include> |
|
34 |
<include>org.gvsig:org.gvsig.raster.tools.algorithm.saveraster:jar</include> |
|
35 |
<include>org.gvsig:org.gvsig.raster.tools.algorithm.swing.api:jar</include> |
|
36 |
<include>org.gvsig:org.gvsig.raster.tools.algorithm.swing.impl:jar</include> |
|
37 |
<include>org.gvsig:org.gvsig.raster.tools.toolbox.algorithm:jar</include> |
|
38 |
</includes> |
|
39 |
</dependencySet> |
|
40 |
</dependencySets> |
|
41 |
</assembly> |
|
0 | 42 |
org.gvsig.raster.tools/tags/org.gvsig.raster.tools-2.2.50/org.gvsig.raster.tools.app.basic/src/main/java/org/gvsig/raster/tools/app/basic/raster/process/ClippingProcess.java | ||
---|---|---|
1 |
/* gvSIG. Geographic Information System of the Valencian Government |
|
2 |
* |
|
3 |
* Copyright (C) 2007-2008 Infrastructures and Transports Department |
|
4 |
* of the Valencian Government (CIT) |
|
5 |
* |
|
6 |
* This program is free software; you can redistribute it and/or |
|
7 |
* modify it under the terms of the GNU General Public License |
|
8 |
* as published by the Free Software Foundation; either version 2 |
|
9 |
* of the License, or (at your option) any later version. |
|
10 |
* |
|
11 |
* This program is distributed in the hope that it will be useful, |
|
12 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
13 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
14 |
* GNU General Public License for more details. |
|
15 |
* |
|
16 |
* You should have received a copy of the GNU General Public License |
|
17 |
* along with this program; if not, write to the Free Software |
|
18 |
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, |
|
19 |
* MA 02110-1301, USA. |
|
20 |
* |
|
21 |
*/ |
|
22 |
package org.gvsig.raster.tools.app.basic.raster.process; |
|
23 |
|
|
24 |
import java.awt.Rectangle; |
|
25 |
import java.awt.geom.AffineTransform; |
|
26 |
import java.awt.geom.Point2D; |
|
27 |
import java.io.File; |
|
28 |
import java.io.IOException; |
|
29 |
import java.util.ArrayList; |
|
30 |
import java.util.List; |
|
31 |
|
|
32 |
import org.cresques.cts.IProjection; |
|
33 |
import org.gvsig.app.project.ProjectManager; |
|
34 |
import org.gvsig.app.project.documents.Document; |
|
35 |
import org.gvsig.app.project.documents.view.BaseViewDocument; |
|
36 |
import org.gvsig.fmap.dal.DALLocator; |
|
37 |
import org.gvsig.fmap.dal.DataManager; |
|
38 |
import org.gvsig.fmap.dal.DataServerExplorer; |
|
39 |
import org.gvsig.fmap.dal.DataServerExplorerParameters; |
|
40 |
import org.gvsig.fmap.dal.coverage.RasterLibrary; |
|
41 |
import org.gvsig.fmap.dal.coverage.RasterLocator; |
|
42 |
import org.gvsig.fmap.dal.coverage.RasterManager; |
|
43 |
import org.gvsig.fmap.dal.coverage.dataset.Buffer; |
|
44 |
import org.gvsig.fmap.dal.coverage.datastruct.Extent; |
|
45 |
import org.gvsig.fmap.dal.coverage.datastruct.NoData; |
|
46 |
import org.gvsig.fmap.dal.coverage.datastruct.Params; |
|
47 |
import org.gvsig.fmap.dal.coverage.exception.NotSupportedExtensionException; |
|
48 |
import org.gvsig.fmap.dal.coverage.exception.ProcessInterruptedException; |
|
49 |
import org.gvsig.fmap.dal.coverage.exception.QueryException; |
|
50 |
import org.gvsig.fmap.dal.coverage.exception.ROIException; |
|
51 |
import org.gvsig.fmap.dal.coverage.exception.RasterDriverException; |
|
52 |
import org.gvsig.fmap.dal.coverage.exception.RmfSerializerException; |
|
53 |
import org.gvsig.fmap.dal.coverage.process.BaseIncrementableTask; |
|
54 |
import org.gvsig.fmap.dal.coverage.store.DataServerWriter; |
|
55 |
import org.gvsig.fmap.dal.coverage.store.RasterDataStore; |
|
56 |
import org.gvsig.fmap.dal.coverage.store.RasterQuery; |
|
57 |
import org.gvsig.fmap.dal.coverage.store.parameter.NewRasterStoreParameters; |
|
58 |
import org.gvsig.fmap.dal.coverage.store.parameter.RemoteStoreParameters; |
|
59 |
import org.gvsig.fmap.dal.coverage.store.props.ColorInterpretation; |
|
60 |
import org.gvsig.fmap.dal.coverage.store.props.ColorTable; |
|
61 |
import org.gvsig.fmap.dal.coverage.util.RasterUtils; |
|
62 |
import org.gvsig.fmap.dal.exception.CloseException; |
|
63 |
import org.gvsig.fmap.dal.exception.DataException; |
|
64 |
import org.gvsig.fmap.dal.exception.InitializeException; |
|
65 |
import org.gvsig.fmap.dal.exception.ProviderNotRegisteredException; |
|
66 |
import org.gvsig.fmap.dal.exception.ValidateDataParametersException; |
|
67 |
import org.gvsig.fmap.mapcontext.layers.FLayer; |
|
68 |
import org.gvsig.fmap.mapcontext.layers.FLayers; |
|
69 |
import org.gvsig.i18n.Messages; |
|
70 |
import org.gvsig.raster.algorithm.process.DataProcess; |
|
71 |
import org.gvsig.raster.fmap.layers.DefaultFLyrRaster; |
|
72 |
import org.gvsig.raster.mainplugin.RasterMainPluginUtils; |
|
73 |
import org.gvsig.raster.roi.ROI; |
|
74 |
import org.gvsig.raster.swing.RasterSwingLibrary; |
|
75 |
import org.gvsig.raster.util.RasterNotLoadException; |
|
76 |
import org.slf4j.LoggerFactory; |
|
77 |
/** |
|
78 |
* <code>ClippingProcess</code> es un proceso que usa un <code>Thread</code> |
|
79 |
* para aplicar un recorte a una capa y guardarlo en disco. Muestra una barra |
|
80 |
* de incremento informativa. |
|
81 |
* |
|
82 |
* @author BorSanZa - Borja S?nchez Zamorano |
|
83 |
*/ |
|
84 |
public class ClippingProcess extends DataProcess { |
|
85 |
public static final String PROCESS_LABEL = "ClippingProcess"; |
|
86 |
public static String FILENAME = "filename"; |
|
87 |
public static String SUFFIX = "suffix"; |
|
88 |
public static String VIEWNAME = "viewname"; |
|
89 |
public static String PX_COORDS = "pixelcoordinates"; |
|
90 |
public static String WORLD_COORDS = "realcoordinates"; |
|
91 |
public static String RASTER_STORE = "layer"; |
|
92 |
public static String DRAWABLE_BANDS = "drawablebands"; |
|
93 |
public static String ONE_LYE_PER_BAND = "onelayerperband"; |
|
94 |
public static String INTERP_METHOD = "interpolationmethod"; |
|
95 |
public static String AT = "affinetransform"; |
|
96 |
public static String COLOR_INTERPR = "colorInterpretation"; |
|
97 |
public static String SELECTED_ROIS = "selectedrois"; |
|
98 |
public static String RESOLUTION = "resolution"; |
|
99 |
public static String DRIVER_PARAMS = "driverparams"; |
|
100 |
public static String VIEW_PROJ = "viewProjection"; |
|
101 |
|
|
102 |
private String fileName = ""; |
|
103 |
private String suffix = ".tif"; |
|
104 |
private RasterDataStore dataStore = null; |
|
105 |
private boolean oneLayerPerBand = false; |
|
106 |
private int[] drawableBands = { 0, 1, 2 }; |
|
107 |
private double[] pValues = null; |
|
108 |
private int interpolationMethod = Buffer.INTERPOLATION_Undefined; |
|
109 |
private String viewName = ""; |
|
110 |
private Params params = null; |
|
111 |
private ColorInterpretation colorInterp = null; |
|
112 |
private ArrayList<ROI> selectedRois = null; |
|
113 |
private AffineTransform affineTransform = null; |
|
114 |
private double[] wcValues = null; |
|
115 |
private RasterManager rManager = RasterLocator.getManager(); |
|
116 |
private BaseIncrementableTask processIncrement = null; |
|
117 |
|
|
118 |
/** |
|
119 |
* Variables de la resoluci?n de salida |
|
120 |
*/ |
|
121 |
private int resolutionWidth = 0; |
|
122 |
private int resolutionHeight = 0; |
|
123 |
|
|
124 |
private Buffer buffer = null; |
|
125 |
private IProjection viewProjection = null; |
|
126 |
|
|
127 |
public static void registerParameters() { |
|
128 |
registerInputParameter(FILENAME, String.class, PROCESS_LABEL); |
|
129 |
registerInputParameter(SUFFIX, String.class, PROCESS_LABEL); |
|
130 |
registerInputParameter(VIEWNAME, String.class, PROCESS_LABEL); |
|
131 |
registerInputParameter(PX_COORDS, Double.class, PROCESS_LABEL); |
|
132 |
registerInputParameter(WORLD_COORDS, Double.class, PROCESS_LABEL); |
|
133 |
registerInputParameter(RASTER_STORE, RasterDataStore.class, PROCESS_LABEL); |
|
134 |
registerInputParameter(DRAWABLE_BANDS, Integer[].class, PROCESS_LABEL); |
|
135 |
registerInputParameter(ONE_LYE_PER_BAND, Boolean.class, PROCESS_LABEL); |
|
136 |
registerInputParameter(INTERP_METHOD, Integer.class, PROCESS_LABEL); |
|
137 |
registerInputParameter(AT, AffineTransform.class, PROCESS_LABEL); |
|
138 |
registerInputParameter(COLOR_INTERPR, ColorInterpretation.class, PROCESS_LABEL); |
|
139 |
registerInputParameter(SELECTED_ROIS, ArrayList.class, PROCESS_LABEL); |
|
140 |
registerInputParameter(RESOLUTION, Integer[].class, PROCESS_LABEL); |
|
141 |
registerInputParameter(DRIVER_PARAMS, Params.class, PROCESS_LABEL); |
|
142 |
registerInputParameter(VIEW_PROJ, IProjection.class, PROCESS_LABEL); |
|
143 |
|
|
144 |
//TODO: Falta definir salidas y asignarlas en el Map |
|
145 |
registerOutputParameter(FILENAME, String.class, PROCESS_LABEL); |
|
146 |
} |
|
147 |
|
|
148 |
/** |
|
149 |
* Par?metros obligatorios al proceso: |
|
150 |
* <UL> |
|
151 |
* <LI>filename: Nombre del fichero de salida</LI> |
|
152 |
* <LI>datawriter: Escritor de datos</LI> |
|
153 |
* <LI>viewname: Nombre de la vista sobre la que se carga la capa al acabar el proceso</LI> |
|
154 |
* <LI>pixelcoordinates: Coordenadas pixel del recorte (ulx, uly, lrx, lry)</LI> |
|
155 |
* <LI>layer: Capa de entrada para el recorte</LI> |
|
156 |
* <LI>drawablebands: Bandas de entrada</LI> |
|
157 |
* <LI>onelayerperband: booleano que informa de si escribimos una banda por fichero de salida o todas en un fichero</LI> |
|
158 |
* <LI>interpolationmethod: M?todo de interpolaci?n.</LI> |
|
159 |
* <LI>affinetransform: Transformaci?n que informa al dataset de salida de su referencia geografica</LI> |
|
160 |
* <LI>resolution: Ancho y alto de la capa de salida</LI> |
|
161 |
* </UL> |
|
162 |
*/ |
|
163 |
@SuppressWarnings("unchecked") |
|
164 |
public void init() { |
|
165 |
fileName = getStringParam("filename"); |
|
166 |
suffix = getStringParam("suffix"); |
|
167 |
viewName = getStringParam("viewname"); |
|
168 |
pValues = getDoubleArrayParam("pixelcoordinates"); |
|
169 |
wcValues = getDoubleArrayParam("realcoordinates"); |
|
170 |
dataStore = getParam("layer") != null ? (RasterDataStore)getParam("layer") : null; |
|
171 |
drawableBands = getIntArrayParam("drawablebands"); |
|
172 |
oneLayerPerBand = getBooleanParam("onelayerperband"); |
|
173 |
interpolationMethod = getIntParam("interpolationmethod"); |
|
174 |
affineTransform = (AffineTransform)getParam("affinetransform"); |
|
175 |
colorInterp = (ColorInterpretation)getParam("colorInterpretation"); |
|
176 |
selectedRois = (ArrayList<ROI>)getParam("selectedrois"); |
|
177 |
if(getIntArrayParam("resolution") != null) { |
|
178 |
resolutionWidth = getIntArrayParam("resolution")[0]; |
|
179 |
resolutionHeight = getIntArrayParam("resolution")[1]; |
|
180 |
} |
|
181 |
params = (Params) getParam("driverparams"); |
|
182 |
viewProjection = getParam("viewProjection") != null ? (IProjection)getParam("viewProjection") : null; |
|
183 |
} |
|
184 |
|
|
185 |
/** |
|
186 |
* Salva la tabla de color al fichero rmf. |
|
187 |
* @param fName |
|
188 |
* @throws IOException |
|
189 |
*/ |
|
190 |
private void saveToRmf(String fileName) { |
|
191 |
int limitNumberOfRequests = 20; |
|
192 |
while (dataStore == null && limitNumberOfRequests > 0) { |
|
193 |
try { |
|
194 |
} catch (IndexOutOfBoundsException e) { |
|
195 |
//En ocasiones, sobre todo con servicios remotos al pedir un datasource da una excepci?n de este tipo |
|
196 |
//se supone que es porque hay un refresco en el mismo momento de la petici?n por lo que como es m?s lento de |
|
197 |
//gestionar pilla a la capa sin datasources asociados ya que est? reasignandolo. Si volvemos a pedirlo debe |
|
198 |
//haberlo cargado ya. |
|
199 |
try { |
|
200 |
Thread.sleep(200); |
|
201 |
} catch (InterruptedException e1) { |
|
202 |
} |
|
203 |
} |
|
204 |
limitNumberOfRequests--; |
|
205 |
} |
|
206 |
|
|
207 |
if (dataStore == null) { |
|
208 |
//RasterToolsUtil.messageBoxError("error_load_layer", this, new Exception("Error writing RMF. limitNumberOfRequests=" + limitNumberOfRequests)); |
|
209 |
return; |
|
210 |
} |
|
211 |
|
|
212 |
// Guardamos en el RMF el valor NoData |
|
213 |
if(dataStore.getNoDataValue() != null) { |
|
214 |
NoData nodata = (NoData)dataStore.getNoDataValue(); |
|
215 |
nodata.setFileName(fileName); |
|
216 |
nodata.save(); |
|
217 |
} |
|
218 |
|
|
219 |
// Guardamos en el RMF la tabla de color |
|
220 |
ColorTable colorTable = dataStore.getColorTable(); |
|
221 |
try { |
|
222 |
rManager.getProviderServices().saveObjectToRmfFile(fileName, ColorTable.class, colorTable); |
|
223 |
} catch (RmfSerializerException e) { |
|
224 |
RasterSwingLibrary.messageBoxError("error_salvando_rmf", this, e); |
|
225 |
} |
|
226 |
} |
|
227 |
|
|
228 |
/** |
|
229 |
* Tarea de recorte |
|
230 |
*/ |
|
231 |
@SuppressWarnings("deprecation") |
|
232 |
public void process() throws ProcessInterruptedException { |
|
233 |
RasterDataStore dstoreCopy = null; |
|
234 |
RasterUtils util = RasterLocator.getManager().getRasterUtils(); |
|
235 |
|
|
236 |
try { |
|
237 |
long t2; |
|
238 |
long t1 = new java.util.Date().getTime(); |
|
239 |
|
|
240 |
try { |
|
241 |
Thread.sleep(1000); |
|
242 |
} catch (InterruptedException e1) { |
|
243 |
e1.printStackTrace(); |
|
244 |
} |
|
245 |
|
|
246 |
insertLineLog(Messages.getText("leyendo_raster")); |
|
247 |
|
|
248 |
dstoreCopy = dataStore.newNotTiledDataStore(); |
|
249 |
RasterQuery query = rManager.createQuery(); |
|
250 |
query.setDrawableBands(drawableBands); |
|
251 |
|
|
252 |
if(dstoreCopy.getParameters() instanceof RemoteStoreParameters && |
|
253 |
!((RemoteStoreParameters)dstoreCopy.getParameters()).isSizeFixed()) { |
|
254 |
insertLineLog(Messages.getText("downloading_image")); |
|
255 |
((RemoteStoreParameters)dstoreCopy.getParameters()).setWidth(resolutionWidth); |
|
256 |
((RemoteStoreParameters)dstoreCopy.getParameters()).setHeight(resolutionHeight); |
|
257 |
Extent bbox = RasterLocator.getManager().getDataStructFactory().createExtent(wcValues[0], wcValues[1], wcValues[2], wcValues[3]); |
|
258 |
query.setAreaOfInterest(bbox, resolutionWidth, resolutionHeight); |
|
259 |
try { |
|
260 |
buffer = dstoreCopy.query(query); |
|
261 |
} catch (QueryException e) { |
|
262 |
RasterSwingLibrary.messageBoxError("No se ha podido asignar la vista al inicial el proceso de recorte.", this, e); |
|
263 |
} |
|
264 |
} else { |
|
265 |
if(interpolationMethod != Buffer.INTERPOLATION_Undefined) { |
|
266 |
try { |
|
267 |
if(pValues != null) { |
|
268 |
if (util.isBufferTooBig(new double[] { pValues[0], pValues[3], pValues[2], pValues[1] }, drawableBands.length)) |
|
269 |
query.setReadOnly(true); |
|
270 |
Rectangle r = new Rectangle((int)pValues[0], (int)pValues[1], (int)Math.abs(pValues[2] - pValues[0]) + 1, (int)Math.abs(pValues[3] - pValues[1]) + 1); |
|
271 |
query.setAreaOfInterest(r); |
|
272 |
} else if(wcValues != null) { |
|
273 |
query.setReadOnly(true); |
|
274 |
Extent e = RasterLocator.getManager().getDataStructFactory().createExtent( |
|
275 |
wcValues[0], wcValues[1], wcValues[2], wcValues[3]); |
|
276 |
query.setAreaOfInterest(e); |
|
277 |
//query.setAreaOfInterest(wcValues[0], wcValues[1], Math.abs(wcValues[0] - wcValues[2]), Math.abs(wcValues[1] - wcValues[3])); |
|
278 |
} |
|
279 |
buffer = dstoreCopy.query(query); |
|
280 |
} catch (QueryException e) { |
|
281 |
RasterSwingLibrary.messageBoxError("No se ha podido asignar la vista al inicial el proceso de recorte.", this, e); |
|
282 |
} |
|
283 |
|
|
284 |
insertLineLog(Messages.getText("interpolando")); |
|
285 |
|
|
286 |
Buffer bufTmp = buffer; |
|
287 |
processIncrement = bufTmp.getIncrementableTask(Buffer.INCREMENTABLE_INTERPOLATION); |
|
288 |
buffer = bufTmp.getAdjustedWindow(resolutionWidth, resolutionHeight, interpolationMethod); |
|
289 |
if(bufTmp != buffer) |
|
290 |
bufTmp.dispose(); |
|
291 |
} else { |
|
292 |
try { |
|
293 |
if (util.isBufferTooBig(new double[] { 0, 0, resolutionWidth, resolutionHeight }, drawableBands.length)) |
|
294 |
query.setReadOnly(true); |
|
295 |
if(pValues != null) { |
|
296 |
Rectangle r = new Rectangle( |
|
297 |
(int)pValues[0], |
|
298 |
(int)pValues[3], |
|
299 |
(int)Math.abs(pValues[2] - pValues[0]) + 1, |
|
300 |
(int)Math.abs(pValues[1] - pValues[3]) + 1); |
|
301 |
query.setAreaOfInterest(r, resolutionWidth, resolutionHeight); |
|
302 |
} |
|
303 |
else if(wcValues != null) { |
|
304 |
Extent bbox = RasterLocator.getManager().getDataStructFactory().createExtent(wcValues[0], wcValues[1], wcValues[2], wcValues[3]); |
|
305 |
query.setAreaOfInterest(bbox, resolutionWidth, resolutionHeight); |
|
306 |
} |
|
307 |
buffer = dstoreCopy.query(query); |
|
308 |
} catch (QueryException e) { |
|
309 |
RasterSwingLibrary.messageBoxError("No se ha podido asignar la vista al inicial el proceso de recorte.", this, e); |
|
310 |
} |
|
311 |
} |
|
312 |
} |
|
313 |
|
|
314 |
//TODO: FUNCIONALIDAD: Poner los getWriter con la proyecci?n del fichero fuente |
|
315 |
|
|
316 |
if ((selectedRois != null) && (!query.isReadOnly())){ |
|
317 |
if (selectedRois.size() > 0){ |
|
318 |
int despX = 0; |
|
319 |
int despY = 0; |
|
320 |
if (pValues != null){ |
|
321 |
despX = (int)pValues[0]; |
|
322 |
despY = (int)pValues[1]; |
|
323 |
} else if (wcValues != null){ |
|
324 |
despX = (int)dstoreCopy.worldToRaster(new Point2D.Double(wcValues[0], wcValues[1])).getX(); |
|
325 |
despY = (int)dstoreCopy.worldToRaster(new Point2D.Double(wcValues[0], wcValues[1])).getY(); |
|
326 |
} |
|
327 |
drawOnlyROIs(buffer, selectedRois, despX, despY); |
|
328 |
} |
|
329 |
} |
|
330 |
|
|
331 |
|
|
332 |
insertLineLog(Messages.getText("salvando_imagen")); |
|
333 |
|
|
334 |
DataManager manager = DALLocator.getDataManager(); |
|
335 |
String provider = "Gdal Store"; |
|
336 |
DataServerExplorerParameters eparams = manager.createServerExplorerParameters("FilesystemExplorer"); |
|
337 |
|
|
338 |
String finalFileName = ""; |
|
339 |
NewRasterStoreParameters sparams = null; |
|
340 |
processIncrement = RasterLocator.getManager().createDataServerWriter(); |
|
341 |
if (oneLayerPerBand) { |
|
342 |
long[] milis = new long[drawableBands.length]; |
|
343 |
String[] fileNames = new String[drawableBands.length]; |
|
344 |
for (int i = 0; i < drawableBands.length; i++) { |
|
345 |
fileNames[i] = fileName + "_B" + drawableBands[i] + suffix; |
|
346 |
|
|
347 |
int index = fileNames[i].lastIndexOf(File.separator); |
|
348 |
if(index < 0) |
|
349 |
index = fileNames[i].length(); |
|
350 |
String path = fileNames[i].substring(0, index); |
|
351 |
String file = fileNames[i].substring(index + 1, fileNames[i].length()); |
|
352 |
|
|
353 |
eparams.setDynValue("initialpath", path); |
|
354 |
DataServerExplorer serverExplorer = manager.openServerExplorer(eparams.getExplorerName(), eparams); |
|
355 |
|
|
356 |
sparams = (NewRasterStoreParameters)serverExplorer.getAddParameters(provider); |
|
357 |
sparams.setDataServer((DataServerWriter)processIncrement); |
|
358 |
sparams.setDestination(path, file); |
|
359 |
sparams.setBuffer(buffer); |
|
360 |
sparams.setColorInterpretation(new String[]{ColorInterpretation.GRAY_BAND}); |
|
361 |
sparams.setWktProjection(dstoreCopy.getWktProjection()); |
|
362 |
sparams.setBand(i); |
|
363 |
sparams.setAffineTransform(affineTransform); |
|
364 |
sparams.setDriverParams(params); |
|
365 |
|
|
366 |
serverExplorer.add(provider, sparams, true); |
|
367 |
|
|
368 |
saveToRmf(fileNames[i]); |
|
369 |
t2 = new java.util.Date().getTime(); |
|
370 |
milis[i] = (t2 - t1); |
|
371 |
t1 = new java.util.Date().getTime(); |
|
372 |
} |
|
373 |
if (incrementableTask != null) { |
|
374 |
incrementableTask.processFinalize(); |
|
375 |
incrementableTask = null; |
|
376 |
} |
|
377 |
if(viewName != null) { |
|
378 |
if (RasterSwingLibrary.messageBoxYesOrNot("cargar_toc", this)) { |
|
379 |
try { |
|
380 |
for (int i = 0; i < drawableBands.length; i++) { |
|
381 |
FLayer lyr = RasterMainPluginUtils.loadLayer(viewName, fileNames[i], null); |
|
382 |
if(lyr != null && lyr instanceof DefaultFLyrRaster) { |
|
383 |
if(dataStore.getProjection() != null) |
|
384 |
((DefaultFLyrRaster)lyr).setRois(dataStore.getRois(dataStore.getProjection())); |
|
385 |
else |
|
386 |
((DefaultFLyrRaster)lyr).setRois(dataStore.getRois(viewProjection)); |
|
387 |
} |
|
388 |
} |
|
389 |
} catch (RasterNotLoadException e) { |
|
390 |
RasterSwingLibrary.messageBoxError("error_load_layer", this, e); |
|
391 |
} |
|
392 |
} |
|
393 |
} |
|
394 |
for (int i = 0; i < drawableBands.length; i++) { |
|
395 |
if (externalActions != null) |
|
396 |
externalActions.end(new Object[] { fileName + "_B" + drawableBands[i] + suffix, new Long(milis[i]) }); |
|
397 |
} |
|
398 |
} else { |
|
399 |
if (isUsingFile(fileName)) { |
|
400 |
incrementableTask.hideWindow(); |
|
401 |
RasterSwingLibrary.messageBoxError("error_opened_file", this); |
|
402 |
return; |
|
403 |
} |
|
404 |
File f = new File(fileName); |
|
405 |
if (f.exists()) { |
|
406 |
f.delete(); |
|
407 |
} |
|
408 |
f = null; |
|
409 |
|
|
410 |
if(suffix != null) |
|
411 |
finalFileName = fileName.endsWith(suffix) ? fileName : fileName + suffix; |
|
412 |
else |
|
413 |
finalFileName = fileName; |
|
414 |
|
|
415 |
int index = finalFileName.lastIndexOf(File.separator); |
|
416 |
if(index < 0) |
|
417 |
index = finalFileName.length(); |
|
418 |
String path = finalFileName.substring(0, index); |
|
419 |
String file = finalFileName.substring(index + 1, finalFileName.length()); |
|
420 |
|
|
421 |
eparams.setDynValue("initialpath", path); |
|
422 |
DataServerExplorer serverExplorer = manager.openServerExplorer(eparams.getExplorerName(), eparams); |
|
423 |
|
|
424 |
try { |
|
425 |
provider = rManager.createWriter(finalFileName).getProviderName(); |
|
426 |
} catch (NotSupportedExtensionException e1) { |
|
427 |
RasterSwingLibrary.messageBoxError("no_driver_escritura", this, e1); |
|
428 |
} catch (RasterDriverException e1) { |
|
429 |
RasterSwingLibrary.messageBoxError("no_driver_escritura", this, e1); |
|
430 |
} |
|
431 |
|
|
432 |
sparams = (NewRasterStoreParameters)serverExplorer.getAddParameters(provider); |
|
433 |
sparams.setDataServer((DataServerWriter)processIncrement); |
|
434 |
sparams.setDestination(path, file); |
|
435 |
sparams.setBuffer(buffer); |
|
436 |
if(colorInterp != null) |
|
437 |
sparams.setColorInterpretation(colorInterp.getValues()); |
|
438 |
sparams.setWktProjection(dstoreCopy.getWktProjection()); |
|
439 |
sparams.setAffineTransform(affineTransform); |
|
440 |
sparams.setDriverParams(params); |
|
441 |
sparams.setBand(-1); |
|
442 |
|
|
443 |
serverExplorer.add(provider, sparams, true); |
|
444 |
|
|
445 |
saveToRmf(finalFileName); |
|
446 |
|
|
447 |
|
|
448 |
t2 = new java.util.Date().getTime(); |
|
449 |
if (incrementableTask != null) { |
|
450 |
incrementableTask.processFinalize(); |
|
451 |
incrementableTask = null; |
|
452 |
} |
|
453 |
//Damos tiempo a parar el Thread del incrementable para que no se cuelgue la ventana |
|
454 |
//El tiempo es como m?nimo el de un bucle del run de la tarea incrementable |
|
455 |
try { |
|
456 |
Thread.sleep(600); |
|
457 |
} catch (InterruptedException e) { |
|
458 |
throw new ProcessInterruptedException(e); |
|
459 |
} |
|
460 |
cutFinalize(finalFileName, (t2 - t1)); |
|
461 |
} |
|
462 |
|
|
463 |
} catch (RasterDriverException e) { |
|
464 |
RasterSwingLibrary.messageBoxError("error_writer", this, e); |
|
465 |
} catch (ValidateDataParametersException e) { |
|
466 |
RasterSwingLibrary.messageBoxError("error_georasterwriter", this); |
|
467 |
} catch (ProviderNotRegisteredException e) { |
|
468 |
RasterSwingLibrary.messageBoxError("error_georasterwriter", this, e); |
|
469 |
} catch (InitializeException e) { |
|
470 |
RasterSwingLibrary.messageBoxError("error_georasterwriter", this, e); |
|
471 |
} catch (DataException e) { |
|
472 |
RasterSwingLibrary.messageBoxError("error_georasterwriter", this, e); |
|
473 |
} catch (Exception e) { |
|
474 |
e.printStackTrace(); |
|
475 |
} finally { |
|
476 |
if (dstoreCopy != null) |
|
477 |
try { |
|
478 |
dstoreCopy.close(); |
|
479 |
} catch (CloseException e) { |
|
480 |
LoggerFactory.getLogger(ClippingProcess.class).debug(Messages.getText("error_writer"), e); |
|
481 |
} |
|
482 |
buffer = null; |
|
483 |
} |
|
484 |
} |
|
485 |
|
|
486 |
|
|
487 |
/** |
|
488 |
* Acciones para poner a NoData los pixels que est?n fuera de las |
|
489 |
* regiones de inter?s seleccionadas. |
|
490 |
* @param buffer |
|
491 |
*/ |
|
492 |
private void drawOnlyROIs(Buffer buffer, List<ROI> rois, int despX, int despY){ |
|
493 |
for (int i = 0 ; i < buffer.getWidth() ; i++){ |
|
494 |
for (int j = 0 ; j < buffer.getHeight() ; j++){ |
|
495 |
boolean inside = false; |
|
496 |
for (int k = 0 ; k < rois.size() ; k++){ |
|
497 |
ROI roi = rois.get(k); |
|
498 |
//TODO: Hacer la comprobacion por coordenadas del mundo en lugar de coordenadas pixel. |
|
499 |
if (roi.isInsideOfPolygon(i + despX, j + despY)){ |
|
500 |
inside = true; |
|
501 |
} |
|
502 |
} |
|
503 |
if (!inside){ |
|
504 |
for (int l = 0 ; l < buffer.getBandCount() ; l++){ |
|
505 |
if (buffer.getDataType() == Buffer.TYPE_BYTE){ |
|
506 |
buffer.setElem(j, i, l, |
|
507 |
buffer.getNoDataValue().isDefined() ? buffer.getNoDataValue().getValue().byteValue() : RasterLibrary.defaultByteNoDataValue); |
|
508 |
} else if (buffer.getDataType() == Buffer.TYPE_SHORT){ |
|
509 |
buffer.setElem(j, i, l, |
|
510 |
buffer.getNoDataValue().isDefined() ? buffer.getNoDataValue().getValue().shortValue() : RasterLibrary.defaultShortNoDataValue); |
|
511 |
} else if (buffer.getDataType() == Buffer.TYPE_INT){ |
|
512 |
buffer.setElem(j, i, l, |
|
513 |
buffer.getNoDataValue().isDefined() ? buffer.getNoDataValue().getValue().intValue() : RasterLibrary.defaultIntegerNoDataValue); |
|
514 |
} else if (buffer.getDataType() == Buffer.TYPE_FLOAT){ |
|
515 |
buffer.setElem(j, i, l, |
|
516 |
buffer.getNoDataValue().isDefined() ? buffer.getNoDataValue().getValue().floatValue() : RasterLibrary.defaultFloatNoDataValue); |
|
517 |
} else if (buffer.getDataType() == Buffer.TYPE_DOUBLE){ |
|
518 |
buffer.setElem(j, i, l, |
|
519 |
buffer.getNoDataValue().isDefined() ? buffer.getNoDataValue().getValue().doubleValue() : RasterLibrary.defaultDoubleNoDataValue); |
|
520 |
} |
|
521 |
} |
|
522 |
} |
|
523 |
} |
|
524 |
} |
|
525 |
} |
|
526 |
|
|
527 |
|
|
528 |
/** |
|
529 |
* Returns true if there is a layer in the current project using the file named with |
|
530 |
* fileName. |
|
531 |
* @param fileName |
|
532 |
* @return |
|
533 |
*/ |
|
534 |
private boolean isUsingFile(String fileName) { |
|
535 |
List<Document> docs = ProjectManager.getInstance().getCurrentProject().getDocuments(); |
|
536 |
|
|
537 |
for (int i = 0 ;i < docs.size() ;i++) { |
|
538 |
if (docs.get(i) instanceof BaseViewDocument) { |
|
539 |
FLayers lyrs = ((BaseViewDocument)docs.get(i)).getMapContext().getLayers(); |
|
540 |
for (int j = 0 ;j < lyrs.getLayersCount() ;j++) { |
|
541 |
if (lyrs.getLayer(j) instanceof DefaultFLyrRaster) { |
|
542 |
DefaultFLyrRaster lyr = (DefaultFLyrRaster)lyrs.getLayer(j); |
|
543 |
if (lyr.getDataStore() != null ){ |
|
544 |
if (fileName.equals(lyr.getDataStore().getName())) { |
|
545 |
return true; |
|
546 |
} |
|
547 |
} |
|
548 |
} |
|
549 |
} |
|
550 |
} |
|
551 |
} |
|
552 |
return false; |
|
553 |
} |
|
554 |
|
|
555 |
|
|
556 |
/** |
|
557 |
* Acciones que se realizan al finalizar de crear los recortes de imagen. |
|
558 |
* Este m?todo es llamado por el thread TailRasterProcess al finalizar. |
|
559 |
*/ |
|
560 |
private void cutFinalize(String fileName, long milis) { |
|
561 |
if (!new File(fileName).exists()) |
|
562 |
return; |
|
563 |
|
|
564 |
if(viewName != null) { |
|
565 |
if (RasterSwingLibrary.messageBoxYesOrNot("cargar_toc", null)) { |
|
566 |
|
|
567 |
try { |
|
568 |
FLayer lyr = RasterMainPluginUtils.loadLayer(viewName, fileName, null); |
|
569 |
if(lyr != null && lyr instanceof DefaultFLyrRaster) { |
|
570 |
if(dataStore.getProjection() != null) |
|
571 |
((DefaultFLyrRaster)lyr).setRois(dataStore.getRois(dataStore.getProjection())); |
|
572 |
else |
|
573 |
((DefaultFLyrRaster)lyr).setRois(dataStore.getRois(viewProjection)); |
|
574 |
} |
|
575 |
} catch (RasterNotLoadException e) { |
|
576 |
RasterSwingLibrary.messageBoxError("error_load_layer", this, e); |
|
577 |
} catch (ROIException e) { |
|
578 |
RasterSwingLibrary.messageBoxError("error_load_layer", this, e); |
|
579 |
} |
|
580 |
} |
|
581 |
} |
|
582 |
|
|
583 |
if (externalActions != null) |
|
584 |
externalActions.end(new Object[]{fileName, new Long(milis)}); |
|
585 |
} |
|
586 |
|
|
587 |
/* |
|
588 |
* (non-Javadoc) |
|
589 |
* @see org.gvsig.gui.beans.incrementabletask.IIncrementable#getPercent() |
|
590 |
*/ |
|
591 |
public int getPercent() { |
|
592 |
return (processIncrement != null) ? processIncrement.getPercent() : 0; |
|
593 |
} |
|
594 |
|
|
595 |
/* |
|
596 |
* (non-Javadoc) |
|
597 |
* @see org.gvsig.gui.beans.incrementabletask.IIncrementable#getTitle() |
|
598 |
*/ |
|
599 |
public String getTitle() { |
|
600 |
return Messages.getText("incremento_recorte"); |
|
601 |
} |
|
602 |
|
|
603 |
/* |
|
604 |
* (non-Javadoc) |
|
605 |
* @see java.lang.Object#finalize() |
|
606 |
*/ |
|
607 |
protected void finalize() throws Throwable { |
|
608 |
fileName = null; |
|
609 |
suffix = null; |
|
610 |
dataStore = null; |
|
611 |
drawableBands = null; |
|
612 |
pValues = null; |
|
613 |
viewName = null; |
|
614 |
params = null; |
|
615 |
colorInterp = null; |
|
616 |
affineTransform = null; |
|
617 |
wcValues = null; |
|
618 |
buffer = null; |
|
619 |
processIncrement = null; |
|
620 |
if(selectedRois != null) { |
|
621 |
selectedRois.clear(); |
|
622 |
selectedRois = null; |
|
623 |
} |
|
624 |
super.finalize(); |
|
625 |
} |
|
626 |
} |
|
0 | 627 |
org.gvsig.raster.tools/tags/org.gvsig.raster.tools-2.2.50/org.gvsig.raster.tools.app.basic/src/main/java/org/gvsig/raster/tools/app/basic/raster/process/FilterProcess.java | ||
---|---|---|
1 |
package org.gvsig.raster.tools.app.basic.raster.process; |
|
2 |
|
|
3 |
import java.io.IOException; |
|
4 |
import java.util.ArrayList; |
|
5 |
import java.util.List; |
|
6 |
|
|
7 |
import javax.swing.SwingUtilities; |
|
8 |
|
|
9 |
import org.cresques.cts.IProjection; |
|
10 |
import org.gvsig.fmap.dal.coverage.RasterLocator; |
|
11 |
import org.gvsig.fmap.dal.coverage.RasterManager; |
|
12 |
import org.gvsig.fmap.dal.coverage.dataset.Buffer; |
|
13 |
import org.gvsig.fmap.dal.coverage.datastruct.NoData; |
|
14 |
import org.gvsig.fmap.dal.coverage.exception.FilterManagerException; |
|
15 |
import org.gvsig.fmap.dal.coverage.exception.FilterTypeException; |
|
16 |
import org.gvsig.fmap.dal.coverage.exception.NotSupportedExtensionException; |
|
17 |
import org.gvsig.fmap.dal.coverage.exception.ProcessInterruptedException; |
|
18 |
import org.gvsig.fmap.dal.coverage.exception.QueryException; |
|
19 |
import org.gvsig.fmap.dal.coverage.exception.ROIException; |
|
20 |
import org.gvsig.fmap.dal.coverage.exception.RasterDriverException; |
|
21 |
import org.gvsig.fmap.dal.coverage.filter.FilterLoader; |
|
22 |
import org.gvsig.fmap.dal.coverage.grid.RasterFilterList; |
|
23 |
import org.gvsig.fmap.dal.coverage.grid.RasterFilterListManager; |
|
24 |
import org.gvsig.fmap.dal.coverage.store.DataServerWriter; |
|
25 |
import org.gvsig.fmap.dal.coverage.store.RasterDataStore; |
|
26 |
import org.gvsig.fmap.dal.coverage.store.RasterQuery; |
|
27 |
import org.gvsig.fmap.dal.coverage.store.RasterWriter; |
|
28 |
import org.gvsig.fmap.dal.coverage.store.props.ColorInterpretation; |
|
29 |
import org.gvsig.fmap.dal.coverage.store.props.Transparency; |
|
30 |
import org.gvsig.fmap.dal.exception.CloseException; |
|
31 |
import org.gvsig.i18n.Messages; |
|
32 |
import org.gvsig.raster.fmap.layers.FLyrRaster; |
|
33 |
import org.gvsig.raster.roi.ROI; |
|
34 |
import org.gvsig.raster.tools.app.basic.raster.bean.previewbase.ParamStruct; |
|
35 |
|
|
36 |
/** |
|
37 |
* Clase donde se hara todo el proceso de aplicar una lista de filtros a una |
|
38 |
* capa. Muestra una ventana de dialogo de incremento informativa. |
|
39 |
* |
|
40 |
* @author BorSanZa - Borja S?nchez Zamorano |
|
41 |
*/ |
|
42 |
public class FilterProcess extends RasterProcess { |
|
43 |
private String filename = ""; |
|
44 |
private RasterDataStore rasterDataSource = null; |
|
45 |
private ArrayList<ParamStruct> listFilterUsed = null; |
|
46 |
|
|
47 |
private RasterFilterList rasterFilterList = null; |
|
48 |
private RasterWriter geoRasterWriter = null; |
|
49 |
private FLyrRaster lyr = null; |
|
50 |
private RasterManager rManager = RasterLocator.getManager(); |
|
51 |
|
|
52 |
public void init() { |
|
53 |
filename = getStringParam("filename"); |
|
54 |
listFilterUsed = (ArrayList) getParam("listfilterused"); |
|
55 |
lyr = (FLyrRaster)getParam("layer"); |
|
56 |
rasterDataSource = lyr.getDataStore(); |
|
57 |
} |
|
58 |
|
|
59 |
/** |
|
60 |
* Devuelve una interpretacion de color. Es usado cuando no conseguimos un |
|
61 |
* rendering y no podemos saber que interpretacion l?gica ten?a antes. |
|
62 |
* @param geoRasterWriter |
|
63 |
*/ |
|
64 |
private ColorInterpretation getColorIntepretation(Buffer buffer, RasterFilterList filterList) { |
|
65 |
ColorInterpretation colorInterpretation = null; |
|
66 |
|
|
67 |
do { |
|
68 |
// Si tiene una tabla de color asignamos las tres bandas |
|
69 |
if (filterList.isActive("colortable")) { |
|
70 |
colorInterpretation = rManager.getDataStructFactory().createColorInterpretation( |
|
71 |
new String[] { |
|
72 |
ColorInterpretation.RED_BAND, |
|
73 |
ColorInterpretation.GREEN_BAND, |
|
74 |
ColorInterpretation.BLUE_BAND, |
|
75 |
ColorInterpretation.ALPHA_BAND |
|
76 |
}); |
|
77 |
break; |
|
78 |
} |
|
79 |
|
|
80 |
// Si el numero de bandas coincide asignamos la misma interpretacion que tenia antes |
|
81 |
if (buffer.getBandCount() == rasterDataSource.getBandCount()) { |
|
82 |
colorInterpretation = rasterDataSource.getColorInterpretation(); |
|
83 |
break; |
|
84 |
} |
|
85 |
|
|
86 |
String[] colorInterp = new String[rasterDataSource.getColorInterpretation().getValues().length]; |
|
87 |
|
|
88 |
for (int i = 0; i < rasterDataSource.getColorInterpretation().getValues().length; i++) { |
|
89 |
if (rasterDataSource.getColorInterpretation().getValues()[i].equals(ColorInterpretation.UNDEF_BAND)) { |
|
90 |
colorInterp[i] = ColorInterpretation.GRAY_BAND; |
|
91 |
continue; |
|
92 |
} |
|
93 |
colorInterp[i] = rasterDataSource.getColorInterpretation().getValues()[i]; |
|
94 |
} |
|
95 |
colorInterpretation = rManager.getDataStructFactory().createColorInterpretation(colorInterp); |
|
96 |
} while (false); |
|
97 |
|
|
98 |
return colorInterpretation; |
|
99 |
} |
|
100 |
|
|
101 |
public void process() throws ProcessInterruptedException, ProcessException { |
|
102 |
DataServerWriter writerBufferServer = null; |
|
103 |
if(lyr != null) |
|
104 |
lyr.setReadingData(Thread.currentThread().getId() + ""); |
|
105 |
|
|
106 |
RasterDataStore dstoreCopy = null; |
|
107 |
RasterQuery query = null; |
|
108 |
Buffer buffer = null; |
|
109 |
Buffer buff = null; |
|
110 |
Buffer alpha = null; |
|
111 |
try { |
|
112 |
insertLineLog(Messages.getText("leyendo_raster")); |
|
113 |
|
|
114 |
//Creaci?n del BufferFactory |
|
115 |
dstoreCopy = rasterDataSource.newNotTiledDataStore(); |
|
116 |
query = rManager.createQuery(); |
|
117 |
//if (!RasterBuffer.loadInMemory(dsetCopy)) |
|
118 |
query.setReadOnly(true); |
|
119 |
|
|
120 |
//Asignaci?n de bandas |
|
121 |
int[] renderBands = lyr.getRender().getRenderColorInterpretation().buildRenderBands(); |
|
122 |
if (renderBands != null) { |
|
123 |
// Si es gris, se reduce a una sola banda |
|
124 |
if ((renderBands.length == 3) && (renderBands[0] == renderBands[1]) && (renderBands[1] == renderBands[2])) |
|
125 |
renderBands = new int[] { renderBands[0] }; |
|
126 |
query.setDrawableBands(renderBands); |
|
127 |
} else |
|
128 |
query.setAllDrawableBands(); |
|
129 |
|
|
130 |
query.setAreaOfInterest(); |
|
131 |
|
|
132 |
buff = dstoreCopy.query(query); |
|
133 |
if(buff.isReadOnlyBuffer()) |
|
134 |
buff.addDrawableBands(renderBands); |
|
135 |
|
|
136 |
insertLineLog(Messages.getText("aplicando_filtros")); |
|
137 |
|
|
138 |
Transparency processTransparency = dstoreCopy.getTransparency().cloneTransparency(); |
|
139 |
processTransparency.setColorInterpretation(lyr.getRender().getRenderColorInterpretation().cloneColorInterpretation()); |
|
140 |
|
|
141 |
List<ROI> roi = null; |
|
142 |
try { |
|
143 |
IProjection proj = dstoreCopy.getProjection(); |
|
144 |
if(proj == null) |
|
145 |
proj = lyr.getMapContext().getProjection(); |
|
146 |
roi = (List<ROI>)dstoreCopy.getRois(proj); |
|
147 |
} catch (ROIException e) { |
|
148 |
} |
|
149 |
|
|
150 |
rasterFilterList = rManager.createEmptyFilterList(dstoreCopy.getDataType()[0]); |
|
151 |
FilterLoader filterLoader = RasterLocator.getManager().createFilterLoader(rasterFilterList); |
|
152 |
filterLoader.addSrcBandCount(dstoreCopy.getBandCount()); |
|
153 |
filterLoader.addSrcDataType(dstoreCopy.getDataType()[0]); |
|
154 |
filterLoader.addSrcStatistics(dstoreCopy.getStatistics()); |
|
155 |
filterLoader.addSrcROI(roi); |
|
156 |
filterLoader.addTransparency(processTransparency); |
|
157 |
filterLoader.addSrcHistogram(dstoreCopy.getHistogramComputer()); |
|
158 |
addSelectedFilters(rasterFilterList, listFilterUsed); |
|
159 |
buffer = filterLoader.applyFilters(buff); |
|
160 |
|
|
161 |
insertLineLog(Messages.getText("guardando_capa")); |
|
162 |
|
|
163 |
writerBufferServer = rManager.createDataServerWriter(); |
|
164 |
writerBufferServer.setBuffer(buffer, -1); |
|
165 |
// TODO: FUNCIONALIDAD: Poner los getWriter con la proyecci?n del fichero fuente |
|
166 |
|
|
167 |
ColorInterpretation colorInterpretation = getColorInterpretation(buffer.getBandCount(), buffer.getDataType()); |
|
168 |
|
|
169 |
geoRasterWriter = rManager.createWriter(writerBufferServer, |
|
170 |
filename, |
|
171 |
buffer.getBandCount(), |
|
172 |
rasterDataSource.getAffineTransform(), |
|
173 |
buffer.getWidth(), |
|
174 |
buffer.getHeight(), |
|
175 |
buffer.getDataType(), |
|
176 |
rManager.createWriter(filename).getParams(), |
|
177 |
null); |
|
178 |
|
|
179 |
if (lyr.getRender() == null) |
|
180 |
colorInterpretation = getColorIntepretation(buffer, rasterFilterList); |
|
181 |
|
|
182 |
geoRasterWriter.setColorBandsInterpretation(colorInterpretation.getValues()); |
|
183 |
|
|
184 |
geoRasterWriter.dataWrite(); |
|
185 |
geoRasterWriter.writeClose(); |
|
186 |
geoRasterWriter = null; |
|
187 |
|
|
188 |
// Guardamos en el RMF el valor NoData |
|
189 |
//Si el del buffer tiene valor es porque alg?n filtro le ha salvado valor nodata por lo que se pone ese |
|
190 |
//sino se pone el de la imagen original |
|
191 |
NoData nodataOrigin = (NoData)rasterDataSource.getNoDataValue(); |
|
192 |
NoData nodataBuffer = (NoData)buffer.getNoDataValue(); |
|
193 |
if(nodataBuffer != null && nodataBuffer.isDefined()) { |
|
194 |
nodataBuffer.setFileName(filename); |
|
195 |
nodataBuffer.save(); |
|
196 |
} else if(nodataOrigin != null && nodataOrigin.isDefined()) { |
|
197 |
nodataOrigin.setFileName(filename); |
|
198 |
nodataOrigin.save(); |
|
199 |
} |
|
200 |
|
|
201 |
SwingUtilities.invokeLater(new Runnable() { |
|
202 |
public void run() { |
|
203 |
if (externalActions != null) |
|
204 |
externalActions.end(filename); |
|
205 |
} |
|
206 |
}); |
|
207 |
} catch (NotSupportedExtensionException e) { |
|
208 |
throw new ProcessException("error_writer_notsupportedextension", e); |
|
209 |
} catch (RasterDriverException e) { |
|
210 |
throw new ProcessException("error_writer", e); |
|
211 |
} catch (IOException e) { |
|
212 |
throw new ProcessException("error_writer", e); |
|
213 |
} catch (FilterTypeException e) { |
|
214 |
throw new ProcessException("error_adding_filters", e); |
|
215 |
} catch (QueryException e) { |
|
216 |
throw new ProcessException("error_loading_data", e); |
|
217 |
} catch (FilterManagerException e) { |
|
218 |
throw new ProcessException("error_adding_filters", e); |
|
219 |
} finally { |
|
220 |
if(writerBufferServer != null) |
|
221 |
writerBufferServer.dispose(); |
|
222 |
if(buff != null) |
|
223 |
buff.dispose(); |
|
224 |
if(rasterFilterList != null) |
|
225 |
rasterFilterList.dispose(); |
|
226 |
if(alpha != null) |
|
227 |
alpha.dispose(); |
|
228 |
if(dstoreCopy != null) |
|
229 |
try { |
|
230 |
dstoreCopy.close(); |
|
231 |
} catch (CloseException e) { |
|
232 |
} |
|
233 |
if(lyr != null) |
|
234 |
lyr.setReadingData(null); |
|
235 |
dispose(); |
|
236 |
} |
|
237 |
} |
|
238 |
|
|
239 |
private ColorInterpretation getColorInterpretation(int nBands, int dataType) { |
|
240 |
//Si la fuente es con paleta, al aplicarle un filtro se genera un ARGB |
|
241 |
if(lyr.existColorTable()) |
|
242 |
return rManager.getDataStructFactory().createColorInterpretation( |
|
243 |
new String[] { ColorInterpretation.RED_BAND, ColorInterpretation.GREEN_BAND, ColorInterpretation.BLUE_BAND, ColorInterpretation.ALPHA_BAND }); |
|
244 |
|
|
245 |
if(dataType == Buffer.TYPE_BYTE) { |
|
246 |
if(nBands == 3) |
|
247 |
return rManager.getDataStructFactory().createColorInterpretation( |
|
248 |
new String[] { ColorInterpretation.RED_BAND, ColorInterpretation.GREEN_BAND, ColorInterpretation.BLUE_BAND }); |
|
249 |
if(nBands == 4) |
|
250 |
return rManager.getDataStructFactory().createColorInterpretation( |
|
251 |
new String[] { ColorInterpretation.RED_BAND, ColorInterpretation.GREEN_BAND, ColorInterpretation.BLUE_BAND, ColorInterpretation.ALPHA_BAND }); |
|
252 |
if(nBands == 2 || nBands > 4) { |
|
253 |
return lyr.getRender().getRenderColorInterpretation(); |
|
254 |
/*int[] renderBands = lyr.getRender().getRenderBands(); |
|
255 |
String[] ci = new String[renderBands.length]; |
|
256 |
for (int i = 0; i < renderBands.length; i++) { |
|
257 |
switch (renderBands[i]) { |
|
258 |
case 0:ci[i] = ColorInterpretation.RED_BAND; break; |
|
259 |
case 1:ci[i] = ColorInterpretation.GREEN_BAND; break; |
|
260 |
case 2:ci[i] = ColorInterpretation.BLUE_BAND; break; |
|
261 |
default: ci[i] = ColorInterpretation.UNDEF_BAND; |
|
262 |
} |
|
263 |
} |
|
264 |
return rManager.getDataStructFactory().createColorInterpretation(ci);*/ |
|
265 |
} |
|
266 |
} |
|
267 |
if(nBands == 1) |
|
268 |
return rManager.getDataStructFactory().createColorInterpretation( |
|
269 |
new String[] { ColorInterpretation.GRAY_BAND }); |
|
270 |
else { |
|
271 |
String[] ci = new String[nBands]; |
|
272 |
for (int i = 0; i < ci.length; i++) { |
|
273 |
ci[i] = ColorInterpretation.UNDEF_BAND; |
|
274 |
} |
|
275 |
return rManager.getDataStructFactory().createColorInterpretation(ci); |
|
276 |
} |
|
277 |
} |
|
278 |
|
|
279 |
/** |
|
280 |
* Sustituye la lista de filtros de filterList por la que le pasamos en forma |
|
281 |
* de ArrayList |
|
282 |
* @param filterList |
|
283 |
* @param listFilterUsed |
|
284 |
* @throws FilterTypeException |
|
285 |
* @throws FilterTypeException |
|
286 |
*/ |
|
287 |
public void addSelectedFilters(RasterFilterList filterList, ArrayList<ParamStruct> listFilterUsed) throws FilterManagerException, FilterTypeException { |
|
288 |
filterList.clear(); |
|
289 |
|
|
290 |
for (int i = 0; i < listFilterUsed.size(); i++) { |
|
291 |
ParamStruct aux = (ParamStruct) listFilterUsed.get(i); |
|
292 |
RasterFilterListManager filterManager = filterList.getManagerByFilterClass(aux.getFilterClass()); |
|
293 |
filterManager.addFilter(aux.getFilterClass(), aux.getFilterParam()); |
|
294 |
} |
|
295 |
|
|
296 |
filterList.resetPercent(); |
|
297 |
} |
|
298 |
|
|
299 |
public int getPercent() { |
|
300 |
if (rasterFilterList == null) |
|
301 |
return 0; |
|
302 |
|
|
303 |
if (rasterFilterList.getPercent() < 100) |
|
304 |
return rasterFilterList.getPercent(); |
|
305 |
|
|
306 |
if (geoRasterWriter == null) |
|
307 |
return 0; |
|
308 |
|
|
309 |
return geoRasterWriter.getPercent(); |
|
310 |
} |
|
311 |
|
|
312 |
public String getTitle() { |
|
313 |
return Messages.getText("aplicando_filtros"); |
|
314 |
} |
|
315 |
|
|
316 |
public void dispose() { |
|
317 |
rasterDataSource = null; |
|
318 |
if(listFilterUsed != null) { |
|
319 |
listFilterUsed.clear(); |
|
320 |
listFilterUsed = null; |
|
321 |
} |
|
322 |
rasterFilterList = null; |
|
323 |
geoRasterWriter = null; |
|
324 |
lyr = null; |
|
325 |
} |
|
326 |
|
|
327 |
@Override |
|
328 |
protected void finalize() throws Throwable { |
|
329 |
dispose(); |
|
330 |
super.finalize(); |
|
331 |
} |
|
332 |
} |
|
0 | 333 |
org.gvsig.raster.tools/tags/org.gvsig.raster.tools-2.2.50/org.gvsig.raster.tools.app.basic/src/main/java/org/gvsig/raster/tools/app/basic/raster/process/IProcessActions.java | ||
---|---|---|
1 |
/* gvSIG. Geographic Information System of the Valencian Government |
|
2 |
* |
|
3 |
* Copyright (C) 2007-2008 Infrastructures and Transports Department |
|
4 |
* of the Valencian Government (CIT) |
|
5 |
* |
|
6 |
* This program is free software; you can redistribute it and/or |
|
7 |
* modify it under the terms of the GNU General Public License |
|
8 |
* as published by the Free Software Foundation; either version 2 |
|
9 |
* of the License, or (at your option) any later version. |
|
10 |
* |
|
11 |
* This program is distributed in the hope that it will be useful, |
|
12 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
13 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
14 |
* GNU General Public License for more details. |
|
15 |
* |
|
16 |
* You should have received a copy of the GNU General Public License |
|
17 |
* along with this program; if not, write to the Free Software |
|
18 |
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, |
|
19 |
* MA 02110-1301, USA. |
|
20 |
* |
|
21 |
*/ |
|
22 |
package org.gvsig.raster.tools.app.basic.raster.process; |
|
23 |
|
|
24 |
/** |
|
25 |
* Acciones que puede ejecutar un proceso sobre un objeto externo. Un proceso |
|
26 |
* debe ser independiente de objetos que sean dependientes de su funcionalidad. Es |
|
27 |
* decir, cualquier extensi?n debe poder usar un proceso y este ejecutar metodos |
|
28 |
* de la funcionalidad. Esto se hace ha trav?s de este interfaz. |
|
29 |
* |
|
30 |
* @version 26/09/2007 |
|
31 |
* @author Nacho Brodin (nachobrodin@gmail.com) |
|
32 |
* |
|
33 |
*/ |
|
34 |
public interface IProcessActions { |
|
35 |
|
|
36 |
/** |
|
37 |
* El proceso comunica que ha sido interrumpido |
|
38 |
* |
|
39 |
*/ |
|
40 |
public void interrupted(); |
|
41 |
|
|
42 |
/** |
|
43 |
* Acciones de finalizaci?n del proceso |
|
44 |
*/ |
|
45 |
public void end(Object param); |
|
46 |
} |
|
0 | 47 |
org.gvsig.raster.tools/tags/org.gvsig.raster.tools-2.2.50/org.gvsig.raster.tools.app.basic/src/main/java/org/gvsig/raster/tools/app/basic/raster/process/OverviewsProcess.java | ||
---|---|---|
1 |
/* gvSIG. Geographic Information System of the Valencian Government |
|
2 |
* |
|
3 |
* Copyright (C) 2007-2008 Infrastructures and Transports Department |
|
4 |
* of the Valencian Government (CIT) |
|
5 |
* |
|
6 |
* This program is free software; you can redistribute it and/or |
|
7 |
* modify it under the terms of the GNU General Public License |
|
8 |
* as published by the Free Software Foundation; either version 2 |
|
9 |
* of the License, or (at your option) any later version. |
|
10 |
* |
|
11 |
* This program is distributed in the hope that it will be useful, |
|
12 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
13 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
14 |
* GNU General Public License for more details. |
|
15 |
* |
|
16 |
* You should have received a copy of the GNU General Public License |
|
17 |
* along with this program; if not, write to the Free Software |
|
18 |
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, |
|
19 |
* MA 02110-1301, USA. |
|
20 |
* |
|
21 |
*/ |
|
22 |
package org.gvsig.raster.tools.app.basic.raster.process; |
|
23 |
|
|
24 |
import java.io.File; |
|
25 |
import java.net.URI; |
|
26 |
|
|
27 |
import org.gvsig.andami.PluginServices; |
|
28 |
import org.gvsig.fmap.dal.coverage.RasterLocator; |
|
29 |
import org.gvsig.fmap.dal.coverage.exception.OverviewException; |
|
30 |
import org.gvsig.fmap.dal.coverage.process.BaseIncrementableTask; |
|
31 |
import org.gvsig.fmap.dal.coverage.process.overview.OverviewBuilder; |
|
32 |
import org.gvsig.raster.fmap.layers.FLyrRaster; |
|
33 |
import org.gvsig.raster.mainplugin.config.Configuration; |
|
34 |
|
|
35 |
|
|
36 |
/** |
|
37 |
* Proceso para la generaci?n de overviews. |
|
38 |
* |
|
39 |
* 10/12/2007 |
|
40 |
* @author Nacho Brodin nachobrodin@gmail.com |
|
41 |
*/ |
|
42 |
public class OverviewsProcess extends RasterProcess implements BaseIncrementableTask { |
|
43 |
private FLyrRaster rasterSE = null; |
|
44 |
private int value = 0; |
|
45 |
private int resamplingAlg = OverviewBuilder.AVERAGE; |
|
46 |
private int[] overviews = new int[] { 2, 4, 8, 16 }; |
|
47 |
private String builder = "GDAL"; |
|
48 |
|
|
49 |
/* |
|
50 |
* (non-Javadoc) |
|
51 |
* @see org.gvsig.rastertools.RasterProcess#init() |
|
52 |
*/ |
|
53 |
public void init() { |
|
54 |
rasterSE = getLayerParam("layer"); |
|
55 |
builder = getStringParam("builder") != null ? getStringParam("builder") : builder; |
|
56 |
|
|
57 |
int overviewsRate = 2; |
|
58 |
int nOverviews = 4; |
|
59 |
overviewsRate = Configuration.getValue("overviews_rate", new Integer(overviewsRate)).intValue(); |
|
60 |
nOverviews = Configuration.getValue("overviews_number", new Integer(nOverviews)).intValue(); |
|
61 |
resamplingAlg = Configuration.getValue("overviews_resampling_algorithm", new Integer(resamplingAlg)).intValue(); |
|
62 |
|
|
63 |
// Leemos de la configuraci?n los valores de algoritmo a usar, |
|
64 |
// n?mero de overviews a generar y proporci?n de la primera overview |
|
65 |
|
|
66 |
overviews = new int[nOverviews]; |
|
67 |
overviews[0] = overviewsRate; |
|
68 |
for (int i = 1; i < nOverviews; i++) |
|
69 |
overviews[i] = overviewsRate * overviews[i - 1]; |
|
70 |
} |
|
71 |
|
|
72 |
/** |
|
73 |
* M?todo donde se ejecutar? el Thread, aqu? se generaran las |
|
74 |
* overviews |
|
75 |
* @throws ProcessException |
|
76 |
*/ |
|
77 |
public void process() throws ProcessException { |
|
78 |
insertLineLog(PluginServices.getText(this, "overviews_generating")); |
|
79 |
OverviewBuilder overviewBuilder = RasterLocator.getManager().getOverviewBuilder(builder); |
|
80 |
|
|
81 |
overviewBuilder.setIncrementListener(this); |
|
82 |
try { |
|
83 |
URI[] uri = rasterSE.getDataStore().getURIByProvider(); |
|
84 |
|
|
85 |
for (int i = 0; i < uri.length; i++) { |
|
86 |
insertLineLog(" Dataset: " + i); |
|
87 |
overviewBuilder.buildOverviews(resamplingAlg, new File(uri[i]).getAbsolutePath(), overviews); |
|
88 |
} |
|
89 |
|
|
90 |
if (externalActions != null) |
|
91 |
externalActions.end(rasterSE); |
|
92 |
} catch (OverviewException e) { |
|
93 |
if (incrementableTask != null) |
|
94 |
incrementableTask.hideWindow(); |
|
95 |
throw new ProcessException("error_write_overviews", e); |
|
96 |
} |
|
97 |
} |
|
98 |
|
|
99 |
/* |
|
100 |
* (non-Javadoc) |
|
101 |
* @see org.gvsig.gui.beans.incrementabletask.IIncrementable#getPercent() |
|
102 |
*/ |
|
103 |
public int getPercent() { |
|
104 |
return value; |
|
105 |
} |
|
106 |
|
|
107 |
/* |
|
108 |
* (non-Javadoc) |
|
109 |
* @see org.gvsig.addo.IOverviewIncrement#setPercent(int) |
|
110 |
*/ |
|
111 |
public void setPercent(int value) { |
|
112 |
this.value = value; |
|
113 |
} |
|
114 |
|
|
115 |
/* |
|
116 |
* (non-Javadoc) |
|
117 |
* @see org.gvsig.gui.beans.incrementabletask.IIncrementable#getTitle() |
|
118 |
*/ |
|
119 |
public String getTitle() { |
|
120 |
return PluginServices.getText(this, "incremento_overview"); |
|
121 |
} |
|
122 |
|
|
123 |
/* |
|
124 |
* (non-Javadoc) |
|
125 |
* @see java.lang.Object#finalize() |
|
126 |
*/ |
|
127 |
protected void finalize() throws Throwable { |
|
128 |
rasterSE = null; |
|
129 |
overviews = null; |
|
130 |
super.finalize(); |
|
131 |
} |
|
132 |
} |
|
0 | 133 |
org.gvsig.raster.tools/tags/org.gvsig.raster.tools-2.2.50/org.gvsig.raster.tools.app.basic/src/main/java/org/gvsig/raster/tools/app/basic/raster/process/StatisticsProcess.java | ||
---|---|---|
1 |
/* gvSIG. Geographic Information System of the Valencian Government |
|
2 |
* |
|
3 |
* Copyright (C) 2007-2008 Infrastructures and Transports Department |
|
4 |
* of the Valencian Government (CIT) |
|
5 |
* |
|
6 |
* This program is free software; you can redistribute it and/or |
|
7 |
* modify it under the terms of the GNU General Public License |
|
8 |
* as published by the Free Software Foundation; either version 2 |
|
9 |
* of the License, or (at your option) any later version. |
|
10 |
* |
|
11 |
* This program is distributed in the hope that it will be useful, |
|
12 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
13 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
14 |
* GNU General Public License for more details. |
|
15 |
* |
|
16 |
* You should have received a copy of the GNU General Public License |
|
17 |
* along with this program; if not, write to the Free Software |
|
18 |
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, |
|
19 |
* MA 02110-1301, USA. |
|
20 |
* |
|
21 |
*/ |
|
22 |
package org.gvsig.raster.tools.app.basic.raster.process; |
|
23 |
|
|
24 |
import javax.swing.SwingUtilities; |
|
25 |
|
|
26 |
import org.gvsig.andami.PluginServices; |
|
27 |
import org.gvsig.fmap.dal.coverage.exception.FileNotOpenException; |
|
28 |
import org.gvsig.fmap.dal.coverage.exception.ProcessInterruptedException; |
|
29 |
import org.gvsig.fmap.dal.coverage.exception.RasterDriverException; |
|
30 |
import org.gvsig.fmap.dal.coverage.store.props.Statistics; |
|
31 |
import org.gvsig.raster.fmap.layers.FLyrRaster; |
|
32 |
|
|
33 |
|
|
34 |
/** |
|
35 |
* Proceso para la generaci?n de estad?sticas. |
|
36 |
* |
|
37 |
* @author Nacho Brodin nachobrodin@gmail.com |
|
38 |
*/ |
|
39 |
public class StatisticsProcess extends RasterProcess { |
|
40 |
private FLyrRaster lyr = null; |
|
41 |
private Statistics stats = null; |
|
42 |
private boolean force = false; |
|
43 |
private double scale = 1; |
|
44 |
|
|
45 |
/** |
|
46 |
* Lanzador del procesos de estad?sticas |
|
47 |
* @param lyr Capa a calcular las estad?sticas |
|
48 |
* @param actions Clase que recoge eventos del proceso |
|
49 |
*/ |
|
50 |
public static void launcher(FLyrRaster lyr, IProcessActions actions) { |
|
51 |
RasterProcess process = new StatisticsProcess(); |
|
52 |
process.addParam("layer", lyr); |
|
53 |
process.addParam("force", new Boolean(false)); |
|
54 |
process.setActions(actions); |
|
55 |
process.start(); |
|
56 |
} |
|
57 |
|
|
58 |
public void init() { |
|
59 |
lyr = getLayerParam("layer"); |
|
60 |
force = getBooleanParam("force"); |
|
61 |
double s = getDoubleParam("scale"); |
|
62 |
if(s > 0 && s < 1) |
|
63 |
scale = s; |
|
64 |
} |
|
65 |
|
|
66 |
/** |
|
67 |
* M?todo donde se ejecutar? el Thread, aqu? se calcular?n las |
|
68 |
* estad?sticas. |
|
69 |
* @throws ProcessException |
|
70 |
*/ |
|
71 |
public void process() throws ProcessInterruptedException, ProcessException { |
|
72 |
insertLineLog(PluginServices.getText(this, "statistics_generation")); |
|
73 |
if(lyr == null || lyr.getDataStore() == null) |
|
74 |
return; |
|
75 |
stats = lyr.getDataStore().getStatistics(); |
|
76 |
lyr.setReadingData(Thread.currentThread().getId() + ""); |
|
77 |
if (force) |
|
78 |
stats.forceToRecalc(); |
|
79 |
try { |
|
80 |
stats.calculate(scale); |
|
81 |
SwingUtilities.invokeLater(new Runnable() { |
|
82 |
public void run() { |
|
83 |
if (externalActions != null) |
|
84 |
externalActions.end(lyr); |
|
85 |
} |
|
86 |
}); |
|
87 |
} catch (FileNotOpenException e) { |
|
88 |
throw new ProcessException("No se ha podido escribir en el fichero rmf", e); |
|
89 |
} catch (RasterDriverException e) { |
|
90 |
throw new ProcessException("Error leyendo bloques de datos para calcular estad?sticas", e); |
|
91 |
} finally { |
|
92 |
lyr.setReadingData(null); |
|
93 |
} |
|
94 |
} |
|
95 |
|
|
96 |
public int getPercent() { |
|
97 |
return (stats != null) ? stats.getPercent() : 0; |
|
98 |
} |
|
99 |
|
|
100 |
public String getTitle() { |
|
101 |
return PluginServices.getText(this, "increase_statistics"); |
|
102 |
} |
|
103 |
} |
|
0 | 104 |
org.gvsig.raster.tools/tags/org.gvsig.raster.tools-2.2.50/org.gvsig.raster.tools.app.basic/src/main/java/org/gvsig/raster/tools/app/basic/raster/process/UniqueProcessQueue.java | ||
---|---|---|
1 |
/* gvSIG. Geographic Information System of the Valencian Government |
|
2 |
* |
|
3 |
* Copyright (C) 2007-2008 Infrastructures and Transports Department |
|
4 |
* of the Valencian Government (CIT) |
|
5 |
* |
|
6 |
* This program is free software; you can redistribute it and/or |
|
7 |
* modify it under the terms of the GNU General Public License |
|
8 |
* as published by the Free Software Foundation; either version 2 |
|
9 |
* of the License, or (at your option) any later version. |
|
10 |
* |
|
11 |
* This program is distributed in the hope that it will be useful, |
|
12 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
13 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
14 |
* GNU General Public License for more details. |
|
15 |
* |
|
16 |
* You should have received a copy of the GNU General Public License |
|
17 |
* along with this program; if not, write to the Free Software |
|
18 |
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, |
|
19 |
* MA 02110-1301, USA. |
|
20 |
* |
|
21 |
*/ |
|
22 |
package org.gvsig.raster.tools.app.basic.raster.process; |
|
23 |
|
|
24 |
import org.gvsig.raster.util.Queue; |
|
25 |
import org.slf4j.LoggerFactory; |
|
26 |
|
|
27 |
/** |
|
28 |
* Cola de procesos de ejecuci?n exclusiva. Los procesos de esta lista se ir?n ejecutando |
|
29 |
* por orden de llegada impidiendo que se ejecuten dos al mismo tiempo. |
|
30 |
* |
|
31 |
* 16/05/2008 |
|
32 |
* @author Nacho Brodin nachobrodin@gmail.com |
|
33 |
*/ |
|
34 |
public class UniqueProcessQueue implements IProcessActions { |
|
35 |
private static final int LAPSE_TIME = 1000; |
|
36 |
|
|
37 |
private Queue queue = new Queue(); |
|
38 |
private RasterProcess executionProcess = null; |
|
39 |
static private UniqueProcessQueue singleton = new UniqueProcessQueue(); |
|
40 |
|
|
41 |
/** |
|
42 |
* Dejamos el constructor privado para que nadie pueda referenciarlo |
|
43 |
*/ |
|
44 |
private UniqueProcessQueue() {} |
|
45 |
|
|
46 |
/** |
|
47 |
* Devuelve una instancia al unico objeto de UniqueProcessQueue que puede existir. |
|
48 |
* @return |
|
49 |
*/ |
|
50 |
static public UniqueProcessQueue getSingleton() { |
|
51 |
return singleton; |
|
52 |
} |
|
53 |
|
|
54 |
/** |
|
55 |
* A?ade un proceso a la cola. |
|
56 |
* @param id Identificador del proceso |
|
57 |
* @param process Proceso |
|
58 |
*/ |
|
59 |
public synchronized void add(RasterProcess process) { |
|
60 |
queue.put(process); |
|
61 |
process.setUniqueProcessActions(this); |
|
62 |
|
|
63 |
//Decisi?n de arranque |
|
64 |
if(queue.size() >= 1 && executionProcess != null) |
|
65 |
start(); |
|
66 |
} |
|
67 |
|
|
68 |
/** |
|
69 |
* Pone en marcha el primer proceso de la lista |
|
70 |
*/ |
|
71 |
public void start() { |
|
72 |
nextProcess(); |
|
73 |
} |
|
74 |
|
|
75 |
private void nextProcess() { |
|
76 |
executionProcess = ((RasterProcess) queue.get()); |
|
77 |
if (executionProcess != null) |
|
78 |
executionProcess.start(); |
|
79 |
} |
|
80 |
|
|
81 |
/** |
|
82 |
* Evento de finalizaci?n de un proceso. Cuando un proceso acaba se |
|
83 |
* pone en marcha el siguiente de la lista si existe. Se asigna un tiempo de latencia para |
|
84 |
* la ejecuci?n del siguiente marcado por LAPSE_TIME. |
|
85 |
*/ |
|
86 |
public void end(Object param) { |
|
87 |
try { |
|
88 |
Thread.sleep(LAPSE_TIME); |
|
89 |
} catch (InterruptedException e) { |
|
90 |
LoggerFactory.getLogger(UniqueProcessQueue.class).debug("sleep Exception", e); |
|
91 |
} |
|
92 |
nextProcess(); |
|
93 |
} |
|
94 |
|
|
95 |
/** |
|
96 |
* How many elements are there in this queue? |
|
97 |
*/ |
|
98 |
public int size() { |
|
99 |
return queue.size(); |
|
100 |
} |
|
101 |
|
|
102 |
/* |
|
103 |
* (non-Javadoc) |
|
104 |
* @see org.gvsig.raster.IProcessActions#interrupted() |
|
105 |
*/ |
|
106 |
public void interrupted() {} |
|
107 |
} |
|
0 | 108 |
Also available in: Unified diff