Revision 2201
org.gvsig.raster.tools/tags/tagdate_11102013_11_26/org.gvsig.raster.tools/org.gvsig.raster.tools.algorithm/org.gvsig.raster.tools.algorithm.saveraster/src/main/java/org/gvsig/raster/tools/algorithm/saveraster/ExternalCancellable.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.algorithm.saveraster; |
|
23 |
|
|
24 |
import org.gvsig.raster.algorithm.gui.IncrementableTask; |
|
25 |
|
|
26 |
|
|
27 |
public class ExternalCancellable implements org.gvsig.fmap.dal.coverage.store.ExternalCancellable { |
|
28 |
private IncrementableTask task = null; |
|
29 |
|
|
30 |
public ExternalCancellable(IncrementableTask task) { |
|
31 |
this.task = task; |
|
32 |
} |
|
33 |
|
|
34 |
/* |
|
35 |
* (non-Javadoc) |
|
36 |
* @see org.gvsig.raster.dataset.io.IExternalCancellable#processFinalize() |
|
37 |
*/ |
|
38 |
public void processFinalize() { |
|
39 |
if(task != null) |
|
40 |
task.processFinalize(); |
|
41 |
} |
|
42 |
} |
|
0 | 43 |
org.gvsig.raster.tools/tags/tagdate_11102013_11_26/org.gvsig.raster.tools/org.gvsig.raster.tools.algorithm/org.gvsig.raster.tools.algorithm.saveraster/src/main/java/org/gvsig/raster/tools/algorithm/saveraster/SaveRasterAlgorithmLibrary.java | ||
---|---|---|
1 |
/* |
|
2 |
* gvSIG. Desktop Geographic Information System. |
|
3 |
* |
|
4 |
* Copyright (C) 2007-2012 gvSIG Association. |
|
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 |
* For any additional information, do not hesitate to contact us |
|
22 |
* at info AT gvsig.com, or visit our website www.gvsig.com. |
|
23 |
*/ |
|
24 |
package org.gvsig.raster.tools.algorithm.saveraster; |
|
25 |
|
|
26 |
import org.gvsig.i18n.Messages; |
|
27 |
import org.gvsig.raster.algorithm.RasterBaseAlgorithmLibrary; |
|
28 |
import org.gvsig.tools.library.AbstractLibrary; |
|
29 |
import org.gvsig.tools.library.LibraryException; |
|
30 |
|
|
31 |
/** |
|
32 |
* Initialization of SaveRasterAlgorithmLibrary library. |
|
33 |
* |
|
34 |
* @author <a href="mailto:nachobrodin@gmail.com">Nacho Brodin</a> |
|
35 |
*/ |
|
36 |
public class SaveRasterAlgorithmLibrary extends AbstractLibrary { |
|
37 |
public static final String PROCESS_LABEL = "SaveRasterProcess"; |
|
38 |
|
|
39 |
@Override |
|
40 |
protected void doInitialize() throws LibraryException { |
|
41 |
// Nothing to do |
|
42 |
} |
|
43 |
|
|
44 |
@Override |
|
45 |
protected void doPostInitialize() throws LibraryException { |
|
46 |
//Registers the process and its parameters |
|
47 |
RasterBaseAlgorithmLibrary.register(PROCESS_LABEL, SaveRasterProcess.class); |
|
48 |
SaveRasterProcess.registerParameters(); |
|
49 |
|
|
50 |
Messages.addResourceFamily( |
|
51 |
"org.gvsig.raster.tools.algorithm.saveraster", |
|
52 |
SaveRasterAlgorithmLibrary.class.getClassLoader(), |
|
53 |
SaveRasterAlgorithmLibrary.class.getClass().getName()); |
|
54 |
//registerGeoProcess(new SaveRasterAlgorithmLibrary()); |
|
55 |
} |
|
56 |
} |
|
0 | 57 |
org.gvsig.raster.tools/tags/tagdate_11102013_11_26/org.gvsig.raster.tools/org.gvsig.raster.tools.algorithm/org.gvsig.raster.tools.algorithm.saveraster/src/main/java/org/gvsig/raster/tools/algorithm/saveraster/RasterizeFLayers.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.algorithm.saveraster; |
|
23 |
|
|
24 |
import java.awt.Color; |
|
25 |
import java.awt.Dimension; |
|
26 |
import java.awt.Graphics2D; |
|
27 |
import java.awt.geom.Rectangle2D; |
|
28 |
import java.awt.image.BufferedImage; |
|
29 |
|
|
30 |
import org.gvsig.fmap.dal.coverage.dataset.Buffer; |
|
31 |
import org.gvsig.fmap.dal.coverage.exception.ProcessInterruptedException; |
|
32 |
import org.gvsig.fmap.dal.coverage.store.DataServerWriter; |
|
33 |
import org.gvsig.fmap.dal.exception.ReadException; |
|
34 |
import org.gvsig.fmap.geom.GeometryLocator; |
|
35 |
import org.gvsig.fmap.geom.GeometryManager; |
|
36 |
import org.gvsig.fmap.geom.Geometry.SUBTYPES; |
|
37 |
import org.gvsig.fmap.geom.exception.CreateEnvelopeException; |
|
38 |
import org.gvsig.fmap.geom.primitive.Envelope; |
|
39 |
import org.gvsig.fmap.mapcontext.ViewPort; |
|
40 |
import org.gvsig.fmap.mapcontext.impl.DefaultMapContextDrawer; |
|
41 |
import org.gvsig.fmap.mapcontext.layers.FLayers; |
|
42 |
import org.gvsig.gui.beans.incrementabletask.IIncrementable; |
|
43 |
import org.gvsig.i18n.Messages; |
|
44 |
import org.gvsig.raster.algorithm.process.DataProcess; |
|
45 |
import org.gvsig.raster.fmap.layers.FLyrRaster; |
|
46 |
import org.gvsig.tools.task.Cancellable; |
|
47 |
import org.slf4j.Logger; |
|
48 |
import org.slf4j.LoggerFactory; |
|
49 |
|
|
50 |
/** |
|
51 |
* Sirve datos solicitados por los drivers que salvan a raster. Hereda de |
|
52 |
* Rasterizer y reescribe el m?todo readData que es el que ser? llamado desde el |
|
53 |
* driver cada vez que vacie el buffer y necesite m?s datos. |
|
54 |
* |
|
55 |
* @version 04/06/2007 |
|
56 |
* @author Nacho Brodin (nachobrodin@gmail.com) |
|
57 |
*/ |
|
58 |
@SuppressWarnings("deprecation") |
|
59 |
public class RasterizeFLayers implements DataServerWriter, IIncrementable { |
|
60 |
private static final GeometryManager geomManager = GeometryLocator.getGeometryManager(); |
|
61 |
private Logger logger = LoggerFactory.getLogger(DataProcess.class.toString()); |
|
62 |
|
|
63 |
private ViewPort viewPort = null; |
|
64 |
private ViewPort viewPortBlock = null; |
|
65 |
private FLayers flayers = null; |
|
66 |
private Color backgroundColor = null; |
|
67 |
private boolean firstRead = true; |
|
68 |
private int nBlocks = 0; |
|
69 |
// private double percentMax = 100.0D; |
|
70 |
protected double wcIntervalo = 0; |
|
71 |
protected Dimension dimension = null; |
|
72 |
protected int blockSize = 0; |
|
73 |
protected double wcAlto = 0; |
|
74 |
protected int lastBlock = 0; |
|
75 |
protected BufferedImage image = null; |
|
76 |
protected int[] rasterData = null; |
|
77 |
protected int contBlocks = 1; |
|
78 |
protected int percent = 0; |
|
79 |
protected int imgHeight = 0; |
|
80 |
|
|
81 |
/** |
|
82 |
* Calculo del viewPort |
|
83 |
* @param vp |
|
84 |
*/ |
|
85 |
private void calcViewPort(ViewPort vp) { |
|
86 |
Rectangle2D ext = null; |
|
87 |
|
|
88 |
if (viewPortBlock == null) |
|
89 |
ext = new Rectangle2D.Double( vp.getExtent().getMinX(), |
|
90 |
vp.getExtent().getMaxY() - wcIntervalo, |
|
91 |
vp.getExtent().getWidth(), |
|
92 |
wcIntervalo |
|
93 |
); |
|
94 |
else |
|
95 |
ext = new Rectangle2D.Double( viewPortBlock.getExtent().getMinX(), |
|
96 |
viewPortBlock.getExtent().getMinY() - wcIntervalo, |
|
97 |
viewPortBlock.getExtent().getWidth(), |
|
98 |
wcIntervalo |
|
99 |
); |
|
100 |
|
|
101 |
viewPortBlock = new ViewPort(vp.getProjection()); |
|
102 |
Envelope env; |
|
103 |
try { |
|
104 |
env = geomManager.createEnvelope(ext.getMinX(), ext.getMinY(), ext.getMaxX(), ext.getMaxY(), SUBTYPES.GEOM2D); |
|
105 |
viewPortBlock.setEnvelope(env); |
|
106 |
} catch (CreateEnvelopeException e) { |
|
107 |
logger.debug("Error creating the envelope", null, e); |
|
108 |
} |
|
109 |
viewPortBlock.setImageSize(dimension); |
|
110 |
viewPortBlock.refreshExtent(); |
|
111 |
} |
|
112 |
|
|
113 |
/** |
|
114 |
* Constructor |
|
115 |
* @param flyrs capas |
|
116 |
* @param vp viewport |
|
117 |
* @param blockSize altura del bloque que se lee de una vez en la imagen de entrada |
|
118 |
* @param mapCtrl Mapcontrol |
|
119 |
*/ |
|
120 |
public RasterizeFLayers(FLayers flyrs, ViewPort vp, int blockSize) { |
|
121 |
this.blockSize = blockSize; |
|
122 |
backgroundColor = vp.getBackColor(); |
|
123 |
viewPort = new ViewPort(vp.getProjection()); |
|
124 |
viewPort.setImageSize(vp.getImageSize()); |
|
125 |
/*Rectangle2D ex = vp.getExtent(); |
|
126 |
Envelope env = null; |
|
127 |
try { |
|
128 |
env = geomManager.createEnvelope(ex.getMinX(), ex.getMinY(), ex.getMaxX(), ex.getMaxY(), SUBTYPES.GEOM2D); |
|
129 |
//viewPortBlock = new ViewPort(vp.getProjection()); |
|
130 |
//viewPortBlock.setEnvelope(env); |
|
131 |
} catch (CreateEnvelopeException e) { |
|
132 |
logger.debug("Error creating the envelope", null, e); |
|
133 |
}*/ |
|
134 |
|
|
135 |
|
|
136 |
// Calculo del viewPort del primer bloque |
|
137 |
viewPort.setEnvelope(vp.getAdjustedExtent()); |
|
138 |
wcAlto = viewPort.getExtent().getMaxY() - viewPort.getExtent().getMinY(); |
|
139 |
wcIntervalo = (blockSize * wcAlto) / viewPort.getImageHeight(); |
|
140 |
dimension = new Dimension(viewPort.getImageWidth(), blockSize); |
|
141 |
|
|
142 |
imgHeight = vp.getImageHeight(); |
|
143 |
nBlocks = (vp.getImageHeight() / blockSize); |
|
144 |
|
|
145 |
// Tama?o de ?ltimo bloque en pixeles |
|
146 |
lastBlock = vp.getImageHeight() - (nBlocks * blockSize); |
|
147 |
|
|
148 |
calcViewPort(viewPort); |
|
149 |
|
|
150 |
this.flayers = flyrs; |
|
151 |
} |
|
152 |
|
|
153 |
/** |
|
154 |
* Compatibilidad con el piloto de raster |
|
155 |
* @see readData |
|
156 |
*/ |
|
157 |
public int[] readARGBData(int sX, int sY, int nBand) throws ProcessInterruptedException, OutOfMemoryError { |
|
158 |
return readData( sX, sY, nBand); |
|
159 |
} |
|
160 |
|
|
161 |
public int[] readData(int sX, int sY, int nBand) throws ProcessInterruptedException, OutOfMemoryError { |
|
162 |
if (nBand == 0) { // Con nBand==0 se devuelven las 3 bandas |
|
163 |
nBlocks = (int) Math.ceil(imgHeight / (double) blockSize); |
|
164 |
image = new BufferedImage(sX, sY, BufferedImage.TYPE_INT_ARGB); |
|
165 |
Graphics2D g = (Graphics2D) image.getGraphics(); |
|
166 |
g.setColor(backgroundColor); |
|
167 |
g.fillRect(0, 0, viewPortBlock.getImageWidth(), viewPortBlock.getImageHeight()); |
|
168 |
try { |
|
169 |
// TODO: FUNCIONALIDAD: Salvar los m?ximos y m?nimos para salvar 16 bits |
|
170 |
|
|
171 |
// Si es la primera lectura salvamos los valores de m?ximo y m?nimo para la aplicaci?n |
|
172 |
// de realce si la imagen es de 16 bits. |
|
173 |
if (firstRead) { |
|
174 |
for (int i = 0; i < flayers.getLayersCount(); i++) |
|
175 |
if (flayers.getLayer(i) instanceof FLyrRaster) { |
|
176 |
FLyrRaster raster = (FLyrRaster) flayers.getLayer(i); |
|
177 |
if (raster.getDataStore().getDataType()[0] == Buffer.TYPE_SHORT || raster.getDataStore().getDataType()[0] == Buffer.TYPE_USHORT) { |
|
178 |
//Statistic stats = raster.getSource().getFilterStack().getStats(); |
|
179 |
//stats.history.add(stats.new History(raster.getName(), stats.minBandValue, stats.maxBandValue, stats.secondMinBandValue, stats.secondMaxBandValue)); |
|
180 |
} |
|
181 |
} |
|
182 |
firstRead = false; |
|
183 |
} |
|
184 |
|
|
185 |
DefaultMapContextDrawer mapContextDrawer = new DefaultMapContextDrawer(); |
|
186 |
mapContextDrawer.setMapContext(flayers.getMapContext()); |
|
187 |
mapContextDrawer.setViewPort(viewPortBlock); |
|
188 |
mapContextDrawer.draw(flayers, image, g, new Cancellable(){ |
|
189 |
public boolean isCanceled() { |
|
190 |
return false; |
|
191 |
} |
|
192 |
|
|
193 |
public void setCanceled(boolean canceled) { |
|
194 |
} |
|
195 |
}, flayers.getMapContext().getScaleView()); |
|
196 |
|
|
197 |
// Si es el ?ltimo bloque vaciamos el historial de m?ximos y m?nimos |
|
198 |
if ((contBlocks + 1) == nBlocks) |
|
199 |
for (int i = 0; i < flayers.getLayersCount(); i++) |
|
200 |
if (flayers.getLayer(i) instanceof FLyrRaster) { |
|
201 |
FLyrRaster raster = (FLyrRaster) flayers.getLayer(i); |
|
202 |
if (raster.getDataStore().getDataType()[0] == Buffer.TYPE_SHORT || raster.getDataStore().getDataType()[0] == Buffer.TYPE_USHORT) { |
|
203 |
//raster.getDatasource().getFilterStack().getStats().history.clear(); |
|
204 |
//Statistic stats = raster.getSource().getFilterStack().getStats(); |
|
205 |
} |
|
206 |
} |
|
207 |
|
|
208 |
} catch (ReadException e) { |
|
209 |
logger.debug("Error en el draw de capa", e); |
|
210 |
} |
|
211 |
rasterData = image.getRGB(0, 0, sX, sY, rasterData, 0, sX); |
|
212 |
|
|
213 |
// Calculamos el viewPort del sgte bloque |
|
214 |
|
|
215 |
if (((contBlocks + 1) * blockSize) <= viewPort.getImageHeight()) |
|
216 |
dimension = new Dimension(sX, sY); |
|
217 |
else { // Calculo de la altura del ?ltimo bloque |
|
218 |
dimension = new Dimension(sX, (viewPort.getImageHeight() - (contBlocks * blockSize))); |
|
219 |
wcIntervalo = (lastBlock * wcAlto) / viewPort.getImageHeight(); |
|
220 |
} |
|
221 |
|
|
222 |
calcViewPort(viewPortBlock); |
|
223 |
|
|
224 |
percent = ((100 * (contBlocks)) / nBlocks); |
|
225 |
contBlocks++; |
|
226 |
|
|
227 |
return rasterData; |
|
228 |
} |
|
229 |
|
|
230 |
return null; |
|
231 |
} |
|
232 |
|
|
233 |
/** |
|
234 |
* Asigna el ancho del bloque |
|
235 |
* @param sizeBlock Ancho del bloque en pixeles |
|
236 |
*/ |
|
237 |
public void setBlockSize(int blockSize) { |
|
238 |
this.blockSize = blockSize; |
|
239 |
} |
|
240 |
|
|
241 |
/** |
|
242 |
* No tiene uso en RasterizerLayer |
|
243 |
*/ |
|
244 |
public byte[][] readByteData(int sizeX, int sizeY) { |
|
245 |
return null; |
|
246 |
} |
|
247 |
|
|
248 |
/** |
|
249 |
* No tiene uso en RasterizerLayer |
|
250 |
*/ |
|
251 |
public double[][] readDoubleData(int sizeX, int sizeY) { |
|
252 |
return null; |
|
253 |
} |
|
254 |
|
|
255 |
/** |
|
256 |
* No tiene uso en RasterizerLayer |
|
257 |
*/ |
|
258 |
public float[][] readFloatData(int sizeX, int sizeY) { |
|
259 |
return null; |
|
260 |
} |
|
261 |
|
|
262 |
/** |
|
263 |
* No tiene uso en RasterizerLayer |
|
264 |
*/ |
|
265 |
public int[][] readIntData(int sizeX, int sizeY) { |
|
266 |
return null; |
|
267 |
} |
|
268 |
|
|
269 |
/** |
|
270 |
* No tiene uso en RasterizerLayer |
|
271 |
*/ |
|
272 |
public short[][] readShortData(int sizeX, int sizeY) { |
|
273 |
return null; |
|
274 |
} |
|
275 |
|
|
276 |
public String getTitle() { |
|
277 |
return Messages.getText("salvando_raster"); |
|
278 |
} |
|
279 |
|
|
280 |
public String getLog() { |
|
281 |
return Messages.getText("salvando_bloque") + " " + Math.min(nBlocks, contBlocks) + " " + Messages.getText("de") + " " + nBlocks; |
|
282 |
} |
|
283 |
|
|
284 |
public String getLabel() { |
|
285 |
return Messages.getText("rasterizando") + "..."; |
|
286 |
} |
|
287 |
|
|
288 |
public int getPercent() { |
|
289 |
return percent; |
|
290 |
} |
|
291 |
|
|
292 |
public boolean isCancelable() { |
|
293 |
return true; |
|
294 |
} |
|
295 |
|
|
296 |
public boolean isPausable() { |
|
297 |
return false; |
|
298 |
} |
|
299 |
|
|
300 |
public void setAlphaBuffer(Buffer alphaBuffer) { |
|
301 |
} |
|
302 |
|
|
303 |
public void setBuffer(Buffer buffer, int nband) { |
|
304 |
} |
|
305 |
|
|
306 |
public Buffer getBuffer() { |
|
307 |
return null; |
|
308 |
} |
|
309 |
|
|
310 |
public void setBand(int nband) { |
|
311 |
} |
|
312 |
|
|
313 |
public void dispose() { |
|
314 |
} |
|
315 |
|
|
316 |
public Buffer getSource() { |
|
317 |
return null; |
|
318 |
} |
|
319 |
|
|
320 |
public void setPercent(int value) { |
|
321 |
} |
|
322 |
} |
|
0 | 323 |
org.gvsig.raster.tools/tags/tagdate_11102013_11_26/org.gvsig.raster.tools/org.gvsig.raster.tools.algorithm/org.gvsig.raster.tools.algorithm.saveraster/src/main/java/org/gvsig/raster/tools/algorithm/saveraster/SaveRasterProcess.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.algorithm.saveraster; |
|
23 |
|
|
24 |
import java.awt.Dimension; |
|
25 |
import java.awt.geom.AffineTransform; |
|
26 |
import java.io.File; |
|
27 |
import java.io.IOException; |
|
28 |
import java.util.Date; |
|
29 |
|
|
30 |
import org.cresques.cts.IProjection; |
|
31 |
import org.gvsig.fmap.dal.coverage.RasterLocator; |
|
32 |
import org.gvsig.fmap.dal.coverage.RasterManager; |
|
33 |
import org.gvsig.fmap.dal.coverage.dataset.Buffer; |
|
34 |
import org.gvsig.fmap.dal.coverage.datastruct.Extent; |
|
35 |
import org.gvsig.fmap.dal.coverage.datastruct.Params; |
|
36 |
import org.gvsig.fmap.dal.coverage.datastruct.ViewPortData; |
|
37 |
import org.gvsig.fmap.dal.coverage.exception.NotSupportedExtensionException; |
|
38 |
import org.gvsig.fmap.dal.coverage.exception.ProcessInterruptedException; |
|
39 |
import org.gvsig.fmap.dal.coverage.exception.RasterDriverException; |
|
40 |
import org.gvsig.fmap.dal.coverage.process.TaskEventManager; |
|
41 |
import org.gvsig.fmap.dal.coverage.store.DataServerWriter; |
|
42 |
import org.gvsig.fmap.dal.coverage.store.RasterWriter; |
|
43 |
import org.gvsig.fmap.dal.coverage.util.CRSUtils; |
|
44 |
import org.gvsig.fmap.geom.primitive.Envelope; |
|
45 |
import org.gvsig.fmap.mapcontext.ViewPort; |
|
46 |
import org.gvsig.fmap.mapcontext.layers.FLayers; |
|
47 |
import org.gvsig.raster.algorithm.process.ProcessException; |
|
48 |
import org.gvsig.raster.algorithm.process.DataProcess; |
|
49 |
|
|
50 |
/** |
|
51 |
* Thread que se encarga de llamar a los writer para realizar la tarea de |
|
52 |
* salvado y/p compresi?n |
|
53 |
* |
|
54 |
* @author Nacho Brodin (nachobrodin@gmail.com) |
|
55 |
*/ |
|
56 |
public class SaveRasterProcess extends DataProcess { |
|
57 |
public static String VIEWPORT = "ViewPort"; |
|
58 |
public static String PATH = "Path"; |
|
59 |
public static String DIMENSION = "Dimension"; |
|
60 |
public static String BLOCKSIZE = "Blocksize"; |
|
61 |
public static String FILENAME = "FileName"; |
|
62 |
public static String PARAMS = "WriterParams"; |
|
63 |
public static String FLYRS = "FLyrs"; |
|
64 |
public static String TIME = "Time"; |
|
65 |
public static String PROJECTION = "Projection"; |
|
66 |
|
|
67 |
private IProjection projection = null; |
|
68 |
private ViewPort viewPort = null; |
|
69 |
private Dimension dimension = null; |
|
70 |
private RasterizeFLayers rasterizerLayer = null; |
|
71 |
private String fileName = ""; |
|
72 |
private Params writerParams = null; |
|
73 |
//private CopyDataset jp2Copy = null; |
|
74 |
private boolean supportImage = false; |
|
75 |
private RasterManager rManager = RasterLocator.getManager(); |
|
76 |
//private Logger logger = LoggerFactory.getLogger(RasterProcess.class.toString()); |
|
77 |
|
|
78 |
public static void registerParameters() { |
|
79 |
registerInputParameter(VIEWPORT, ViewPort.class, SaveRasterAlgorithmLibrary.PROCESS_LABEL); |
|
80 |
registerInputParameter(PATH, String.class, SaveRasterAlgorithmLibrary.PROCESS_LABEL); |
|
81 |
registerInputParameter(DIMENSION, Dimension.class, SaveRasterAlgorithmLibrary.PROCESS_LABEL); |
|
82 |
registerInputParameter(FLYRS, FLayers.class, SaveRasterAlgorithmLibrary.PROCESS_LABEL); |
|
83 |
registerInputParameter(PARAMS, Params.class, SaveRasterAlgorithmLibrary.PROCESS_LABEL); |
|
84 |
registerOutputParameter(PROJECTION, IProjection.class, SaveRasterAlgorithmLibrary.PROCESS_LABEL); |
|
85 |
|
|
86 |
registerOutputParameter(FILENAME, String.class, SaveRasterAlgorithmLibrary.PROCESS_LABEL); |
|
87 |
registerOutputParameter(TIME, Long.class, SaveRasterAlgorithmLibrary.PROCESS_LABEL); |
|
88 |
} |
|
89 |
|
|
90 |
public void init() { |
|
91 |
viewPort = getParam(VIEWPORT) != null ? (ViewPort)getParam(VIEWPORT) : null; |
|
92 |
dimension = getParam(DIMENSION) != null ? (Dimension) getParam(DIMENSION) : null; |
|
93 |
FLayers flyrs = getParam(FLYRS) != null ? (FLayers) getParam(FLYRS) : null; |
|
94 |
int blockSize = getIntParam(BLOCKSIZE); |
|
95 |
rasterizerLayer = new RasterizeFLayers(flyrs, viewPort, blockSize); |
|
96 |
fileName = getStringParam(FILENAME); |
|
97 |
writerParams = getParam(PARAMS) != null ? (Params) getParam(PARAMS) : null; |
|
98 |
projection = getParam(PROJECTION) != null ? (IProjection) getParam(PROJECTION) : null; |
|
99 |
//supportImage = getBooleanParam("remotelayers") && fileName.endsWith(".jp2"); |
|
100 |
} |
|
101 |
|
|
102 |
/** |
|
103 |
* Procesos de escritura de una porci?n de la vista. |
|
104 |
*/ |
|
105 |
public void process() throws ProcessInterruptedException, ProcessException { |
|
106 |
TaskEventManager task = rManager.getRasterTask(); |
|
107 |
|
|
108 |
//jp2Copy = null; |
|
109 |
long t2; |
|
110 |
long t1 = new java.util.Date().getTime(); |
|
111 |
|
|
112 |
//Creamos el driver |
|
113 |
Envelope env = viewPort.getAdjustedEnvelope(); |
|
114 |
Extent ex = rManager.getDataStructFactory().createExtent(env.getMinimum(0), env.getMaximum(1), env.getMaximum(0), env.getMinimum(1)); |
|
115 |
Dimension imgSz = viewPort.getImageSize(); |
|
116 |
ViewPortData vpData = rManager.getDataStructFactory().createViewPortData(viewPort.getProjection(), ex, imgSz ); |
|
117 |
AffineTransform at = new AffineTransform(vpData.getExtent().width() / imgSz.width, |
|
118 |
0, 0, |
|
119 |
-(vpData.getExtent().height() / imgSz.height), |
|
120 |
vpData.getExtent().getULX(), |
|
121 |
vpData.getExtent().getULY()); |
|
122 |
String oldFileName = fileName; |
|
123 |
if(supportImage) { |
|
124 |
fileName = fileName.substring(0, Math.min(fileName.lastIndexOf(File.separator) + 1, fileName.length() - 1)); |
|
125 |
fileName += rManager.getFileUtils().usesOnlyLayerName() + ".tif"; |
|
126 |
writerParams = getWriterParams(fileName); |
|
127 |
} |
|
128 |
|
|
129 |
//Ejecutamos el driver con los datos pasados |
|
130 |
try { |
|
131 |
write(fileName, at, writerParams, rasterizerLayer); |
|
132 |
|
|
133 |
if(task.getEvent() != null) |
|
134 |
task.manageEvent(task.getEvent()); |
|
135 |
|
|
136 |
/*if(supportImage) { |
|
137 |
try { |
|
138 |
insertLineLog(Messages.getText("saving_jp2")); |
|
139 |
jp2Copy = new CopyDataset(fileName, oldFileName, incrementableTask); |
|
140 |
jp2Copy.copy(); |
|
141 |
new File(fileName).delete(); |
|
142 |
new File(rManager.getFileUtils().getRMFNameFromFileName(fileName)).delete(); |
|
143 |
} catch (LoadLayerException e) { |
|
144 |
throw new ProcessException("error_processing", e); |
|
145 |
} |
|
146 |
jp2Copy = null; |
|
147 |
} */ |
|
148 |
t2 = new Date().getTime(); |
|
149 |
try { |
|
150 |
saveRasterFinalize(oldFileName, (t2 - t1)); |
|
151 |
} catch(ArrayIndexOutOfBoundsException exc) { |
|
152 |
//Si la ventana se ha cerrado ya es porque ha sido cancelada por lo que |
|
153 |
//producir? esta excepci?n. En este caso no se lanza la ventana de informaci?n |
|
154 |
//de finalizaci?n. |
|
155 |
} |
|
156 |
|
|
157 |
} catch(IOException ev) { |
|
158 |
throw new ProcessException("error_processing", ev); |
|
159 |
} catch(OutOfMemoryError ev) { |
|
160 |
throw new ProcessException("memoria_excedida", ev); |
|
161 |
} finally { |
|
162 |
if (incrementableTask != null) { |
|
163 |
incrementableTask.processFinalize(); |
|
164 |
incrementableTask = null; |
|
165 |
} |
|
166 |
} |
|
167 |
} |
|
168 |
|
|
169 |
/** |
|
170 |
* |
|
171 |
* @param name |
|
172 |
* @param at |
|
173 |
* @throws IOException |
|
174 |
* @throws ProcessException |
|
175 |
* @throws InterruptedException |
|
176 |
*/ |
|
177 |
private void write(String name, AffineTransform at, Params writerParams, DataServerWriter rasterizerLayer) throws IOException, ProcessInterruptedException, ProcessException { |
|
178 |
//TODO: Usar el nuevo API basado en NewRasterStoreParameters y DataServerExplorer. Ejemplo en ClippingProcess |
|
179 |
|
|
180 |
TaskEventManager task = rManager.getRasterTask(); |
|
181 |
RasterWriter geoRasterWriter = null; |
|
182 |
try { |
|
183 |
//TODO: FUNCIONALIDAD: Poner los gerWriter con la proyecci?n de la vista |
|
184 |
geoRasterWriter = rManager.createWriter(rasterizerLayer, name, |
|
185 |
3, at, dimension.width, |
|
186 |
dimension.height, Buffer.TYPE_IMAGE, writerParams, null); |
|
187 |
CRSUtils crsUtil = RasterLocator.getManager().getCRSUtils(); |
|
188 |
geoRasterWriter.setWkt(crsUtil.convertIProjectionToWkt(projection)); |
|
189 |
} catch (NotSupportedExtensionException e) { |
|
190 |
throw new ProcessException("extension_no_soportada", e); |
|
191 |
} catch (RasterDriverException e) { |
|
192 |
throw new ProcessException("no_driver_escritura", e); |
|
193 |
} |
|
194 |
|
|
195 |
if(task.getEvent() != null) |
|
196 |
task.manageEvent(task.getEvent()); |
|
197 |
|
|
198 |
geoRasterWriter.setCancellableRasterDriver(new ExternalCancellable(incrementableTask)); |
|
199 |
geoRasterWriter.dataWrite(); |
|
200 |
geoRasterWriter.writeClose(); |
|
201 |
} |
|
202 |
|
|
203 |
/** |
|
204 |
* Obtiene los par?metros del driver de escritura. Si el driver no se ha creado a?n se obtienen |
|
205 |
* unos par?metros con la inicializaci?n por defecto. Si se ha creado ya y se han modificado se |
|
206 |
* devuelven los par?metros con las modificaciones. Si se cambia de driver se devolver? un WriterParams |
|
207 |
* como si fuera la primera vez que se abre. |
|
208 |
* @param name Nombre del fichero sobre el que se salva. |
|
209 |
* @return WriterParams |
|
210 |
*/ |
|
211 |
private Params getWriterParams(String name) throws ProcessException { |
|
212 |
RasterWriter writer = null; |
|
213 |
String ext = rManager.getFileUtils().getExtensionFromFileName(name); |
|
214 |
try { |
|
215 |
if(writer == null) //La primera vez que se obtiene el driver |
|
216 |
writer = rManager.createWriter(name); |
|
217 |
else { |
|
218 |
String newType = rManager.getProviderServices().getWriteDriverType(ext); |
|
219 |
String oldType = writer.getDriverName(); |
|
220 |
if(!newType.equals(oldType)) //Cambio de driver despu?s de haber seleccionado y modificado las propiedades de uno |
|
221 |
writer = rManager.createWriter(name); |
|
222 |
} |
|
223 |
|
|
224 |
if(writer == null) |
|
225 |
throw new ProcessException("no_driver_escritura"); |
|
226 |
|
|
227 |
return writer.getParams(); |
|
228 |
|
|
229 |
} catch (NotSupportedExtensionException e1) { |
|
230 |
throw new ProcessException("no_driver_escritura", e1); |
|
231 |
} catch (RasterDriverException e1) { |
|
232 |
throw new ProcessException("no_driver_escritura", e1); |
|
233 |
} |
|
234 |
} |
|
235 |
|
|
236 |
/** |
|
237 |
* Acciones que se realizan al finalizar de salvar a raster. |
|
238 |
* @param fileName Nombre del fichero |
|
239 |
* @param milis Tiempo que ha tardado en ejecutarse |
|
240 |
*/ |
|
241 |
private void saveRasterFinalize(String fileName, long milis) { |
|
242 |
if (incrementableTask != null) |
|
243 |
incrementableTask.hideWindow(); |
|
244 |
externalActions.end(new Object[]{fileName, new Long(milis)}); |
|
245 |
} |
|
246 |
|
|
247 |
/* |
|
248 |
* (non-Javadoc) |
|
249 |
* @see org.gvsig.gui.beans.incrementabletask.IIncrementable#getPercent() |
|
250 |
*/ |
|
251 |
public int getPercent() { |
|
252 |
if(rasterizerLayer != null) |
|
253 |
return rasterizerLayer.getPercent(); |
|
254 |
return 0; |
|
255 |
} |
|
256 |
|
|
257 |
/* |
|
258 |
* (non-Javadoc) |
|
259 |
* @see org.gvsig.gui.beans.incrementabletask.IIncrementable#getTitle() |
|
260 |
*/ |
|
261 |
public String getTitle() { |
|
262 |
if(rasterizerLayer != null) |
|
263 |
return rasterizerLayer.getTitle(); |
|
264 |
return null; |
|
265 |
} |
|
266 |
|
|
267 |
/* |
|
268 |
* (non-Javadoc) |
|
269 |
* @see org.gvsig.rastertools.RasterProcess#getLog() |
|
270 |
*/ |
|
271 |
public String getLog() { |
|
272 |
if(rasterizerLayer != null) |
|
273 |
return rasterizerLayer.getLog(); |
|
274 |
return null; |
|
275 |
} |
|
276 |
|
|
277 |
/* |
|
278 |
* (non-Javadoc) |
|
279 |
* @see org.gvsig.gui.beans.incrementabletask.IIncrementable#getLabel() |
|
280 |
*/ |
|
281 |
public String getLabel() { |
|
282 |
if(rasterizerLayer != null) |
|
283 |
return rasterizerLayer.getLabel(); |
|
284 |
return null; |
|
285 |
} |
|
286 |
} |
|
0 | 287 |
org.gvsig.raster.tools/tags/tagdate_11102013_11_26/org.gvsig.raster.tools/org.gvsig.raster.tools.algorithm/org.gvsig.raster.tools.algorithm.saveraster/src/main/resources/META-INF/services/org.gvsig.tools.library.Library | ||
---|---|---|
1 |
org.gvsig.raster.tools.algorithm.saveraster.SaveRasterAlgorithmLibrary |
org.gvsig.raster.tools/tags/tagdate_11102013_11_26/org.gvsig.raster.tools/org.gvsig.raster.tools.algorithm/org.gvsig.raster.tools.algorithm.saveraster/pom.xml | ||
---|---|---|
1 |
<?xml version="1.0" encoding="ISO-8859-1"?> |
|
2 |
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> |
|
3 |
<modelVersion>4.0.0</modelVersion> |
|
4 |
<artifactId>org.gvsig.raster.tools.algorithm.saveraster</artifactId> |
|
5 |
<packaging>jar</packaging> |
|
6 |
<name>org.gvsig.raster.tools.algorithm.saveraster</name> |
|
7 |
<parent> |
|
8 |
<groupId>org.gvsig</groupId> |
|
9 |
<artifactId>org.gvsig.raster.tools.algorithm</artifactId> |
|
10 |
<version>2.1.0-SNAPSHOT</version> |
|
11 |
</parent> |
|
12 |
<dependencies> |
|
13 |
<dependency> |
|
14 |
<groupId>org.gvsig</groupId> |
|
15 |
<artifactId>org.gvsig.raster.algorithm</artifactId> |
|
16 |
<scope>compile</scope> |
|
17 |
</dependency> |
|
18 |
<!--Dependencia debido a que este algoritmo rasteriza capas de gvSIG.--> |
|
19 |
<dependency> |
|
20 |
<groupId>org.gvsig</groupId> |
|
21 |
<artifactId>org.gvsig.raster.fmap</artifactId> |
|
22 |
<scope>compile</scope> |
|
23 |
</dependency> |
|
24 |
</dependencies> |
|
25 |
</project> |
|
0 | 26 |
org.gvsig.raster.tools/tags/tagdate_11102013_11_26/org.gvsig.raster.tools/org.gvsig.raster.tools.algorithm/pom.xml | ||
---|---|---|
1 |
<?xml version="1.0" encoding="ISO-8859-1"?> |
|
2 |
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> |
|
3 |
<modelVersion>4.0.0</modelVersion> |
|
4 |
<artifactId>org.gvsig.raster.tools.algorithm</artifactId> |
|
5 |
<packaging>pom</packaging> |
|
6 |
<name>org.gvsig.raster.tools.algorithm</name> |
|
7 |
<parent> |
|
8 |
<groupId>org.gvsig</groupId> |
|
9 |
<artifactId>org.gvsig.raster.tools</artifactId> |
|
10 |
<version>2.1.0-SNAPSHOT</version> |
|
11 |
</parent> |
|
12 |
<dependencies> |
|
13 |
<dependency> |
|
14 |
<groupId>org.gvsig</groupId> |
|
15 |
<artifactId>org.gvsig.raster.lib.api</artifactId> |
|
16 |
<scope>compile</scope> |
|
17 |
</dependency> |
|
18 |
<dependency> |
|
19 |
<groupId>org.gvsig</groupId> |
|
20 |
<artifactId>org.gvsig.raster.lib.impl</artifactId> |
|
21 |
<scope>compile</scope> |
|
22 |
</dependency> |
|
23 |
<dependency> |
|
24 |
<groupId>org.gvsig</groupId> |
|
25 |
<artifactId>org.gvsig.metadata.lib.basic.api</artifactId> |
|
26 |
<scope>compile</scope> |
|
27 |
</dependency> |
|
28 |
<dependency> |
|
29 |
<groupId>org.gvsig</groupId> |
|
30 |
<artifactId>org.gvsig.raster.cache.lib.api</artifactId> |
|
31 |
<scope>compile</scope> |
|
32 |
</dependency> |
|
33 |
<!--<dependency> |
|
34 |
<groupId>org.gvsig</groupId> |
|
35 |
<artifactId>org.gvsig.jproj</artifactId> |
|
36 |
<classifier>${native_classifier}</classifier> |
|
37 |
<type>tar.gz</type> |
|
38 |
<scope>runtime</scope> |
|
39 |
</dependency>--> |
|
40 |
<dependency> |
|
41 |
<groupId>org.gvsig</groupId> |
|
42 |
<artifactId>org.gvsig.tools.lib</artifactId> |
|
43 |
<scope>compile</scope> |
|
44 |
</dependency> |
|
45 |
<dependency> |
|
46 |
<groupId>org.gvsig</groupId> |
|
47 |
<artifactId>org.gvsig.i18n</artifactId> |
|
48 |
<scope>compile</scope> |
|
49 |
</dependency> |
|
50 |
<dependency> |
|
51 |
<groupId>org.gvsig</groupId> |
|
52 |
<artifactId>org.gvsig.ui</artifactId> |
|
53 |
<scope>compile</scope> |
|
54 |
</dependency> |
|
55 |
|
|
56 |
<dependency> |
|
57 |
<groupId>org.gvsig</groupId> |
|
58 |
<artifactId>org.gvsig.projection.api</artifactId> |
|
59 |
<scope>compile</scope> |
|
60 |
</dependency> |
|
61 |
<dependency> |
|
62 |
<groupId>org.gvsig</groupId> |
|
63 |
<artifactId>org.gvsig.projection.cresques.impl</artifactId> |
|
64 |
<scope>runtime</scope> |
|
65 |
</dependency> |
|
66 |
<dependency> |
|
67 |
<groupId>org.gvsig</groupId> |
|
68 |
<artifactId>org.gvsig.compat.api</artifactId> |
|
69 |
<scope>compile</scope> |
|
70 |
</dependency> |
|
71 |
<dependency> |
|
72 |
<groupId>org.gvsig</groupId> |
|
73 |
<artifactId>org.gvsig.compat.se</artifactId> |
|
74 |
<scope>compile</scope> |
|
75 |
</dependency> |
|
76 |
<dependency> |
|
77 |
<groupId>org.gvsig</groupId> |
|
78 |
<artifactId>org.gvsig.fmap.dal.api</artifactId> |
|
79 |
<scope>compile</scope> |
|
80 |
</dependency> |
|
81 |
<dependency> |
|
82 |
<groupId>org.gvsig</groupId> |
|
83 |
<artifactId>org.gvsig.fmap.dal.impl</artifactId> |
|
84 |
<scope>compile</scope> |
|
85 |
</dependency> |
|
86 |
<dependency> |
|
87 |
<groupId>org.gvsig</groupId> |
|
88 |
<artifactId>org.gvsig.fmap.dal.file.lib</artifactId> |
|
89 |
<scope>compile</scope> |
|
90 |
</dependency> |
|
91 |
<dependency> |
|
92 |
<groupId>org.gvsig</groupId> |
|
93 |
<artifactId>org.gvsig.fmap.dal.spi</artifactId> |
|
94 |
<scope>compile</scope> |
|
95 |
</dependency> |
|
96 |
<dependency> |
|
97 |
<groupId>org.gvsig</groupId> |
|
98 |
<artifactId>org.gvsig.fmap.geometry.api</artifactId> |
|
99 |
<scope>compile</scope> |
|
100 |
</dependency> |
|
101 |
<dependency> |
|
102 |
<groupId>org.gvsig</groupId> |
|
103 |
<artifactId>org.gvsig.fmap.geometry.impl</artifactId> |
|
104 |
<scope>runtime</scope> |
|
105 |
</dependency> |
|
106 |
<dependency> |
|
107 |
<groupId>org.gvsig</groupId> |
|
108 |
<artifactId>org.gvsig.fmap.geometry.operation</artifactId> |
|
109 |
<scope>runtime</scope> |
|
110 |
</dependency> |
|
111 |
</dependencies> |
|
112 |
<modules> |
|
113 |
<module>org.gvsig.raster.tools.algorithm.swing</module> |
|
114 |
<module>org.gvsig.raster.tools.algorithm.maskthreshold</module> |
|
115 |
<module>org.gvsig.raster.tools.algorithm.layerdatatype</module> |
|
116 |
<module>org.gvsig.raster.tools.algorithm.saveraster</module> |
|
117 |
<!--<module>org.gvsig.raster.tools.algorithm.clip</module>--> |
|
118 |
</modules> |
|
119 |
</project> |
|
0 | 120 |
org.gvsig.raster.tools/tags/tagdate_11102013_11_26/org.gvsig.raster.tools/org.gvsig.raster.tools.algorithm/org.gvsig.raster.tools.algorithm.clip/src/main/java/org/gvsig/raster/tools/algorithm/clip/ClipAlgorithmLibrary.java | ||
---|---|---|
1 |
/* |
|
2 |
* gvSIG. Desktop Geographic Information System. |
|
3 |
* |
|
4 |
* Copyright (C) 2007-2012 gvSIG Association. |
|
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 |
* For any additional information, do not hesitate to contact us |
|
22 |
* at info AT gvsig.com, or visit our website www.gvsig.com. |
|
23 |
*/ |
|
24 |
package org.gvsig.raster.tools.algorithm.clip; |
|
25 |
|
|
26 |
import org.gvsig.i18n.Messages; |
|
27 |
import org.gvsig.raster.algorithm.RasterBaseAlgorithmLibrary; |
|
28 |
import org.gvsig.tools.library.AbstractLibrary; |
|
29 |
import org.gvsig.tools.library.LibraryException; |
|
30 |
|
|
31 |
/** |
|
32 |
* Initialization of ClipAlgorithmLibrary library. |
|
33 |
* |
|
34 |
* @author <a href="mailto:nachobrodin@gmail.com">Nacho Brodin</a> |
|
35 |
*/ |
|
36 |
public class ClipAlgorithmLibrary extends AbstractLibrary { |
|
37 |
public static final String PROCESS_LABEL = "ClipProcess"; |
|
38 |
|
|
39 |
@Override |
|
40 |
protected void doInitialize() throws LibraryException { |
|
41 |
// Nothing to do |
|
42 |
} |
|
43 |
|
|
44 |
@Override |
|
45 |
public void doPostInitialize() throws LibraryException { |
|
46 |
//Registers the process and its parameters |
|
47 |
RasterBaseAlgorithmLibrary.register(PROCESS_LABEL, ClipProcess.class); |
|
48 |
ClipProcess.registerParameters(); |
|
49 |
|
|
50 |
Messages.addResourceFamily( |
|
51 |
"org.gvsig.raster.tools.algorithm.clip", |
|
52 |
ClipAlgorithmLibrary.class.getClassLoader(), |
|
53 |
ClipAlgorithmLibrary.class.getClass().getName()); |
|
54 |
//registerGeoProcess(new ClipAlgorithmLibrary()); |
|
55 |
} |
|
56 |
} |
|
0 | 57 |
org.gvsig.raster.tools/tags/tagdate_11102013_11_26/org.gvsig.raster.tools/org.gvsig.raster.tools.algorithm/org.gvsig.raster.tools.algorithm.clip/src/main/java/org/gvsig/raster/tools/algorithm/clip/ClipException.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.algorithm.clip; |
|
23 |
|
|
24 |
import org.gvsig.raster.algorithm.process.ProcessException; |
|
25 |
|
|
26 |
|
|
27 |
/** |
|
28 |
* This exception is thrown if happen problems processing data with this algorithm. |
|
29 |
* |
|
30 |
* @author Nacho Brodin (nachobrodin@gmail.com) |
|
31 |
* |
|
32 |
*/ |
|
33 |
public class ClipException extends ProcessException { |
|
34 |
private static final long serialVersionUID = -3022090543908771484L; |
|
35 |
|
|
36 |
public ClipException(String msg){ |
|
37 |
super(msg); |
|
38 |
} |
|
39 |
|
|
40 |
public ClipException(String msg, Throwable e){ |
|
41 |
super(msg, e); |
|
42 |
} |
|
43 |
} |
|
0 | 44 |
org.gvsig.raster.tools/tags/tagdate_11102013_11_26/org.gvsig.raster.tools/org.gvsig.raster.tools.algorithm/org.gvsig.raster.tools.algorithm.clip/src/main/java/org/gvsig/raster/tools/algorithm/clip/ClipProcess.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.algorithm.clip; |
|
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 |
|
|
30 |
import org.gvsig.fmap.dal.DALLocator; |
|
31 |
import org.gvsig.fmap.dal.DataManager; |
|
32 |
import org.gvsig.fmap.dal.DataServerExplorer; |
|
33 |
import org.gvsig.fmap.dal.DataServerExplorerParameters; |
|
34 |
import org.gvsig.fmap.dal.coverage.RasterLibrary; |
|
35 |
import org.gvsig.fmap.dal.coverage.RasterLocator; |
|
36 |
import org.gvsig.fmap.dal.coverage.RasterManager; |
|
37 |
import org.gvsig.fmap.dal.coverage.dataset.Buffer; |
|
38 |
import org.gvsig.fmap.dal.coverage.datastruct.Extent; |
|
39 |
import org.gvsig.fmap.dal.coverage.datastruct.NoData; |
|
40 |
import org.gvsig.fmap.dal.coverage.datastruct.Params; |
|
41 |
import org.gvsig.fmap.dal.coverage.exception.InvalidSetViewException; |
|
42 |
import org.gvsig.fmap.dal.coverage.exception.NotSupportedExtensionException; |
|
43 |
import org.gvsig.fmap.dal.coverage.exception.ProcessInterruptedException; |
|
44 |
import org.gvsig.fmap.dal.coverage.exception.RasterDriverException; |
|
45 |
import org.gvsig.fmap.dal.coverage.exception.RmfSerializerException; |
|
46 |
import org.gvsig.fmap.dal.coverage.process.BaseIncrementableTask; |
|
47 |
import org.gvsig.fmap.dal.coverage.store.DataServerWriter; |
|
48 |
import org.gvsig.fmap.dal.coverage.store.RasterDataStore; |
|
49 |
import org.gvsig.fmap.dal.coverage.store.RasterQuery; |
|
50 |
import org.gvsig.fmap.dal.coverage.store.parameter.NewRasterStoreParameters; |
|
51 |
import org.gvsig.fmap.dal.coverage.store.parameter.RemoteStoreParameters; |
|
52 |
import org.gvsig.fmap.dal.coverage.store.props.ColorInterpretation; |
|
53 |
import org.gvsig.fmap.dal.coverage.store.props.ColorTable; |
|
54 |
import org.gvsig.fmap.dal.coverage.util.RasterUtils; |
|
55 |
import org.gvsig.fmap.dal.exception.CloseException; |
|
56 |
import org.gvsig.fmap.dal.exception.DataException; |
|
57 |
import org.gvsig.fmap.dal.exception.InitializeException; |
|
58 |
import org.gvsig.fmap.dal.exception.ProviderNotRegisteredException; |
|
59 |
import org.gvsig.fmap.dal.exception.ValidateDataParametersException; |
|
60 |
import org.gvsig.i18n.Messages; |
|
61 |
import org.gvsig.raster.algorithm.RasterBaseAlgorithmLibrary; |
|
62 |
import org.gvsig.raster.algorithm.process.RasterProcess; |
|
63 |
import org.gvsig.raster.fmap.layers.FLyrRaster; |
|
64 |
import org.gvsig.raster.fmap.roi.VectorialROI; |
|
65 |
|
|
66 |
/** |
|
67 |
* <code>ClippingProcess</code> es un proceso que usa un <code>Thread</code> |
|
68 |
* para aplicar un recorte a una capa y guardarlo en disco. Muestra una barra |
|
69 |
* de incremento informativa. |
|
70 |
* |
|
71 |
* @version 24/04/2007 |
|
72 |
* @author BorSanZa - Borja S?nchez Zamorano |
|
73 |
*/ |
|
74 |
public class ClipProcess extends RasterProcess { |
|
75 |
public static String LAYER = "Layer"; |
|
76 |
public static String PATH = "Path"; |
|
77 |
public static String FILENAME = "filename"; |
|
78 |
public static String TIME = "Time"; |
|
79 |
|
|
80 |
public static String SUFFIX = "suffix"; |
|
81 |
public static String PX_COORDS = "pixelcoordinates"; |
|
82 |
public static String WORLD_COORDS = "realcoordinates"; |
|
83 |
public static String DRAW_BANDS = "drawablebands"; |
|
84 |
public static String ONE_BY_BAND = "onelayerperband"; |
|
85 |
public static String INTERP_METHOD = "interpolationmethod"; |
|
86 |
public static String AT = "affinetransform"; |
|
87 |
public static String COLOR_INTERP = "colorInterpretation"; |
|
88 |
public static String SELECTED_ROIS = "selectedrois"; |
|
89 |
public static String RESOLUTION = "resolution"; |
|
90 |
public static String DRIVER_PARAMS = "driverparams"; |
|
91 |
|
|
92 |
private String fileName = ""; |
|
93 |
private String suffix = ".tif"; |
|
94 |
private FLyrRaster rasterSE = null; |
|
95 |
private boolean oneLayerPerBand = false; |
|
96 |
private int[] drawableBands = { 0, 1, 2 }; |
|
97 |
private double[] pValues = null; |
|
98 |
private int interpolationMethod = Buffer.INTERPOLATION_Undefined; |
|
99 |
private Params params = null; |
|
100 |
private ColorInterpretation colorInterp = null; |
|
101 |
private ArrayList<VectorialROI> selectedRois = null; |
|
102 |
private AffineTransform affineTransform = null; |
|
103 |
private double[] wcValues = null; |
|
104 |
private RasterManager rManager = RasterLocator.getManager(); |
|
105 |
private BaseIncrementableTask processIncrement = null; |
|
106 |
|
|
107 |
/** |
|
108 |
* Variables de la resoluci?n de salida |
|
109 |
*/ |
|
110 |
private int resolutionWidth = 0; |
|
111 |
private int resolutionHeight = 0; |
|
112 |
|
|
113 |
private Buffer buffer = null; |
|
114 |
|
|
115 |
/** |
|
116 |
* Par?metros obligatorios al proceso: |
|
117 |
* <UL> |
|
118 |
* <LI>filename: Nombre del fichero de salida</LI> |
|
119 |
* <LI>datawriter: Escritor de datos</LI> |
|
120 |
* <LI>viewname: Nombre de la vista sobre la que se carga la capa al acabar el proceso</LI> |
|
121 |
* <LI>pixelcoordinates: Coordenadas pixel del recorte (ulx, uly, lrx, lry)</LI> |
|
122 |
* <LI>layer: Capa de entrada para el recorte</LI> |
|
123 |
* <LI>drawablebands: Bandas de entrada</LI> |
|
124 |
* <LI>onelayerperband: booleano que informa de si escribimos una banda por fichero de salida o todas en un fichero</LI> |
|
125 |
* <LI>interpolationmethod: M?todo de interpolaci?n.</LI> |
|
126 |
* <LI>affinetransform: Transformaci?n que informa al dataset de salida de su referencia geografica</LI> |
|
127 |
* <LI>resolution: Ancho y alto de la capa de salida</LI> |
|
128 |
* </UL> |
|
129 |
*/ |
|
130 |
@SuppressWarnings("unchecked") |
|
131 |
public void init() { |
|
132 |
fileName = getStringParam(FILENAME); |
|
133 |
suffix = getStringParam(SUFFIX); |
|
134 |
pValues = getDoubleArrayParam(PX_COORDS); |
|
135 |
wcValues = getDoubleArrayParam(WORLD_COORDS); |
|
136 |
rasterSE = getParam(LAYER) != null ? (FLyrRaster) getParam(LAYER) : null; |
|
137 |
drawableBands = getIntArrayParam(DRAW_BANDS); |
|
138 |
oneLayerPerBand = getBooleanParam(ONE_BY_BAND); |
|
139 |
interpolationMethod = getIntParam(INTERP_METHOD); |
|
140 |
affineTransform = (AffineTransform)getParam(AT); |
|
141 |
colorInterp = (ColorInterpretation)getParam(COLOR_INTERP); |
|
142 |
selectedRois = (ArrayList<VectorialROI>)getParam(SELECTED_ROIS); |
|
143 |
if(getIntArrayParam(RESOLUTION) != null) { |
|
144 |
resolutionWidth = getIntArrayParam(RESOLUTION)[0]; |
|
145 |
resolutionHeight = getIntArrayParam(RESOLUTION)[1]; |
|
146 |
} |
|
147 |
params = (Params) getParam(DRIVER_PARAMS); |
|
148 |
} |
|
149 |
|
|
150 |
public static void registerParameters() { |
|
151 |
LAYER = RasterBaseAlgorithmLibrary.registerInputParameter(LAYER, FLyrRaster.class); |
|
152 |
SUFFIX = RasterBaseAlgorithmLibrary.registerInputParameter(SUFFIX, String.class); |
|
153 |
PX_COORDS = RasterBaseAlgorithmLibrary.registerInputParameter(PX_COORDS, double[].class); |
|
154 |
WORLD_COORDS = RasterBaseAlgorithmLibrary.registerInputParameter(WORLD_COORDS, double[].class); |
|
155 |
DRAW_BANDS = RasterBaseAlgorithmLibrary.registerInputParameter(DRAW_BANDS, int[].class); |
|
156 |
ONE_BY_BAND = RasterBaseAlgorithmLibrary.registerInputParameter(ONE_BY_BAND, Boolean.class); |
|
157 |
INTERP_METHOD = RasterBaseAlgorithmLibrary.registerInputParameter(INTERP_METHOD, Integer.class); |
|
158 |
AT = RasterBaseAlgorithmLibrary.registerInputParameter(AT, AffineTransform.class); |
|
159 |
COLOR_INTERP = RasterBaseAlgorithmLibrary.registerInputParameter(COLOR_INTERP, ColorInterpretation.class); |
|
160 |
SELECTED_ROIS = RasterBaseAlgorithmLibrary.registerInputParameter(SELECTED_ROIS, ArrayList.class); |
|
161 |
RESOLUTION = RasterBaseAlgorithmLibrary.registerInputParameter(RESOLUTION, int[].class); |
|
162 |
DRIVER_PARAMS = RasterBaseAlgorithmLibrary.registerOutputParameter(DRIVER_PARAMS, Params.class); |
|
163 |
|
|
164 |
PATH = RasterBaseAlgorithmLibrary.registerInputParameter(PATH, String.class); |
|
165 |
FILENAME = RasterBaseAlgorithmLibrary.registerOutputParameter(FILENAME, String.class); |
|
166 |
TIME = RasterBaseAlgorithmLibrary.registerOutputParameter(TIME, Long.class); |
|
167 |
} |
|
168 |
|
|
169 |
/** |
|
170 |
* Salva la tabla de color al fichero rmf. |
|
171 |
* @param fName |
|
172 |
* @throws ClipException |
|
173 |
* @throws IOException |
|
174 |
*/ |
|
175 |
private void saveToRmf(String fileName) throws ClipException { |
|
176 |
RasterDataStore rds = null; |
|
177 |
int limitNumberOfRequests = 20; |
|
178 |
while (rds == null && limitNumberOfRequests > 0) { |
|
179 |
try { |
|
180 |
rds = rasterSE.getDataStore(); |
|
181 |
} catch (IndexOutOfBoundsException e) { |
|
182 |
//En ocasiones, sobre todo con servicios remotos al pedir un datasource da una excepci?n de este tipo |
|
183 |
//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 |
|
184 |
//gestionar pilla a la capa sin datasources asociados ya que est? reasignandolo. Si volvemos a pedirlo debe |
|
185 |
//haberlo cargado ya. |
|
186 |
try { |
|
187 |
Thread.sleep(200); |
|
188 |
} catch (InterruptedException e1) { |
|
189 |
} |
|
190 |
} |
|
191 |
limitNumberOfRequests--; |
|
192 |
} |
|
193 |
|
|
194 |
if (rds == null) { |
|
195 |
//RasterToolsUtil.messageBoxError("error_load_layer", this, new Exception("Error writing RMF. limitNumberOfRequests=" + limitNumberOfRequests)); |
|
196 |
return; |
|
197 |
} |
|
198 |
|
|
199 |
// Guardamos en el RMF el valor NoData |
|
200 |
if(rasterSE.getNoDataValue() != null) { |
|
201 |
NoData nodata = (NoData)rasterSE.getNoDataValue(); |
|
202 |
nodata.setFileName(fileName); |
|
203 |
nodata.save(); |
|
204 |
} |
|
205 |
|
|
206 |
// Guardamos en el RMF la tabla de color |
|
207 |
ColorTable colorTable = rasterSE.getRender().getColorTable(); |
|
208 |
try { |
|
209 |
rManager.getProviderServices().saveObjectToRmfFile(fileName, ColorTable.class, colorTable); |
|
210 |
} catch (RmfSerializerException e) { |
|
211 |
throw new ClipException("error_salvando_rmf", e); |
|
212 |
} |
|
213 |
} |
|
214 |
|
|
215 |
/** |
|
216 |
* Tarea de recorte |
|
217 |
* @throws ClipException |
|
218 |
*/ |
|
219 |
@SuppressWarnings("deprecation") |
|
220 |
public void process() throws ProcessInterruptedException, ClipException { |
|
221 |
RasterDataStore dstoreCopy = null; |
|
222 |
RasterUtils util = RasterLocator.getManager().getRasterUtils(); |
|
223 |
|
|
224 |
try { |
|
225 |
long t2; |
|
226 |
long t1 = new java.util.Date().getTime(); |
|
227 |
|
|
228 |
try { |
|
229 |
Thread.sleep(1000); |
|
230 |
} catch (InterruptedException e1) { |
|
231 |
e1.printStackTrace(); |
|
232 |
} |
|
233 |
|
|
234 |
insertLineLog(Messages.getText("leyendo_raster")); |
|
235 |
|
|
236 |
dstoreCopy = rasterSE.getDataStore().newDataStore(); |
|
237 |
RasterQuery query = rManager.createQuery(); |
|
238 |
query.setDrawableBands(drawableBands); |
|
239 |
|
|
240 |
if(dstoreCopy.getParameters() instanceof RemoteStoreParameters && |
|
241 |
!((RemoteStoreParameters)dstoreCopy.getParameters()).isSizeFixed()) { |
|
242 |
insertLineLog(Messages.getText("downloading_image")); |
|
243 |
((RemoteStoreParameters)dstoreCopy.getParameters()).setWidth(resolutionWidth); |
|
244 |
((RemoteStoreParameters)dstoreCopy.getParameters()).setHeight(resolutionHeight); |
|
245 |
Extent bbox = RasterLocator.getManager().getDataStructFactory().createExtent(wcValues[0], wcValues[1], wcValues[2], wcValues[3]); |
|
246 |
query.setAreaOfInterest(bbox, resolutionWidth, resolutionHeight); |
|
247 |
try { |
|
248 |
buffer = dstoreCopy.query(query); |
|
249 |
} catch (InvalidSetViewException e) { |
|
250 |
throw new ClipException("No se ha podido asignar la vista al inicial el proceso de recorte.", e); |
|
251 |
} |
|
252 |
} else { |
|
253 |
if(interpolationMethod != Buffer.INTERPOLATION_Undefined) { |
|
254 |
try { |
|
255 |
if(pValues != null) { |
|
256 |
if (util.isBufferTooBig(new double[] { pValues[0], pValues[3], pValues[2], pValues[1] }, drawableBands.length)) |
|
257 |
query.setReadOnly(true); |
|
258 |
query.setAreaOfInterest((int)pValues[0], (int)pValues[1], (int)Math.abs(pValues[2] - pValues[0]) + 1, (int)Math.abs(pValues[3] - pValues[1]) + 1); |
|
259 |
} else if(wcValues != null) { |
|
260 |
query.setReadOnly(true); |
|
261 |
query.setAreaOfInterest(wcValues[0], wcValues[1], Math.abs(wcValues[0] - wcValues[2]), Math.abs(wcValues[1] - wcValues[3])); |
|
262 |
} |
|
263 |
buffer = dstoreCopy.query(query); |
|
264 |
} catch (InvalidSetViewException e) { |
|
265 |
throw new ClipException("No se ha podido asignar la vista al inicial el proceso de recorte.", e); |
|
266 |
} |
|
267 |
|
|
268 |
insertLineLog(Messages.getText("interpolando")); |
|
269 |
|
|
270 |
Buffer bufTmp = buffer; |
|
271 |
processIncrement = bufTmp.getIncrementableTask(Buffer.INCREMENTABLE_INTERPOLATION); |
|
272 |
buffer = bufTmp.getAdjustedWindow(resolutionWidth, resolutionHeight, interpolationMethod); |
|
273 |
if(bufTmp != buffer) |
|
274 |
bufTmp.dispose(); |
|
275 |
} else { |
|
276 |
try { |
|
277 |
if (util.isBufferTooBig(new double[] { 0, 0, resolutionWidth, resolutionHeight }, drawableBands.length)) |
|
278 |
query.setReadOnly(true); |
|
279 |
if(pValues != null) |
|
280 |
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); |
|
281 |
else if(wcValues != null) { |
|
282 |
Extent bbox = RasterLocator.getManager().getDataStructFactory().createExtent(wcValues[0], wcValues[1], wcValues[2], wcValues[3]); |
|
283 |
query.setAreaOfInterest(bbox, resolutionWidth, resolutionHeight); |
|
284 |
} |
|
285 |
buffer = dstoreCopy.query(query); |
|
286 |
} catch (InvalidSetViewException e) { |
|
287 |
throw new ClipException("No se ha podido asignar la vista al inicial el proceso de recorte.", e); |
|
288 |
} |
|
289 |
} |
|
290 |
} |
|
291 |
|
|
292 |
//TODO: FUNCIONALIDAD: Poner los getWriter con la proyecci?n del fichero fuente |
|
293 |
|
|
294 |
if ((selectedRois != null) && (!query.isReadOnly())){ |
|
295 |
if (selectedRois.size() > 0){ |
|
296 |
int despX = 0; |
|
297 |
int despY = 0; |
|
298 |
if (pValues != null){ |
|
299 |
despX = (int)pValues[0]; |
|
300 |
despY = (int)pValues[1]; |
|
301 |
} else if (wcValues != null){ |
|
302 |
despX = (int)dstoreCopy.worldToRaster(new Point2D.Double(wcValues[0], wcValues[1])).getX(); |
|
303 |
despY = (int)dstoreCopy.worldToRaster(new Point2D.Double(wcValues[0], wcValues[1])).getY(); |
|
304 |
} |
|
305 |
drawOnlyROIs(buffer, selectedRois, despX, despY); |
|
306 |
} |
|
307 |
} |
|
308 |
|
|
309 |
|
|
310 |
insertLineLog(Messages.getText("salvando_imagen")); |
|
311 |
|
|
312 |
DataManager manager = DALLocator.getDataManager(); |
|
313 |
String provider = "Gdal Store"; |
|
314 |
DataServerExplorerParameters eparams = manager.createServerExplorerParameters("FilesystemExplorer"); |
|
315 |
|
|
316 |
String finalFileName = ""; |
|
317 |
NewRasterStoreParameters sparams = null; |
|
318 |
processIncrement = RasterLocator.getManager().createDataServerWriter(); |
|
319 |
if (oneLayerPerBand) { |
|
320 |
long[] milis = new long[drawableBands.length]; |
|
321 |
String[] fileNames = new String[drawableBands.length]; |
|
322 |
for (int i = 0; i < drawableBands.length; i++) { |
|
323 |
fileNames[i] = fileName + "_B" + drawableBands[i] + suffix; |
|
324 |
|
|
325 |
int index = fileNames[i].lastIndexOf(File.separator); |
|
326 |
if(index < 0) |
|
327 |
index = fileNames[i].length(); |
|
328 |
String path = fileNames[i].substring(0, index); |
|
329 |
String file = fileNames[i].substring(index + 1, fileNames[i].length()); |
|
330 |
|
|
331 |
eparams.setDynValue("initialpath", path); |
|
332 |
DataServerExplorer serverExplorer = manager.openServerExplorer(eparams.getExplorerName(), eparams); |
|
333 |
|
|
334 |
sparams = (NewRasterStoreParameters)serverExplorer.getAddParameters(provider); |
|
335 |
sparams.setDataServer((DataServerWriter)processIncrement); |
|
336 |
sparams.setDestination(path, file); |
|
337 |
sparams.setBuffer(buffer); |
|
338 |
sparams.setColorInterpretation(new String[]{ColorInterpretation.GRAY_BAND}); |
|
339 |
sparams.setWktProjection(dstoreCopy.getWktProjection()); |
|
340 |
sparams.setBand(i); |
|
341 |
sparams.setAffineTransform(affineTransform); |
|
342 |
sparams.setDriverParams(params); |
|
343 |
|
|
344 |
serverExplorer.add(provider, sparams, true); |
|
345 |
|
|
346 |
saveToRmf(fileNames[i]); |
|
347 |
t2 = new java.util.Date().getTime(); |
|
348 |
milis[i] = (t2 - t1); |
|
349 |
t1 = new java.util.Date().getTime(); |
|
350 |
} |
|
351 |
if (incrementableTask != null) { |
|
352 |
incrementableTask.processFinalize(); |
|
353 |
incrementableTask = null; |
|
354 |
} |
|
355 |
for (int i = 0; i < drawableBands.length; i++) { |
|
356 |
if (externalActions != null) |
|
357 |
externalActions.end(new Object[] { fileName + "_B" + drawableBands[i] + suffix, new Long(milis[i]) }); |
|
358 |
} |
|
359 |
} else { |
|
360 |
File f = new File(fileName); |
|
361 |
if (f.exists()) { |
|
362 |
f.delete(); |
|
363 |
} |
|
364 |
f = null; |
|
365 |
|
|
366 |
if(suffix != null) |
|
367 |
finalFileName = fileName.endsWith(suffix) ? fileName : fileName + suffix; |
|
368 |
else |
|
369 |
finalFileName = fileName; |
|
370 |
|
|
371 |
int index = finalFileName.lastIndexOf(File.separator); |
|
372 |
if(index < 0) |
|
373 |
index = finalFileName.length(); |
|
374 |
String path = finalFileName.substring(0, index); |
|
375 |
String file = finalFileName.substring(index + 1, finalFileName.length()); |
|
376 |
|
|
377 |
eparams.setDynValue("initialpath", path); |
|
378 |
DataServerExplorer serverExplorer = manager.openServerExplorer(eparams.getExplorerName(), eparams); |
|
379 |
|
|
380 |
try { |
|
381 |
provider = rManager.createWriter(finalFileName).getProviderName(); |
|
382 |
} catch (NotSupportedExtensionException e1) { |
|
383 |
throw new ClipException(Messages.getText("no_driver_escritura")); |
|
384 |
} catch (RasterDriverException e1) { |
|
385 |
throw new ClipException(Messages.getText("no_driver_escritura")); |
|
386 |
} |
|
387 |
|
|
388 |
sparams = (NewRasterStoreParameters)serverExplorer.getAddParameters(provider); |
|
389 |
sparams.setDataServer((DataServerWriter)processIncrement); |
|
390 |
sparams.setDestination(path, file); |
|
391 |
sparams.setBuffer(buffer); |
|
392 |
if(colorInterp != null) |
|
393 |
sparams.setColorInterpretation(colorInterp.getValues()); |
|
394 |
sparams.setWktProjection(dstoreCopy.getWktProjection()); |
|
395 |
sparams.setAffineTransform(affineTransform); |
|
396 |
sparams.setDriverParams(params); |
|
397 |
sparams.setBand(-1); |
|
398 |
|
|
399 |
serverExplorer.add(provider, sparams, true); |
|
400 |
|
|
401 |
saveToRmf(finalFileName); |
|
402 |
|
|
403 |
|
|
404 |
t2 = new java.util.Date().getTime(); |
|
405 |
if (incrementableTask != null) { |
|
406 |
incrementableTask.processFinalize(); |
|
407 |
incrementableTask = null; |
|
408 |
} |
|
409 |
//Damos tiempo a parar el Thread del incrementable para que no se cuelgue la ventana |
|
410 |
//El tiempo es como m?nimo el de un bucle del run de la tarea incrementable |
|
411 |
try { |
|
412 |
Thread.sleep(600); |
|
413 |
} catch (InterruptedException e) { |
|
414 |
throw new ProcessInterruptedException(e); |
|
415 |
} |
|
416 |
if (externalActions != null) |
|
417 |
externalActions.end(new Object[]{fileName, new Long((t2 - t1))}); |
|
418 |
} |
|
419 |
|
|
420 |
} catch (RasterDriverException e) { |
|
421 |
throw new ClipException(Messages.getText("error_writer")); |
|
422 |
} catch (ValidateDataParametersException e) { |
|
423 |
throw new ClipException(Messages.getText("error_georasterwriter")); |
|
424 |
} catch (ProviderNotRegisteredException e) { |
|
425 |
throw new ClipException(Messages.getText("error_georasterwriter")); |
|
426 |
} catch (InitializeException e) { |
|
427 |
throw new ClipException(Messages.getText("error_georasterwriter")); |
|
428 |
} catch (DataException e) { |
|
429 |
throw new ClipException(Messages.getText("error_georasterwriter")); |
|
430 |
} catch (Exception e) { |
|
431 |
e.printStackTrace(); |
|
432 |
} finally { |
|
433 |
if (dstoreCopy != null) |
|
434 |
try { |
|
435 |
dstoreCopy.close(); |
|
436 |
} catch (CloseException e) { |
Also available in: Unified diff