Statistics
| Revision:

gvsig-raster / org.gvsig.raster.reproject / branches / org.gvsig.raster.reproject_dataaccess_refactoring / org.gvsig.raster.reproject.algorithm / src / main / java / org / gvsig / raster / reproject / algorithm / ReprojectProcess.java @ 2308

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

    
24
import org.cresques.cts.IProjection;
25
import org.gvsig.fmap.dal.coverage.exception.ProcessInterruptedException;
26
import org.gvsig.fmap.dal.coverage.store.RasterDataStore;
27
import org.gvsig.i18n.Messages;
28
import org.gvsig.raster.algorithm.process.DataProcess;
29

    
30
/**
31
 * Process to reproject layers. The size of the new image and the pixel size can
32
 * be passed by parameter. If some of these values are zero everyone are calculated
33
 * automatically
34
 *
35
 * 10/12/2007
36
 * @author Nacho Brodin nachobrodin@gmail.com
37
 */
38
public class ReprojectProcess extends DataProcess {
39
        public static String[]    INTERP_METHODS  = new String[]{"Nearest", "Bilinear", "InverseDistance"};
40
        
41
        public static String      RASTER_STORE    = "RasterStore";
42
        public static String      PATH            = "Path";
43
        public static String      DST_PROJECTION  = "DST_Projection";
44
        public static String      SRC_PROJECTION  = "SRC_Projection";
45
        public static String      SIZEX           = "SizeX";
46
        public static String      SIZEY           = "SizeY";
47
        public static String      CELLSIZE        = "CellSize";
48
        public static String      FILENAME        = "FileName";
49
        public static String      INTERPOLATION   = "Interpolation";
50
        
51
        private RasterDataStore   store          = null;
52
        private String            filename       = null;
53
        private IProjection       projdst        = null;
54
        private IProjection       projsrc        = null;
55
        private Reproject         reproject      = null;
56
        private int               w              = 0;
57
        private int               h              = 0;
58
        private double            cellSize       = 0;
59
        private int               interpolation  = 0;
60
        
61
        public static void registerParameters() {
62
                registerInputParameter(RASTER_STORE, RasterDataStore.class, RasterReprojectionAlgorithmLibrary.PROCESS_LABEL);
63
                registerInputParameter(PATH, String.class, RasterReprojectionAlgorithmLibrary.PROCESS_LABEL);
64
                registerInputParameter(DST_PROJECTION, IProjection.class, RasterReprojectionAlgorithmLibrary.PROCESS_LABEL);
65
                registerInputParameter(SRC_PROJECTION, IProjection.class, RasterReprojectionAlgorithmLibrary.PROCESS_LABEL);
66
                registerInputParameter(SIZEX, Integer.class, RasterReprojectionAlgorithmLibrary.PROCESS_LABEL);
67
                registerInputParameter(SIZEY, Integer.class, RasterReprojectionAlgorithmLibrary.PROCESS_LABEL);
68
                registerInputParameter(CELLSIZE, Double.class, RasterReprojectionAlgorithmLibrary.PROCESS_LABEL);
69
                registerInputParameter(INTERPOLATION, Integer.class, RasterReprojectionAlgorithmLibrary.PROCESS_LABEL); 
70
                
71
                registerOutputParameter(FILENAME, String.class, RasterReprojectionAlgorithmLibrary.PROCESS_LABEL);
72
        }
73
        
74
        public void init() {
75
                store = getParam(RASTER_STORE) != null ? (RasterDataStore)getParam(RASTER_STORE) : null;
76
                filename = getStringParam(PATH);
77
                projdst = getParam(DST_PROJECTION) != null ? (IProjection) getParam(DST_PROJECTION) : null;
78
                projsrc = getParam(SRC_PROJECTION) != null ? (IProjection) getParam(SRC_PROJECTION) : null; 
79
                w = getIntParam(SIZEX);
80
                h = getIntParam(SIZEY);
81
                cellSize = getDoubleParam(CELLSIZE);
82
                interpolation = getIntParam(INTERPOLATION);
83
        }
84
        
85
        /**
86
         * M?todo donde se ejecutar? el Thread, aqu? se reproyecta el raster.
87
         */
88
        public void process() throws ProcessInterruptedException {
89
                insertLineLog(Messages.getText("reprojecting"));
90
                
91
                store = store.newNotTiledDataStore();
92
                
93
                reproject = new Reproject(store, filename, interpolation, this);
94
                try {
95
                        int result = reproject.warp(projdst, projsrc, w, h, cellSize);
96
                        if(result != 0) {
97
                                if (incrementableTask != null) {
98
                                        incrementableTask.processFinalize();
99
                                        setProgressActive(false);
100
                                }
101
                                messageBoxError("transformation_not_possible", this);
102
                                return;
103
                        }
104

    
105
                        addOutputValue(FILENAME, filename);
106
                } catch (ReprojectException e) {
107
                        if (incrementableTask != null)
108
                                incrementableTask.processFinalize();
109
                        messageBoxError("error_reprojecting", this, e);
110
                }
111
        }
112
        
113
        public String getTitle() {
114
                return Messages.getText("reprojecting");
115
        }
116
}