Statistics
| Revision:

svn-gvsig-desktop / trunk / extensions / extRasterTools-SE / src / org / gvsig / rastertools / reproject / ReprojectProcess.java @ 30541

History | View | Annotate | Download (4.06 KB)

1
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
2
*
3
* Copyright (C) 2005 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.reproject;
20

    
21
import java.io.IOException;
22

    
23
import javax.swing.SwingUtilities;
24

    
25
import org.cresques.cts.IProjection;
26
import org.gvsig.fmap.raster.layers.FLyrRasterSE;
27
import org.gvsig.raster.RasterProcess;
28
import org.gvsig.raster.util.RasterToolsUtil;
29
import org.gvsig.raster.util.RasterUtilities;
30

    
31
import com.iver.andami.PluginServices;
32
/**
33
 * Proceso para la generaci?n de capas reproyectadas.
34
 *
35
 * 10/12/2007
36
 * @author Nacho Brodin nachobrodin@gmail.com
37
 */
38
public class ReprojectProcess extends RasterProcess {
39
        private FLyrRasterSE lyr       = null;
40
        private String       filename  = null;
41
        private IProjection  proj      = null;
42
        private IProjection  projsrc   = null;
43
        private Reproject    reproject = null;
44
        private long         milis     = 0;
45
        private Boolean      isInTOC   = null;
46
        
47
        /*
48
         * (non-Javadoc)
49
         * @see org.gvsig.rastertools.RasterProcess#init()
50
         */
51
        public void init() {
52
                lyr = getLayerParam("layer");
53
                filename = getStringParam("path");
54
                proj = (IProjection) getParam("projection");
55
                projsrc = (IProjection) getParam("srcprojection");
56
                isInTOC = (Boolean) getParam("isintoc");
57
                if(lyr.getFileName() != null)
58
                for (int i = 0; i < lyr.getFileName().length; i++) {
59
                        try {
60
                                if(!RasterUtilities.existsWorldFile(lyr.getFileName()[i]))
61
                                        RasterUtilities.createWorldFile(lyr.getFileName()[i], lyr.getAffineTransform(), (int)lyr.getPxWidth(), (int)lyr.getPxHeight());
62
                        } catch (IOException e) {
63
                                RasterToolsUtil.debug("Error creando los worldfile", null, e);
64
                        }        
65
                }
66
        }
67

    
68
        /**
69
         * M?todo donde se ejecutar? el Thread, aqu? se reproyecta el raster.
70
         */
71
        public void process() throws InterruptedException {
72
                long t1 = new java.util.Date().getTime();
73
                insertLineLog(PluginServices.getText(this, "reprojecting"));
74
                reproject = new Reproject(lyr, filename);
75
                try {
76
                        int result = reproject.warp(proj, projsrc);
77
                        if(result != 0) {
78
                                if (incrementableTask != null) {
79
                                        incrementableTask.processFinalize();
80
                                        setProgressActive(false);
81
                                }
82
                                RasterToolsUtil.messageBoxError("transformation_not_possible", this);
83
                                return;
84
                        }
85
                        
86
                        // Si hay que cerrar la capa de origen
87
                        if ((isInTOC != null) && (isInTOC.booleanValue() == false)) {
88
                                lyr.setRemoveRasterFlag(true);
89
                                lyr.removeLayerListener(null);
90
                        }
91

    
92
                        long t2 = new java.util.Date().getTime();
93
                        milis = t2 - t1;
94
                        
95
                        SwingUtilities.invokeLater(new Runnable() {
96
                                public void run() {
97
                                        if (externalActions != null) {
98
                                                externalActions.end(new Object[]{filename, new Long(milis), isInTOC});
99
                                        }
100
                                }
101
                        });
102
                } catch (ReprojectException e) {
103
                        if (incrementableTask != null) {
104
                                incrementableTask.processFinalize();
105
                                setProgressActive(false);
106
                        }
107
                        RasterToolsUtil.messageBoxError(e.getMessage(), this, e);
108
                        return;
109
                }
110
        }
111

    
112
        /*
113
         * (non-Javadoc)
114
         * @see org.gvsig.gui.beans.incrementabletask.IIncrementable#getPercent()
115
         */
116
        public int getPercent() {
117
                if(reproject != null)
118
                        return reproject.getPercent();
119
                else 
120
                        return 0;
121
        }
122

    
123
        /*
124
         * (non-Javadoc)
125
         * @see org.gvsig.gui.beans.incrementabletask.IIncrementable#getTitle()
126
         */
127
        public String getTitle() {
128
                return PluginServices.getText(this, "reprojecting");
129
        }
130
}