gvsig-raster / org.gvsig.raster.tools / branches / org.gvsig.raster.tools_dataaccess_refactoring / org.gvsig.raster.tools.app.basic / src / main / java / org / gvsig / raster / tools / app / basic / tool / saveraster / operation / CopyDataset.java @ 2340
History | View | Annotate | Download (5.77 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.tool.saveraster.operation; |
23 |
|
24 |
import java.io.File; |
25 |
|
26 |
import org.gvsig.fmap.dal.coverage.RasterLocator; |
27 |
import org.gvsig.fmap.dal.coverage.RasterManager; |
28 |
import org.gvsig.fmap.dal.coverage.dataset.Buffer; |
29 |
import org.gvsig.fmap.dal.coverage.datastruct.Params; |
30 |
import org.gvsig.fmap.dal.coverage.exception.NotSupportedExtensionException; |
31 |
import org.gvsig.fmap.dal.coverage.exception.ProcessInterruptedException; |
32 |
import org.gvsig.fmap.dal.coverage.exception.RasterDriverException; |
33 |
import org.gvsig.fmap.mapcontext.exceptions.LoadLayerException; |
34 |
import org.gvsig.gui.beans.incrementabletask.IncrementableTask; |
35 |
import org.gvsig.raster.algorithm.process.DataProcess; |
36 |
import org.gvsig.raster.algorithm.process.ProcessException; |
37 |
import org.gvsig.raster.fmap.layers.DefaultFLyrRaster; |
38 |
import org.gvsig.raster.fmap.layers.FLyrRaster; |
39 |
import org.gvsig.raster.swing.RasterSwingLibrary; |
40 |
import org.gvsig.raster.tools.app.basic.raster.process.ClippingProcess; |
41 |
import org.gvsig.raster.tools.app.basic.tool.saveas.SaveAsActions; |
42 |
|
43 |
/**
|
44 |
* Builds a copy of a raster file
|
45 |
*
|
46 |
* @author Nacho Brodin (nachobrodin@gmail.com)
|
47 |
*/
|
48 |
public class CopyDataset { |
49 |
private String fDstName = null; |
50 |
private String fSrcName = null; |
51 |
private FLyrRaster src = null; |
52 |
private DataProcess clippingProcess = null; |
53 |
private IncrementableTask incrementableTask = null; |
54 |
private RasterManager rManager = RasterLocator.getManager();
|
55 |
|
56 |
/**
|
57 |
* Constructor
|
58 |
* @param src Nombre del fichero fuente
|
59 |
* @param dst Nombre del fichero destino
|
60 |
* @throws LoadLayerException
|
61 |
* @throws LoadLayerException
|
62 |
* @throws RasterDriverException
|
63 |
* @throws NotSupportedExtensionException
|
64 |
*/
|
65 |
public CopyDataset(String src, String dst) throws LoadLayerException { |
66 |
fSrcName = src; |
67 |
fDstName = dst; |
68 |
File f = new File(fDstName); |
69 |
if(f.exists())
|
70 |
f.delete(); |
71 |
this.src = DefaultFLyrRaster.createLayer("lyr", new File(fSrcName)); |
72 |
} |
73 |
|
74 |
/**
|
75 |
* Constructor
|
76 |
* @param src Nombre del fichero fuente
|
77 |
* @param dst Nombre del fichero destino
|
78 |
* @throws LoadLayerException
|
79 |
* @throws RasterDriverException
|
80 |
* @throws NotSupportedExtensionException
|
81 |
*/
|
82 |
public CopyDataset(String src, String dst, IncrementableTask incrementableTask) throws LoadLayerException { |
83 |
fSrcName = src; |
84 |
fDstName = dst; |
85 |
this.incrementableTask = incrementableTask;
|
86 |
File f = new File(fDstName); |
87 |
if(f.exists())
|
88 |
f.delete(); |
89 |
this.src = DefaultFLyrRaster.createLayer("lyr", new File(fSrcName)); |
90 |
} |
91 |
|
92 |
/**
|
93 |
* Funci?n que realiza la copia del dataset
|
94 |
* @throws ProcessException
|
95 |
* @throws org.gvsig.raster.algorithm.process.ProcessException
|
96 |
* @throws InterruptedException
|
97 |
*/
|
98 |
@SuppressWarnings("deprecation") |
99 |
public void copy() throws ProcessInterruptedException, ProcessException { |
100 |
// Creaci?n de par?metros
|
101 |
int[] dValues = new int[] { 0, (int) src.getDataStore().getHeight(), (int) src.getDataStore().getWidth(), 0 }; |
102 |
int[] drawableBands = new int[src.getDataStore().getBandCount()]; |
103 |
for (int i = 0; i < src.getDataStore().getBandCount(); i++) |
104 |
drawableBands[i] = i; |
105 |
Params params = null;
|
106 |
try {
|
107 |
params = rManager.createWriter(fDstName).getParams(); |
108 |
} catch (NotSupportedExtensionException e1) {
|
109 |
RasterSwingLibrary.messageBoxError("no_driver_escritura", this, e1); |
110 |
} catch (RasterDriverException e1) {
|
111 |
RasterSwingLibrary.messageBoxError("no_driver_escritura", this, e1); |
112 |
} |
113 |
|
114 |
// Lanzamiento del proceso de guardado
|
115 |
clippingProcess = new ClippingProcess();
|
116 |
clippingProcess.setActions(new SaveAsActions());
|
117 |
if(incrementableTask != null) |
118 |
clippingProcess.addParam("cancellable", new ExternalCancellable(incrementableTask)); |
119 |
clippingProcess.addParam("showenddialog", new Boolean(false)); |
120 |
clippingProcess.addParam("pixelcoordinates", dValues);
|
121 |
int index = fDstName.lastIndexOf("."); |
122 |
if(index > 0) { |
123 |
String suffix = fDstName.substring(index, fDstName.length());
|
124 |
if(suffix.length() == 4) |
125 |
clippingProcess.addParam("suffix", suffix);
|
126 |
} |
127 |
clippingProcess.addParam("filename", fDstName);
|
128 |
clippingProcess.addParam("layer", src.getDataStore());
|
129 |
clippingProcess.addParam("drawablebands", drawableBands);
|
130 |
clippingProcess.addParam("colorInterpretation", src.getDataStore().getColorInterpretation());
|
131 |
clippingProcess.addParam("onelayerperband", new Boolean(false)); |
132 |
clippingProcess.addParam("interpolationmethod", new Integer(Buffer.INTERPOLATION_NearestNeighbour)); |
133 |
clippingProcess.addParam("affinetransform", src.getDataStore().getAffineTransform());
|
134 |
clippingProcess.addParam("resolution", new int[]{(int) src.getDataStore().getWidth(), |
135 |
(int) src.getDataStore().getHeight()});
|
136 |
clippingProcess.addParam("driverparams", params);
|
137 |
clippingProcess.execute(); |
138 |
} |
139 |
|
140 |
/**
|
141 |
* Obtiene el incremento de escritura
|
142 |
* @return
|
143 |
*/
|
144 |
public int getPercent() { |
145 |
if(clippingProcess != null) |
146 |
return clippingProcess.getPercent();
|
147 |
return 0; |
148 |
} |
149 |
} |