gvsig-raster / org.gvsig.raster.tools / trunk / org.gvsig.raster.tools / org.gvsig.raster.tools.app / org.gvsig.raster.tools.app.basic / src / main / java / org / gvsig / raster / tools / app / basic / raster / process / ClippingProcess.java @ 1081
History | View | Annotate | Download (22.4 KB)
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.geom.AffineTransform; |
25 |
import java.awt.geom.Point2D; |
26 |
import java.io.File; |
27 |
import java.io.IOException; |
28 |
import java.util.ArrayList; |
29 |
import java.util.List; |
30 |
|
31 |
import org.gvsig.app.project.ProjectManager; |
32 |
import org.gvsig.app.project.documents.Document; |
33 |
import org.gvsig.app.project.documents.view.BaseViewDocument; |
34 |
import org.gvsig.fmap.dal.DALLocator; |
35 |
import org.gvsig.fmap.dal.DataManager; |
36 |
import org.gvsig.fmap.dal.DataServerExplorer; |
37 |
import org.gvsig.fmap.dal.DataServerExplorerParameters; |
38 |
import org.gvsig.fmap.dal.coverage.RasterLibrary; |
39 |
import org.gvsig.fmap.dal.coverage.RasterLocator; |
40 |
import org.gvsig.fmap.dal.coverage.RasterManager; |
41 |
import org.gvsig.fmap.dal.coverage.dataset.Buffer; |
42 |
import org.gvsig.fmap.dal.coverage.datastruct.Extent; |
43 |
import org.gvsig.fmap.dal.coverage.datastruct.NoData; |
44 |
import org.gvsig.fmap.dal.coverage.datastruct.Params; |
45 |
import org.gvsig.fmap.dal.coverage.exception.InvalidSetViewException; |
46 |
import org.gvsig.fmap.dal.coverage.exception.NotSupportedExtensionException; |
47 |
import org.gvsig.fmap.dal.coverage.exception.ProcessInterruptedException; |
48 |
import org.gvsig.fmap.dal.coverage.exception.RasterDriverException; |
49 |
import org.gvsig.fmap.dal.coverage.exception.RmfSerializerException; |
50 |
import org.gvsig.fmap.dal.coverage.process.BaseIncrementableTask; |
51 |
import org.gvsig.fmap.dal.coverage.store.DataServerWriter; |
52 |
import org.gvsig.fmap.dal.coverage.store.RasterDataStore; |
53 |
import org.gvsig.fmap.dal.coverage.store.RasterQuery; |
54 |
import org.gvsig.fmap.dal.coverage.store.parameter.NewRasterStoreParameters; |
55 |
import org.gvsig.fmap.dal.coverage.store.parameter.RemoteStoreParameters; |
56 |
import org.gvsig.fmap.dal.coverage.store.props.ColorInterpretation; |
57 |
import org.gvsig.fmap.dal.coverage.store.props.ColorTable; |
58 |
import org.gvsig.fmap.dal.coverage.util.RasterUtils; |
59 |
import org.gvsig.fmap.dal.exception.CloseException; |
60 |
import org.gvsig.fmap.dal.exception.DataException; |
61 |
import org.gvsig.fmap.dal.exception.InitializeException; |
62 |
import org.gvsig.fmap.dal.exception.ProviderNotRegisteredException; |
63 |
import org.gvsig.fmap.dal.exception.ValidateDataParametersException; |
64 |
import org.gvsig.fmap.mapcontext.layers.FLayer; |
65 |
import org.gvsig.fmap.mapcontext.layers.FLayers; |
66 |
import org.gvsig.raster.fmap.layers.DefaultFLyrRaster; |
67 |
import org.gvsig.raster.fmap.layers.FLyrRaster; |
68 |
import org.gvsig.raster.fmap.roi.VectorialROI; |
69 |
import org.gvsig.raster.tools.app.basic.RasterToolsUtil; |
70 |
import org.gvsig.raster.util.RasterNotLoadException; |
71 |
/**
|
72 |
* <code>ClippingProcess</code> es un proceso que usa un <code>Thread</code>
|
73 |
* para aplicar un recorte a una capa y guardarlo en disco. Muestra una barra
|
74 |
* de incremento informativa.
|
75 |
*
|
76 |
* @version 24/04/2007
|
77 |
* @author BorSanZa - Borja S?nchez Zamorano (borja.sanchez@iver.es)
|
78 |
*/
|
79 |
public class ClippingProcess extends RasterProcess { |
80 |
private String fileName = ""; |
81 |
private String suffix = ".tif"; |
82 |
private FLyrRaster rasterSE = null; |
83 |
private boolean oneLayerPerBand = false; |
84 |
private int[] drawableBands = { 0, 1, 2 }; |
85 |
private double[] pValues = null; |
86 |
private int interpolationMethod = Buffer.INTERPOLATION_Undefined; |
87 |
private String viewName = ""; |
88 |
private Params params = null; |
89 |
private ColorInterpretation colorInterp = null; |
90 |
private ArrayList<VectorialROI> selectedRois = null; |
91 |
private AffineTransform affineTransform = null; |
92 |
private double[] wcValues = null; |
93 |
private RasterManager rManager = RasterLocator.getManager();
|
94 |
private BaseIncrementableTask processIncrement = null; |
95 |
|
96 |
/**
|
97 |
* Variables de la resoluci?n de salida
|
98 |
*/
|
99 |
private int resolutionWidth = 0; |
100 |
private int resolutionHeight = 0; |
101 |
|
102 |
private Buffer buffer = null; |
103 |
|
104 |
/**
|
105 |
* Par?metros obligatorios al proceso:
|
106 |
* <UL>
|
107 |
* <LI>filename: Nombre del fichero de salida</LI>
|
108 |
* <LI>datawriter: Escritor de datos</LI>
|
109 |
* <LI>viewname: Nombre de la vista sobre la que se carga la capa al acabar el proceso</LI>
|
110 |
* <LI>pixelcoordinates: Coordenadas pixel del recorte (ulx, uly, lrx, lry)</LI>
|
111 |
* <LI>layer: Capa de entrada para el recorte</LI>
|
112 |
* <LI>drawablebands: Bandas de entrada</LI>
|
113 |
* <LI>onelayerperband: booleano que informa de si escribimos una banda por fichero de salida o todas en un fichero</LI>
|
114 |
* <LI>interpolationmethod: M?todo de interpolaci?n.</LI>
|
115 |
* <LI>affinetransform: Transformaci?n que informa al dataset de salida de su referencia geografica</LI>
|
116 |
* <LI>resolution: Ancho y alto de la capa de salida</LI>
|
117 |
* </UL>
|
118 |
*/
|
119 |
@SuppressWarnings("unchecked") |
120 |
public void init() { |
121 |
fileName = getStringParam("filename");
|
122 |
suffix = getStringParam("suffix");
|
123 |
viewName = getStringParam("viewname");
|
124 |
pValues = getDoubleArrayParam("pixelcoordinates");
|
125 |
wcValues = getDoubleArrayParam("realcoordinates");
|
126 |
rasterSE = (FLyrRaster)getLayerParam("layer");
|
127 |
drawableBands = getIntArrayParam("drawablebands");
|
128 |
oneLayerPerBand = getBooleanParam("onelayerperband");
|
129 |
interpolationMethod = getIntParam("interpolationmethod");
|
130 |
affineTransform = (AffineTransform)getParam("affinetransform"); |
131 |
colorInterp = (ColorInterpretation)getParam("colorInterpretation");
|
132 |
selectedRois = (ArrayList<VectorialROI>)getParam("selectedrois"); |
133 |
if(getIntArrayParam("resolution") != null) { |
134 |
resolutionWidth = getIntArrayParam("resolution")[0]; |
135 |
resolutionHeight = getIntArrayParam("resolution")[1]; |
136 |
} |
137 |
params = (Params) getParam("driverparams");
|
138 |
} |
139 |
|
140 |
/**
|
141 |
* Salva la tabla de color al fichero rmf.
|
142 |
* @param fName
|
143 |
* @throws IOException
|
144 |
*/
|
145 |
private void saveToRmf(String fileName) { |
146 |
RasterDataStore rds = null;
|
147 |
int limitNumberOfRequests = 20; |
148 |
while (rds == null && limitNumberOfRequests > 0) { |
149 |
try {
|
150 |
rds = rasterSE.getDataStore(); |
151 |
} catch (IndexOutOfBoundsException e) { |
152 |
//En ocasiones, sobre todo con servicios remotos al pedir un datasource da una excepci?n de este tipo
|
153 |
//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
|
154 |
//gestionar pilla a la capa sin datasources asociados ya que est? reasignandolo. Si volvemos a pedirlo debe
|
155 |
//haberlo cargado ya.
|
156 |
try {
|
157 |
Thread.sleep(200); |
158 |
} catch (InterruptedException e1) { |
159 |
} |
160 |
} |
161 |
limitNumberOfRequests--; |
162 |
} |
163 |
|
164 |
if (rds == null) { |
165 |
//RasterToolsUtil.messageBoxError("error_load_layer", this, new Exception("Error writing RMF. limitNumberOfRequests=" + limitNumberOfRequests));
|
166 |
return;
|
167 |
} |
168 |
|
169 |
// Guardamos en el RMF el valor NoData
|
170 |
if(rasterSE.getNoDataValue() != null) { |
171 |
NoData nodata = (NoData)rasterSE.getNoDataValue(); |
172 |
nodata.setFileName(fileName); |
173 |
nodata.save(); |
174 |
} |
175 |
|
176 |
// Guardamos en el RMF la tabla de color
|
177 |
ColorTable colorTable = rasterSE.getRender().getColorTable(); |
178 |
try {
|
179 |
rManager.getProviderServices().saveObjectToRmfFile(fileName, ColorTable.class, colorTable); |
180 |
} catch (RmfSerializerException e) {
|
181 |
RasterToolsUtil.messageBoxError("error_salvando_rmf", this, e); |
182 |
} |
183 |
} |
184 |
|
185 |
/**
|
186 |
* Tarea de recorte
|
187 |
*/
|
188 |
@SuppressWarnings("deprecation") |
189 |
public void process() throws ProcessInterruptedException { |
190 |
RasterDataStore dstoreCopy = null;
|
191 |
RasterUtils util = RasterLocator.getManager().getRasterUtils(); |
192 |
|
193 |
try {
|
194 |
long t2;
|
195 |
long t1 = new java.util.Date().getTime(); |
196 |
|
197 |
try {
|
198 |
Thread.sleep(1000); |
199 |
} catch (InterruptedException e1) { |
200 |
e1.printStackTrace(); |
201 |
} |
202 |
|
203 |
insertLineLog(RasterToolsUtil.getText(this, "leyendo_raster")); |
204 |
|
205 |
dstoreCopy = rasterSE.getDataStore().newDataStore(); |
206 |
RasterQuery query = rManager.createQuery(); |
207 |
query.setDrawableBands(drawableBands); |
208 |
|
209 |
if(dstoreCopy.getParameters() instanceof RemoteStoreParameters && |
210 |
!((RemoteStoreParameters)dstoreCopy.getParameters()).isSizeFixed()) { |
211 |
insertLineLog(RasterToolsUtil.getText(this, "downloading_image")); |
212 |
((RemoteStoreParameters)dstoreCopy.getParameters()).setWidth(resolutionWidth); |
213 |
((RemoteStoreParameters)dstoreCopy.getParameters()).setHeight(resolutionHeight); |
214 |
Extent bbox = RasterLocator.getManager().getDataStructFactory().createExtent(wcValues[0], wcValues[1], wcValues[2], wcValues[3]); |
215 |
query.setAreaOfInterest(bbox, resolutionWidth, resolutionHeight); |
216 |
try {
|
217 |
buffer = dstoreCopy.query(query); |
218 |
} catch (InvalidSetViewException e) {
|
219 |
RasterToolsUtil.messageBoxError("No se ha podido asignar la vista al inicial el proceso de recorte.", this, e); |
220 |
} |
221 |
} else {
|
222 |
if(interpolationMethod != Buffer.INTERPOLATION_Undefined) { |
223 |
try {
|
224 |
if(pValues != null) { |
225 |
if (util.isBufferTooBig(new double[] { pValues[0], pValues[3], pValues[2], pValues[1] }, drawableBands.length)) |
226 |
query.setReadOnly(true);
|
227 |
query.setAreaOfInterest((int)pValues[0], (int)pValues[1], (int)Math.abs(pValues[2] - pValues[0]) + 1, (int)Math.abs(pValues[3] - pValues[1]) + 1); |
228 |
} else if(wcValues != null) { |
229 |
query.setReadOnly(true);
|
230 |
query.setAreaOfInterest(wcValues[0], wcValues[1], Math.abs(wcValues[0] - wcValues[2]), Math.abs(wcValues[1] - wcValues[3])); |
231 |
} |
232 |
buffer = dstoreCopy.query(query); |
233 |
} catch (InvalidSetViewException e) {
|
234 |
RasterToolsUtil.messageBoxError("No se ha podido asignar la vista al inicial el proceso de recorte.", this, e); |
235 |
} |
236 |
|
237 |
insertLineLog(RasterToolsUtil.getText(this, "interpolando")); |
238 |
|
239 |
Buffer bufTmp = buffer;
|
240 |
processIncrement = bufTmp.getIncrementableTask(Buffer.INCREMENTABLE_INTERPOLATION);
|
241 |
buffer = bufTmp.getAdjustedWindow(resolutionWidth, resolutionHeight, interpolationMethod); |
242 |
if(bufTmp != buffer)
|
243 |
bufTmp.dispose(); |
244 |
} else {
|
245 |
try {
|
246 |
if (util.isBufferTooBig(new double[] { 0, 0, resolutionWidth, resolutionHeight }, drawableBands.length)) |
247 |
query.setReadOnly(true);
|
248 |
if(pValues != null) |
249 |
query.setAreaOfInterest((int)pValues[0], (int)pValues[3], (int)Math.abs(pValues[2] - pValues[0]) + 1, (int)Math.abs(pValues[1] - pValues[3]) + 1, resolutionWidth, resolutionHeight); |
250 |
else if(wcValues != null) { |
251 |
Extent bbox = RasterLocator.getManager().getDataStructFactory().createExtent(wcValues[0], wcValues[1], wcValues[2], wcValues[3]); |
252 |
query.setAreaOfInterest(bbox, resolutionWidth, resolutionHeight); |
253 |
} |
254 |
buffer = dstoreCopy.query(query); |
255 |
} catch (InvalidSetViewException e) {
|
256 |
RasterToolsUtil.messageBoxError("No se ha podido asignar la vista al inicial el proceso de recorte.", this, e); |
257 |
} |
258 |
} |
259 |
} |
260 |
|
261 |
//TODO: FUNCIONALIDAD: Poner los getWriter con la proyecci?n del fichero fuente
|
262 |
|
263 |
if ((selectedRois != null) && (!query.isReadOnly())){ |
264 |
if (selectedRois.size() > 0){ |
265 |
int despX = 0; |
266 |
int despY = 0; |
267 |
if (pValues != null){ |
268 |
despX = (int)pValues[0]; |
269 |
despY = (int)pValues[1]; |
270 |
} else if (wcValues != null){ |
271 |
despX = (int)dstoreCopy.worldToRaster(new Point2D.Double(wcValues[0], wcValues[1])).getX(); |
272 |
despY = (int)dstoreCopy.worldToRaster(new Point2D.Double(wcValues[0], wcValues[1])).getY(); |
273 |
} |
274 |
drawOnlyROIs(buffer, selectedRois, despX, despY); |
275 |
} |
276 |
} |
277 |
|
278 |
|
279 |
insertLineLog(RasterToolsUtil.getText(this, "salvando_imagen")); |
280 |
|
281 |
DataManager manager = DALLocator.getDataManager(); |
282 |
String provider = "Gdal Store"; |
283 |
DataServerExplorerParameters eparams = manager.createServerExplorerParameters("FilesystemExplorer");
|
284 |
|
285 |
String finalFileName = ""; |
286 |
NewRasterStoreParameters sparams = null;
|
287 |
processIncrement = RasterLocator.getManager().createDataServerWriter(); |
288 |
if (oneLayerPerBand) {
|
289 |
long[] milis = new long[drawableBands.length]; |
290 |
String[] fileNames = new String[drawableBands.length]; |
291 |
for (int i = 0; i < drawableBands.length; i++) { |
292 |
fileNames[i] = fileName + "_B" + drawableBands[i] + suffix;
|
293 |
|
294 |
int index = fileNames[i].lastIndexOf(File.separator); |
295 |
if(index < 0) |
296 |
index = fileNames[i].length(); |
297 |
String path = fileNames[i].substring(0, index); |
298 |
String file = fileNames[i].substring(index + 1, fileNames[i].length()); |
299 |
|
300 |
eparams.setDynValue("initialpath", path);
|
301 |
DataServerExplorer serverExplorer = manager.openServerExplorer(eparams.getExplorerName(), eparams); |
302 |
|
303 |
sparams = (NewRasterStoreParameters)serverExplorer.getAddParameters(provider); |
304 |
sparams.setDataServer((DataServerWriter)processIncrement); |
305 |
sparams.setDestination(path, file); |
306 |
sparams.setBuffer(buffer); |
307 |
sparams.setColorInterpretation(new String[]{ColorInterpretation.GRAY_BAND}); |
308 |
sparams.setWktProjection(dstoreCopy.getWktProjection()); |
309 |
sparams.setBand(i); |
310 |
sparams.setAffineTransform(affineTransform); |
311 |
sparams.setDriverParams(params); |
312 |
|
313 |
serverExplorer.add(provider, sparams, true);
|
314 |
|
315 |
saveToRmf(fileNames[i]); |
316 |
t2 = new java.util.Date().getTime();
|
317 |
milis[i] = (t2 - t1); |
318 |
t1 = new java.util.Date().getTime();
|
319 |
} |
320 |
if (incrementableTask != null) { |
321 |
incrementableTask.processFinalize(); |
322 |
incrementableTask = null;
|
323 |
} |
324 |
if(viewName != null) { |
325 |
if (RasterToolsUtil.messageBoxYesOrNot("cargar_toc", this)) { |
326 |
try {
|
327 |
for (int i = 0; i < drawableBands.length; i++) { |
328 |
FLayer lyr = RasterToolsUtil.loadLayer(viewName, fileNames[i], null);
|
329 |
if(lyr != null && lyr instanceof DefaultFLyrRaster) |
330 |
((DefaultFLyrRaster)lyr).setRois(rasterSE.getRois()); |
331 |
} |
332 |
} catch (RasterNotLoadException e) {
|
333 |
RasterToolsUtil.messageBoxError("error_load_layer", this, e); |
334 |
} |
335 |
} |
336 |
} |
337 |
for (int i = 0; i < drawableBands.length; i++) { |
338 |
if (externalActions != null) |
339 |
externalActions.end(new Object[] { fileName + "_B" + drawableBands[i] + suffix, new Long(milis[i]) }); |
340 |
} |
341 |
} else {
|
342 |
if (isUsingFile(fileName)) {
|
343 |
incrementableTask.hideWindow(); |
344 |
RasterToolsUtil.messageBoxError("error_opened_file", this); |
345 |
return;
|
346 |
} |
347 |
File f = new File(fileName); |
348 |
if (f.exists()) {
|
349 |
f.delete(); |
350 |
} |
351 |
f = null;
|
352 |
|
353 |
if(suffix != null) |
354 |
finalFileName = fileName.endsWith(suffix) ? fileName : fileName + suffix; |
355 |
else
|
356 |
finalFileName = fileName; |
357 |
|
358 |
int index = finalFileName.lastIndexOf(File.separator); |
359 |
if(index < 0) |
360 |
index = finalFileName.length(); |
361 |
String path = finalFileName.substring(0, index); |
362 |
String file = finalFileName.substring(index + 1, finalFileName.length()); |
363 |
|
364 |
eparams.setDynValue("initialpath", path);
|
365 |
DataServerExplorer serverExplorer = manager.openServerExplorer(eparams.getExplorerName(), eparams); |
366 |
|
367 |
try {
|
368 |
provider = rManager.createWriter(finalFileName).getProviderName(); |
369 |
} catch (NotSupportedExtensionException e1) {
|
370 |
RasterToolsUtil.messageBoxError("no_driver_escritura", this, e1); |
371 |
} catch (RasterDriverException e1) {
|
372 |
RasterToolsUtil.messageBoxError("no_driver_escritura", this, e1); |
373 |
} |
374 |
|
375 |
sparams = (NewRasterStoreParameters)serverExplorer.getAddParameters(provider); |
376 |
sparams.setDataServer((DataServerWriter)processIncrement); |
377 |
sparams.setDestination(path, file); |
378 |
sparams.setBuffer(buffer); |
379 |
if(colorInterp != null) |
380 |
sparams.setColorInterpretation(colorInterp.getValues()); |
381 |
sparams.setWktProjection(dstoreCopy.getWktProjection()); |
382 |
sparams.setAffineTransform(affineTransform); |
383 |
sparams.setDriverParams(params); |
384 |
sparams.setBand(-1);
|
385 |
|
386 |
serverExplorer.add(provider, sparams, true);
|
387 |
|
388 |
saveToRmf(finalFileName); |
389 |
|
390 |
|
391 |
t2 = new java.util.Date().getTime();
|
392 |
if (incrementableTask != null) { |
393 |
incrementableTask.processFinalize(); |
394 |
incrementableTask = null;
|
395 |
} |
396 |
//Damos tiempo a parar el Thread del incrementable para que no se cuelgue la ventana
|
397 |
//El tiempo es como m?nimo el de un bucle del run de la tarea incrementable
|
398 |
try {
|
399 |
Thread.sleep(600); |
400 |
} catch (InterruptedException e) { |
401 |
throw new ProcessInterruptedException(e); |
402 |
} |
403 |
cutFinalize(finalFileName, (t2 - t1)); |
404 |
} |
405 |
|
406 |
} catch (RasterDriverException e) {
|
407 |
RasterToolsUtil.messageBoxError("error_writer", this, e); |
408 |
} catch (ValidateDataParametersException e) {
|
409 |
RasterToolsUtil.messageBoxError("error_georasterwriter", this, e); |
410 |
} catch (ProviderNotRegisteredException e) {
|
411 |
RasterToolsUtil.messageBoxError("error_georasterwriter", this, e); |
412 |
} catch (InitializeException e) {
|
413 |
RasterToolsUtil.messageBoxError("error_georasterwriter", this, e); |
414 |
} catch (DataException e) {
|
415 |
RasterToolsUtil.messageBoxError("error_georasterwriter", this, e); |
416 |
} catch (Exception e) { |
417 |
e.printStackTrace(); |
418 |
} finally {
|
419 |
if (dstoreCopy != null) |
420 |
try {
|
421 |
dstoreCopy.close(); |
422 |
} catch (CloseException e) {
|
423 |
RasterToolsUtil.debug("error_writer", this, e); |
424 |
} |
425 |
buffer = null;
|
426 |
} |
427 |
} |
428 |
|
429 |
|
430 |
/**
|
431 |
* Acciones para poner a NoData los pixels que est?n fuera de las
|
432 |
* regiones de inter?s seleccionadas.
|
433 |
* @param buffer
|
434 |
*/
|
435 |
private void drawOnlyROIs(Buffer buffer, ArrayList<VectorialROI> rois, int despX, int despY){ |
436 |
for (int i = 0 ; i < buffer.getWidth() ; i++){ |
437 |
for (int j = 0 ; j < buffer.getHeight() ; j++){ |
438 |
boolean inside = false; |
439 |
for (int k = 0 ; k < rois.size() ; k++){ |
440 |
VectorialROI roi = (VectorialROI)rois.get(k); |
441 |
//TODO: Hacer la comprobacion por coordenadas del mundo en lugar de coordenadas pixel.
|
442 |
if (roi.isInGrid(i + despX, j + despY)){
|
443 |
inside = true;
|
444 |
} |
445 |
} |
446 |
if (!inside){
|
447 |
for (int l = 0 ; l < buffer.getBandCount() ; l++){ |
448 |
if (buffer.getDataType() == Buffer.TYPE_BYTE){ |
449 |
buffer.setElem(j, i, l, |
450 |
buffer.getNoDataValue().isDefined() ? buffer.getNoDataValue().getValue().byteValue() : RasterLibrary.defaultByteNoDataValue); |
451 |
} else if (buffer.getDataType() == Buffer.TYPE_SHORT){ |
452 |
buffer.setElem(j, i, l, |
453 |
buffer.getNoDataValue().isDefined() ? buffer.getNoDataValue().getValue().shortValue() : RasterLibrary.defaultShortNoDataValue); |
454 |
} else if (buffer.getDataType() == Buffer.TYPE_INT){ |
455 |
buffer.setElem(j, i, l, |
456 |
buffer.getNoDataValue().isDefined() ? buffer.getNoDataValue().getValue().intValue() : RasterLibrary.defaultIntegerNoDataValue); |
457 |
} else if (buffer.getDataType() == Buffer.TYPE_FLOAT){ |
458 |
buffer.setElem(j, i, l, |
459 |
buffer.getNoDataValue().isDefined() ? buffer.getNoDataValue().getValue().floatValue() : RasterLibrary.defaultFloatNoDataValue); |
460 |
} else if (buffer.getDataType() == Buffer.TYPE_DOUBLE){ |
461 |
buffer.setElem(j, i, l, |
462 |
buffer.getNoDataValue().isDefined() ? buffer.getNoDataValue().getValue().doubleValue() : RasterLibrary.defaultDoubleNoDataValue); |
463 |
} |
464 |
} |
465 |
} |
466 |
} |
467 |
} |
468 |
} |
469 |
|
470 |
|
471 |
/**
|
472 |
* Returns true if there is a layer in the current project using the file named with
|
473 |
* fileName.
|
474 |
* @param fileName
|
475 |
* @return
|
476 |
*/
|
477 |
private boolean isUsingFile(String fileName) { |
478 |
List<Document> docs = ProjectManager.getInstance().getCurrentProject().getDocuments(); |
479 |
|
480 |
for (int i = 0 ;i < docs.size() ;i++) { |
481 |
if (docs.get(i) instanceof BaseViewDocument) { |
482 |
FLayers lyrs = ((BaseViewDocument)docs.get(i)).getMapContext().getLayers(); |
483 |
for (int j = 0 ;j < lyrs.getLayersCount() ;j++) { |
484 |
if (lyrs.getLayer(j) instanceof DefaultFLyrRaster) { |
485 |
DefaultFLyrRaster lyr = (DefaultFLyrRaster)lyrs.getLayer(j); |
486 |
if (lyr.getDataStore() != null ){ |
487 |
if (fileName.equals(lyr.getDataStore().getName())) {
|
488 |
return true; |
489 |
} |
490 |
} |
491 |
} |
492 |
} |
493 |
} |
494 |
} |
495 |
return false; |
496 |
} |
497 |
|
498 |
|
499 |
/**
|
500 |
* Acciones que se realizan al finalizar de crear los recortes de imagen.
|
501 |
* Este m?todo es llamado por el thread TailRasterProcess al finalizar.
|
502 |
*/
|
503 |
private void cutFinalize(String fileName, long milis) { |
504 |
if (!new File(fileName).exists()) |
505 |
return;
|
506 |
|
507 |
if(viewName != null) { |
508 |
if (RasterToolsUtil.messageBoxYesOrNot("cargar_toc", this)) { |
509 |
|
510 |
try {
|
511 |
FLayer lyr = RasterToolsUtil.loadLayer(viewName, fileName, null);
|
512 |
if(lyr != null && lyr instanceof DefaultFLyrRaster) |
513 |
((DefaultFLyrRaster)lyr).setRois(rasterSE.getRois()); |
514 |
} catch (RasterNotLoadException e) {
|
515 |
RasterToolsUtil.messageBoxError("error_load_layer", this, e); |
516 |
} |
517 |
} |
518 |
} |
519 |
|
520 |
if (externalActions != null) |
521 |
externalActions.end(new Object[]{fileName, new Long(milis)}); |
522 |
} |
523 |
|
524 |
/*
|
525 |
* (non-Javadoc)
|
526 |
* @see org.gvsig.gui.beans.incrementabletask.IIncrementable#getPercent()
|
527 |
*/
|
528 |
public int getPercent() { |
529 |
return (processIncrement != null) ? processIncrement.getPercent() : 0; |
530 |
} |
531 |
|
532 |
/*
|
533 |
* (non-Javadoc)
|
534 |
* @see org.gvsig.gui.beans.incrementabletask.IIncrementable#getTitle()
|
535 |
*/
|
536 |
public String getTitle() { |
537 |
return RasterToolsUtil.getText(this, "incremento_recorte"); |
538 |
} |
539 |
|
540 |
/*
|
541 |
* (non-Javadoc)
|
542 |
* @see java.lang.Object#finalize()
|
543 |
*/
|
544 |
protected void finalize() throws Throwable { |
545 |
fileName = null;
|
546 |
suffix = null;
|
547 |
rasterSE = null;
|
548 |
drawableBands = null;
|
549 |
pValues = null;
|
550 |
viewName = null;
|
551 |
params = null;
|
552 |
colorInterp = null;
|
553 |
affineTransform = null;
|
554 |
wcValues = null;
|
555 |
buffer = null;
|
556 |
processIncrement = null;
|
557 |
if(selectedRois != null) { |
558 |
selectedRois.clear(); |
559 |
selectedRois = null;
|
560 |
} |
561 |
super.finalize();
|
562 |
} |
563 |
} |