svn-gvsig-desktop / trunk / extensions / extRasterTools-SE / src / org / gvsig / rastertools / saveraster / operations / SaveRasterProcess.java @ 18277
History | View | Annotate | Download (5.29 KB)
1 | 11283 | nacho | /* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
|
---|---|---|---|
2 | *
|
||
3 | * Copyright (C) 2007 IVER T.I. and Generalitat Valenciana.
|
||
4 | *
|
||
5 | * This program is free software; you can redistribute it and/or
|
||
6 | * modify it under the terms of the GNU General Public License
|
||
7 | * as published by the Free Software Foundation; either version 2
|
||
8 | * of the License, or (at your option) any later version.
|
||
9 | *
|
||
10 | * This program is distributed in the hope that it will be useful,
|
||
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||
13 | * GNU General Public License for more details.
|
||
14 | *
|
||
15 | * You should have received a copy of the GNU General Public License
|
||
16 | * along with this program; if not, write to the Free Software
|
||
17 | * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,USA.
|
||
18 | */
|
||
19 | package org.gvsig.rastertools.saveraster.operations; |
||
20 | |||
21 | import java.awt.Component; |
||
22 | import java.awt.Dimension; |
||
23 | 12793 | nacho | import java.awt.geom.AffineTransform; |
24 | 11283 | nacho | import java.io.IOException; |
25 | 17721 | bsanchez | import java.util.Date; |
26 | 11283 | nacho | |
27 | import javax.swing.JOptionPane; |
||
28 | |||
29 | import org.gvsig.raster.dataset.GeoRasterWriter; |
||
30 | 12496 | nacho | import org.gvsig.raster.dataset.IBuffer; |
31 | 11283 | nacho | import org.gvsig.raster.dataset.IDataWriter; |
32 | import org.gvsig.raster.dataset.NotSupportedExtensionException; |
||
33 | 11653 | bsanchez | import org.gvsig.raster.dataset.Params; |
34 | 16591 | nbrodin | import org.gvsig.raster.dataset.io.RasterDriverException; |
35 | 12383 | nacho | import org.gvsig.raster.datastruct.Extent; |
36 | import org.gvsig.raster.datastruct.ViewPortData; |
||
37 | 17721 | bsanchez | import org.gvsig.rastertools.RasterProcess; |
38 | 11283 | nacho | |
39 | import com.iver.andami.PluginServices; |
||
40 | import com.iver.cit.gvsig.fmap.ViewPort; |
||
41 | /**
|
||
42 | 15782 | bsanchez | * Thread que se encarga de llamar a los writer para realizar la tarea de
|
43 | * salvado y/p compresi?n
|
||
44 | 15929 | bsanchez | *
|
45 | 15782 | bsanchez | * @author Nacho Brodin (nachobrodin@gmail.com)
|
46 | 11283 | nacho | */
|
47 | 17721 | bsanchez | public class SaveRasterProcess extends RasterProcess { |
48 | private ViewPort viewPort = null; |
||
49 | 15782 | bsanchez | private Dimension dimension = null; |
50 | 17721 | bsanchez | private RasterizerLayer rasterizerLayer = null; |
51 | private String fileName = ""; |
||
52 | private Params writerParams = null; |
||
53 | 15929 | bsanchez | |
54 | 17721 | bsanchez | /*
|
55 | * (non-Javadoc)
|
||
56 | * @see org.gvsig.rastertools.RasterProcess#init()
|
||
57 | 15929 | bsanchez | */
|
58 | 17721 | bsanchez | public void init() { |
59 | viewPort = (ViewPort) getParam("viewport");
|
||
60 | dimension = (Dimension) getParam("dimension"); |
||
61 | rasterizerLayer = (RasterizerLayer) getParam("rasterizerlayer");
|
||
62 | fileName = getStringParam("filename");
|
||
63 | writerParams = (Params) getParam("writerparams");
|
||
64 | 11307 | nacho | } |
65 | 15929 | bsanchez | |
66 | 11307 | nacho | /**
|
67 | 17857 | nbrodin | * Procesos de escritura de una porci?n de la vista.
|
68 | 11307 | nacho | */
|
69 | 17721 | bsanchez | public void process() throws InterruptedException { |
70 | GeoRasterWriter geoRasterWriter = null;
|
||
71 | 11283 | nacho | long t2;
|
72 | 17721 | bsanchez | long t1 = new java.util.Date().getTime(); |
73 | 15929 | bsanchez | |
74 | 11283 | nacho | //Creamos el driver
|
75 | 17721 | bsanchez | Extent ex = new Extent(viewPort.getAdjustedExtent());
|
76 | Dimension imgSz = viewPort.getImageSize();
|
||
77 | ViewPortData vpData = new ViewPortData(viewPort.getProjection(), ex, imgSz );
|
||
78 | 15929 | bsanchez | AffineTransform at = new AffineTransform(vpData.getExtent().width() / imgSz.width, |
79 | 0, 0, |
||
80 | 12793 | nacho | -(vpData.getExtent().height() / imgSz.height), |
81 | vpData.getExtent().getULX(), |
||
82 | vpData.getExtent().getULY()); |
||
83 | 15929 | bsanchez | |
84 | 11283 | nacho | try {
|
85 | 12470 | nacho | //TODO: FUNCIONALIDAD: Poner los gerWriter con la proyecci?n de la vista
|
86 | 17721 | bsanchez | geoRasterWriter = GeoRasterWriter.getWriter((IDataWriter)rasterizerLayer, fileName, |
87 | 15929 | bsanchez | 3, at, dimension.width,
|
88 | 17721 | bsanchez | dimension.height, IBuffer.TYPE_IMAGE, writerParams, null);
|
89 | 11283 | nacho | } catch (NotSupportedExtensionException e) {
|
90 | JOptionPane.showMessageDialog((Component)PluginServices.getMainFrame(), |
||
91 | PluginServices.getText(this, "extension_no_soportada")); |
||
92 | } catch (RasterDriverException e) {
|
||
93 | JOptionPane.showMessageDialog((Component)PluginServices.getMainFrame(), |
||
94 | PluginServices.getText(this, "no_driver_escritura")); |
||
95 | } |
||
96 | 15929 | bsanchez | |
97 | 11283 | nacho | //Ejecutamos el driver con los datos pasados
|
98 | 11307 | nacho | try {
|
99 | 17721 | bsanchez | geoRasterWriter.dataWrite(); |
100 | geoRasterWriter.writeClose(); |
||
101 | t2 = new Date().getTime(); |
||
102 | 13420 | nacho | try {
|
103 | 17721 | bsanchez | saveRasterFinalize(fileName, (t2 - t1)); |
104 | 13420 | nacho | } catch(ArrayIndexOutOfBoundsException exc) { |
105 | //Si la ventana se ha cerrado ya es porque ha sido cancelada por lo que
|
||
106 | //producir? esta excepci?n. En este caso no se lanza la ventana de informaci?n
|
||
107 | //de finalizaci?n.
|
||
108 | } |
||
109 | 11307 | nacho | } catch(IOException ev) { |
110 | 11283 | nacho | return;
|
111 | 15929 | bsanchez | } |
112 | 11283 | nacho | } |
113 | 15929 | bsanchez | |
114 | 13420 | nacho | /**
|
115 | 17721 | bsanchez | * Acciones que se realizan al finalizar de salvar a raster.
|
116 | * @param fileName Nombre del fichero
|
||
117 | * @param milis Tiempo que ha tardado en ejecutarse
|
||
118 | 11283 | nacho | */
|
119 | 17721 | bsanchez | private void saveRasterFinalize(String fileName, long milis) { |
120 | 17857 | nbrodin | if (incrementableTask != null) |
121 | incrementableTask.hideWindow(); |
||
122 | 17721 | bsanchez | externalActions.end(new Object[]{fileName, new Long(milis)}); |
123 | 11283 | nacho | } |
124 | 15929 | bsanchez | |
125 | 17721 | bsanchez | /*
|
126 | * (non-Javadoc)
|
||
127 | * @see org.gvsig.gui.beans.incrementabletask.IIncrementable#getPercent()
|
||
128 | 11283 | nacho | */
|
129 | 17721 | bsanchez | public int getPercent() { |
130 | 17857 | nbrodin | if(rasterizerLayer != null) |
131 | return rasterizerLayer.getPercent();
|
||
132 | 17721 | bsanchez | return 0; |
133 | 11283 | nacho | } |
134 | 15929 | bsanchez | |
135 | 11307 | nacho | /*
|
136 | 17721 | bsanchez | * (non-Javadoc)
|
137 | * @see org.gvsig.gui.beans.incrementabletask.IIncrementable#getTitle()
|
||
138 | 11307 | nacho | */
|
139 | 17721 | bsanchez | public String getTitle() { |
140 | 17857 | nbrodin | if(rasterizerLayer != null) |
141 | return rasterizerLayer.getTitle();
|
||
142 | 17721 | bsanchez | return null; |
143 | 11307 | nacho | } |
144 | 17857 | nbrodin | |
145 | /*
|
||
146 | * (non-Javadoc)
|
||
147 | * @see org.gvsig.rastertools.RasterProcess#getLog()
|
||
148 | */
|
||
149 | public String getLog() { |
||
150 | if(rasterizerLayer != null) |
||
151 | return rasterizerLayer.getLog();
|
||
152 | return null; |
||
153 | } |
||
154 | |||
155 | /*
|
||
156 | * (non-Javadoc)
|
||
157 | * @see org.gvsig.gui.beans.incrementabletask.IIncrementable#getLabel()
|
||
158 | */
|
||
159 | public String getLabel() { |
||
160 | if(rasterizerLayer != null) |
||
161 | return rasterizerLayer.getLabel();
|
||
162 | return null; |
||
163 | } |
||
164 | 15782 | bsanchez | } |