Statistics
| Revision:

gvsig-raster / org.gvsig.raster.tools / trunk / org.gvsig.raster.tools / org.gvsig.raster.tools.algorithm / org.gvsig.raster.tools.algorithm.reproject / src / main / java / org / gvsig / raster / tools / algorithm / reproject / ReprojectProcess.java @ 1747

History | View | Annotate | Download (6.37 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.algorithm.reproject;
23

    
24
import java.util.HashMap;
25

    
26
import javax.swing.SwingUtilities;
27

    
28
import org.cresques.cts.IProjection;
29
import org.gvsig.fmap.dal.coverage.exception.CloneException;
30
import org.gvsig.fmap.dal.coverage.exception.ProcessInterruptedException;
31
import org.gvsig.fmap.dal.coverage.store.RasterDataStore;
32
import org.gvsig.i18n.Messages;
33
import org.gvsig.raster.tools.algorithm.base.RasterBaseAlgorithmLibrary;
34
import org.gvsig.raster.tools.algorithm.base.process.RasterProcess;
35

    
36
/**
37
 * Process to reproject layers. The size of the new image and the pixel size can
38
 * be passed by parameter. If some of these values are zero everyone are calculated
39
 * automatically
40
 *
41
 * 10/12/2007
42
 * @author Nacho Brodin nachobrodin@gmail.com
43
 */
44
public class ReprojectProcess extends RasterProcess {
45
        public static String[]    INTERP_METHODS  = new String[]{"Nearest", "Bilinear", "InverseDistance"};
46
        
47
        public static String      RASTER_STORE    = "RasterStore";
48
        public static String      PATH            = "Path";
49
        public static String      DST_PROJECTION  = "DST_Projection";
50
        public static String      SRC_PROJECTION  = "SRC_Projection";
51
        public static String      SIZEX           = "SizeX";
52
        public static String      SIZEY           = "SizeY";
53
        public static String      CELLSIZE        = "CellSize";
54
        public static String      FILENAME        = "FileName";
55
        public static String      TIME            = "Time";
56
        public static String      INTERPOLATION   = "Interpolation";
57
        
58
        private RasterDataStore   store          = null;
59
        private String            filename       = null;
60
        private IProjection       projdst        = null;
61
        private IProjection       projsrc        = null;
62
        private Reproject         reproject      = null;
63
        private long              milis          = 0;
64
        private int               w              = 0;
65
        private int               h              = 0;
66
        private double            cellSize       = 0;
67
        private int               interpolation  = 0;
68
        
69
        public static void registerParameters() {
70
                RASTER_STORE = RasterBaseAlgorithmLibrary.registerInputParameter(RASTER_STORE, RasterDataStore.class);
71
                PATH = RasterBaseAlgorithmLibrary.registerInputParameter(PATH, String.class);
72
                DST_PROJECTION = RasterBaseAlgorithmLibrary.registerInputParameter(DST_PROJECTION, IProjection.class);
73
                SRC_PROJECTION = RasterBaseAlgorithmLibrary.registerInputParameter(SRC_PROJECTION, IProjection.class);
74
                SIZEX = RasterBaseAlgorithmLibrary.registerInputParameter(SIZEX, Integer.class);
75
                SIZEY = RasterBaseAlgorithmLibrary.registerInputParameter(SIZEY, Integer.class);
76
                CELLSIZE = RasterBaseAlgorithmLibrary.registerInputParameter(CELLSIZE, Double.class);
77
                INTERPOLATION = RasterBaseAlgorithmLibrary.registerInputParameter(INTERPOLATION, Integer.class); 
78
                
79
                FILENAME = RasterBaseAlgorithmLibrary.registerOutputParameter(FILENAME, String.class);
80
                TIME = RasterBaseAlgorithmLibrary.registerOutputParameter(TIME, Long.class);
81
        }
82
        
83
        /*
84
         * (non-Javadoc)
85
         * @see org.gvsig.rastertools.RasterProcess#init()
86
         */
87
        public void init() {
88
                store = getParam(RASTER_STORE) != null ? (RasterDataStore)getParam(RASTER_STORE) : null;
89
                filename = getStringParam(PATH);
90
                projdst = getParam(DST_PROJECTION) != null ? (IProjection) getParam(DST_PROJECTION) : null;
91
                projsrc = getParam(SRC_PROJECTION) != null ? (IProjection) getParam(SRC_PROJECTION) : null; 
92
                w = getIntParam(SIZEX);
93
                h = getIntParam(SIZEY);
94
                cellSize = getDoubleParam(CELLSIZE);
95
                interpolation = getIntParam(INTERPOLATION);
96
        }
97
        
98
        /**
99
         * M?todo donde se ejecutar? el Thread, aqu? se reproyecta el raster.
100
         */
101
        public void process() throws ProcessInterruptedException {
102
                long t1 = new java.util.Date().getTime();
103
                insertLineLog(Messages.getText("reprojecting"));
104
                
105
                try {
106
                        store = store.cloneDataStore();
107
                } catch (CloneException e1) {
108
                        messageBoxError("error_reprojecting", this, e1);
109
                }
110
                
111
                reproject = new Reproject(store, filename, interpolation, this);
112
                try {
113
                        int result = reproject.warp(projdst, projsrc, w, h, cellSize);
114
                        if(result != 0) {
115
                                if (incrementableTask != null) {
116
                                        incrementableTask.processFinalize();
117
                                        setProgressActive(false);
118
                                }
119
                                messageBoxError("transformation_not_possible", this);
120
                                return;
121
                        }
122

    
123
                        long t2 = new java.util.Date().getTime();
124
                        milis = t2 - t1;
125
                        
126
                        SwingUtilities.invokeLater(new Runnable() {
127
                                public void run() {
128
                                        if (externalActions != null) {
129
                                                HashMap<String, Object> map = new HashMap<String, Object>();
130
                                                map.put(FILENAME, filename);
131
                                                map.put(TIME, new Long(milis));
132
                                                externalActions.end(map);
133
                                        }
134
                                }
135
                        });
136
                } catch (ReprojectException e) {
137
                        if (incrementableTask != null)
138
                                incrementableTask.processFinalize();
139
                        messageBoxError("error_reprojecting", this, e);
140
                }
141
        }
142
        
143
        /*
144
         * (non-Javadoc)
145
         * @see org.gvsig.raster.tools.app.basic.raster.process.RasterProcess#getResult()
146
         */
147
        public Object getResult() {
148
                HashMap<String, Object> map = new HashMap<String, Object>();
149
                map.put(FILENAME, filename);
150
                map.put(TIME, new Long(milis));
151
                return map;
152
        }
153

    
154
        /*
155
         * (non-Javadoc)
156
         * @see org.gvsig.gui.beans.incrementabletask.IIncrementable#getPercent()
157
         */
158
        public int getPercent() {
159
                if(reproject != null)
160
                        return reproject.getPercent();
161
                else 
162
                        return 0;
163
        }
164

    
165
        /*
166
         * (non-Javadoc)
167
         * @see org.gvsig.gui.beans.incrementabletask.IIncrementable#getTitle()
168
         */
169
        public String getTitle() {
170
                return Messages.getText("reprojecting");
171
        }
172
}